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 void clear();
106
107 void fromString(const std::string& line);
108 std::string toString() const;
109 size_type size() const;
110
111 bool read(ConnectionReader& reader);
112 bool write(ConnectionWriter& writer) const;
113
114 void onCommencement();
115
116 const char* getBytes() const;
117 size_t byteCount() const;
118
119 void copyRange(const BottleImpl* alt, size_type first = 0, size_type len = npos);
120
121 bool fromBytes(const yarp::os::Bytes& data);
122 void toBytes(yarp::os::Bytes& data);
123
124 bool fromBytes(yarp::os::ConnectionReader& reader);
125
126 void fromBinary(const char* text, size_t len);
127
128 void specialize(std::int32_t subCode);
129 int getSpecialization();
130 void setNested(bool nested);
131
132 std::int32_t subCode();
133
135 {
136 // all Values are Storables -- important invariant!
137 add((Storable*)(bit));
138 }
139
141 {
142 // all Values are Storables -- important invariant!
143 if (!bit.isNull()) {
144 add((Storable*)(bit.clone()));
145 }
146 }
147
148 yarp::os::Value& addBit(const char* str)
149 {
150 size_type len = size();
151 std::string x(str);
152 smartAdd(x);
153 if (size() > len) {
154 return get((int)size() - 1);
155 }
156 return get(-1);
157 }
158
160 {
161 static StoreNull storeNull;
162 return storeNull;
163 }
164
165 // check if a piece of text is a completed bottle
166 static bool isComplete(const char* txt);
167
169 {
170 dirty = true;
171 }
172
173 bool checkIndex(size_type index) const;
174
176 bool ro;
177
178 void edit();
179
180 Value& findGroupBit(const std::string& key) const;
181 Value& findBit(const std::string& key) const;
182
183private:
184 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<Storable*>) content;
185 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::vector<char>) data;
186 int speciality;
187 bool nested;
188 bool dirty;
189
190 void add(Storable* s);
191 void smartAdd(const std::string& str);
192
193 /*
194 * Bottle is using a lazy synchronization method. Whenever some operation
195 * is performed, a dirty flag is set, and when it is used, the synch()
196 * method is called.
197 *
198 * The const version of the synch() method performs a const_cast, and
199 * calls the non-const version. This allows to call it in const methods.
200 * Conceptually this is not completely wrong because it does not modify
201 * the external state of the class, but just some internal representation.
202 */
203 void synch();
204 void synch() const;
205};
206
207} // namespace yarp::os::impl
208
209
210#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:64
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 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:134
void addBit(const yarp::os::Value &bit)
Definition BottleImpl.h:140
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:148
static StoreNull & getNull()
Definition BottleImpl.h:159
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:43
A 32-bit floating point number item.
Definition Storable.h:672
A 64-bit floating point number item.
Definition Storable.h:747
A 16-bit integer item.
Definition Storable.h:416
A 32-bit integer item.
Definition Storable.h:502
A 64-bit integer item.
Definition Storable.h:587
A 8-bit integer item.
Definition Storable.h:330
A 32 bit vocabulary item.
Definition Storable.h:822
A 64 bit vocabulary item.
Definition Storable.h:908
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