Skip to content
Snippets Groups Projects
Commit b7324a31 authored by Florent Lamiraux's avatar Florent Lamiraux
Browse files

Merge branch 'topic/proto-command' into topic/singleton

Conflicts:
	tests/entity.cpp
parents 71bf1af7 12c5bfcf
No related branches found
Tags v2.5
No related merge requests found
......@@ -71,7 +71,6 @@ namespace dynamicgraph
/// customize the command-line by overriding commandLine ().
class DYNAMIC_GRAPH_DLLAPI Entity : private boost::noncopyable
{
DYNAMIC_GRAPH_ENTITY_DECL ();
public:
typedef std::map< std::string,SignalBase<int>* > SignalMap;
typedef std::map<const std::string, command::Command*> CommandMap_t;
......@@ -83,6 +82,7 @@ namespace dynamicgraph
{
return name;
}
virtual const std::string& getClassName () const = 0;
SignalBase<int>& getSignal (const std::string& signalName);
const SignalBase<int>& getSignal (const std::string& signalName) const;
......
......@@ -34,9 +34,6 @@ using namespace std;
using namespace dynamicgraph;
using dynamicgraph::command::Command;
const std::string Entity::CLASS_NAME = "Entity";
void Entity::
entityRegistration ()
{
......@@ -58,7 +55,7 @@ Entity( const string& name__ )
if( name.length ()==0 )
{
stringstream oss; oss << rand ();
name = this->getClassName();
//name = this->getClassName(); Cannot call a virtual function from the constructor
name+="::";
name+=oss.str ();
}
......
......@@ -26,33 +26,43 @@
using boost::test_tools::output_test_stream;
extern "C" {
dynamicgraph::Entity* EntityMaker_Entity(const std::string& objname)
namespace dynamicgraph
{
class CustomEntity : public Entity
{
return new dynamicgraph::Entity (objname);
}
public:
static const std::string CLASS_NAME;
virtual const std::string& getClassName () const
{
return CLASS_NAME;
}
CustomEntity (const std::string n)
: Entity (n)
{
}
};
DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN (CustomEntity,"CustomEntity");
}
BOOST_AUTO_TEST_CASE (constructor)
{
dynamicgraph::FactoryStorage::getInstance()->registerEntity
(dynamicgraph::Entity::CLASS_NAME, &EntityMaker_Entity);
BOOST_CHECK_EQUAL (dynamicgraph::Entity::CLASS_NAME, "Entity");
BOOST_CHECK_EQUAL (dynamicgraph::CustomEntity::CLASS_NAME, "CustomEntity");
dynamicgraph::Entity& entity =
*dynamicgraph::FactoryStorage::getInstance()->newEntity("Entity",
*dynamicgraph::FactoryStorage::getInstance()->newEntity("CustomEntity",
"my-entity");
BOOST_CHECK_EQUAL (entity.getName (), "my-entity");
BOOST_CHECK_EQUAL (entity.getClassName (), dynamicgraph::Entity::CLASS_NAME);
BOOST_CHECK_EQUAL (entity.getClassName (),
dynamicgraph::CustomEntity::CLASS_NAME);
dynamicgraph::Entity entity2 ("");
dynamicgraph::CustomEntity entity2 ("");
}
BOOST_AUTO_TEST_CASE (signal)
{
dynamicgraph::Entity& entity =
*dynamicgraph::FactoryStorage::getInstance()->newEntity("Entity", "");
dynamicgraph::PoolStorage::getInstance()->getEntity("my-entity");
// Non const getter.
try
......@@ -99,7 +109,7 @@ BOOST_AUTO_TEST_CASE (display)
output_test_stream output;
entity.display(output);
BOOST_CHECK (output.is_equal ("Entity: my-entity"));
BOOST_CHECK (output.is_equal ("CustomEntity: my-entity"));
}
BOOST_AUTO_TEST_CASE (getCommandList)
......@@ -140,7 +150,7 @@ BOOST_AUTO_TEST_CASE (commandLine_print)
std::istringstream args;
entity.commandLine("print", args, output);
BOOST_CHECK (output.is_equal ("Entity: my-entity\n"));
BOOST_CHECK (output.is_equal ("CustomEntity: my-entity\n"));
}
BOOST_AUTO_TEST_CASE (commandLine_signals)
......
......@@ -26,9 +26,29 @@
using boost::test_tools::output_test_stream;
namespace dynamicgraph
{
class CustomEntity : public Entity
{
public:
static const std::string CLASS_NAME;
virtual const std::string& getClassName () const
{
return CLASS_NAME;
}
CustomEntity (const std::string n)
: Entity (n)
{
}
};
const std::string CustomEntity::CLASS_NAME = "CustomEntity";
}
dynamicgraph::Entity* makeEntity(const std::string& objectName)
{
return new dynamicgraph::Entity (objectName);
return new dynamicgraph::CustomEntity (objectName);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment