Atlas  0.7.0
Networking protocol for the Worldforge system.
Root.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/Root.h>
9 
11 using Atlas::Message::MapType;
12 
13 namespace Atlas { namespace Objects {
14 
15 const std::string ID_ATTR = "id";
16 const std::string PARENT_ATTR = "parent";
17 const std::string STAMP_ATTR = "stamp";
18 const std::string OBJTYPE_ATTR = "objtype";
19 const std::string NAME_ATTR = "name";
20 
21 int RootData::getAttrClass(const std::string& name) const
22 {
23  if (allocator.attr_flags_Data.find(name) != allocator.attr_flags_Data.end()) {
24  return ROOT_NO;
25  }
26  return BaseObjectData::getAttrClass(name);
27 }
28 
29 bool RootData::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 BaseObjectData::getAttrFlag(name, flag);
37 }
38 
39 int RootData::copyAttr(const std::string& name, Element & attr) const
40 {
41  if (name == ID_ATTR) { attr = getId(); return 0; }
42  if (name == PARENT_ATTR) { attr = getParent(); return 0; }
43  if (name == STAMP_ATTR) { attr = getStamp(); return 0; }
44  if (name == OBJTYPE_ATTR) { attr = getObjtype(); return 0; }
45  if (name == NAME_ATTR) { attr = getName(); return 0; }
46  return BaseObjectData::copyAttr(name, attr);
47 }
48 
49 void RootData::setAttr(std::string name, Element attr, const Atlas::Objects::Factories* factories)
50 {
51  if (name == ID_ATTR) { setId(attr.moveString()); return; }
52  if (name == PARENT_ATTR) { setParent(attr.moveString()); return; }
53  if (name == STAMP_ATTR) { setStamp(attr.asFloat()); return; }
54  if (name == OBJTYPE_ATTR) { setObjtype(attr.moveString()); return; }
55  if (name == NAME_ATTR) { setName(attr.moveString()); return; }
56  BaseObjectData::setAttr(std::move(name), std::move(attr), factories);
57 }
58 
59 void RootData::removeAttr(const std::string& name)
60 {
61  if (name == ID_ATTR)
62  { m_attrFlags &= ~ID_FLAG; return;}
63  if (name == PARENT_ATTR)
64  { m_attrFlags &= ~PARENT_FLAG; return;}
65  if (name == STAMP_ATTR)
66  { m_attrFlags &= ~STAMP_FLAG; return;}
67  if (name == OBJTYPE_ATTR)
68  { m_attrFlags &= ~OBJTYPE_FLAG; return;}
69  if (name == NAME_ATTR)
70  { m_attrFlags &= ~NAME_FLAG; return;}
72 }
73 
74 inline void RootData::sendId(Atlas::Bridge & b) const
75 {
76  if(m_attrFlags & ID_FLAG) {
77  b.mapStringItem(ID_ATTR, attr_id);
78  }
79 }
80 
81 inline void RootData::sendParent(Atlas::Bridge & b) const
82 {
83  if((m_attrFlags & PARENT_FLAG) || !((RootData *)m_defaults)->attr_parent.empty()) {
84  b.mapStringItem(PARENT_ATTR, getParent());
85  }
86 }
87 
88 inline void RootData::sendStamp(Atlas::Bridge & b) const
89 {
90  if(m_attrFlags & STAMP_FLAG) {
91  b.mapFloatItem(STAMP_ATTR, attr_stamp);
92  }
93 }
94 
95 inline void RootData::sendObjtype(Atlas::Bridge & b) const
96 {
97  if((m_attrFlags & OBJTYPE_FLAG) || !((RootData *)m_defaults)->attr_objtype.empty()) {
98  b.mapStringItem(OBJTYPE_ATTR, getObjtype());
99  }
100 }
101 
102 inline void RootData::sendName(Atlas::Bridge & b) const
103 {
104  if(m_attrFlags & NAME_FLAG) {
105  b.mapStringItem(NAME_ATTR, attr_name);
106  }
107 }
108 
110 {
111  sendId(b);
112  sendParent(b);
113  sendStamp(b);
114  sendObjtype(b);
115  sendName(b);
117 }
118 
119 void RootData::addToMessage(MapType & m) const
120 {
122  if(m_attrFlags & ID_FLAG)
123  m[ID_ATTR] = attr_id;
124  const std::string& l_attr_parent = getParent();
125  if (!l_attr_parent.empty())
126  m[PARENT_ATTR] = l_attr_parent;
127  if(m_attrFlags & STAMP_FLAG)
128  m[STAMP_ATTR] = attr_stamp;
129  const std::string& l_attr_objtype = getObjtype();
130  if (!l_attr_objtype.empty())
131  m[OBJTYPE_ATTR] = l_attr_objtype;
132  if(m_attrFlags & NAME_FLAG)
133  m[NAME_ATTR] = attr_name;
134 }
135 
136 Allocator<RootData> RootData::allocator;
137 
138 
139 
141 {
142  allocator.free(this);
143 }
144 
145 
146 
148 {
149 }
150 
152 {
153  return copyInstance<RootData>(*this);
154 }
155 
156 bool RootData::instanceOf(int classNo) const
157 {
158  if(ROOT_NO == classNo) return true;
159  return BaseObjectData::instanceOf(classNo);
160 }
161 
162 void RootData::fillDefaultObjectInstance(RootData& data, std::map<std::string, uint32_t>& attr_data)
163 {
164  data.attr_stamp = 0.0;
165  data.attr_objtype = default_objtype;
166  data.attr_parent = default_parent;
167  attr_data[ID_ATTR] = ID_FLAG;
168  attr_data[PARENT_ATTR] = PARENT_FLAG;
169  attr_data[STAMP_ATTR] = STAMP_FLAG;
170  attr_data[OBJTYPE_ATTR] = OBJTYPE_FLAG;
171  attr_data[NAME_ATTR] = NAME_FLAG;
172 }
173 
174 } } // namespace Atlas::Objects
Atlas::Objects::RootData::setObjtype
void setObjtype(std::string val)
Set the "objtype" attribute.
Definition: Root.h:199
Atlas::Objects::RootData::sendId
void sendId(Atlas::Bridge &) const
Send the "id" attribute to an Atlas::Bridge.
Definition: Root.cpp:74
Atlas::Objects::RootData::getAttrFlag
bool getAttrFlag(const std::string &name, uint32_t &flag) const override
Find the flag for the attribute "name".
Definition: Root.cpp:29
Atlas::Objects::BaseObjectData::getAttrClass
virtual int getAttrClass(const std::string &name) const
Find the class which contains the attribute "name".
Definition: BaseObject.cpp:114
Atlas::Objects::RootData::setName
void setName(std::string val)
Set the "name" attribute.
Definition: Root.h:207
Atlas::Objects::RootData::attr_stamp
double attr_stamp
Last time this object was modified.
Definition: Root.h:127
Atlas::Objects::RootData::setId
void setId(std::string val)
Set the "id" attribute.
Definition: Root.h:175
Atlas::Objects::RootData::removeAttr
void removeAttr(const std::string &name) override
Remove the attribute "name". This will not work for static attributes.
Definition: Root.cpp:59
Atlas::Objects::RootData::setAttr
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
Atlas::Objects::RootData::getAttrClass
int getAttrClass(const std::string &name) const override
Find the class which contains the attribute "name".
Definition: Root.cpp:21
Atlas::Message::Element::moveString
StringType && moveString()
Definition: Element.h:467
Atlas::Objects::RootData::attr_parent
std::string attr_parent
The object this inherits attributes from.
Definition: Root.h:125
Atlas::Objects::RootData::sendParent
void sendParent(Atlas::Bridge &) const
Send the "parent" attribute to an Atlas::Bridge.
Definition: Root.cpp:81
Atlas::Message::Element
Definition: Element.h:39
Atlas::Objects::BaseObjectData::sendContents
virtual void sendContents(Atlas::Bridge &b) const
Send the contents of this object to a Bridge.
Definition: BaseObject.cpp:106
Atlas::Objects::Allocator
Definition: BaseObject.h:78
Atlas::Objects::RootData::free
void free() override
Free an instance of this class, returning it to the memory pool.
Definition: Root.cpp:140
Atlas::Objects::RootData::copyAttr
int copyAttr(const std::string &name, Atlas::Message::Element &attr) const override
Definition: Root.cpp:39
Atlas::Objects::RootData::instanceOf
bool instanceOf(int classNo) const override
Is this instance of some class?
Definition: Root.cpp:156
Atlas::Objects::BaseObjectData::instanceOf
virtual bool instanceOf(int classNo) const
Is this instance of some class?
Definition: BaseObject.cpp:30
Atlas::Objects::RootData::reset
void reset() override
Resets the object as it's returned to the pool.
Definition: Root.cpp:147
Atlas::Objects::RootData::setParent
void setParent(std::string val)
Set the "parent" attribute.
Definition: Root.h:183
Atlas::Objects::BaseObjectData::m_defaults
BaseObjectData * m_defaults
Definition: BaseObject.h:330
Atlas::Objects::RootData::getObjtype
const std::string & getObjtype() const
Retrieve the "objtype" attribute.
Definition: Root.h:258
Atlas::Bridge
Definition: Bridge.h:36
Atlas::Objects::RootData::sendObjtype
void sendObjtype(Atlas::Bridge &) const
Send the "objtype" attribute to an Atlas::Bridge.
Definition: Root.cpp:95
Atlas::Objects::RootData::getParent
const std::string & getParent() const
Retrieve the "parent" attribute.
Definition: Root.h:228
Atlas::Objects::BaseObjectData::getAttrFlag
virtual bool getAttrFlag(const std::string &name, uint32_t &flag) const
Find the flag for the attribute "name".
Definition: BaseObject.cpp:119
Atlas::Objects::RootData::setStamp
void setStamp(double val)
Set the "stamp" attribute.
Definition: Root.h:191
Atlas::Objects::RootData::attr_name
std::string attr_name
Name of object.
Definition: Root.h:131
Atlas::Objects::BaseObjectData::setAttr
virtual void setAttr(std::string name, Atlas::Message::Element attr, const Atlas::Objects::Factories *factories=nullptr)
Set the attribute "name" to the value given by "attr".
Definition: BaseObject.cpp:72
Atlas::Objects::RootData::copy
RootData * copy() const override
Copy this object.
Definition: Root.cpp:151
Atlas::Objects::RootData::getId
const std::string & getId() const
Retrieve the "id" attribute.
Definition: Root.h:213
Atlas::Message::Element::asFloat
FloatType asFloat() const
Retrieve the current value as a double.
Definition: Element.h:414
Atlas::Objects::RootData::getStamp
double getStamp() const
Retrieve the "stamp" attribute.
Definition: Root.h:243
Atlas::Objects::RootData::sendName
void sendName(Atlas::Bridge &) const
Send the "name" attribute to an Atlas::Bridge.
Definition: Root.cpp:102
Atlas::Objects::RootData::attr_objtype
std::string attr_objtype
What kind of object this is.
Definition: Root.h:129
Atlas::Objects::Factories
Definition: Factories.h:76
Atlas::Objects::RootData::sendContents
void sendContents(Atlas::Bridge &b) const override
Send the contents of this object to a Bridge.
Definition: Root.cpp:109
Atlas::Objects::RootData
All objects inherit from this..
Definition: Root.h:37
Atlas::Objects::RootData::addToMessage
void addToMessage(Atlas::Message::MapType &) const override
Write this object to an existing Element.
Definition: Root.cpp:119
Atlas::Objects::BaseObjectData::copyAttr
virtual int copyAttr(const std::string &name, Atlas::Message::Element &attr) const
Definition: BaseObject.cpp:62
Atlas::Objects::BaseObjectData::removeAttr
virtual void removeAttr(const std::string &name)
Remove the attribute "name".
Definition: BaseObject.cpp:77
Atlas::Objects::BaseObjectData::addToMessage
virtual void addToMessage(Atlas::Message::MapType &) const
Write this object to an existing Element.
Definition: BaseObject.cpp:99
Atlas::Objects::RootData::sendStamp
void sendStamp(Atlas::Bridge &) const
Send the "stamp" attribute to an Atlas::Bridge.
Definition: Root.cpp:88
Atlas
Definition: Bridge.h:20
Atlas::Objects::RootData::getName
const std::string & getName() const
Retrieve the "name" attribute.
Definition: Root.h:273
Atlas::Objects::RootData::attr_id
std::string attr_id
Id of object.
Definition: Root.h:123