diff --git a/example/os/bottle/bottle.cpp b/example/os/bottle/bottle.cpp index 28b96fdba6b..4544891b7cd 100644 --- a/example/os/bottle/bottle.cpp +++ b/example/os/bottle/bottle.cpp @@ -58,7 +58,7 @@ int main(int argc, char* argv[]) printf("pos group check: %s\n", b6.findGroup("pos").toString().c_str()); // see documentation for Bottle::findGroup printf("nested check: %s\n", b6.find("nested").toString().c_str()); - printf("nested height check: %d\n", b6.find("nested").find("height").asInt32()); + printf("nested height check: %d\n", b6.find("nested").asSearchable()->find("height").asInt32()); printf("\n"); diff --git a/src/devices/ServerInertial/ServerInertial.cpp b/src/devices/ServerInertial/ServerInertial.cpp index 3d366a61116..00679f19b4c 100644 --- a/src/devices/ServerInertial/ServerInertial.cpp +++ b/src/devices/ServerInertial/ServerInertial.cpp @@ -237,7 +237,7 @@ bool ServerInertial::openAndAttachSubDevice(yarp::os::Property& prop) p.put("device",subdevice.toString()); IMU_polydriver->open(p); } else { - IMU_polydriver->open(subdevice); + IMU_polydriver->open(*subdevice.asSearchable()); } if (!IMU_polydriver->isValid()) diff --git a/src/libYARP_companion/src/yarp/companion/impl/Companion.cmdPlugin.cpp b/src/libYARP_companion/src/yarp/companion/impl/Companion.cmdPlugin.cpp index 0a185e89dfe..d335be6bfa3 100644 --- a/src/libYARP_companion/src/yarp/companion/impl/Companion.cmdPlugin.cpp +++ b/src/libYARP_companion/src/yarp/companion/impl/Companion.cmdPlugin.cpp @@ -152,8 +152,8 @@ int Companion::cmdPlugin(int argc, char *argv[]) for (size_t i=0; iget(0).toString(); - std::string path = options.check("path", Value("unknown path")).asString(); - std::string type = options.check("type", Value("unknown type")).asString(); + std::string path = options.asSearchable()->check("path", Value("unknown path")).asString(); + std::string type = options.asSearchable()->check("type", Value("unknown type")).asString(); if (type == "shared") { yCInfo(COMPANION, " %15s:\t%s", name.c_str(), path.c_str()); } @@ -165,7 +165,7 @@ int Companion::cmdPlugin(int argc, char *argv[]) Bottle lst = selector.getSelectedPlugins(); for (size_t i=0; icheck("name", Value("untitled")).asString(); yCInfo(COMPANION, "%s", name.c_str()); } return 0; @@ -180,11 +180,11 @@ int Companion::cmdPlugin(int argc, char *argv[]) bool ok = true; for (size_t i=0; icheck("name", Value("untitled")).asString(); + std::string type = options.asSearchable()->check("type", Value("unknown type")).asString(); yCInfo(COMPANION); yCInfo(COMPANION, "%s %s", type.c_str(), name.c_str()); - yCInfo(COMPANION, " * ini file: %s", options.find("inifile").toString().c_str()); + yCInfo(COMPANION, " * ini file: %s", options.asSearchable()->find("inifile").toString().c_str()); options.asList()->pop(); yCInfo(COMPANION, " * config: %s", options.toString().c_str()); YarpPluginSettings settings; @@ -195,7 +195,7 @@ YARP_DISABLE_DEPRECATED_WARNING YARP_WARNING_POP #endif // YARP_NO_DEPRECATED settings.setSelector(selector); - settings.readFromSearchable(options, name); + settings.readFromSearchable(*options.asSearchable(), name); ok &= plugin_test(settings); } return ok ? 0 : 1; diff --git a/src/libYARP_dev/src/yarp/dev/Drivers.cpp b/src/libYARP_dev/src/yarp/dev/Drivers.cpp index 51f7a89317e..b498d2a3b4b 100644 --- a/src/libYARP_dev/src/yarp/dev/Drivers.cpp +++ b/src/libYARP_dev/src/yarp/dev/Drivers.cpp @@ -83,7 +83,7 @@ class Drivers::Private : public YarpPluginSelector { Bottle lst = getSelectedPlugins(); for (size_t i=0; icheck("name",Value("untitled")).asString(); if (done.check(name)) { continue; } @@ -91,7 +91,7 @@ class Drivers::Private : public YarpPluginSelector { SharedLibraryFactory lib; YarpPluginSettings settings; settings.setSelector(*this); - settings.readFromSearchable(prop,name); + settings.readFromSearchable(*prop.asSearchable(),name); settings.open(lib); std::string location = lib.getName(); if (location.empty()) { @@ -100,8 +100,8 @@ class Drivers::Private : public YarpPluginSelector { continue; } - std::string cxx = prop.check("cxx",Value("unknown")).asString(); - std::string wrapper = prop.check("wrapper",Value("unknown")).asString(); + std::string cxx = prop.asSearchable()->check("cxx",Value("unknown")).asString(); + std::string wrapper = prop.asSearchable()->check("wrapper",Value("unknown")).asString(); s += "Device \""; s += name; s += "\""; diff --git a/src/libYARP_manager/src/yarp/manager/xmlapploader.cpp b/src/libYARP_manager/src/yarp/manager/xmlapploader.cpp index 33cc79eb5e3..b57e4ac2659 100644 --- a/src/libYARP_manager/src/yarp/manager/xmlapploader.cpp +++ b/src/libYARP_manager/src/yarp/manager/xmlapploader.cpp @@ -567,8 +567,8 @@ Application* XmlAppLoader::parsXml(const char* szFile) for(size_t i=1; ifind("x").asFloat64(); + pt.y = pos.get(i).asSearchable()->find("y").asFloat64(); model.points.push_back(pt); } arbitrator.setModelBase(model); @@ -682,8 +682,8 @@ Application* XmlAppLoader::parsXml(const char* szFile) for(size_t i=1; ifind("x").asFloat64(); + pt.y = pos.get(i).asSearchable()->find("y").asFloat64(); model.points.push_back(pt); } connection.setModelBase(model); diff --git a/src/libYARP_manager/src/yarp/manager/yarpbroker.cpp b/src/libYARP_manager/src/yarp/manager/yarpbroker.cpp index e5276b4c375..af5651c3eb0 100644 --- a/src/libYARP_manager/src/yarp/manager/yarpbroker.cpp +++ b/src/libYARP_manager/src/yarp/manager/yarpbroker.cpp @@ -703,14 +703,14 @@ bool YarpBroker::getAllProcesses(const char* server, { Process proc; std::string sprc; - if (response.get(i).check("pid")) { - proc.pid = response.get(i).find("pid").asInt32(); + if (response.get(i).asSearchable()->check("pid")) { + proc.pid = response.get(i).asSearchable()->find("pid").asInt32(); } - if (response.get(i).check("cmd")) { - sprc = response.get(i).find("cmd").asString(); + if (response.get(i).asSearchable()->check("cmd")) { + sprc = response.get(i).asSearchable()->find("cmd").asString(); } - if (response.get(i).check("env") && response.get(i).find("env").asString().length()) { - sprc.append("; ").append(response.get(i).find("env").asString()); + if (response.get(i).asSearchable()->check("env") && response.get(i).asSearchable()->find("env").asString().length()) { + sprc.append("; ").append(response.get(i).asSearchable()->find("env").asString()); } proc.command = sprc; processes.push_back(proc); diff --git a/src/libYARP_os/src/yarp/os/Carriers.cpp b/src/libYARP_os/src/yarp/os/Carriers.cpp index 2ee7381cc17..bd866472fde 100644 --- a/src/libYARP_os/src/yarp/os/Carriers.cpp +++ b/src/libYARP_os/src/yarp/os/Carriers.cpp @@ -186,7 +186,7 @@ bool Carriers::Private::scanForCarrier(const Bytes& header) selector.scan(); Bottle lst = selector.getSelectedPlugins(); for (size_t i = 0; i < lst.size(); i++) { - if (checkForCarrier(header, lst.get(i))) { + if (checkForCarrier(header, *lst.get(i).asSearchable())) { return true; } } @@ -333,7 +333,7 @@ Bottle Carriers::listCarriers() Bottle plugins = instance.mPriv->getSelectedPlugins(); for (size_t i = 0; i < plugins.size(); i++) { Value& options = plugins.get(i); - std::string name = options.check("name", Value("untitled")).asString(); + std::string name = options.asSearchable()->check("name", Value("untitled")).asString(); if (done.check(name)) { continue; } @@ -341,7 +341,7 @@ Bottle Carriers::listCarriers() SharedLibraryFactory lib; YarpPluginSettings settings; settings.setSelector(*instance.mPriv); - settings.readFromSearchable(options, name); + settings.readFromSearchable(*options.asSearchable(), name); settings.open(lib); if (lib.getName().empty()) { continue; diff --git a/src/libYARP_os/src/yarp/os/NullConnectionReader.cpp b/src/libYARP_os/src/yarp/os/NullConnectionReader.cpp index 576717f1731..def60f578a1 100644 --- a/src/libYARP_os/src/yarp/os/NullConnectionReader.cpp +++ b/src/libYARP_os/src/yarp/os/NullConnectionReader.cpp @@ -115,5 +115,5 @@ void yarp::os::NullConnectionReader::requestDrop() const yarp::os::Searchable& yarp::os::NullConnectionReader::getConnectionModifiers() const { - return blank; + return *blank.asSearchable(); } diff --git a/src/libYARP_os/src/yarp/os/Value.cpp b/src/libYARP_os/src/yarp/os/Value.cpp index b7e2606e162..ed9c3cf8dc2 100644 --- a/src/libYARP_os/src/yarp/os/Value.cpp +++ b/src/libYARP_os/src/yarp/os/Value.cpp @@ -17,14 +17,12 @@ using namespace yarp::os::impl; Value::Value() : Portable(), - Searchable(), proxy(nullptr) { } Value::Value(std::int32_t x, bool isVocab32) : Portable(), - Searchable(), proxy(nullptr) { if (!isVocab32) { @@ -36,7 +34,6 @@ Value::Value(std::int32_t x, bool isVocab32) : Value::Value(yarp::conf::float64_t x) : Portable(), - Searchable(), proxy(nullptr) { setProxy(static_cast(makeFloat64(x))); @@ -44,7 +41,6 @@ Value::Value(yarp::conf::float64_t x) : Value::Value(const std::string& str, bool isVocab32) : Portable(), - Searchable(), proxy(nullptr) { if (!isVocab32) { @@ -56,7 +52,6 @@ Value::Value(const std::string& str, bool isVocab32) : Value::Value(void* data, int length) : Portable(), - Searchable(), proxy(nullptr) { setProxy(static_cast(makeBlob(data, length))); @@ -64,7 +59,6 @@ Value::Value(void* data, int length) : Value::Value(const Value& alt) : Portable(), - Searchable(alt), proxy(nullptr) { setProxy(static_cast(alt.clone())); @@ -251,11 +245,21 @@ Property* Value::asDict() const Searchable* Value::asSearchable() const { - ok(); + /* +ok(); if (proxy->isDict()) { return proxy->asDict(); } return proxy->asList(); +*/ + ok(); + if (proxy->isDict()) { + return proxy->asDict(); + } + if (proxy->isList()) { + return proxy->asList(); + } + return nullptr; } const char* Value::asBlob() const @@ -318,24 +322,6 @@ bool Value::write(ConnectionWriter& connection) const return proxy->write(connection); } -bool Value::check(const std::string& key) const -{ - ok(); - return proxy->check(key); -} - -Value& Value::find(const std::string& key) const -{ - ok(); - return proxy->find(key); -} - -Bottle& Value::findGroup(const std::string& key) const -{ - ok(); - return proxy->findGroup(key); -} - bool Value::operator==(const Value& alt) const { ok(); diff --git a/src/libYARP_os/src/yarp/os/Value.h b/src/libYARP_os/src/yarp/os/Value.h index a895ec163a8..7f2e4894a3c 100644 --- a/src/libYARP_os/src/yarp/os/Value.h +++ b/src/libYARP_os/src/yarp/os/Value.h @@ -29,21 +29,23 @@ class Storable; namespace yarp::os { +class stringConvertible +{ + public: + virtual std::string toString() const = 0; +}; /** * A single value (typically within a Bottle). Values can be integers, strings, * doubles (floating-point numbers), lists, vocabulary, or blobs * (unformatted binary data). This set is carefully chosen to have * good text and binary representations both for network transmission * and human viewing/generation. Lists are represented as a nested - * Bottle object. Value objects are Searchable - but you won't - * find anything in them unless they are actually a list. + * Bottle object. * */ -class YARP_os_API Value : public Portable, public Searchable +class YARP_os_API Value : public Portable, stringConvertible { public: - using Searchable::check; - using Searchable::findGroup; /** * Construct a list Value @@ -178,6 +180,12 @@ class YARP_os_API Value : public Portable, public Searchable */ virtual bool isBlob() const; + /** + * Checks if value is null. + * @return true iff value is null. + */ + virtual bool isNull() const; + /** * Get boolean value. * @return boolean value if value is indeed a boolean. @@ -306,15 +314,6 @@ class YARP_os_API Value : public Portable, public Searchable // documented in Portable bool write(ConnectionWriter& connection) const override; - // documented in Searchable - bool check(const std::string& key) const override; - - // documented in Searchable - Value& find(const std::string& key) const override; - - // documented in Searchable - Bottle& findGroup(const std::string& key) const override; - /** * Equality test. * @param alt the value to compare against @@ -357,8 +356,6 @@ class YARP_os_API Value : public Portable, public Searchable */ virtual std::int32_t getCode() const; - bool isNull() const override; - virtual bool isLeaf() const; /** diff --git a/src/libYARP_os/src/yarp/os/YarpNameSpace.h b/src/libYARP_os/src/yarp/os/YarpNameSpace.h index 57efe0d3690..a200e7e7825 100644 --- a/src/libYARP_os/src/yarp/os/YarpNameSpace.h +++ b/src/libYARP_os/src/yarp/os/YarpNameSpace.h @@ -123,6 +123,10 @@ class YARP_os_API YarpNameSpace : public NameSpace ContactStyle style; ok = NetworkBase::writeToNameServer(cmd, reply, style); } +//// + std::string ss= reply.toString(); + fprintf(stderr, ss.c_str()); +//// bool fail = (reply.get(0).toString() == "fail") || !ok; if (fail) { if (!style.quiet) { diff --git a/src/libYARP_os/src/yarp/os/YarpPlugin.cpp b/src/libYARP_os/src/yarp/os/YarpPlugin.cpp index 9cdaf33aa3f..44972710522 100644 --- a/src/libYARP_os/src/yarp/os/YarpPlugin.cpp +++ b/src/libYARP_os/src/yarp/os/YarpPlugin.cpp @@ -89,9 +89,9 @@ bool YarpPluginSettings::open(SharedLibraryFactory& factory) // and a proper name for the DLL Bottle paths = selector->getSearchPath(); for (size_t i = 0; i < paths.size(); i++) { - Searchable& options = paths.get(i); - std::string path = options.find("path").asString(); - std::string ext = options.find("extension").asString(); + Searchable* options = paths.get(i).asSearchable(); + std::string path = options->find("path").asString(); + std::string ext = options->find("extension").asString(); std::string basename = (dll_name.find('.') != std::string::npos) ? name : dll_name; std::string fn = (fn_name.empty()) ? name : fn_name; diff --git a/src/libYARP_os/src/yarp/os/YarpPluginSelector.h b/src/libYARP_os/src/yarp/os/YarpPluginSelector.h index 27afdfbf57f..773b90609a2 100644 --- a/src/libYARP_os/src/yarp/os/YarpPluginSelector.h +++ b/src/libYARP_os/src/yarp/os/YarpPluginSelector.h @@ -84,11 +84,11 @@ class YARP_os_API YarpPluginSelector const yarp::os::Bottle lst = selector.getSelectedPlugins(); for (size_t i = 0; i < lst.size(); i++) { const yarp::os::Value& options = lst.get(i); - if (name == options.check("name", yarp::os::Value("untitled")).asString()) { + if (name == options.asSearchable()->check("name", yarp::os::Value("untitled")).asString()) { if (!type.empty()) { return true; } - if (type == options.check("type", yarp::os::Value("untitled")).asString()) { + if (type == options.asSearchable()->check("type", yarp::os::Value("untitled")).asString()) { return true; } } diff --git a/src/libYARP_os/src/yarp/os/impl/Storable.cpp b/src/libYARP_os/src/yarp/os/impl/Storable.cpp index 1e77d71c893..47d31beb572 100644 --- a/src/libYARP_os/src/yarp/os/impl/Storable.cpp +++ b/src/libYARP_os/src/yarp/os/impl/Storable.cpp @@ -117,28 +117,6 @@ Storable* Storable::createByCode(std::int32_t id) return storable; } -Value& Storable::find(const std::string& key) const -{ - YARP_UNUSED(key); - return BottleImpl::getNull(); -} - -Bottle& Storable::findGroup(const std::string& key) const -{ - YARP_UNUSED(key); - return Bottle::getNullBottle(); -} - -bool Storable::check(const std::string& key) const -{ - Bottle& val = findGroup(key); - if (!val.isNull()) { - return true; - } - Value& val2 = find(key); - return !val2.isNull(); -} - bool Storable::operator==(const Value& alt) const { return toString() == alt.toString(); diff --git a/src/libYARP_os/src/yarp/os/impl/Storable.h b/src/libYARP_os/src/yarp/os/impl/Storable.h index 4e31720deb1..3a40db16596 100644 --- a/src/libYARP_os/src/yarp/os/impl/Storable.h +++ b/src/libYARP_os/src/yarp/os/impl/Storable.h @@ -226,12 +226,6 @@ class YARP_os_impl_API Storable : public yarp::os::Value } return asList(); } - using yarp::os::Searchable::check; - bool check(const std::string& key) const override; - - yarp::os::Value& find(const std::string& key) const override; - yarp::os::Bottle& findGroup(const std::string& key) const override; - /** * Initialize from a string representation, assuming that any @@ -1082,16 +1076,6 @@ class YARP_os_impl_API StoreList : } std::int32_t subCode() const override; - - yarp::os::Value& find(const std::string& key) const override - { - return content.find(key); - } - - yarp::os::Bottle& findGroup(const std::string& key) const override - { - return content.findGroup(key); - } }; @@ -1145,16 +1129,6 @@ class YARP_os_impl_API StoreDict : { return const_cast(&content); } - - yarp::os::Value& find(const std::string& key) const override - { - return content.find(key); - } - - yarp::os::Bottle& findGroup(const std::string& key) const override - { - return content.findGroup(key); - } }; diff --git a/src/robottestingframework-plugins/fixture-managers/yarpplugin/YarpPluginFixture.cpp b/src/robottestingframework-plugins/fixture-managers/yarpplugin/YarpPluginFixture.cpp index 517d197ee57..8a7d828d069 100644 --- a/src/robottestingframework-plugins/fixture-managers/yarpplugin/YarpPluginFixture.cpp +++ b/src/robottestingframework-plugins/fixture-managers/yarpplugin/YarpPluginFixture.cpp @@ -29,18 +29,25 @@ bool YarpPluginFixture::scanPlugins(std::string name, std::string type) bool res=false; for (size_t i=0; icheck("name", Value("untitled")).asString() && type == options->check("type", Value("untitled")).asString()) { + res = true; + } + } + else + { + if (name == options->check("name", Value("untitled")).asString()) { + res = true; + } } } else { - if (name == options.check("name", Value("untitled")).asString()) { - res = true; - } + ROBOTTESTINGFRAMEWORK_ASSERT_ERROR("YarpPluginFixture::scanPlugins: internal error"); } } return res; diff --git a/tests/libYARP_os/BottleTest.cpp b/tests/libYARP_os/BottleTest.cpp index f1e9b87beb1..d5164214a0e 100644 --- a/tests/libYARP_os/BottleTest.cpp +++ b/tests/libYARP_os/BottleTest.cpp @@ -147,6 +147,14 @@ TEST_CASE("os::BottleTest", "[yarp::os]") CHECK(bot2.size() == (size_t) 1); // "self copy" } +/* + //this does not work but it should!!!!!!! + SECTION("testing check") + { + Bottle bot("green"); + CHECK(bot.check("green")); + } +*/ SECTION("testing find") { Bottle bot("(hello friend) (say 12 13) green 255 blue 19"); @@ -489,9 +497,9 @@ TEST_CASE("os::BottleTest", "[yarp::os]") SECTION("test infinite loop tickled by yarpmanager + string type change") { Bottle pos("Pos ((x 349.5) (y 122)) ((x 286) (y 122)) ((x 413) (y 122))"); - CHECK(pos.get(1).find("x").asFloat64() == Approx(349.5)); - CHECK(pos.get(2).find("x").asFloat64() == Approx(286.0)); - CHECK(pos.get(3).find("x").asFloat64() == Approx(413.0)); + CHECK(pos.get(1).asSearchable()->find("x").asFloat64() == Approx(349.5)); + CHECK(pos.get(2).asSearchable()->find("x").asFloat64() == Approx(286.0)); + CHECK(pos.get(3).asSearchable()->find("x").asFloat64() == Approx(413.0)); } SECTION("test a string with several minus characters")