YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
Value.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef YARP_OS_VALUE_H
8#define YARP_OS_VALUE_H
9
10#include <yarp/conf/numeric.h>
11
12#include <yarp/os/Bottle.h>
13#include <yarp/os/Portable.h>
14#include <yarp/os/Searchable.h>
15#include <yarp/os/Vocab32.h>
16#include <yarp/os/Vocab64.h>
17
18#include <cstddef> // defines size_t
19#include <string>
20
21namespace yarp::os {
22class Property;
23} // namespace yarp::os
24
25#ifndef DOXYGEN_SHOULD_SKIP_THIS
26namespace yarp::os::impl {
27class Storable;
28} // namespace yarp::os::impl
29#endif // DOXYGEN_SHOULD_SKIP_THIS
30
31namespace yarp::os {
32
43class YARP_os_API Value : public Portable, public Searchable
44{
45public:
46 using Searchable::check;
47 using Searchable::findGroup;
48
52 explicit Value();
53
60 explicit Value(std::int32_t x, bool isVocab32 = false);
61
66 explicit Value(yarp::conf::float64_t x);
67
74 explicit Value(const std::string& str, bool isVocab32 = false);
75
81 Value(void* data, int length);
82
87 Value(const Value& alt);
88
94 const Value& operator=(const Value& alt);
95
99 ~Value() override;
100
105 virtual bool isBool() const;
106
112 virtual bool isInt8() const;
113
119 virtual bool isInt16() const;
120
126 virtual bool isInt32() const;
127
133 virtual bool isInt64() const;
134
140 virtual bool isFloat32() const;
141
147 virtual bool isFloat64() const;
148
153 virtual bool isString() const;
154
159 virtual bool isList() const;
160
166 virtual bool isVocab32() const;
167
173 virtual bool isVocab64() const;
174
180 virtual bool isBlob() const;
181
188 virtual bool asBool() const;
189
199 virtual std::int8_t asInt8() const;
200
210 virtual std::int16_t asInt16() const;
211
221 virtual std::int32_t asInt32() const;
222
232 virtual std::int64_t asInt64() const;
233
243 virtual yarp::conf::float32_t asFloat32() const;
244
254 virtual yarp::conf::float64_t asFloat64() const;
255
260 virtual yarp::conf::vocab32_t asVocab32() const;
261
266 virtual yarp::conf::vocab64_t asVocab64() const;
267
273 virtual std::string asString() const;
274
280 virtual Bottle* asList() const;
281
287 virtual const char* asBlob() const;
288
294 virtual size_t asBlobLength() const;
295
296 // documented in Portable
297 bool read(ConnectionReader& connection) override;
298
299 // documented in Portable
300 bool write(ConnectionWriter& connection) const override;
301
302 // documented in Searchable
303 bool check(const std::string& key) const override;
304
305 // documented in Searchable
306 Value& find(const std::string& key) const override;
307
308 // documented in Searchable
309 Bottle& findGroup(const std::string& key) const override;
310
316 bool operator==(const Value& alt) const;
317
323 bool operator!=(const Value& alt) const;
324
331 void fromString(const char* str);
332
333 std::string toString() const override;
334
339 virtual Value* create() const;
340
345 virtual Value* clone() const;
346
351 virtual std::int32_t getCode() const;
352
353 bool isNull() const override;
354
355 virtual bool isLeaf() const;
356
362 static Value* makeInt8(std::int8_t x);
363
369 static Value* makeInt16(std::int16_t x);
370
376 static Value* makeInt32(std::int32_t x);
377
383 static Value* makeInt64(std::int64_t x);
384
390 static Value* makeFloat32(yarp::conf::float32_t x);
391
397 static Value* makeFloat64(yarp::conf::float64_t x);
398
404 static Value* makeString(const std::string& str);
405
411 static Value* makeVocab32(yarp::conf::vocab32_t v);
412
421 static Value* makeVocab32(char a, char b = 0, char c = 0, char d = 0)
422 {
423 return makeVocab32(yarp::os::createVocab32(a, b, c, d));
424 }
425
432 static Value* makeVocab32(const std::string& str)
433 {
434 return makeVocab32(yarp::os::Vocab32::encode(str));
435 }
436
443 static Value* makeBlob(void* data, int length);
444
449 static Value* makeList();
450
456 static Value* makeList(const char* txt);
457
464 static Value* makeValue(const std::string& txt);
465
466
471 static Value& getNullValue();
472
473#ifndef DOXYGEN_SHOULD_SKIP_THIS
474private:
476
478 void ok() const;
479#endif // DOXYGEN_SHOULD_SKIP_THIS
480};
481
482} // namespace yarp::os
483
484#endif // YARP_OS_VALUE_H
bool operator==(const struct v4l2_control &left, const struct v4l2_control &right)
Definition CApiMock.h:65
std::string toString(const T &value)
convert an arbitrary type to string.
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
A base class for nested structures that can be searched.
Definition Searchable.h:31
A single value (typically within a Bottle).
Definition Value.h:44
static Value * makeVocab32(char a, char b=0, char c=0, char d=0)
Create a 32 bit vocabulary identifier Value.
Definition Value.h:421
static Value * makeVocab32(const std::string &str)
Create a 32 bit vocabulary identifier Value If the string is longer than 4 characters,...
Definition Value.h:432
A single item in a Bottle.
Definition Storable.h:43
std::int32_t vocab32_t
Definition numeric.h:78
std::int64_t vocab64_t
Definition numeric.h:79
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
Definition Vocab32.cpp:11
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
Definition Vocab32.h:27
#define YARP_os_API
Definition api.h:18