YARP
Yet Another Robot Platform
Bottle.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  * 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 class NetworkBase;
43 
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 #if defined(SWIG) && (SWIG_VERSION < 0x300011)
76  typedef size_t size_type;
77 #else
78  using size_type = size_t;
79 #endif
80  // FIXME this can be constexpr, but swig 3.0.8 is not happy
81  static const size_type npos;
82 
83  using Searchable::check;
84  using Searchable::findGroup;
85 
89  Bottle();
90 
101  explicit Bottle(const std::string& text);
102 
108  Bottle(const Bottle& rhs);
109 
114  Bottle(std::initializer_list<yarp::os::Value> values);
115 
122  Bottle& operator=(const Bottle& bottle);
123 
127  virtual ~Bottle();
128 
132  void clear();
133 
140  YARP_DEPRECATED_INTERNAL_MSG("Use addInt32 instead") // Since YARP 3.0.0
141  inline void addInt(int x)
142  {
143  addInt32(static_cast<std::int32_t>(x));
144  }
145 
151  void addInt8(std::int8_t x);
152 
158  void addInt16(std::int16_t x);
159 
165  void addInt32(std::int32_t x);
166 
172  void addInt64(std::int64_t x);
173 
179  void addVocab(int x);
180 
188  YARP_DEPRECATED_INTERNAL_MSG("Use addFloat64 instead") // Since YARP 3.0.0
189  inline void addDouble(double x)
190  {
191  addFloat64(static_cast<yarp::conf::float64_t>(x));
192  }
193 
200  void addFloat32(yarp::conf::float32_t x);
201 
208  void addFloat64(yarp::conf::float64_t x);
209 
215  void addString(const char* str);
216 
222  void addString(const std::string& str);
223 
229  void add(const Value& value);
230 
240  void add(Value* value);
241 
250  Bottle& addList();
251 
258  Property& addDict();
259 
266  Value pop();
267 
280  Value& get(size_type index) const;
281 
287  size_type size() const;
288 
299  void fromString(const std::string& text);
300 
307  void fromBinary(const char* buf, size_t len);
308 
319  const char* toBinary(size_t* size = nullptr);
320 
329  std::string toString() const override;
330 
337  bool write(ConnectionWriter& writer) const override;
338 
345  bool read(ConnectionReader& reader) override;
346 
357  bool write(PortReader& reader, bool textMode = false);
358 
368  bool read(const PortWriter& writer, bool textMode = false);
369 
370  void onCommencement() const override;
371 
372  bool check(const std::string& key) const override;
373 
374  Value& find(const std::string& key) const override;
375 
376  Bottle& findGroup(const std::string& key) const override;
377 
378  bool isNull() const override;
379 
387  void copy(const Bottle& alt, size_type first = 0, size_type len = npos);
388 
394  static Bottle& getNullBottle();
395 
402  bool operator==(const Bottle& alt) const;
403 
410  bool operator!=(const Bottle& alt) const;
411 
418  void append(const Bottle& alt);
419 
426  Bottle tail() const;
427 
435  void hasChanged();
436 
437  static std::string toString(int x);
438 
444  int getSpecialization();
445 
453  static std::string describeBottleCode(int code);
454 
455 
456 protected:
457  void setReadOnly(bool readOnly);
458 
459 
460 private:
461  friend class yarp::os::NetworkBase;
462 #ifndef DOXYGEN_SHOULD_SKIP_THIS
463  friend class yarp::os::impl::Storable;
464  friend class yarp::os::impl::StoreList;
465  friend class yarp::os::impl::BottleImpl;
467 #endif // DOXYGEN_SHOULD_SKIP_THIS
468 };
469 
470 } // namespace os
471 } // namespace yarp
472 
473 #endif // YARP_OS_BOTTLE_H
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:553
#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:516
size_t size_type
Definition: Bottle.h:78
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
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:1036
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:35
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
static const size_type npos
Definition: Bottle.h:81
#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.