25 Entity::Entity(yarp::os::Bottle &b)
34 this->m_entity_type =
"unknown";
40 this->m_name = b.m_name;
42 this->m_opc_id = b.m_opc_id;
45 Bottle Entity::asBottle()
const 50 bName.addString(
"name");
51 bName.addString(m_name.c_str());
55 bEntity.addString(
"entity");
56 bEntity.addString(m_entity_type.c_str());
57 b.addList() = bEntity;
60 bProperties.addString(
"intrinsic_properties");
61 Bottle& bPropertiesGlob = bProperties.addList();
62 for(
auto& m_property : m_properties)
64 Bottle bPropertiesValues;
65 bPropertiesValues.addString(m_property.first.c_str());
66 bPropertiesValues.addString(m_property.second.c_str());
67 bPropertiesGlob.addList() = bPropertiesValues;
69 b.addList() = bProperties;
73 Bottle Entity::asBottleOnlyModifiedProperties()
const 75 Bottle current_entity = this->asBottle();
78 for(
unsigned int p=0; p<current_entity.size(); p++)
80 string currentTag = current_entity.get(p).asList()->get(0).asString();
81 Value ¤tValue = current_entity.find(currentTag.c_str());
82 Value &originalValue = m_original_entity.find(currentTag.c_str());
84 if (currentValue.toString() != originalValue.toString())
86 Bottle &bSub=new_entity.addList();
87 bSub.addString(currentTag);
88 bSub.add(currentValue);
95 bool Entity::fromBottle(
const Bottle &b)
97 if (!b.check(
"name") || !b.check(
"entity"))
101 m_name = b.find(
"name").asString().c_str();
102 m_entity_type = b.find(
"entity").asString().c_str();
104 Bottle* bProperties = b.find(
"intrinsic_properties").asList();
106 for(
unsigned int i=0; i< bProperties->size() ; i++)
108 std::string pTag = bProperties->get(i).asList()->get(0).asString().c_str();
109 std::string pVal = bProperties->get(i).asList()->get(1).asString().c_str();
110 m_properties[pTag] = pVal;
116 string Entity::toString()
const 118 std::ostringstream oss;
119 oss <<
"**************"<<endl;
120 oss <<
"Name : " << m_name<<endl;
121 oss <<
"ID : " << m_opc_id<<endl;
122 oss <<
"Type : " << m_entity_type<<endl;
123 oss <<
"Intrinsic properties: "<<endl;
124 for(
const auto& prop : m_properties) {
125 oss<<
'\t'<<prop.first<<
" : "<<prop.second<<endl;
131 bool Entity::operator==(
const Entity &b)
const 133 return (this->m_opc_id == b.m_opc_id);
137 bool Entity::operator<(
const Entity &b)
const 139 return (this->m_opc_id < b.m_opc_id );
143 bool Entity::operator>(
const Entity &b)
const 145 return (this->m_opc_id > b.m_opc_id );
149 void Entity::changeName(std::string sName)
Represent any entity that can be stored within the OPC.
std::string m_entity_type