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_VOCAB64 (2 + 16)// 0000 0000 0001 0010
25#define BOTTLE_TAG_FLOAT32 (2 + 8) // 0000 0000 0000 1010
26#define BOTTLE_TAG_FLOAT64 (4 + 16)// 0000 0000 0001 0100
27#define BOTTLE_TAG_STRING (4) // 0000 0000 0000 0100
28#define BOTTLE_TAG_BLOB (4 + 8) // 0000 0000 0000 1100
29#define BOTTLE_TAG_LIST 256 // 0000 0001 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
180 void addVocab64(yarp::conf::vocab64_t x);
181
190 void addVocab32(char a, char b = 0, char c = 0, char d = 0)
191 {
192 addVocab32(yarp::os::createVocab32(a, b, c, d));
193 }
194
200 void addVocab32(const std::string& str)
201 {
202 addVocab32(yarp::os::Vocab32::encode(str));
203 }
204
211 void addFloat32(yarp::conf::float32_t x);
212
219 void addFloat64(yarp::conf::float64_t x);
220
226 void addString(const char* str);
227
233 void addString(const std::string& str);
234
240 void add(const Value& value);
241
251 void add(Value* value);
252
261 Bottle& addList();
262
269 Value pop();
270
283 Value& get(size_type index) const;
284
290 size_type size() const;
291
302 void fromString(const std::string& text);
303
310 void fromBinary(const char* buf, size_t len);
311
322 const char* toBinary(size_t* size = nullptr);
323
332 std::string toString() const override;
333
340 bool write(ConnectionWriter& writer) const override;
341
348 bool read(ConnectionReader& reader) override;
349
360 bool write(PortReader& reader, bool textMode = false);
361
371 bool read(const PortWriter& writer, bool textMode = false);
372
373 void onCommencement() const override;
374
375 bool check(const std::string& key) const override;
376
377 Value& find(const std::string& key) const override;
378
379 Bottle& findGroup(const std::string& key) const override;
380
381 bool isNull() const override;
382
390 void copy(const Bottle& alt, size_type first = 0, size_type len = npos);
391
397 static Bottle& getNullBottle();
398
405 bool operator==(const Bottle& alt) const;
406
413 bool operator!=(const Bottle& alt) const;
414
421 void append(const Bottle& alt);
422
429 Bottle tail() const;
430
438 void hasChanged();
439
440 static std::string toString(int x);
441
447 int getSpecialization();
448
456 static std::string describeBottleCode(int code);
457
458
459protected:
460 void setReadOnly(bool readOnly);
461
462
463private:
465#ifndef DOXYGEN_SHOULD_SKIP_THIS
466 friend class yarp::os::impl::Storable;
467 friend class yarp::os::impl::StoreList;
468 friend class yarp::os::impl::BottleImpl;
470#endif // DOXYGEN_SHOULD_SKIP_THIS
471};
472
473} // namespace yarp::os
474
475#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:200
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:190
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 base class for nested structures that can be searched.
Definition Searchable.h:31
A single value (typically within a Bottle).
Definition Value.h:44
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:43
A nested list of items.
Definition Storable.h:1117
std::int32_t vocab32_t
Definition numeric.h:78
double float64_t
Definition numeric.h:77
float float32_t
Definition numeric.h:76
std::int64_t vocab64_t
Definition numeric.h:79
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
Definition Vocab32.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 Vocab32.h:27
#define YARP_os_API
Definition api.h:18