YARP  2.3.70
Yet Another Robot Platform
Bottle.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006, 2008 RobotCub Consortium, Arjan Gijsberts
3  * Authors: Paul Fitzpatrick, Arjan Gijsberts
4  * CopyPolicy: Released under the terms of the LGPLv2.1 or later, see LGPL.TXT
5  */
6 
7 #ifndef YARP_OS_BOTTLE_H
8 #define YARP_OS_BOTTLE_H
9 
10 #include <yarp/os/Portable.h>
11 #include <yarp/os/Searchable.h>
12 
13 #include <yarp/os/ConstString.h>
14 #include <yarp/os/Property.h>
15 #include <yarp/os/Value.h>
16 
17 #define BOTTLE_TAG_INT 1 // 0000 0000 0001
18 #define BOTTLE_TAG_VOCAB (1 + 8) // 0000 0000 1001
19 #define BOTTLE_TAG_DOUBLE (2 + 8) // 0000 0000 1010
20 #define BOTTLE_TAG_STRING (4) // 0000 0000 0100
21 #define BOTTLE_TAG_BLOB (4 + 8) // 0000 0000 1100
22 #define BOTTLE_TAG_INT64 (1 + 16) // 0000 0001 0001
23 #define BOTTLE_TAG_LIST 256 // 0001 0000 0000
24 #define BOTTLE_TAG_DICT 512 // 0010 0000 0000
25 
26 namespace yarp {
27  namespace os {
28  class Bottle;
29  class NetworkBase;
30  namespace impl {
31  class BottleImpl;
32  class Storable;
33  class StoreList;
34  }
35  }
36 }
37 
57 class YARP_OS_API yarp::os::Bottle : public Portable, public Searchable
58 {
59 public:
60  using Searchable::check;
62 
66  Bottle();
67 
78  explicit Bottle(const ConstString& text);
79 
85  Bottle(const Bottle& bottle);
86 
93  Bottle& operator=(const Bottle& bottle);
94 
98  virtual ~Bottle();
99 
103  void clear();
104 
110  void addInt(int x);
111 
117  void addInt64(const YARP_INT64& x);
118 
124  void addVocab(int x);
125 
132  void addDouble(double x);
133 
139  void addString(const char* str);
140 
146  void addString(const ConstString& str);
147 
153  void add(const Value& value);
154 
164  void add(Value* value);
165 
174  Bottle& addList();
175 
182  Property& addDict();
183 
190  Value pop();
191 
204  Value& get(int index) const;
205 
211  int size() const;
212 
223  void fromString(const ConstString& text);
224 
231  void fromBinary(const char* buf, int len);
232 
243  const char* toBinary(size_t* size = YARP_NULLPTR);
244 
253  ConstString toString() const YARP_OVERRIDE;
254 
261  bool write(ConnectionWriter& writer) YARP_OVERRIDE;
262 
269  bool read(ConnectionReader& reader) YARP_OVERRIDE;
270 
281  bool write(PortReader& reader, bool textMode = false);
282 
292  bool read(PortWriter& writer, bool textMode = false);
293 
294  void onCommencement() YARP_OVERRIDE;
295 
296  virtual bool check(const ConstString& key) const YARP_OVERRIDE;
297 
298  virtual Value& find(const ConstString& key) const YARP_OVERRIDE;
299 
300  Bottle& findGroup(const ConstString& key) const YARP_OVERRIDE;
301 
302  virtual bool isNull() const YARP_OVERRIDE;
303 
311  void copy(const Bottle& alt, int first = 0, int len = -1);
312 
318  static Bottle& getNullBottle();
319 
326  bool operator==(const Bottle& alt);
327 
334  bool operator!=(const Bottle& alt);
335 
342  void append(const Bottle& alt);
343 
350  Bottle tail() const;
351 
359  void hasChanged();
360 
361  static ConstString toString(int x);
362 
368  int getSpecialization();
369 
377  static ConstString describeBottleCode(int code);
378 
379 #ifndef YARP_NO_DEPRECATED // since YARP 2.3.65
380  // worked "accidentally", user code relies on this
384  YARP_DEPRECATED void add(const char* txt);
385 #endif
386 
387 
388 protected:
389  void setReadOnly(bool readOnly);
390 
391 
392 private:
393  friend class yarp::os::NetworkBase;
398 
399  static void fini();
400 };
401 
402 #endif // YARP_OS_BOTTLE_H
virtual YARP_SSIZE_T read(const Bytes &b) override
bool operator!=(const yarp::os::ConstString &lhs, const yarp::os::ConstString &rhs)
Definition: ConstString.h:498
A single item in a Bottle.
Definition: BottleImpl.h:46
A class for storing options and configuration information.
Definition: Property.h:32
A base class for nested structures that can be searched.
Definition: Searchable.h:56
This is a base class for objects that can be both read from and be written to the YARP network...
Definition: Portable.h:26
yarp::os::impl::BottleImpl *const implementation
Definition: Bottle.h:397
bool operator==(const yarp::os::ConstString &lhs, const yarp::os::ConstString &rhs)
Relational operations for ConstString.
Definition: ConstString.h:483
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
The main, catch-all namespace for YARP.
A string with almost the same api as std::string.
Definition: ConstString.h:44
virtual Bottle & findGroup(const ConstString &key) const =0
Gets a list corresponding to a given keyword.
A nested list of items.
Definition: BottleImpl.h:354
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:25
A flexible data format for holding a bunch of numbers and strings.
Definition: BottleImpl.h:435
A simple collection of objects that can be described and transmitted in a portable way...
Definition: Bottle.h:57
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:36
virtual bool check(const ConstString &key) const =0
Check if there exists a property of the given name.
std::string toString(const T &value)
convert an arbitary type to string.
virtual void write(const Bytes &b) override