YARP
Yet Another Robot Platform
Bottle.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * Copyright (C) 2006, 2008 Arjan Gijsberts
5  * All rights reserved.
6  *
7  * This software may be modified and distributed under the terms of the
8  * BSD-3-Clause license. See the accompanying LICENSE file for details.
9  */
10 
11 #ifndef YARP_OS_BOTTLE_H
12 #define YARP_OS_BOTTLE_H
13 
14 #include <yarp/os/Portable.h>
15 #include <yarp/os/Searchable.h>
16 #include <yarp/os/Property.h>
17 #include <yarp/os/Value.h>
18 
19 #include <string>
20 
21 #define BOTTLE_TAG_INT8 32 // 0000 0000 0010 0000
22 #define BOTTLE_TAG_INT16 64 // 0000 0000 0100 0000
23 #define BOTTLE_TAG_INT32 1 // 0000 0000 0000 0001
24 #define BOTTLE_TAG_INT64 (1 + 16) // 0000 0000 0001 0001
25 #define BOTTLE_TAG_VOCAB (1 + 8) // 0000 0000 0000 1001
26 #define BOTTLE_TAG_FLOAT32 128 // 0000 0000 1000 0000
27 #define BOTTLE_TAG_FLOAT64 (2 + 8) // 0000 0000 0000 1010
28 #define BOTTLE_TAG_STRING (4) // 0000 0000 0000 0100
29 #define BOTTLE_TAG_BLOB (4 + 8) // 0000 0000 0000 1100
30 #define BOTTLE_TAG_LIST 256 // 0000 0001 0000 0000
31 #define BOTTLE_TAG_DICT 512 // 0000 0010 0000 0000
32 
33 YARP_DEPRECATED_INTERNAL_MSG("Use BOTTLE_TAG_INT32 instead") // Since YARP 3.0.0
35 
36 YARP_DEPRECATED_INTERNAL_MSG("Use BOTTLE_TAG_FLOAT64 instead") // Since YARP 3.0.0
37 constexpr std::int32_t BOTTLE_TAG_INT = BOTTLE_TAG_INT32;
38 
39 namespace yarp {
40  namespace os {
41  class Bottle;
42  class NetworkBase;
43  namespace impl {
44  class BottleImpl;
45  class Storable;
46  class StoreList;
47  }
48  }
49 }
50 
70 class YARP_OS_API yarp::os::Bottle : public Portable, public Searchable
71 {
72 public:
73  using Searchable::check;
74  using Searchable::findGroup;
75 
79  Bottle();
80 
91  explicit Bottle(const std::string& text);
92 
98  Bottle(const Bottle& bottle);
99 
106  Bottle& operator=(const Bottle& bottle);
107 
111  virtual ~Bottle();
112 
116  void clear();
117 
124  YARP_DEPRECATED_INTERNAL_MSG("Use addInt32 instead") // Since YARP 3.0.0
125  inline void addInt(int x) { addInt32(static_cast<std::int32_t>(x)); }
126 
132  void addInt8(std::int8_t x);
133 
139  void addInt16(std::int16_t x);
140 
146  void addInt32(std::int32_t x);
147 
153  void addInt64(std::int64_t x);
154 
160  void addVocab(int x);
161 
169  YARP_DEPRECATED_INTERNAL_MSG("Use addFloat64 instead") // Since YARP 3.0.0
170  inline void addDouble(double x) { addFloat64(static_cast<yarp::conf::float64_t>(x)); }
171 
178  void addFloat32(yarp::conf::float32_t x);
179 
186  void addFloat64(yarp::conf::float64_t x);
187 
193  void addString(const char* str);
194 
200  void addString(const std::string& str);
201 
207  void add(const Value& value);
208 
218  void add(Value* value);
219 
228  Bottle& addList();
229 
236  Property& addDict();
237 
244  Value pop();
245 
258  Value& get(size_t index) const;
259 
265  size_t size() const;
266 
277  void fromString(const std::string& text);
278 
285  void fromBinary(const char* buf, size_t len);
286 
297  const char* toBinary(size_t* size = nullptr);
298 
307  std::string toString() const override;
308 
315  bool write(ConnectionWriter& writer) const override;
316 
323  bool read(ConnectionReader& reader) override;
324 
335  bool write(PortReader& reader, bool textMode = false);
336 
346  bool read(const PortWriter& writer, bool textMode = false);
347 
348  void onCommencement() const override;
349 
350  virtual bool check(const std::string& key) const override;
351 
352  virtual Value& find(const std::string& key) const override;
353 
354  Bottle& findGroup(const std::string& key) const override;
355 
356  virtual bool isNull() const override;
357 
365  void copy(const Bottle& alt, int first = 0, int len = -1);
366 
372  static Bottle& getNullBottle();
373 
380  bool operator==(const Bottle& alt) const;
381 
388  bool operator!=(const Bottle& alt) const;
389 
396  void append(const Bottle& alt);
397 
404  Bottle tail() const;
405 
413  void hasChanged();
414 
415  static std::string toString(int x);
416 
422  int getSpecialization();
423 
431  static std::string describeBottleCode(int code);
432 
433 
434 protected:
435  void setReadOnly(bool readOnly);
436 
437 
438 private:
439  friend class yarp::os::NetworkBase;
444 
445 };
446 
447 #endif // YARP_OS_BOTTLE_H
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:430
#define BOTTLE_TAG_INT32
Definition: Bottle.h:23
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:393
A single item in a Bottle.
Definition: Storable.h:46
A class for storing options and configuration information.
Definition: Property.h:35
A base class for nested structures that can be searched.
Definition: Searchable.h:65
This is a base class for objects that can be both read from and be written to the YARP network...
Definition: Portable.h:27
STL namespace.
yarp::os::impl::BottleImpl *const implementation
Definition: Bottle.h:443
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:26
The main, catch-all namespace for YARP.
A nested list of items.
Definition: Storable.h:508
constexpr std::int32_t BOTTLE_TAG_INT
Definition: Bottle.h:37
An interface for writing to a network connection.
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:27
A flexible data format for holding a bunch of numbers and strings.
Definition: BottleImpl.h:34
A simple collection of objects that can be described and transmitted in a portable way...
Definition: Bottle.h:70
#define BOTTLE_TAG_FLOAT64
Definition: Bottle.h:27
Utilities for manipulating the YARP network, excluding initialization and shutdown.
Definition: Network.h:43
An interface for reading from a network connection.
A single value (typically within a Bottle).
Definition: Value.h:40
constexpr std::int32_t BOTTLE_TAG_DOUBLE
Definition: Bottle.h:34
std::string toString(const T &value)
convert an arbitary type to string.