YARP
Yet Another Robot Platform
Bottle.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-FileCopyrightText: 2006, 2008 Arjan Gijsberts
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef YARP_OS_BOTTLE_H
9 #define YARP_OS_BOTTLE_H
10 
11 #include <yarp/os/Portable.h>
12 #include <yarp/os/Property.h>
13 #include <yarp/os/Searchable.h>
14 #include <yarp/os/Value.h>
15 #include <yarp/os/Vocab.h>
16 
17 #include <string>
18 
19 #define BOTTLE_TAG_INT8 32 // 0000 0000 0010 0000
20 #define BOTTLE_TAG_INT16 64 // 0000 0000 0100 0000
21 #define BOTTLE_TAG_INT32 1 // 0000 0000 0000 0001
22 #define BOTTLE_TAG_INT64 (1 + 16) // 0000 0000 0001 0001
23 #define BOTTLE_TAG_VOCAB32 (1 + 8) // 0000 0000 0000 1001
24 #define BOTTLE_TAG_FLOAT32 128 // 0000 0000 1000 0000
25 #define BOTTLE_TAG_FLOAT64 (2 + 8) // 0000 0000 0000 1010
26 #define BOTTLE_TAG_STRING (4) // 0000 0000 0000 0100
27 #define BOTTLE_TAG_BLOB (4 + 8) // 0000 0000 0000 1100
28 #define BOTTLE_TAG_LIST 256 // 0000 0001 0000 0000
29 #define BOTTLE_TAG_DICT 512 // 0000 0010 0000 0000
30 
31 YARP_DEPRECATED_MSG("Use BOTTLE_TAG_INT32 instead") // Since YARP 3.5.0
32 constexpr std::int32_t BOTTLE_TAG_DOUBLE = BOTTLE_TAG_FLOAT64;
33 
34 YARP_DEPRECATED_MSG("Use BOTTLE_TAG_FLOAT64 instead") // Since YARP 3.5.0
35 constexpr std::int32_t BOTTLE_TAG_INT = BOTTLE_TAG_INT32;
36 
37 YARP_DEPRECATED_MSG("Use BOTTLE_TAG_VOCAB32 instead") // Since YARP 3.5.0
38 constexpr std::int32_t BOTTLE_TAG_VOCAB = BOTTLE_TAG_VOCAB32;
39 
40 namespace yarp {
41 namespace os {
42 
43 class NetworkBase;
44 
45 #ifndef DOXYGEN_SHOULD_SKIP_THIS
46 namespace impl {
47 class BottleImpl;
48 class Storable;
49 class StoreList;
50 } // namespace impl
51 #endif // DOXYGEN_SHOULD_SKIP_THIS
52 
53 
73 class YARP_os_API Bottle : public Portable, public Searchable
74 {
75 public:
76 #if defined(SWIG) && (SWIG_VERSION < 0x300011)
77  typedef size_t size_type;
78 #else
79  using size_type = size_t;
80 #endif
81  // FIXME this can be constexpr, but swig 3.0.8 is not happy
82  static const size_type npos;
83 
84  using Searchable::check;
86 
90  Bottle();
91 
102  explicit Bottle(const std::string& text);
103 
109  Bottle(const Bottle& rhs);
110 
116  Bottle(Bottle&& rhs) noexcept;
117 
122  Bottle(std::initializer_list<yarp::os::Value> values);
123 
130  Bottle& operator=(const Bottle& rhs);
131 
138  Bottle& operator=(Bottle&& rhs) noexcept;
139 
143  ~Bottle() override;
144 
148  void clear();
149 
150 #ifndef YARP_NO_DEPRECATED // Since YARP 3.5.0
158  YARP_DEPRECATED_MSG("Use addInt32 instead")
159  inline void addInt(int x)
160  {
161  addInt32(static_cast<std::int32_t>(x));
162  }
163 #endif // YARP_NO_DEPRECATED
164 
170  void addInt8(std::int8_t x);
171 
177  void addInt16(std::int16_t x);
178 
184  void addInt32(std::int32_t x);
185 
191  void addInt64(std::int64_t x);
192 
193 #ifndef YARP_NO_DEPRECATED // Since YARP 3.5.0
200  YARP_DEPRECATED_MSG("Use addVocab32 instead")
202  {
203  return addVocab32(x);
204  }
205 #endif // YARP_NO_DEPRECATED
206 
212  void addVocab32(yarp::conf::vocab32_t x);
213 
222  void addVocab32(char a, char b = 0, char c = 0, char d = 0)
223  {
224  addVocab32(yarp::os::createVocab32(a, b, c, d));
225  }
226 
232  void addVocab32(const std::string& str)
233  {
234  addVocab32(yarp::os::Vocab32::encode(str));
235  }
236 
237 #ifndef YARP_NO_DEPRECATED // Since YARP 3.5.0
246  YARP_DEPRECATED_MSG("Use addFloat64 instead")
247  inline void addDouble(double x)
248  {
249  addFloat64(static_cast<yarp::conf::float64_t>(x));
250  }
251 #endif // YARP_NO_DEPRECATED
252 
259  void addFloat32(yarp::conf::float32_t x);
260 
267  void addFloat64(yarp::conf::float64_t x);
268 
274  void addString(const char* str);
275 
281  void addString(const std::string& str);
282 
288  void add(const Value& value);
289 
299  void add(Value* value);
300 
309  Bottle& addList();
310 
317  Property& addDict();
318 
325  Value pop();
326 
339  Value& get(size_type index) const;
340 
346  size_type size() const;
347 
358  void fromString(const std::string& text);
359 
366  void fromBinary(const char* buf, size_t len);
367 
378  const char* toBinary(size_t* size = nullptr);
379 
388  std::string toString() const override;
389 
396  bool write(ConnectionWriter& writer) const override;
397 
404  bool read(ConnectionReader& reader) override;
405 
416  bool write(PortReader& reader, bool textMode = false);
417 
427  bool read(const PortWriter& writer, bool textMode = false);
428 
429  void onCommencement() const override;
430 
431  bool check(const std::string& key) const override;
432 
433  Value& find(const std::string& key) const override;
434 
435  Bottle& findGroup(const std::string& key) const override;
436 
437  bool isNull() const override;
438 
446  void copy(const Bottle& alt, size_type first = 0, size_type len = npos);
447 
453  static Bottle& getNullBottle();
454 
461  bool operator==(const Bottle& alt) const;
462 
469  bool operator!=(const Bottle& alt) const;
470 
477  void append(const Bottle& alt);
478 
485  Bottle tail() const;
486 
494  void hasChanged();
495 
496  static std::string toString(int x);
497 
503  int getSpecialization();
504 
512  static std::string describeBottleCode(int code);
513 
514 
515 protected:
516  void setReadOnly(bool readOnly);
517 
518 
519 private:
520  friend class yarp::os::NetworkBase;
521 #ifndef DOXYGEN_SHOULD_SKIP_THIS
522  friend class yarp::os::impl::Storable;
523  friend class yarp::os::impl::StoreList;
524  friend class yarp::os::impl::BottleImpl;
526 #endif // DOXYGEN_SHOULD_SKIP_THIS
527 };
528 
529 } // namespace os
530 } // namespace yarp
531 
532 #endif // YARP_OS_BOTTLE_H
#define BOTTLE_TAG_FLOAT64
Definition: Bottle.h:25
#define BOTTLE_TAG_INT32
Definition: Bottle.h:21
constexpr std::int32_t BOTTLE_TAG_INT
Definition: Bottle.h:35
constexpr std::int32_t BOTTLE_TAG_DOUBLE
Definition: Bottle.h:32
constexpr std::int32_t BOTTLE_TAG_VOCAB
Definition: Bottle.h:38
#define BOTTLE_TAG_VOCAB32
Definition: Bottle.h:23
RandScalar * implementation(void *t)
Definition: RandnScalar.cpp:17
A simple collection of objects that can be described and transmitted in a portable way.
Definition: Bottle.h:74
void addVocab32(const std::string &str)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.h:232
void addDouble(double x)
Places a floating point number in the bottle, at the end of the list.
Definition: Bottle.h:247
size_t size_type
Definition: Bottle.h:79
void addInt(int x)
Places an integer in the bottle, at the end of the list.
Definition: Bottle.h:159
void addVocab32(char a, char b=0, char c=0, char d=0)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.h:222
static const size_type npos
Definition: Bottle.h:82
void addVocab(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Definition: Bottle.h:201
Bottle(std::initializer_list< yarp::os::Value > values)
Initializer list constructor.
An interface for reading from a network connection.
An interface for writing to a network connection.
Utilities for manipulating the YARP network, excluding initialization and shutdown.
Definition: Network.h:41
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:25
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
This is a base class for objects that can be both read from and be written to the YARP network.
Definition: Portable.h:26
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:66
A single value (typically within a Bottle).
Definition: Value.h:45
A flexible data format for holding a bunch of numbers and strings.
Definition: BottleImpl.h:33
A single item in a Bottle.
Definition: Storable.h:44
A nested list of items.
Definition: Storable.h:1040
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2885
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
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:28
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:923
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:1099
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18