47 backing = std::make_unique<Property>(*(
rhs.backing));
56 backing = std::make_unique<Property>(*(
rhs.backing));
102 std::map<std::string, PropertyItem>
data;
130 return &(
entry->second);
133 void put(
const std::string& key,
const std::string& val)
138 p->bot.addString(key);
139 p->bot.addString(val);
147 p->bot.addString(key);
156 p->bot.addString(key);
165 p->bot.addString(key);
166 p->backing = std::make_unique<Property>();
167 return *(
p->backing);
175 bool check(
const std::string& key)
const
186 return p->bot.get(1);
248 for (
int i = 0;
i < argc;
i++) {
249 std::string
work = argv[
i];
251 if (
work.length() >= 2) {
252 if (
work[0] ==
'-' &&
work[1] ==
'-') {
255 if (
work.find(
"::") != std::string::npos) {
267 if (
work.find(
'\\') != std::string::npos) {
272 for (
char i :
work) {
294 for (
size_t i = 0;
i <
total.size();
i++) {
297 if (
term ==
nullptr) {
300 std::string key =
term->get(0).asString();
301 std::string base = key;
302 while (key.length() > 0) {
304 size_t at = key.find(
"::");
305 if (at != std::string::npos) {
306 base = key.substr(0, at);
307 key = key.substr(at + 2);
313 if (cursor ==
nullptr) {
323 if (cursor !=
nullptr) {
330 bool readDir(
const std::string&
dirname, yarp::os::impl::DIR*&
dir, std::string& result,
const std::string&
section = std::string())
336 yarp::os::impl::closedir(
dir);
338 int n = yarp::os::impl::scandir(
dirname.c_str(), &
namelist,
nullptr, yarp::os::impl::alphasort);
342 for (
int i = 0;
i <
n;
i++) {
345 auto len =
static_cast<int>(name.length());
349 if (name.substr(len - 4) !=
".ini") {
353 std::replace(
fname.begin(),
fname.end(),
'\\',
'/');
358 result.append(
"[include ").append(
section).append(
" \"").append(
fname).append(
"\" \"").append(
fname).append(
"\"]\n");
368 yarp::os::impl::DIR*
dir = yarp::os::impl::opendir(
fname.c_str());
369 if (
dir !=
nullptr) {
375 if (
fin ==
nullptr) {
379 while (
fgets(buf,
sizeof(buf) - 1,
fin) !=
nullptr) {
391 "path to search for config files")
403 std::string
trial = s;
420 size_t index =
fname.rfind(
'/');
421 if (index == std::string::npos) {
422 index =
fname.rfind(
'\\');
424 if (index != std::string::npos) {
425 path =
fname.substr(0, index);
457 yarp::os::impl::DIR*
dir = yarp::os::impl::opendir(
dirname.c_str());
458 if (
dir ==
nullptr) {
499 if (buf.find(
"//") != std::string::npos || buf.find(
'#') != std::string::npos) {
503 for (
unsigned int i = 0;
i < buf.length();
i++) {
512 buf = buf.substr(0,
i - 1);
521 buf = buf.substr(0,
i - 1);
526 prespace = (ch ==
' ' || ch ==
'\t');
537 if (buf.length() > 0 && buf[0] ==
'[') {
538 size_t stop = buf.find(
']');
539 if (stop != std::string::npos) {
540 buf = buf.substr(1, stop - 1);
541 size_t space = buf.find(
' ');
542 if (space != std::string::npos) {
545 if (bot.
size() > 1) {
551 if (
accum.size() >= 1) {
578 if (
accum.size() >= 1) {
583 if (bot.
size() > 2) {
586 if (bot.
size() == 3) {
592 }
else if (bot.
size() == 4) {
599 if (target ==
nullptr) {
619 p.toString().c_str());
622 accum.fromString(
p.toString());
626 accum.toString().c_str());
628 if (
accum.size() >= 1) {
653 if (target ==
nullptr) {
673 if (bot.
size() >= 1) {
679 for (
size_t i = 0;
i < bot.
size();
i++) {
685 accum.addList().copy(bot);
692 if (
accum.size() >= 1) {
699 accum.addString(tag);
705 "MERGE %s, got %s\n",
707 accum.toString().c_str());
719 for (
size_t i = 0;
i < bot.
size();
i++) {
731 for (
const auto&
it :
data) {
744 std::string input = txt;
745 if (input.find(
'$') == std::string::npos) {
755 for (
size_t i = 0;
i <= input.length();
i++) {
757 if (
i < input.length()) {
780 if ((
isalnum(ch) != 0) || (ch ==
'_')) {
784 if (ch ==
'(' || ch ==
'{') {
785 if (var.length() == 0) {
795 add =
env.find(var).toString();
798 add =
env2.find(var).toString();
801 if (var ==
"__YARP__") {
805 if (add.find(
'\\') != std::string::npos) {
842 char**
szarg =
new char*[128 + 1];
865 for (
i = 0;
i < len;
i++) {
886 if (
nullptr != argv[*argc]) {
891 for (
j = 0;
j < *argc;
j++) {
893 for (
i = 0;
i < len;
i++) {
894 if (
'\1' == argv[
j][
i]) {
904 if (
pTmp !=
nullptr) {
907 while (*
pTmp ==
' ') {
948 prop.mPriv =
nullptr;
956 for (
const auto& val :
values) {
957 put(val.first, val.second);
970 Portable::operator=(
static_cast<const Portable&
>(
rhs));
971 mPriv->data =
rhs.mPriv->data;
980 Portable::operator=(std::move(
static_cast<Portable&
>(
rhs)));
981 std::swap(mPriv,
rhs.mPriv);
989 mPriv->put(key, value);
994 mPriv->put(key, value);
1000 mPriv->put(key, value);
1015 return mPriv->check(key);
1025 return mPriv->get(key);
1037 mPriv->fromString(txt,
wipe);
1043 return mPriv->toString();
1052 mPriv->fromCommand(argc, argv,
wipe);
1062 mPriv->fromArguments(arguments,
wipe);
1090 mPriv->fromConfig(txt,
env,
wipe);
1098 bool ok = b.
read(reader);
1110 return b.
write(writer);
1116 Bottle* result = mPriv->getBottle(key);
1117 if (result !=
nullptr) {
1129 std::string str = url;
1137 for (
char ch : str) {
1143 }
else if (ch ==
'&') {
1147 if (!key.empty() && !val.empty()) {
1151 }
else if (ch ==
'?') {
1156 }
else if (ch ==
'%') {
1161 if (ch >=
'0' && ch <=
'9') {
1164 if (ch >=
'A' && ch <=
'F') {
1165 hex = ch -
'A' + 10;
1167 if (ch >=
'a' && ch <=
'f') {
1168 hex = ch -
'a' + 10;
std::string toString() const
PropertyItem(PropertyItem &&rhs) noexcept=default
PropertyItem & operator=(const PropertyItem &rhs)
PropertyItem & operator=(PropertyItem &&rhs) noexcept=default
PropertyItem(const PropertyItem &rhs)
std::unique_ptr< Property > backing
void unput(const std::string &key)
void fromCommand(int argc, char *argv[], bool wipe=true)
void put(const std::string &key, const Value &bit)
Value & get(const std::string &key) const
Bottle * getBottle(const std::string &key) const
void parseArguments(char *azParam, int *argc, char **argv, int max_arg)
Property & addGroup(const std::string &key)
std::string toString() const
bool check(const std::string &key) const
void put(const std::string &key, const std::string &val)
void fromArguments(const char *command, bool wipe=true)
bool fromConfigDir(const std::string &dirname, const std::string §ion, bool wipe=true)
void fromConfig(const char *txt, Searchable &env, bool wipe=true)
void fromBottle(Bottle &bot, bool wipe=true)
Bottle & putBottle(const char *key)
void fromString(const std::string &txt, bool wipe=true)
std::map< std::string, PropertyItem > data
PropertyItem * getProp(const std::string &key, bool create=true)
bool fromConfigFile(const std::string &fname, Searchable &env, bool wipe=true)
PropertyItem * getPropNoCreate(const std::string &key) const
Bottle & putBottleCompat(const char *key, const Bottle &val)
bool readDir(const std::string &dirname, yarp::os::impl::DIR *&dir, std::string &result, const std::string §ion=std::string())
Bottle & putBottle(const char *key, const Bottle &val)
std::string expand(const char *txt, Searchable &env, Searchable &env2)
void put(const std::string &key, Value *bit)
bool readFile(const std::string &fname, std::string &result, bool allowDir)
void splitArguments(char *line, char **args)
A simple collection of objects that can be described and transmitted in a portable way.
static Bottle & getNullBottle()
A special Bottle with no content.
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
void fromString(const std::string &text)
Initializes bottle from a string.
void append(const Bottle &alt)
Append the content of the given bottle to the current list.
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
size_type size() const
Gets the number of elements in the bottle.
bool read(ConnectionReader &reader) override
Set the bottle's value based on input from a network connection.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
void copy(const Bottle &alt, size_type first=0, size_type len=npos)
Copy all or part of another Bottle.
Bottle tail() const
Get all but the first element of a bottle.
bool write(ConnectionWriter &writer) const override
Output a representation of the bottle to a network connection.
bool isNull() const override
Checks if the object is invalid.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
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.
This is a base class for objects that can be both read from and be written to the YARP network.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
std::string toString() const override
Return a standard text representation of the content of the object.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
bool fromConfigFile(const std::string &fname, bool wipe=true)
Interprets a file as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
void fromConfig(const char *txt, bool wipe=true)
Parses text in the configuration format described in fromConfigFile().
bool check(const std::string &key) const override
Check if there exists a property of the given name.
Property & operator=(const Property &prop)
Copy assignment operator.
bool write(ConnectionWriter &writer) const override
Write this object to a network connection.
bool read(ConnectionReader &reader) override
Read this object from a network connection.
bool fromConfigDir(const std::string &dirname, const std::string §ion=std::string(), bool wipe=true)
Interprets all files in a directory as lists of properties as described in fromConfigFile().
void clear()
Remove all associations.
void fromArguments(const char *arguments, bool wipe=true)
Interprets a list of command arguments as a list of properties.
~Property() override
Destructor.
Property & addGroup(const std::string &key)
Add a nested group.
Bottle & findGroup(const std::string &key) const override
Gets a list corresponding to a given keyword.
void fromQuery(const char *url, bool wipe=true)
Parses text in a url.
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
void fromCommand(int argc, char *argv[], bool skipFirst=true, bool wipe=true)
Interprets a list of command arguments as a list of properties.
Helper class for finding config files and other external resources.
bool setDefaultContext(const std::string &contextName)
Sets the context for the current ResourceFinder object.
bool configure(int argc, char *argv[], bool skipFirstArgument=true)
Sets up the ResourceFinder.
std::string findFile(const std::string &name)
Find the full path to a file.
bool setDefaultConfigFile(const std::string &fname)
Provide a default value for the configuration file (can be overridden from command line with the –fro...
A base class for nested structures that can be searched.
Searchable & operator=(const Searchable &rhs)=default
Copy assignment operator.
A single value (typically within a Bottle).
static Value * makeFloat64(yarp::conf::float64_t x)
Create a 64-bit floating point Value.
static Value * makeValue(const std::string &txt)
Create a Value from a text description.
static Value & getNullValue()
Return an invalid, "null" Value.
std::string toString() const override
Return a standard text representation of the content of the object.
static Value * makeInt32(std::int32_t x)
Create a 32-bit integer Value.
virtual std::string asString() const
Get string value.
static bool isComplete(const char *txt)
#define yCError(component,...)
#define yCAssert(component, x)
#define yCTrace(component,...)
#define yCWarning(component,...)
#define yCDebug(component,...)
#define YARP_OS_LOG_COMPONENT(name, name_string)
std::string get_string(const std::string &key, bool *found=nullptr)
Read a string from an environment variable.
ContainerT split(const typename ContainerT::value_type &s, std::basic_regex< typename ContainerT::value_type::value_type > regex)
Utility to split a string by a separator, into a vector of strings.
The components from which ports and connections are built.
An interface to the operating system, including Port based communication.