File: Container.cpp

package info (click to toggle)
cyphesis-cpp 0.5.16-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 5,084 kB
  • ctags: 3,627
  • sloc: cpp: 30,418; python: 4,812; xml: 4,674; sh: 4,118; makefile: 902; ansic: 617
file content (179 lines) | stat: -rw-r--r-- 4,203 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// Cyphesis Online RPG Server and AI Engine
// Copyright (C) 2004 Alistair Riddoch
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

// $Id: Container.cpp,v 1.5 2006-12-11 21:23:53 alriddoch Exp $

#include "Container.h"
#include "Entity.h"

#include <Atlas/Message/Element.h>
#include <Atlas/Objects/RootEntity.h>

Container::Container_const_iterator::Container_const_iterator() : m_refCount(0)
{
}

Container::Container_const_iterator::~Container_const_iterator()
{
}

Container::Container()
{
}

Container::~Container()
{
}

Container::const_iterator StdContainer::begin() const
{
    const_iterator ci(new StdContainer_const_iterator(m_entities.begin()));
    return ci;
}

Container::const_iterator StdContainer::end() const
{
    const_iterator ci(new StdContainer_const_iterator(m_entities.end()));
    return ci;
}

#if 0
NonContainer::NonContainer()
{
}

NonContainer::~NonContainer()
{
}

int NonContainer::size()
{
    return 0;
}

#if 0
// There should be a link error if these are ever used without the
// implementation issues being sorted out. Exactly how do we implement it
// so that this entity cannot be a container?

void NonContainer::insert(Entity *)
{
    // Error
}

void NonContainer::erase(Entity *)
{
    // Error
}

void NonContainer::reParent()
{
    // Error
}
#endif

void NonContainer::addToMessage(const std::string &, Atlas::Message::MapType &)
{
    // Do nothing, as we never have any contents.
}
#endif

StdContainer::StdContainer_const_iterator::StdContainer_const_iterator(EntitySet::const_iterator I) : m_iter(I)
{
}

StdContainer::StdContainer_const_iterator::~StdContainer_const_iterator()
{
}

StdContainer::StdContainer_const_iterator & StdContainer::StdContainer_const_iterator::operator++()
{
    ++m_iter;
    return *this;
}

bool StdContainer::StdContainer_const_iterator::operator==(const Container_const_iterator & o)
{
    const StdContainer::StdContainer_const_iterator * other = dynamic_cast<const StdContainer::StdContainer_const_iterator *>(&o);
    if (other == 0) {
        return false;
    }
    return (m_iter == other->m_iter);
}

Entity * StdContainer::StdContainer_const_iterator::operator*() const
{
    return (*m_iter);
}

/// \brief StdContainer constructor
StdContainer::StdContainer()
{
}

StdContainer::~StdContainer()
{
}

int StdContainer::size() const
{
    return m_entities.size();
}

bool StdContainer::empty() const
{
    return m_entities.empty();
}

void StdContainer::insert(Entity * ent)
{
    m_entities.insert(ent);
}

void StdContainer::erase(Entity * ent)
{
    m_entities.erase(ent);
}

void StdContainer::reParent()
{
    // WTF
}

void StdContainer::addToMessage(const std::string & key,
                                Atlas::Message::MapType & map) const
{
    Atlas::Message::Element & e = map[key];
    e = Atlas::Message::ListType();
    Atlas::Message::ListType & contlist = e.asList();
    EntitySet::const_iterator Iend = m_entities.end();
    for (EntitySet::const_iterator I = m_entities.begin(); I != Iend; ++I) {
        contlist.push_back((*I)->getId());
    }
}

void StdContainer::addToEntity(const std::string & key,
                               const Atlas::Objects::Entity::RootEntity & ent) const
{
    Atlas::Message::Element v = Atlas::Message::ListType();
    Atlas::Message::ListType & contlist = v.asList();
    EntitySet::const_iterator Iend = m_entities.end();
    for (EntitySet::const_iterator I = m_entities.begin(); I != Iend; ++I) {
        contlist.push_back((*I)->getId());
    }
    ent->setAttr(key, v);
}