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 isDict() const;
167
173 virtual bool isVocab32() const;
174
180 virtual bool isVocab64() const;
181
187 virtual bool isBlob() const;
188
195 virtual bool asBool() const;
196
206 virtual std::int8_t asInt8() const;
207
217 virtual std::int16_t asInt16() const;
218
228 virtual std::int32_t asInt32() const;
229
239 virtual std::int64_t asInt64() const;
240
250 virtual yarp::conf::float32_t asFloat32() const;
251
261 virtual yarp::conf::float64_t asFloat64() const;
262
267 virtual yarp::conf::vocab32_t asVocab32() const;
268
273 virtual yarp::conf::vocab64_t asVocab64() const;
274
280 virtual std::string asString() const;
281
287 virtual Bottle* asList() const;
288
294 virtual Property* asDict() const;
295
301 virtual Searchable* asSearchable() const;
302
308 virtual const char* asBlob() const;
309
315 virtual size_t asBlobLength() const;
316
317 // documented in Portable
318 bool read(ConnectionReader& connection) override;
319
320 // documented in Portable
321 bool write(ConnectionWriter& connection) const override;
322
323 // documented in Searchable
324 bool check(const std::string& key) const override;
325
326 // documented in Searchable
327 Value& find(const std::string& key) const override;
328
329 // documented in Searchable
330 Bottle& findGroup(const std::string& key) const override;
331
337 bool operator==(const Value& alt) const;
338
344 bool operator!=(const Value& alt) const;
345
352 void fromString(const char* str);
353
354 std::string toString() const override;
355
360 virtual Value* create() const;
361
366 virtual Value* clone() const;
367
372 virtual std::int32_t getCode() const;
373
374 bool isNull() const override;
375
376 virtual bool isLeaf() const;
377
383 static Value* makeInt8(std::int8_t x);
384
390 static Value* makeInt16(std::int16_t x);
391
397 static Value* makeInt32(std::int32_t x);
398
404 static Value* makeInt64(std::int64_t x);
405
411 static Value* makeFloat32(yarp::conf::float32_t x);
412
418 static Value* makeFloat64(yarp::conf::float64_t x);
419
425 static Value* makeString(const std::string& str);
426
432 static Value* makeVocab32(yarp::conf::vocab32_t v);
433
442 static Value* makeVocab32(char a, char b = 0, char c = 0, char d = 0)
443 {
444 return makeVocab32(yarp::os::createVocab32(a, b, c, d));
445 }
446
453 static Value* makeVocab32(const std::string& str)
454 {
455 return makeVocab32(yarp::os::Vocab32::encode(str));
456 }
457
464 static Value* makeBlob(void* data, int length);
465
470 static Value* makeList();
471
477 static Value* makeList(const char* txt);
478
485 static Value* makeValue(const std::string& txt);
486
487
492 static Value& getNullValue();
493
494#ifndef DOXYGEN_SHOULD_SKIP_THIS
495private:
497
499 void ok() const;
500#endif // DOXYGEN_SHOULD_SKIP_THIS
501};
502
503} // namespace yarp::os
504
505#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:65
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 class for storing options and configuration information.
Definition Property.h:33
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:442
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:453
A single item in a Bottle.
Definition Storable.h:44
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