YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
31namespace yarp::os {
32
33class NetworkBase;
34
35#ifndef DOXYGEN_SHOULD_SKIP_THIS
36namespace impl {
37class BottleImpl;
38class Storable;
39class StoreList;
40} // namespace impl
41#endif // DOXYGEN_SHOULD_SKIP_THIS
42
43
63class YARP_os_API Bottle : public Portable, public Searchable
64{
65public:
66#if defined(SWIG) && (SWIG_VERSION < 0x300011)
67 typedef size_t size_type;
68#else
70#endif
71 // FIXME this can be constexpr, but swig 3.0.8 is not happy
72 static const size_type npos;
73
74 using Searchable::check;
75 using Searchable::findGroup;
76
80 Bottle();
81
92 explicit Bottle(const std::string& text);
93
99 Bottle(const Bottle& rhs);
100
106 Bottle(Bottle&& rhs) noexcept;
107
112 Bottle(std::initializer_list<yarp::os::Value> values);
113
120 Bottle& operator=(const Bottle& rhs);
121
128 Bottle& operator=(Bottle&& rhs) noexcept;
129
133 ~Bottle() override;
134
138 void clear();
139
145 void addInt8(std::int8_t x);
146
152 void addInt16(std::int16_t x);
153
159 void addInt32(std::int32_t x);
160
166 void addInt64(std::int64_t x);
167
173 void addVocab32(yarp::conf::vocab32_t x);
174
183 void addVocab32(char a, char b = 0, char c = 0, char d = 0)
184 {
185 addVocab32(yarp::os::createVocab32(a, b, c, d));
186 }
187
193 void addVocab32(const std::string& str)
194 {
195 addVocab32(yarp::os::Vocab32::encode(str));
196 }
197
204 void addFloat32(yarp::conf::float32_t x);
205
212 void addFloat64(yarp::conf::float64_t x);
213
219 void addString(const char* str);
220
226 void addString(const std::string& str);
227
233 void add(const Value& value);
234
244 void add(Value* value);
245
254 Bottle& addList();
255
262 Property& addDict();
263
270 Value pop();
271
284 Value& get(size_type index) const;
285
291 size_type size() const;
292
303 void fromString(const std::string& text);
304
311 void fromBinary(const char* buf, size_t len);
312
323 const char* toBinary(size_t* size = nullptr);
324
333 std::string toString() const override;
334
341 bool write(ConnectionWriter& writer) const override;
342
349 bool read(ConnectionReader& reader) override;
350
361 bool write(PortReader& reader, bool textMode = false);
362
372 bool read(const PortWriter& writer, bool textMode = false);
373
374 void onCommencement() const override;
375
376 bool check(const std::string& key) const override;
377
378 Value& find(const std::string& key) const override;
379
380 Bottle& findGroup(const std::string& key) const override;
381
382 bool isNull() const override;
383
391 void copy(const Bottle& alt, size_type first = 0, size_type len = npos);
392
398 static Bottle& getNullBottle();
399
406 bool operator==(const Bottle& alt) const;
407
414 bool operator!=(const Bottle& alt) const;
415
422 void append(const Bottle& alt);
423
430 Bottle tail() const;
431
439 void hasChanged();
440
441 static std::string toString(int x);
442
448 int getSpecialization();
449
457 static std::string describeBottleCode(int code);
458
459
460protected:
461 void setReadOnly(bool readOnly);
462
463
464private:
466#ifndef DOXYGEN_SHOULD_SKIP_THIS
467 friend class yarp::os::impl::Storable;
468 friend class yarp::os::impl::StoreList;
469 friend class yarp::os::impl::BottleImpl;
471#endif // DOXYGEN_SHOULD_SKIP_THIS
472};
473
474} // namespace yarp::os
475
476#endif // YARP_OS_BOTTLE_H
bool operator==(const struct v4l2_control &left, const struct v4l2_control &right)
Definition CApiMock.h:65
std::string toString(const T &value)
convert an arbitrary type to string.
size_t size_t
RandScalar * implementation(void *t)
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:64
void addVocab32(const std::string &str)
Places a vocabulary item in the bottle, at the end of the list.
Definition Bottle.h:193
size_t size_type
Definition Bottle.h:69
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:183
static const size_type npos
Definition Bottle.h:72
Bottle(std::initializer_list< yarp::os::Value > values)
Initializer list constructor.
A mini-server for performing network communication in the background.
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:38
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition PortReader.h:24
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition PortWriter.h:23
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
A class for storing options and configuration information.
Definition Property.h:33
A base class for nested structures that can be searched.
Definition Searchable.h:31
A single value (typically within a Bottle).
Definition Value.h:43
A flexible data format for holding a bunch of numbers and strings.
Definition BottleImpl.h:34
A single item in a Bottle.
Definition Storable.h:42
A nested list of items.
Definition Storable.h:1038
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
An interface to the operating system, including Port based communication.
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:27
#define YARP_os_API
Definition api.h:18