From 833193342f093f742835401b443e5db3b0e9954b Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Sat, 18 Mar 2017 03:20:05 +0100 Subject: [PATCH] Commands: define basic properties of unbound CommandSetup --- src/proc/cmd.hpp | 1 + src/proc/control/command-setup.cpp | 9 ++++- src/proc/control/command-setup.hpp | 34 +++++++++++++++---- .../core/proc/control/command-setup-test.cpp | 31 ++++++++++++++++- 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/src/proc/cmd.hpp b/src/proc/cmd.hpp index c6cab24f7..b272a71d7 100644 --- a/src/proc/cmd.hpp +++ b/src/proc/cmd.hpp @@ -55,6 +55,7 @@ namespace cmd { // using std::string; // using lib::Symbol; using control::Command; + using control::CommandSetup; //using std::shared_ptr; diff --git a/src/proc/control/command-setup.cpp b/src/proc/control/command-setup.cpp index ab3828224..73adbc2c7 100644 --- a/src/proc/control/command-setup.cpp +++ b/src/proc/control/command-setup.cpp @@ -36,6 +36,7 @@ #include "lib/error.hpp" //#include "lib/symbol.hpp" //#include "lib/format-string.hpp" +#include "proc/control/command-setup.hpp" #include "proc/control/command-instance-manager.hpp" //#include @@ -60,9 +61,15 @@ namespace control { /** storage for.... */ + CommandSetup::~CommandSetup() { } + + CommandSetup::CommandSetup(Literal cmdID) + : cmdID_(cmdID) + { } + + // emit dtors of embedded objects here.... CommandInstanceManager::~CommandInstanceManager() { } - CommandSetup::~CommandSetup() { } CommandInstanceManager::CommandInstanceManager() { } diff --git a/src/proc/control/command-setup.hpp b/src/proc/control/command-setup.hpp index 19fc759d0..43bf39bf8 100644 --- a/src/proc/control/command-setup.hpp +++ b/src/proc/control/command-setup.hpp @@ -55,11 +55,11 @@ #include "lib/error.hpp" #include "proc/control/command.hpp" -//#include "lib/symbol.hpp" +#include "lib/symbol.hpp" //#include "proc/common.hpp" #include -//#include +#include @@ -67,8 +67,9 @@ namespace proc { namespace control { -// using std::string; + using std::string; // using lib::Symbol; + using lib::Literal; //using std::shared_ptr; @@ -77,15 +78,36 @@ namespace control { * @todo write type comment */ class CommandSetup - : boost::noncopyable { + Literal cmdID_; public: - ~CommandSetup(); + CommandSetup (Literal cmdID); + CommandSetup (CommandSetup const&) = delete; + CommandSetup (CommandSetup &&) = default; + CommandSetup& operator= (CommandSetup const&) = delete; + + operator Literal const&() const + { + return cmdID_; + } + operator string() const + { + return string{cmdID_}; + } - private: + friend bool + operator== (CommandSetup const& left, CommandSetup const& right) + { + return left.cmdID_ == right.cmdID_; + } + friend bool + operator!= (CommandSetup const& left, CommandSetup const& right) + { + return left.cmdID_ != right.cmdID_; + } }; diff --git a/tests/core/proc/control/command-setup-test.cpp b/tests/core/proc/control/command-setup-test.cpp index 9a7337fad..a07e80356 100644 --- a/tests/core/proc/control/command-setup-test.cpp +++ b/tests/core/proc/control/command-setup-test.cpp @@ -31,6 +31,7 @@ //#include "lib/p.hpp" //#include +#include //using std::rand; @@ -43,6 +44,8 @@ namespace test { //using lib::time::TimeVar; //using lib::time::TimeValue; //using lib::time::Offset; + using lib::Literal; + using std::string; @@ -78,7 +81,33 @@ namespace test { void verify_DefinitionSetup() { - UNIMPLEMENTED("create CommandSetup instances"); + // can be created from arbitrary character literal + CommandSetup def_empty{"to be or not to be"}; + + // at runtime it is nothing but a dressed-up C-string + Literal empty_text = def_empty; + CHECK (empty_text == "to be or not to be"); + CHECK (sizeof(def_empty) == sizeof(Literal)); + CHECK (sizeof(def_empty) == sizeof(char*)); + + const char* actualContent = reinterpret_cast(def_empty); + CHECK (actualContent == empty_text); + + // for convenience a string conversion is provided... + CHECK (string(def_empty) == string(empty_text)); + + // can be equality compared based on sting (ID) content + CHECK (def_empty == CommandSetup("to be or not to be")); + CHECK (def_empty != CommandSetup("to pee or not to pee")); + + + CommandSetup def_0{"test.CommandSetup.def_0"}; + CommandSetup def_1{"test.CommandSetup.def_1"}; + CommandSetup def_2{"test.CommandSetup.def_2"}; + +//////////// does not compile -- copy is prohibited... +// CommandSetup empty2{def_empty}; +// def_empty = def_1; }