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/Property.h>
16 #include <yarp/os/Searchable.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 
42 // Forward declarations
43 class NetworkBase;
44 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45 namespace impl {
46 class BottleImpl;
47 class Storable;
48 class StoreList;
49 } // namespace impl
50 #endif // DOXYGEN_SHOULD_SKIP_THIS
51 
52 
72 class YARP_OS_API Bottle : public Portable, public Searchable
73 {
74 public:
75  using Searchable::check;
76  using Searchable::findGroup;
77 
81  Bottle();
82 
93  explicit Bottle(const std::string& text);
94 
100  Bottle(const Bottle& bottle);
101 
108  Bottle& operator=(const Bottle& bottle);
109 
113  virtual ~Bottle();
114 
118  void clear();
119 
126  YARP_DEPRECATED_INTERNAL_MSG("Use addInt32 instead") // Since YARP 3.0.0
127  inline void addInt(int x)
128  {
129  addInt32(static_cast<std::int32_t>(x));
130  }
131 
137  void addInt8(std::int8_t x);
138 
144  void addInt16(std::int16_t x);
145 
151  void addInt32(std::int32_t x);
152 
158  void addInt64(std::int64_t x);
159 
165  void addVocab(int x);
166 
174  YARP_DEPRECATED_INTERNAL_MSG("Use addFloat64 instead") // Since YARP 3.0.0
175  inline void addDouble(double x)
176  {
177  addFloat64(static_cast<yarp::conf::float64_t>(x));
178  }
179 
186  void addFloat32(yarp::conf::float32_t x);
187 
194  void addFloat64(yarp::conf::float64_t x);
195 
201  void addString(const char* str);
202 
208  void addString(const std::string& str);
209 
215  void add(const Value& value);
216 
226  void add(Value* value);
227 
236  Bottle& addList();
237 
244  Property& addDict();
245 
252  Value pop();
253 
266  Value& get(size_t index) const;
267 
273  size_t size() const;
274 
285  void fromString(const std::string& text);
286 
293  void fromBinary(const char* buf, size_t len);
294 
305  const char* toBinary(size_t* size = nullptr);
306 
315  std::string toString() const override;
316 
323  bool write(ConnectionWriter& writer) const override;
324 
331  bool read(ConnectionReader& reader) override;
332 
343  bool write(PortReader& reader, bool textMode = false);
344 
354  bool read(const PortWriter& writer, bool textMode = false);
355 
356  void onCommencement() const override;
357 
358  virtual bool check(const std::string& key) const override;
359 
360  virtual Value& find(const std::string& key) const override;
361 
362  Bottle& findGroup(const std::string& key) const override;
363 
364  virtual bool isNull() const override;
365 
373  void copy(const Bottle& alt, int first = 0, int len = -1);
374 
380  static Bottle& getNullBottle();
381 
388  bool operator==(const Bottle& alt) const;
389 
396  bool operator!=(const Bottle& alt) const;
397 
404  void append(const Bottle& alt);
405 
412  Bottle tail() const;
413 
421  void hasChanged();
422 
423  static std::string toString(int x);
424 
430  int getSpecialization();
431 
439  static std::string describeBottleCode(int code);
440 
441 
442 protected:
443  void setReadOnly(bool readOnly);
444 
445 
446 private:
447  friend class yarp::os::NetworkBase;
448 #ifndef DOXYGEN_SHOULD_SKIP_THIS
449  friend class yarp::os::impl::Storable;
450  friend class yarp::os::impl::StoreList;
451  friend class yarp::os::impl::BottleImpl;
453 #endif // DOXYGEN_SHOULD_SKIP_THIS
454 };
455 
456 } // namespace os
457 } // namespace yarp
458 
459 #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:34
A base class for nested structures that can be searched.
Definition: Searchable.h:66
This is a base class for objects that can be both read from and be written to the YARP network...
Definition: Portable.h:28
STL namespace.
#define YARP_OS_API
Definition: api.h:19
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.
Definition: numeric.h:47
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:72
#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.
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
RandScalar * implementation(void *t)
Definition: RandnScalar.cpp:20
constexpr std::int32_t BOTTLE_TAG_DOUBLE
Definition: Bottle.h:34
std::string toString(const T &value)
convert an arbitrary type to string.