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#define BOTTLE_TAG_DICT 512 // 0000 0010 0000 0000
31
32namespace yarp::os {
33
34class NetworkBase;
35
36#ifndef DOXYGEN_SHOULD_SKIP_THIS
37namespace impl {
38class BottleImpl;
39class Storable;
40class StoreList;
41} // namespace impl
42#endif // DOXYGEN_SHOULD_SKIP_THIS
43
44
64class YARP_os_API Bottle : public Portable, public Searchable
65{
66public:
67#if defined(SWIG) && (SWIG_VERSION < 0x300011)
68 typedef size_t size_type;
69#else
71#endif
72 // FIXME this can be constexpr, but swig 3.0.8 is not happy
73 static const size_type npos;
74
75 using Searchable::check;
76 using Searchable::findGroup;
77
81 Bottle();
82
93 explicit Bottle(const std::string& text);
94
100 Bottle(const Bottle& rhs);
101
107 Bottle(Bottle&& rhs) noexcept;
108
113 Bottle(std::initializer_list<yarp::os::Value> values);
114
121 Bottle& operator=(const Bottle& rhs);
122
129 Bottle& operator=(Bottle&& rhs) noexcept;
130
134 ~Bottle() override;
135
139 void clear();
140
146 void addInt8(std::int8_t x);
147
153 void addInt16(std::int16_t x);
154
160 void addInt32(std::int32_t x);
161
167 void addInt64(std::int64_t x);
168
174 void addVocab32(yarp::conf::vocab32_t x);
175
181 void addVocab64(yarp::conf::vocab64_t x);
182
191 void addVocab32(char a, char b = 0, char c = 0, char d = 0)
192 {
193 addVocab32(yarp::os::createVocab32(a, b, c, d));
194 }
195
201 void addVocab32(const std::string& str)
202 {
203 addVocab32(yarp::os::Vocab32::encode(str));
204 }
205
212 void addFloat32(yarp::conf::float32_t x);
213
220 void addFloat64(yarp::conf::float64_t x);
221
227 void addString(const char* str);
228
234 void addString(const std::string& str);
235
241 void add(const Value& value);
242
252 void add(Value* value);
253
262 Bottle& addList();
263
270 Property& addDict();
271
278 Value pop();
279
292 Value& get(size_type index) const;
293
299 size_type size() const;
300
311 void fromString(const std::string& text);
312
319 void fromBinary(const char* buf, size_t len);
320
331 const char* toBinary(size_t* size = nullptr);
332
341 std::string toString() const override;
342
349 bool write(ConnectionWriter& writer) const override;
350
357 bool read(ConnectionReader& reader) override;
358
369 bool write(PortReader& reader, bool textMode = false);
370
380 bool read(const PortWriter& writer, bool textMode = false);
381
382 void onCommencement() const override;
383
384 bool check(const std::string& key) const override;
385
386 Value& find(const std::string& key) const override;
387
388 Bottle& findGroup(const std::string& key) const override;
389
390 bool isNull() const override;
391
399 void copy(const Bottle& alt, size_type first = 0, size_type len = npos);
400
406 static Bottle& getNullBottle();
407
414 bool operator==(const Bottle& alt) const;
415
422 bool operator!=(const Bottle& alt) const;
423
430 void append(const Bottle& alt);
431
438 Bottle tail() const;
439
447 void hasChanged();
448
449 static std::string toString(int x);
450
456 int getSpecialization();
457
465 static std::string describeBottleCode(int code);
466
467
468protected:
469 void setReadOnly(bool readOnly);
470
471
472private:
474#ifndef DOXYGEN_SHOULD_SKIP_THIS
475 friend class yarp::os::impl::Storable;
476 friend class yarp::os::impl::StoreList;
477 friend class yarp::os::impl::BottleImpl;
479#endif // DOXYGEN_SHOULD_SKIP_THIS
480};
481
482} // namespace yarp::os
483
484#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:65
void addVocab32(const std::string &str)
Places a vocabulary item in the bottle, at the end of the list.
Definition Bottle.h:201
size_t size_type
Definition Bottle.h:70
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:191
static const size_type npos
Definition Bottle.h:73
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: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:44
A nested list of items.
Definition Storable.h:1136
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