YARP
Yet Another Robot Platform
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/Vocab.h>
16
17#include <cstddef> // defines size_t
18#include <string>
19
20namespace yarp::os {
21class Property;
22} // namespace yarp::os
23
24#ifndef DOXYGEN_SHOULD_SKIP_THIS
25namespace yarp::os::impl {
26class Storable;
27} // namespace yarp::os::impl
28#endif // DOXYGEN_SHOULD_SKIP_THIS
29
30namespace yarp::os {
31
42class YARP_os_API Value : public Portable, public Searchable
43{
44public:
47
51 explicit Value();
52
59 explicit Value(std::int32_t x, bool isVocab32 = false);
60
65 explicit Value(yarp::conf::float64_t x);
66
73 explicit Value(const std::string& str, bool isVocab32 = false);
74
80 Value(void* data, int length);
81
86 Value(const Value& alt);
87
93 const Value& operator=(const Value& alt);
94
98 ~Value() override;
99
104 virtual bool isBool() const;
105
111 virtual bool isInt8() const;
112
118 virtual bool isInt16() const;
119
125 virtual bool isInt32() const;
126
132 virtual bool isInt64() const;
133
139 virtual bool isFloat32() const;
140
146 virtual bool isFloat64() const;
147
152 virtual bool isString() const;
153
158 virtual bool isList() const;
159
165 virtual bool isDict() const;
166
172 virtual bool isVocab32() const;
173
179 virtual bool isBlob() const;
180
187 virtual bool asBool() const;
188
198 virtual std::int8_t asInt8() const;
199
209 virtual std::int16_t asInt16() const;
210
220 virtual std::int32_t asInt32() const;
221
231 virtual std::int64_t asInt64() const;
232
242 virtual yarp::conf::float32_t asFloat32() const;
243
253 virtual yarp::conf::float64_t asFloat64() const;
254
259 virtual yarp::conf::vocab32_t asVocab32() const;
260
266 virtual std::string asString() const;
267
273 virtual Bottle* asList() const;
274
280 virtual Property* asDict() const;
281
287 virtual Searchable* asSearchable() const;
288
294 virtual const char* asBlob() const;
295
301 virtual size_t asBlobLength() const;
302
303 // documented in Portable
304 bool read(ConnectionReader& connection) override;
305
306 // documented in Portable
307 bool write(ConnectionWriter& connection) const override;
308
309 // documented in Searchable
310 bool check(const std::string& key) const override;
311
312 // documented in Searchable
313 Value& find(const std::string& key) const override;
314
315 // documented in Searchable
316 Bottle& findGroup(const std::string& key) const override;
317
323 bool operator==(const Value& alt) const;
324
330 bool operator!=(const Value& alt) const;
331
338 void fromString(const char* str);
339
340 std::string toString() const override;
341
346 virtual Value* create() const;
347
352 virtual Value* clone() const;
353
358 virtual std::int32_t getCode() const;
359
360 bool isNull() const override;
361
362 virtual bool isLeaf() const;
363
369 static Value* makeInt8(std::int8_t x);
370
376 static Value* makeInt16(std::int16_t x);
377
383 static Value* makeInt32(std::int32_t x);
384
390 static Value* makeInt64(std::int64_t x);
391
397 static Value* makeFloat32(yarp::conf::float32_t x);
398
404 static Value* makeFloat64(yarp::conf::float64_t x);
405
411 static Value* makeString(const std::string& str);
412
418 static Value* makeVocab32(yarp::conf::vocab32_t v);
419
428 static Value* makeVocab32(char a, char b = 0, char c = 0, char d = 0)
429 {
430 return makeVocab32(yarp::os::createVocab32(a, b, c, d));
431 }
432
439 static Value* makeVocab32(const std::string& str)
440 {
441 return makeVocab32(yarp::os::Vocab32::encode(str));
442 }
443
450 static Value* makeBlob(void* data, int length);
451
456 static Value* makeList();
457
463 static Value* makeList(const char* txt);
464
471 static Value* makeValue(const std::string& txt);
472
473
478 static Value& getNullValue();
479
480#ifndef DOXYGEN_SHOULD_SKIP_THIS
481private:
483
484 void setProxy(yarp::os::impl::Storable* proxy);
485 void ok() const;
486#endif // DOXYGEN_SHOULD_SKIP_THIS
487};
488
489} // namespace yarp::os
490
491#endif // YARP_OS_VALUE_H
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:64
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:56
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.
A single value (typically within a Bottle).
Definition: Value.h:43
static Value * makeVocab32(char a, char b=0, char c=0, char d=0)
Create a vocabulary identifier Value.
Definition: Value.h:428
static Value * makeVocab32(const std::string &str)
Create a vocabulary identifier Value If the string is longer than 4 characters, only the first 4 are ...
Definition: Value.h:439
A single item in a Bottle.
Definition: Storable.h:42
std::string toString(const T &value)
convert an arbitrary type to string.
std::int32_t vocab32_t
Definition: numeric.h:78
double float64_t
Definition: numeric.h:77
float float32_t
Definition: numeric.h:76
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
Definition: Vocab.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: Vocab.h:27
std::string findGroup(const robotinterface::ParamList &list, const std::string &name)
Definition: Types.cpp:47
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:915
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:1091
#define YARP_os_API
Definition: api.h:18