~ubuntu-branches/ubuntu/breezy/atlas-cpp/breezy

« back to all changes in this revision

Viewing changes to Atlas/Objects/RootEntity.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2005-10-02 11:41:44 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20051002114144-8qmn4d1cdn9g27ta
Tags: 0.5.98-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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-2004 Al Riddoch.
 
5
// Automatically generated using gen_cpp.py.
 
6
 
 
7
#include <Atlas/Objects/RootEntity.h>
 
8
 
 
9
using Atlas::Message::Element;
 
10
using Atlas::Message::MapType;
 
11
 
 
12
namespace Atlas { namespace Objects { namespace Entity { 
 
13
 
 
14
int RootEntityData::getAttrClass(const std::string& name) const
 
15
{
 
16
    if (attr_flags_RootEntityData->find(name) != attr_flags_RootEntityData->end()) {
 
17
        return ROOT_ENTITY_NO;
 
18
    }
 
19
    return RootData::getAttrClass(name);
 
20
}
 
21
 
 
22
int RootEntityData::getAttrFlag(const std::string& name) const
 
23
{
 
24
    std::map<std::string, int>::const_iterator I = attr_flags_RootEntityData->find(name);
 
25
    if (I != attr_flags_RootEntityData->end()) {
 
26
        return I->second;
 
27
    }
 
28
    return RootData::getAttrFlag(name);
 
29
}
 
30
 
 
31
int RootEntityData::copyAttr(const std::string& name, Element & attr) const
 
32
{
 
33
    if (name == "loc") { attr = getLoc(); return 0; }
 
34
    if (name == "pos") { attr = getPosAsList(); return 0; }
 
35
    if (name == "velocity") { attr = getVelocityAsList(); return 0; }
 
36
    if (name == "contains") { attr = getContainsAsList(); return 0; }
 
37
    if (name == "stamp_contains") { attr = getStampContains(); return 0; }
 
38
    return RootData::copyAttr(name, attr);
 
39
}
 
40
 
 
41
void RootEntityData::setAttr(const std::string& name, const Element& attr)
 
42
{
 
43
    if (name == "loc") { setLoc(attr.asString()); return; }
 
44
    if (name == "pos") { setPosAsList(attr.asList()); return; }
 
45
    if (name == "velocity") { setVelocityAsList(attr.asList()); return; }
 
46
    if (name == "contains") { setContainsAsList(attr.asList()); return; }
 
47
    if (name == "stamp_contains") { setStampContains(attr.asFloat()); return; }
 
48
    RootData::setAttr(name, attr);
 
49
}
 
50
 
 
51
void RootEntityData::removeAttr(const std::string& name)
 
52
{
 
53
    if (name == "loc")
 
54
        { m_attrFlags &= ~LOC_FLAG; return;}
 
55
    if (name == "pos")
 
56
        { m_attrFlags &= ~POS_FLAG; return;}
 
57
    if (name == "velocity")
 
58
        { m_attrFlags &= ~VELOCITY_FLAG; return;}
 
59
    if (name == "contains")
 
60
        { m_attrFlags &= ~CONTAINS_FLAG; return;}
 
61
    if (name == "stamp_contains")
 
62
        { m_attrFlags &= ~STAMP_CONTAINS_FLAG; return;}
 
63
    RootData::removeAttr(name);
 
64
}
 
65
 
 
66
inline void RootEntityData::sendLoc(Atlas::Bridge & b) const
 
67
{
 
68
    if(m_attrFlags & LOC_FLAG) {
 
69
        b.mapStringItem("loc", attr_loc);
 
70
    }
 
71
}
 
72
 
 
73
inline void RootEntityData::sendPos(Atlas::Bridge & b) const
 
74
{
 
75
    if(m_attrFlags & POS_FLAG) {
 
76
        b.mapListItem("pos");
 
77
        const std::vector<double> & v = attr_pos;
 
78
        std::vector<double>::const_iterator I = v.begin();
 
79
        for(; I != v.end(); ++I) {
 
80
            b.listFloatItem(*I);
 
81
        }
 
82
        b.listEnd();
 
83
    }
 
84
}
 
85
 
 
86
inline void RootEntityData::sendVelocity(Atlas::Bridge & b) const
 
87
{
 
88
    if(m_attrFlags & VELOCITY_FLAG) {
 
89
        b.mapListItem("velocity");
 
90
        const std::vector<double> & v = attr_velocity;
 
91
        std::vector<double>::const_iterator I = v.begin();
 
92
        for(; I != v.end(); ++I) {
 
93
            b.listFloatItem(*I);
 
94
        }
 
95
        b.listEnd();
 
96
    }
 
97
}
 
98
 
 
99
inline void RootEntityData::sendContains(Atlas::Bridge & b) const
 
100
{
 
101
    if(m_attrFlags & CONTAINS_FLAG) {
 
102
        b.mapListItem("contains");
 
103
        const std::list<std::string> & l = attr_contains;
 
104
        std::list<std::string>::const_iterator I = l.begin();
 
105
        for(; I != l.end(); ++I) {
 
106
            b.listStringItem(*I);
 
107
        }
 
108
        b.listEnd();
 
109
    }
 
110
}
 
111
 
 
112
inline void RootEntityData::sendStampContains(Atlas::Bridge & b) const
 
113
{
 
114
    if(m_attrFlags & STAMP_CONTAINS_FLAG) {
 
115
        b.mapFloatItem("stamp_contains", attr_stamp_contains);
 
116
    }
 
117
}
 
118
 
 
119
void RootEntityData::sendContents(Bridge & b) const
 
120
{
 
121
    sendLoc(b);
 
122
    sendPos(b);
 
123
    sendVelocity(b);
 
124
    sendContains(b);
 
125
    sendStampContains(b);
 
126
    RootData::sendContents(b);
 
127
}
 
128
 
 
129
void RootEntityData::addToMessage(MapType & m) const
 
130
{
 
131
    RootData::addToMessage(m);
 
132
    if(m_attrFlags & LOC_FLAG)
 
133
        m["loc"] = attr_loc;
 
134
    if(m_attrFlags & POS_FLAG)
 
135
        m["pos"] = getPosAsList();
 
136
    if(m_attrFlags & VELOCITY_FLAG)
 
137
        m["velocity"] = getVelocityAsList();
 
138
    if(m_attrFlags & CONTAINS_FLAG)
 
139
        m["contains"] = getContainsAsList();
 
140
    if(m_attrFlags & STAMP_CONTAINS_FLAG)
 
141
        m["stamp_contains"] = attr_stamp_contains;
 
142
    return;
 
143
}
 
144
 
 
145
void RootEntityData::iterate(int& current_class, std::string& attr) const
 
146
{
 
147
    // If we've already finished this class, chain to the parent
 
148
    if(current_class >= 0 && current_class != ROOT_ENTITY_NO) {
 
149
        RootData::iterate(current_class, attr);
 
150
        return;
 
151
    }
 
152
 
 
153
    static const char *attr_list[] = {"loc","pos","velocity","contains","stamp_contains",};
 
154
    static const unsigned n_attr = sizeof(attr_list) / sizeof(const char*);
 
155
 
 
156
    unsigned next_attr = n_attr; // so we chain to the parent if we don't find attr
 
157
 
 
158
    if(attr.empty()) // just staring on this class
 
159
        next_attr = 0;
 
160
    else {
 
161
      for(unsigned i = 0; i < n_attr; ++i) {
 
162
         if(attr == attr_list[i]) {
 
163
             next_attr = i + 1;
 
164
             break;
 
165
         }
 
166
      }
 
167
    }
 
168
 
 
169
    if(next_attr == n_attr) { // last one on the list
 
170
        current_class = -1;
 
171
        attr = "";
 
172
        RootData::iterate(current_class, attr); // chain to parent
 
173
    }
 
174
    else {
 
175
        current_class = ROOT_ENTITY_NO;
 
176
        attr = attr_list[next_attr];
 
177
    }
 
178
}
 
179
 
 
180
RootEntityData::~RootEntityData()
 
181
{
 
182
}
 
183
 
 
184
RootEntityData * RootEntityData::copy() const
 
185
{
 
186
    RootEntityData * copied = RootEntityData::alloc();
 
187
    *copied = *this;
 
188
    copied->m_refCount = 0;
 
189
    return copied;
 
190
}
 
191
 
 
192
bool RootEntityData::instanceOf(int classNo) const
 
193
{
 
194
    if(ROOT_ENTITY_NO == classNo) return true;
 
195
    return RootData::instanceOf(classNo);
 
196
}
 
197
 
 
198
//freelist related methods specific to this class
 
199
RootEntityData *RootEntityData::defaults_RootEntityData = 0;
 
200
RootEntityData *RootEntityData::begin_RootEntityData = 0;
 
201
 
 
202
RootEntityData *RootEntityData::alloc()
 
203
{
 
204
    if(begin_RootEntityData) {
 
205
        RootEntityData *res = begin_RootEntityData;
 
206
        assert( res->m_refCount == 0 );
 
207
        res->m_attrFlags = 0;
 
208
        res->m_attributes.clear();
 
209
        begin_RootEntityData = (RootEntityData *)begin_RootEntityData->m_next;
 
210
        return res;
 
211
    }
 
212
    return new RootEntityData(RootEntityData::getDefaultObjectInstance());
 
213
}
 
214
 
 
215
void RootEntityData::free()
 
216
{
 
217
    m_next = begin_RootEntityData;
 
218
    begin_RootEntityData = this;
 
219
}
 
220
 
 
221
std::map<std::string, int> * RootEntityData::attr_flags_RootEntityData = 0;
 
222
 
 
223
RootEntityData *RootEntityData::getDefaultObjectInstance()
 
224
{
 
225
    if (defaults_RootEntityData == 0) {
 
226
        defaults_RootEntityData = new RootEntityData;
 
227
        defaults_RootEntityData->attr_objtype = "obj";
 
228
        defaults_RootEntityData->attr_pos.clear();
 
229
        defaults_RootEntityData->attr_pos.push_back(0.0);
 
230
        defaults_RootEntityData->attr_pos.push_back(0.0);
 
231
        defaults_RootEntityData->attr_pos.push_back(0.0);
 
232
        defaults_RootEntityData->attr_velocity.clear();
 
233
        defaults_RootEntityData->attr_velocity.push_back(0.0);
 
234
        defaults_RootEntityData->attr_velocity.push_back(0.0);
 
235
        defaults_RootEntityData->attr_velocity.push_back(0.0);
 
236
        defaults_RootEntityData->attr_stamp_contains = 0.0;
 
237
        defaults_RootEntityData->attr_stamp = 0.0;
 
238
        defaults_RootEntityData->attr_parents = std::list<std::string>(1, "root_entity");
 
239
        attr_flags_RootEntityData = new std::map<std::string, int>;
 
240
        (*attr_flags_RootEntityData)["loc"] = LOC_FLAG;
 
241
        (*attr_flags_RootEntityData)["pos"] = POS_FLAG;
 
242
        (*attr_flags_RootEntityData)["velocity"] = VELOCITY_FLAG;
 
243
        (*attr_flags_RootEntityData)["contains"] = CONTAINS_FLAG;
 
244
        (*attr_flags_RootEntityData)["stamp_contains"] = STAMP_CONTAINS_FLAG;
 
245
        RootData::getDefaultObjectInstance();
 
246
    }
 
247
    return defaults_RootEntityData;
 
248
}
 
249
 
 
250
RootEntityData *RootEntityData::getDefaultObject()
 
251
{
 
252
    return RootEntityData::getDefaultObjectInstance();
 
253
}
 
254
 
 
255
} } } // namespace Atlas::Objects::Entity