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