Atlas  0.7.0
Networking protocol for the Worldforge system.
RootEntity.cpp
1 // This file may be redistributed and modified only under the terms of
2 // the GNU Lesser General Public License (See COPYING for details).
3 // Copyright 2000-2001 Stefanus Du Toit and Aloril.
4 // Copyright 2001-2005 Alistair Riddoch.
5 // Copyright 2011-2020 Erik Ogenvik.
6 // Automatically generated using gen_cpp.py. Don't edit directly.
7 
8 #include <Atlas/Objects/RootEntity.h>
9 
11 using Atlas::Message::MapType;
12 
13 namespace Atlas { namespace Objects { namespace Entity {
14 
15 const std::string LOC_ATTR = "loc";
16 const std::string POS_ATTR = "pos";
17 const std::string VELOCITY_ATTR = "velocity";
18 const std::string CONTAINS_ATTR = "contains";
19 const std::string STAMP_CONTAINS_ATTR = "stamp_contains";
20 
21 int RootEntityData::getAttrClass(const std::string& name) const
22 {
23  if (allocator.attr_flags_Data.find(name) != allocator.attr_flags_Data.end()) {
24  return ROOT_ENTITY_NO;
25  }
26  return RootData::getAttrClass(name);
27 }
28 
29 bool RootEntityData::getAttrFlag(const std::string& name, uint32_t& flag) const
30 {
31  auto I = allocator.attr_flags_Data.find(name);
32  if (I != allocator.attr_flags_Data.end()) {
33  flag = I->second;
34  return true;
35  }
36  return RootData::getAttrFlag(name, flag);
37 }
38 
39 int RootEntityData::copyAttr(const std::string& name, Element & attr) const
40 {
41  if (name == LOC_ATTR) { attr = getLoc(); return 0; }
42  if (name == POS_ATTR) { attr = getPosAsList(); return 0; }
43  if (name == VELOCITY_ATTR) { attr = getVelocityAsList(); return 0; }
44  if (name == CONTAINS_ATTR) { attr = getContainsAsList(); return 0; }
45  if (name == STAMP_CONTAINS_ATTR) { attr = getStampContains(); return 0; }
46  return RootData::copyAttr(name, attr);
47 }
48 
49 void RootEntityData::setAttr(std::string name, Element attr, const Atlas::Objects::Factories* factories)
50 {
51  if (name == LOC_ATTR) { setLoc(attr.moveString()); return; }
52  if (name == POS_ATTR) { setPosAsList(attr.moveList()); return; }
53  if (name == VELOCITY_ATTR) { setVelocityAsList(attr.moveList()); return; }
54  if (name == CONTAINS_ATTR) { setContainsAsList(attr.moveList()); return; }
55  if (name == STAMP_CONTAINS_ATTR) { setStampContains(attr.asFloat()); return; }
56  RootData::setAttr(std::move(name), std::move(attr), factories);
57 }
58 
59 void RootEntityData::removeAttr(const std::string& name)
60 {
61  if (name == LOC_ATTR)
62  { m_attrFlags &= ~LOC_FLAG; return;}
63  if (name == POS_ATTR)
64  { m_attrFlags &= ~POS_FLAG; return;}
65  if (name == VELOCITY_ATTR)
66  { m_attrFlags &= ~VELOCITY_FLAG; return;}
67  if (name == CONTAINS_ATTR)
68  { m_attrFlags &= ~CONTAINS_FLAG; return;}
69  if (name == STAMP_CONTAINS_ATTR)
70  { m_attrFlags &= ~STAMP_CONTAINS_FLAG; return;}
72 }
73 
74 inline void RootEntityData::sendLoc(Atlas::Bridge & b) const
75 {
76  if(m_attrFlags & LOC_FLAG) {
77  b.mapStringItem(LOC_ATTR, attr_loc);
78  }
79 }
80 
81 inline void RootEntityData::sendPos(Atlas::Bridge & b) const
82 {
83  if(m_attrFlags & POS_FLAG) {
84  b.mapListItem(POS_ATTR);
85  for(const auto& item : attr_pos) {
86  b.listFloatItem(item);
87  }
88  b.listEnd();
89  }
90 }
91 
93 {
94  if(m_attrFlags & VELOCITY_FLAG) {
95  b.mapListItem(VELOCITY_ATTR);
96  for(const auto& item : attr_velocity) {
97  b.listFloatItem(item);
98  }
99  b.listEnd();
100  }
101 }
102 
104 {
105  if(m_attrFlags & CONTAINS_FLAG) {
106  b.mapListItem(CONTAINS_ATTR);
107  for(const auto& item : attr_contains) {
108  b.listStringItem(item);
109  }
110  b.listEnd();
111  }
112 }
113 
115 {
116  if(m_attrFlags & STAMP_CONTAINS_FLAG) {
117  b.mapFloatItem(STAMP_CONTAINS_ATTR, attr_stamp_contains);
118  }
119 }
120 
122 {
123  sendLoc(b);
124  sendPos(b);
125  sendVelocity(b);
126  sendContains(b);
129 }
130 
131 void RootEntityData::addToMessage(MapType & m) const
132 {
134  if(m_attrFlags & LOC_FLAG)
135  m[LOC_ATTR] = attr_loc;
136  if(m_attrFlags & POS_FLAG)
137  m[POS_ATTR] = getPosAsList();
138  if(m_attrFlags & VELOCITY_FLAG)
139  m[VELOCITY_ATTR] = getVelocityAsList();
140  if(m_attrFlags & CONTAINS_FLAG)
141  m[CONTAINS_ATTR] = getContainsAsList();
142  if(m_attrFlags & STAMP_CONTAINS_FLAG)
143  m[STAMP_CONTAINS_ATTR] = attr_stamp_contains;
144 }
145 
146 Allocator<RootEntityData> RootEntityData::allocator;
147 
148 
149 
151 {
152  allocator.free(this);
153 }
154 
155 
156 
158 {
159  RootData::reset();
160 }
161 
163 {
164  return copyInstance<RootEntityData>(*this);
165 }
166 
167 bool RootEntityData::instanceOf(int classNo) const
168 {
169  if(ROOT_ENTITY_NO == classNo) return true;
170  return RootData::instanceOf(classNo);
171 }
172 
173 void RootEntityData::fillDefaultObjectInstance(RootEntityData& data, std::map<std::string, uint32_t>& attr_data)
174 {
175  data.attr_objtype = default_objtype;
176  data.attr_pos.clear();
177  data.attr_pos.push_back(0.0);
178  data.attr_pos.push_back(0.0);
179  data.attr_pos.push_back(0.0);
180  data.attr_velocity.clear();
181  data.attr_velocity.push_back(0.0);
182  data.attr_velocity.push_back(0.0);
183  data.attr_velocity.push_back(0.0);
184  data.attr_stamp_contains = 0.0;
185  data.attr_stamp = 0.0;
186  data.attr_parent = default_parent;
187  attr_data[LOC_ATTR] = LOC_FLAG;
188  attr_data[POS_ATTR] = POS_FLAG;
189  attr_data[VELOCITY_ATTR] = VELOCITY_FLAG;
190  attr_data[CONTAINS_ATTR] = CONTAINS_FLAG;
191  attr_data[STAMP_CONTAINS_ATTR] = STAMP_CONTAINS_FLAG;
192 }
193 
194 } } } // namespace Atlas::Objects::Entity
void sendStampContains(Atlas::Bridge &) const
Send the "stamp_contains" attribute to an Atlas::Bridge.
Definition: RootEntity.cpp:114
std::string attr_parent
The object this inherits attributes from.
Definition: Root.h:125
void reset() override
Resets the object as it&#39;s returned to the pool.
Definition: RootEntity.cpp:157
std::string attr_objtype
What kind of object this is.
Definition: Root.h:129
bool getAttrFlag(const std::string &name, uint32_t &flag) const override
Find the flag for the attribute "name".
Definition: RootEntity.cpp:29
std::vector< double > attr_velocity
Velocity object is moving, usually world is 3D.
Definition: RootEntity.h:136
ListType && moveList()
Definition: Element.h:559
virtual void listFloatItem(double)=0
bool instanceOf(int classNo) const override
Is this instance of some class?
Definition: Root.cpp:156
StringType && moveString()
Definition: Element.h:493
Atlas::Message::ListType getContainsAsList() const
Retrieve the "contains" attribute AsList.
Definition: RootEntity.h:335
int getAttrClass(const std::string &name) const override
Find the class which contains the attribute "name".
Definition: RootEntity.cpp:21
void sendContents(Atlas::Bridge &b) const override
Send the contents of this object to a Bridge.
Definition: Root.cpp:109
void removeAttr(const std::string &name) override
Remove the attribute "name". This will not work for static attributes.
Definition: RootEntity.cpp:59
void sendPos(Atlas::Bridge &) const
Send the "pos" attribute to an Atlas::Bridge.
Definition: RootEntity.cpp:81
void addToMessage(Atlas::Message::MapType &) const override
Write this object to an existing Element.
Definition: RootEntity.cpp:131
int copyAttr(const std::string &name, Atlas::Message::Element &attr) const override
Definition: Root.cpp:39
Atlas::Message::ListType getVelocityAsList() const
Retrieve the "velocity" attribute AsList.
Definition: RootEntity.h:310
virtual void mapListItem(std::string name)=0
void setVelocityAsList(const Atlas::Message::ListType &val)
Set the "velocity" attribute AsList.
Definition: RootEntity.h:217
Atlas::Message::ListType getPosAsList() const
Retrieve the "pos" attribute AsList.
Definition: RootEntity.h:285
void removeAttr(const std::string &name) override
Remove the attribute "name". This will not work for static attributes.
Definition: Root.cpp:59
void free() override
Free an instance of this class, returning it to the memory pool.
Definition: RootEntity.cpp:150
void setAttr(std::string name, Atlas::Message::Element attr, const Atlas::Objects::Factories *factories=nullptr) override
Set the attribute "name" to the value given by"attr".
Definition: Root.cpp:49
FloatType asFloat() const
Retrieve the current value as a double.
Definition: Element.h:440
Starting point for entity hierarchy.
Definition: RootEntity.h:31
virtual void mapStringItem(std::string name, std::string)=0
void setAttr(std::string name, Atlas::Message::Element attr, const Atlas::Objects::Factories *factories=nullptr) override
Set the attribute "name" to the value given by"attr".
Definition: RootEntity.cpp:49
void sendLoc(Atlas::Bridge &) const
Send the "loc" attribute to an Atlas::Bridge.
Definition: RootEntity.cpp:74
void setPosAsList(const Atlas::Message::ListType &val)
Set the "pos" attribute AsList.
Definition: RootEntity.h:198
int copyAttr(const std::string &name, Atlas::Message::Element &attr) const override
Definition: RootEntity.cpp:39
void setStampContains(double val)
Set the "stamp_contains" attribute.
Definition: RootEntity.h:249
void sendVelocity(Atlas::Bridge &) const
Send the "velocity" attribute to an Atlas::Bridge.
Definition: RootEntity.cpp:92
bool instanceOf(int classNo) const override
Is this instance of some class?
Definition: RootEntity.cpp:167
int getAttrClass(const std::string &name) const override
Find the class which contains the attribute "name".
Definition: Root.cpp:21
void addToMessage(Atlas::Message::MapType &) const override
Write this object to an existing Element.
Definition: Root.cpp:119
std::vector< double > attr_pos
Position coordinates, usually world is 3D.
Definition: RootEntity.h:134
bool getAttrFlag(const std::string &name, uint32_t &flag) const override
Find the flag for the attribute "name".
Definition: Root.cpp:29
const std::string & getLoc() const
Retrieve the "loc" attribute.
Definition: RootEntity.h:255
virtual void mapFloatItem(std::string name, double)=0
virtual void listStringItem(std::string)=0
virtual void listEnd()=0
void setLoc(std::string val)
Set the "loc" attribute.
Definition: RootEntity.h:184
void setContainsAsList(const Atlas::Message::ListType &val)
Set the "contains" attribute AsList.
Definition: RootEntity.h:236
RootEntityData * copy() const override
Copy this object.
Definition: RootEntity.cpp:162
void sendContents(Atlas::Bridge &b) const override
Send the contents of this object to a Bridge.
Definition: RootEntity.cpp:121
std::string attr_loc
Reference object for coordinates (location).
Definition: RootEntity.h:132
double attr_stamp
Last time this object was modified.
Definition: Root.h:127
void sendContains(Atlas::Bridge &) const
Send the "contains" attribute to an Atlas::Bridge.
Definition: RootEntity.cpp:103
void reset() override
Resets the object as it&#39;s returned to the pool.
Definition: Root.cpp:147
double getStampContains() const
Retrieve the "stamp_contains" attribute.
Definition: RootEntity.h:345
Definition: Bridge.h:20
std::vector< std::string > attr_contains
List of objects that use this object as reference system (usually same as what this object contains)...
Definition: RootEntity.h:138
double attr_stamp_contains
Last time any object that uses this as reference recursively has been modified.
Definition: RootEntity.h:140