YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
BottleImpl.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_IMPL_BOTTLEIMPL_H
9#define YARP_OS_IMPL_BOTTLEIMPL_H
10
11#include <yarp/os/Bytes.h>
13
14#include <vector>
15
16namespace yarp::os {
17
18class Bottle;
19class Property;
20class ConnectionReader;
21class ConnectionWriter;
22
23} // namespace yarp::os
24
25namespace yarp::os::impl {
26
27
34{
35public:
37 static constexpr size_type npos = static_cast<size_type>(-1);
38
39 BottleImpl();
40 BottleImpl(Searchable* parent);
41 virtual ~BottleImpl();
42
44
45 bool isInt8(int index);
46 bool isInt16(int index);
47 bool isInt32(int index);
48 bool isInt64(int index);
49 bool isFloat32(int index);
50 bool isFloat64(int index);
51 bool isString(int index);
52 bool isList(int index);
53
54 Storable* pop();
55
56 Storable& get(size_type index) const;
57
58 void addInt8(std::int8_t x)
59 {
60 add(new StoreInt8(x));
61 }
62
63 void addInt16(std::int16_t x)
64 {
65 add(new StoreInt16(x));
66 }
67
68 void addInt32(std::int32_t x)
69 {
70 add(new StoreInt32(x));
71 }
72
73 void addInt64(std::int64_t x)
74 {
75 add(new StoreInt64(x));
76 }
77
79 {
80 add(new StoreFloat32(x));
81 }
82
84 {
85 add(new StoreFloat64(x));
86 }
87
89 {
90 add(new StoreVocab32(x));
91 }
92
94 {
95 add(new StoreVocab64(x));
96 }
97
98 void addString(const std::string& text)
99 {
100 add(new StoreString(text));
101 }
102
103 yarp::os::Bottle& addList();
104
105 yarp::os::Property& addDict();
106
107 void clear();
108
109 void fromString(const std::string& line);
110 std::string toString() const;
111 size_type size() const;
112
113 bool read(ConnectionReader& reader);
114 bool write(ConnectionWriter& writer) const;
115
116 void onCommencement();
117
118 const char* getBytes() const;
119 size_t byteCount() const;
120
121 void copyRange(const BottleImpl* alt, size_type first = 0, size_type len = npos);
122
123 bool fromBytes(const yarp::os::Bytes& data);
124 void toBytes(yarp::os::Bytes& data);
125
126 bool fromBytes(yarp::os::ConnectionReader& reader);
127
128 void fromBinary(const char* text, size_t len);
129
130 void specialize(std::int32_t subCode);
131 int getSpecialization();
132 void setNested(bool nested);
133
134 std::int32_t subCode();
135
137 {
138 // all Values are Storables -- important invariant!
139 add((Storable*)(bit));
140 }
141
143 {
144 // all Values are Storables -- important invariant!
145 if (!bit.isNull()) {
146 add((Storable*)(bit.clone()));
147 }
148 }
149
150 yarp::os::Value& addBit(const char* str)
151 {
152 size_type len = size();
153 std::string x(str);
154 smartAdd(x);
155 if (size() > len) {
156 return get((int)size() - 1);
157 }
158 return get(-1);
159 }
160
162 {
163 static StoreNull storeNull;
164 return storeNull;
165 }
166
167 // check if a piece of text is a completed bottle
168 static bool isComplete(const char* txt);
169
171 {
172 dirty = true;
173 }
174
175 bool checkIndex(size_type index) const;
176
178 bool ro;
179
180 void edit();
181
182 Value& findGroupBit(const std::string& key) const;
183 Value& findBit(const std::string& key) const;
184
185private:
186 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<Storable*>) content;
187 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<char>) data;
188 int speciality;
189 bool nested;
190 bool dirty;
191
192 void add(Storable* s);
193 void smartAdd(const std::string& str);
194
195 /*
196 * Bottle is using a lazy synchronization method. Whenever some operation
197 * is performed, a dirty flag is set, and when it is used, the synch()
198 * method is called.
199 *
200 * The const version of the synch() method performs a const_cast, and
201 * calls the non-const version. This allows to call it in const methods.
202 * Conceptually this is not completely wrong because it does not modify
203 * the external state of the class, but just some internal representation.
204 */
205 void synch();
206 void synch() const;
207};
208
209} // namespace yarp::os::impl
210
211
212#endif // YARP_OS_IMPL_BOTTLEIMPL_H
std::string toString(const T &value)
convert an arbitrary type to string.
size_t size_t
A simple collection of objects that can be described and transmitted in a portable way.
Definition Bottle.h:65
A mini-server for performing network communication in the background.
A simple abstraction for a block of bytes.
Definition Bytes.h:24
An interface for reading from a network connection.
An interface for writing to a network connection.
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
void addFloat64(yarp::conf::float64_t x)
Definition BottleImpl.h:83
void addInt32(std::int32_t x)
Definition BottleImpl.h:68
void addVocab32(yarp::conf::vocab32_t x)
Definition BottleImpl.h:88
void addBit(yarp::os::Value *bit)
Definition BottleImpl.h:136
void addBit(const yarp::os::Value &bit)
Definition BottleImpl.h:142
void addInt8(std::int8_t x)
Definition BottleImpl.h:58
void addString(const std::string &text)
Definition BottleImpl.h:98
yarp::os::Value & addBit(const char *str)
Definition BottleImpl.h:150
static StoreNull & getNull()
Definition BottleImpl.h:161
void addFloat32(yarp::conf::float32_t x)
Definition BottleImpl.h:78
void addInt64(std::int64_t x)
Definition BottleImpl.h:73
void addInt16(std::int16_t x)
Definition BottleImpl.h:63
void addVocab64(yarp::conf::vocab64_t x)
Definition BottleImpl.h:93
A single item in a Bottle.
Definition Storable.h:44
A 32-bit floating point number item.
Definition Storable.h:691
A 64-bit floating point number item.
Definition Storable.h:766
A 16-bit integer item.
Definition Storable.h:435
A 32-bit integer item.
Definition Storable.h:521
A 64-bit integer item.
Definition Storable.h:606
A 8-bit integer item.
Definition Storable.h:349
A 32 bit vocabulary item.
Definition Storable.h:841
A 64 bit vocabulary item.
Definition Storable.h:927
std::int32_t vocab32_t
Definition numeric.h:78
std::int64_t vocab64_t
Definition numeric.h:79
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition system.h:338
#define YARP_os_impl_API
Definition api.h:46