|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
36 BottleImpl::BottleImpl() :
72 for (
auto& i : content) {
79 void BottleImpl::smartAdd(
const std::string& str)
81 if (str.length() > 0) {
85 bool numberLike =
true;
87 bool hexActive =
false;
91 bool hasPeriodOrE =
false;
92 for (
size_t i = 0; i < str.length(); i++) {
93 if (str ==
"inf" || str ==
"-inf" || str ==
"nan") {
101 if (periodCount > 1) {
105 if (!hexActive && (ch2 ==
'e' || ch2 ==
'E')) {
109 if (ch2 ==
'x' || ch2 ==
'X') {
116 if (ch2 ==
'0' || ch2 ==
'+' || ch2 ==
'-') {
117 if (ch2 ==
'+' || ch2 ==
'-') {
127 if (!((ch2 >=
'0' && ch2 <=
'9') || ch2 ==
'.' || ch2 ==
'e' ||
128 ch2 ==
'E' || ch2 ==
'+' || ch2 ==
'-' ||
129 (hexActive && ((ch2 >=
'a' && ch2 <=
'f') ||
130 (ch2 >=
'A' && ch2 <=
'F'))))) {
136 if (
static_cast<int>(str.length()) - (hexStart + 1) > 8) {
143 ((ch >=
'0' && ch <=
'9') || ch ==
'+' || ch ==
'-' || ch ==
'.' || ch ==
'i' || ch ==
'n' ) &&
144 (ch !=
'.' || str.length() > 1)) {
146 s =
new StoreInt64(0);
148 s =
new StoreFloat64(0);
150 }
else if (ch ==
'(') {
152 }
else if (ch ==
'[') {
153 s =
new StoreVocab();
154 }
else if (ch ==
'{') {
157 s = ss =
new StoreString(
"");
167 && s->
asInt64() >= std::numeric_limits<int32_t>::min()
168 && s->
asInt64() <= std::numeric_limits<int32_t>::max()) {
176 if (str.length() == 0 || str[0] !=
'\"') {
180 s =
new StoreVocab(
static_cast<int>(
'1'));
181 }
else if (val ==
"false") {
183 s =
new StoreVocab(0);
203 std::string nline = line +
" ";
205 for (
char ch : nline) {
211 if (ch !=
' ' && ch !=
'\t' && ch !=
'\n' && ch !=
'\r') {
237 if ((!quoted) && (ch ==
',' || ch ==
' ' || ch ==
'\t' ||
238 ch ==
'\n' || ch ==
'\r') &&
239 (nestedAlt == 0) && (nested == 0)) {
265 std::string nline = txt;
268 for (
char ch : nline) {
273 if (ch !=
' ' && ch !=
'\t' && ch !=
'\n' && ch !=
'\r') {
300 (ch ==
' ' || ch ==
'\t' || ch ==
'\n' || ch ==
'\r') &&
301 (nestedAlt == 0) && (nested == 0)) {
311 return nested == 0 && nestedAlt == 0 && !quoted;
318 for (
unsigned int i = 0; i < content.size(); i++) {
330 return content.size();
339 std::int32_t
id = speciality;
340 yCTrace(BOTTLEIMPL,
"READING, nest flag is %d", nested);
343 yCTrace(BOTTLEIMPL,
"READ subcode %" PRId32,
id);
345 yCTrace(BOTTLEIMPL,
"READ skipped subcode %" PRId32, speciality);
348 if (storable ==
nullptr) {
349 yCError(BOTTLEIMPL,
"Reader failed, unrecognized object code %" PRId32,
id);
360 std::string wrapper(text, len);
365 reader.
reset(sis,
nullptr, route, len,
false);
372 std::string wrapper(data.
get(), data.
length());
377 reader.
reset(sis,
nullptr, route, data.
length(),
false);
390 yCTrace(BOTTLEIMPL,
"READ got top level code %" PRId32, code);
400 yCTrace(BOTTLEIMPL,
"READ bottle length %d", len);
401 for (
int i = 0; i < len; i++) {
421 yCTrace(BOTTLEIMPL,
"am I nested? %d", nested);
459 bool done = (str.length() <= 0);
461 if (str[str.length() - 1] ==
'\\') {
462 str = str.substr(0, str.length() - 1);
493 yCTrace(BOTTLEIMPL,
"READ got top level code %" PRId32, code);
504 std::int32_t len = 0;
509 yCTrace(BOTTLEIMPL,
"READ got length %d", len);
510 for (
int i = 0; i < len; i++) {
520 void BottleImpl::synch()
const
525 void BottleImpl::synch()
533 BufferedConnectionWriter writer;
539 writer.appendInt32(
static_cast<std::int32_t
>(
size()));
540 for (
auto s : content) {
541 if (speciality == 0) {
543 writer.appendInt32(s->
getCode());
549 s->
asList()->implementation->setNested(
true);
553 data.resize(writer.dataSize(),
' ');
554 MemoryOutputStream m(&data[0]);
574 this->nested = nested;
585 return index <
size();
634 stb = content[
size() - 1];
638 yCAssert(BOTTLEIMPL, stb !=
nullptr);
651 return lst->internal();
658 return lst->internal();
664 if (len == 0 || alt->
size() == 0) {
679 const size_t last = src->
size() - 1;
680 for (
size_t i = 0; (i < len) && (first + i <= last); ++i) {
688 yCFatal(BOTTLEIMPL,
"Attempted to modify the null bottle");
697 for (
size_t i = 0; i <
size(); i++) {
698 Value* org = &(
get(
static_cast<int>(i)));
713 for (
size_t i = 0; i <
size(); i++) {
714 Value* org = &(
get(
static_cast<int>(i)));
719 cursor = &(bot->
get(0));
726 if ((
parent !=
nullptr) && (
parent->getMonitor() !=
nullptr)) {
729 report.isFound =
true;
731 report.value =
get(
static_cast<int>(i + 1)).
toString();
734 parent->reportToMonitor(report);
737 return get(
static_cast<int>(i + 1));
741 if ((
parent !=
nullptr) && (
parent->getMonitor() !=
nullptr)) {
744 parent->reportToMonitor(report);
void specialize(std::int32_t subCode)
A simple collection of objects that can be described and transmitted in a portable way.
static Storable * createByCode(std::int32_t id)
virtual void fromStringNested(const std::string &src)
Initialize from a string representation.
bool read(ConnectionReader &reader)
constexpr yarp::conf::vocab32_t createVocab(char a, char b=0, char c=0, char d=0)
yarp::os::Property & addDict()
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the network connection.
void reset(yarp::os::InputStream &in, TwoWayStream *str, const Route &route, size_t len, bool textMode, bool bareMode=false)
virtual Storable * cloneStorable() const
Typed synonym for clone()
A base class for nested structures that can be searched.
virtual std::string toStringNested() const
Create string representation, including any syntax that should wrap it such as braces or parentheses.
Value & findBit(const std::string &key) const
std::int32_t expectInt32() override
Read a 32-bit integer from the network connection.
A flexible data format for holding a bunch of numbers and strings.
void fromBinary(const char *text, size_t len)
bool isError() const override
Lets Readable objects read from the underlying InputStream associated with the connection between two...
Information about a connection between two ports.
A single item in a Bottle.
Value & findGroupBit(const std::string &key) const
void copyRange(const BottleImpl *alt, size_type first=0, size_type len=npos)
bool isFloat32(int index)
std::int64_t asInt64() const override
Get 64-bit integer value.
const char * getBytes() const
virtual bool isError() const =0
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
An interface for writing to a network connection.
void fromString(const std::string &line)
bool write(ConnectionWriter &writer) const
static bool isComplete(const char *txt)
bool checkIndex(size_type index) const
virtual bool isError() const =0
std::string asString() const override
Get string value.
yarp::os::Bottle * asList() const override
Get list value.
A simple abstraction for a block of bytes.
std::string toString() const override=0
Return a standard text representation of the content of the object.
virtual bool isList() const
Checks if value is a list.
#define yCAssert(component, x)
An interface for reading from a network connection.
std::string toString() const
void setNested(bool nested)
#define yCError(component,...)
virtual bool isTextMode() const =0
Check if the connection is text mode.
virtual std::int32_t getCode() const
Get standard type code of value.
bool isInt64() const override
Checks if value is a 64-bit integer.
virtual std::string expectText(const char terminatingChar='\n')=0
Read some text from the network connection.
virtual bool isTextMode() const =0
Check if the connection is text mode.
std::int32_t asInt32() const override
Get 32-bit integer value.
bool fromBytes(const yarp::os::Bytes &data)
virtual bool writeRaw(ConnectionWriter &connection) const =0
virtual Bottle * asList() const
Get list value.
#define yCTrace(component,...)
yarp::os::Bottle & addList()
std::string toString() const override
Return a standard text representation of the content of the object.
A single value (typically within a Bottle).
static const std::int32_t code
#define YARP_OS_LOG_COMPONENT(name, name_string)
void toBytes(yarp::os::Bytes &data)
std::int32_t subCoder(T &content)
virtual bool readRaw(ConnectionReader &connection)=0
virtual void appendText(const std::string &str, const char terminate='\n')=0
Send a terminated string to the network connection.
bool isFloat64(int index)
static StoreNull & getNull()
A class for storing options and configuration information.
bool isList() const override
Checks if value is a list.
Storable & get(size_type index) const
#define yCFatal(component,...)