YARP
Yet Another Robot Platform
Value.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2019 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_VALUE_H
11 #define YARP_OS_VALUE_H
12 
13 #include <yarp/conf/numeric.h>
14 
15 #include <yarp/os/Bottle.h>
16 #include <yarp/os/Portable.h>
17 #include <yarp/os/Searchable.h>
18 
19 #include <cstddef> // defines size_t
20 #include <string>
21 
22 namespace yarp {
23 namespace os {
24 class Property;
25 #ifndef DOXYGEN_SHOULD_SKIP_THIS
26 namespace impl {
27 class Storable;
28 }
29 #endif // DOXYGEN_SHOULD_SKIP_THIS
30 } // namespace os
31 } // namespace yarp
32 
33 namespace yarp {
34 namespace os {
35 
46 class YARP_OS_API Value : public Portable, public Searchable
47 {
48 public:
49  using Searchable::check;
51 
55  explicit Value();
56 
63  explicit Value(std::int32_t x, bool isVocab = false);
64 
69  explicit Value(yarp::conf::float64_t x);
70 
77  explicit Value(const std::string& str, bool isVocab = false);
78 
84  Value(void* data, int length);
85 
90  Value(const Value& alt);
91 
97  const Value& operator=(const Value& alt);
98 
102  virtual ~Value();
103 
108  virtual bool isBool() const;
109 
115  YARP_DEPRECATED_INTERNAL_MSG("Use isInt32 instead") // Since YARP 3.0.0
116  inline virtual bool isInt() const final
117  {
118  return isInt32();
119  }
120 
126  virtual bool isInt8() const;
127 
133  virtual bool isInt16() const;
134 
140  virtual bool isInt32() const;
141 
147  virtual bool isInt64() const;
148 
155  YARP_DEPRECATED_INTERNAL_MSG("Use isFloat64 instead") // Since YARP 3.0.0
156  inline virtual bool isDouble() const final
157  {
158  return isFloat64();
159  }
160 
166  virtual bool isFloat32() const;
167 
173  virtual bool isFloat64() const;
174 
179  virtual bool isString() const;
180 
185  virtual bool isList() const;
186 
192  virtual bool isDict() const;
193 
199  virtual bool isVocab() const;
200 
206  virtual bool isBlob() const;
207 
214  virtual bool asBool() const;
215 
223  YARP_DEPRECATED_INTERNAL_MSG("Use asInt32 instead") // Since YARP 3.0.0
224  inline virtual int asInt() const final
225  {
226  return static_cast<int>(asInt32());
227  }
228 
238  virtual std::int8_t asInt8() const;
239 
249  virtual std::int16_t asInt16() const;
250 
260  virtual std::int32_t asInt32() const;
261 
271  virtual std::int64_t asInt64() const;
272 
280  YARP_DEPRECATED_INTERNAL_MSG("Use asFloat64 instead") // Since YARP 3.0.0
281  inline virtual double asDouble() const final
282  {
283  return static_cast<double>(asFloat64());
284  }
285 
295  virtual yarp::conf::float32_t asFloat32() const;
296 
306  virtual yarp::conf::float64_t asFloat64() const;
307 
312  virtual std::int32_t asVocab() const;
313 
319  virtual std::string asString() const;
320 
326  virtual Bottle* asList() const;
327 
333  virtual Property* asDict() const;
334 
340  virtual Searchable* asSearchable() const;
341 
347  virtual const char* asBlob() const;
348 
354  virtual size_t asBlobLength() const;
355 
356  // documented in Portable
357  bool read(ConnectionReader& connection) override;
358 
359  // documented in Portable
360  bool write(ConnectionWriter& connection) const override;
361 
362  // documented in Searchable
363  bool check(const std::string& key) const override;
364 
365  // documented in Searchable
366  Value& find(const std::string& key) const override;
367 
368  // documented in Searchable
369  Bottle& findGroup(const std::string& key) const override;
370 
376  bool operator==(const Value& alt) const;
377 
383  bool operator!=(const Value& alt) const;
384 
391  void fromString(const char* str);
392 
393  std::string toString() const override;
394 
399  virtual Value* create() const;
400 
405  virtual Value* clone() const;
406 
411  virtual std::int32_t getCode() const;
412 
413  bool isNull() const override;
414 
415  virtual bool isLeaf() const;
416 
423  YARP_DEPRECATED_INTERNAL_MSG("Use makeInt32 instead") // Since YARP 3.0.0
424  inline static Value* makeInt(int x)
425  {
426  return makeInt32(static_cast<std::int32_t>(x));
427  }
428 
434  static Value* makeInt8(std::int8_t x);
435 
441  static Value* makeInt16(std::int16_t x);
442 
448  static Value* makeInt32(std::int32_t x);
449 
455  static Value* makeInt64(std::int64_t x);
456 
463  YARP_DEPRECATED_INTERNAL_MSG("Use makeFloat64 instead") // Since YARP 3.0.0
464  inline static Value* makeDouble(double x)
465  {
466  return makeFloat64(static_cast<yarp::conf::float64_t>(x));
467  }
468 
474  static Value* makeFloat32(yarp::conf::float32_t x);
475 
481  static Value* makeFloat64(yarp::conf::float64_t x);
482 
488  static Value* makeString(const std::string& str);
489 
495  static Value* makeVocab(std::int32_t v);
496 
502  static Value* makeVocab(const std::string& str);
503 
510  static Value* makeBlob(void* data, int length);
511 
516  static Value* makeList();
517 
523  static Value* makeList(const char* txt);
524 
531  static Value* makeValue(const std::string& txt);
532 
533 
538  static Value& getNullValue();
539 
540 #ifndef DOXYGEN_SHOULD_SKIP_THIS
541 private:
543 
544  void setProxy(yarp::os::impl::Storable* proxy);
545  void ok() const;
546 #endif // DOXYGEN_SHOULD_SKIP_THIS
547 };
548 
549 } // namespace os
550 } // namespace yarp
551 
552 #endif // YARP_OS_VALUE_H
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:553
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:516
A single item in a Bottle.
Definition: Storable.h:44
A class for storing options and configuration information.
Definition: Property.h:34
A base class for nested structures that can be searched.
Definition: Searchable.h:68
This is a base class for objects that can be both read from and be written to the YARP network...
Definition: Portable.h:28
#define YARP_OS_API
Definition: api.h:19
The main, catch-all namespace for YARP.
Definition: numeric.h:47
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
An interface for writing to a network connection.
A simple collection of objects that can be described and transmitted in a portable way...
Definition: Bottle.h:72
An interface for reading from a network connection.
double float64_t
Definition: numeric.h:51
float float32_t
Definition: numeric.h:50
#define YARP_DEPRECATED_INTERNAL_MSG(X)
Definition: api.h:139
A single value (typically within a Bottle).
Definition: Value.h:46
std::string toString(const T &value)
convert an arbitrary type to string.
virtual Bottle & findGroup(const std::string &key) const =0
Gets a list corresponding to a given keyword.