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
11using Atlas::Message::MapType;
12
13namespace Atlas { namespace Objects {
14
15const std::string ID_ATTR = "id";
16const std::string PARENT_ATTR = "parent";
17const std::string STAMP_ATTR = "stamp";
18const std::string OBJTYPE_ATTR = "objtype";
19const std::string NAME_ATTR = "name";
20
21int 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 }
27}
28
29bool 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
39int 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
49void 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
59void 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
74inline void RootData::sendId(Atlas::Bridge & b) const
75{
76 if(m_attrFlags & ID_FLAG) {
77 b.mapStringItem(ID_ATTR, attr_id);
78 }
79}
80
81inline 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
88inline void RootData::sendStamp(Atlas::Bridge & b) const
89{
90 if(m_attrFlags & STAMP_FLAG) {
91 b.mapFloatItem(STAMP_ATTR, attr_stamp);
92 }
93}
94
96{
97 if((m_attrFlags & OBJTYPE_FLAG) || !((RootData *)m_defaults)->attr_objtype.empty()) {
98 b.mapStringItem(OBJTYPE_ATTR, getObjtype());
99 }
100}
101
102inline 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
119void 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
136Allocator<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
156bool RootData::instanceOf(int classNo) const
157{
158 if(ROOT_NO == classNo) return true;
159 return BaseObjectData::instanceOf(classNo);
160}
161
162void 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
StringType && moveString()
Definition: Element.h:467
FloatType asFloat() const
Retrieve the current value as a double.
Definition: Element.h:414
virtual void addToMessage(Atlas::Message::MapType &) const
Write this object to an existing Element.
Definition: BaseObject.cpp:99
virtual void removeAttr(const std::string &name)
Remove the attribute "name".
Definition: BaseObject.cpp:77
virtual int getAttrClass(const std::string &name) const
Find the class which contains the attribute "name".
Definition: BaseObject.cpp:114
BaseObjectData * m_defaults
Definition: BaseObject.h:330
virtual bool getAttrFlag(const std::string &name, uint32_t &flag) const
Find the flag for the attribute "name".
Definition: BaseObject.cpp:119
virtual int copyAttr(const std::string &name, Atlas::Message::Element &attr) const
Definition: BaseObject.cpp:62
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
virtual void sendContents(Atlas::Bridge &b) const
Send the contents of this object to a Bridge.
Definition: BaseObject.cpp:106
virtual bool instanceOf(int classNo) const
Is this instance of some class?
Definition: BaseObject.cpp:30
All objects inherit from this..
Definition: Root.h:37
const std::string & getId() const
Retrieve the "id" attribute.
Definition: Root.h:213
void sendId(Atlas::Bridge &) const
Send the "id" attribute to an Atlas::Bridge.
Definition: Root.cpp:74
std::string attr_objtype
What kind of object this is.
Definition: Root.h:129
const std::string & getObjtype() const
Retrieve the "objtype" attribute.
Definition: Root.h:258
void setObjtype(std::string val)
Set the "objtype" attribute.
Definition: Root.h:199
void setParent(std::string val)
Set the "parent" attribute.
Definition: Root.h:183
void reset() override
Resets the object as it's returned to the pool.
Definition: Root.cpp:147
void setName(std::string val)
Set the "name" attribute.
Definition: Root.h:207
std::string attr_parent
The object this inherits attributes from.
Definition: Root.h:125
int copyAttr(const std::string &name, Atlas::Message::Element &attr) const override
Definition: Root.cpp:39
void sendObjtype(Atlas::Bridge &) const
Send the "objtype" attribute to an Atlas::Bridge.
Definition: Root.cpp:95
double attr_stamp
Last time this object was modified.
Definition: Root.h:127
double getStamp() const
Retrieve the "stamp" attribute.
Definition: Root.h:243
std::string attr_name
Name of object.
Definition: Root.h:131
bool getAttrFlag(const std::string &name, uint32_t &flag) const override
Find the flag for the attribute "name".
Definition: Root.cpp:29
void addToMessage(Atlas::Message::MapType &) const override
Write this object to an existing Element.
Definition: Root.cpp:119
std::string attr_id
Id of object.
Definition: Root.h:123
void sendStamp(Atlas::Bridge &) const
Send the "stamp" attribute to an Atlas::Bridge.
Definition: Root.cpp:88
const std::string & getName() const
Retrieve the "name" attribute.
Definition: Root.h:273
bool instanceOf(int classNo) const override
Is this instance of some class?
Definition: Root.cpp:156
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
void sendParent(Atlas::Bridge &) const
Send the "parent" attribute to an Atlas::Bridge.
Definition: Root.cpp:81
void sendName(Atlas::Bridge &) const
Send the "name" attribute to an Atlas::Bridge.
Definition: Root.cpp:102
int getAttrClass(const std::string &name) const override
Find the class which contains the attribute "name".
Definition: Root.cpp:21
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: Root.cpp:140
RootData * copy() const override
Copy this object.
Definition: Root.cpp:151
void setId(std::string val)
Set the "id" attribute.
Definition: Root.h:175
const std::string & getParent() const
Retrieve the "parent" attribute.
Definition: Root.h:228
void sendContents(Atlas::Bridge &b) const override
Send the contents of this object to a Bridge.
Definition: Root.cpp:109
void setStamp(double val)
Set the "stamp" attribute.
Definition: Root.h:191
Definition: Bridge.h:20