FIFE  2008.0
object.cpp
1 /***************************************************************************
2  * Copyright (C) 2006-2011 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 // Standard C++ library includes
23 
24 // 3rd party library includes
25 
26 // FIFE includes
27 // These includes are split up in two parts, separated by one empty line
28 // First block: files included from the FIFE root src directory
29 // Second block: files included from the same folder
30 #include "util/base/exception.h"
31 
32 #include "object.h"
33 #include "action.h"
34 #include "ipather.h"
35 
36 namespace FIFE {
37  Object::Object(const std::string& identifier, const std::string& name_space, Object* inherited):
38  m_id(identifier),
39  m_namespace(name_space),
40  m_filename(""),
41  m_inherited(inherited),
42  m_actions(NULL),
43  m_blocking(false),
44  m_static(false),
45  m_pather(NULL),
46  m_visual(NULL),
47  m_defaultaction(NULL) {
48  }
49 
51  if (m_actions) {
52  std::map<std::string, Action*>::const_iterator i(m_actions->begin());
53  while (i != m_actions->end()) {
54  delete i->second;
55  ++i;
56  }
57  delete m_actions;
58  }
59  delete m_visual;
60  }
61 
62  Action* Object::createAction(const std::string& identifier, bool is_default) {
63  if (!m_actions) {
64  m_actions = new std::map<std::string, Action*>;
65  }
66 
67  std::map<std::string, Action*>::const_iterator it = m_actions->begin();
68  for(; it != m_actions->end(); ++it) {
69  if(identifier == it->second->getId()) {
70  throw NameClash(identifier);
71  }
72  }
73 
74  Action* a = getAction(identifier);
75  if (!a) {
76  a = new Action(identifier);
77  (*m_actions)[identifier] = a;
78  if (is_default || (!m_defaultaction)) {
79  m_defaultaction = a;
80  }
81  }
82  return a;
83  }
84 
85  Action* Object::getAction(const std::string& identifier) const {
86  std::map<std::string, Action*>::const_iterator i;
87  if (m_actions) {
88  i = m_actions->find(identifier);
89  }
90  if ((!m_actions) || (i == m_actions->end())) {
91  if (m_inherited) {
92  return m_inherited->getAction(identifier);
93  }
94  return NULL;
95  }
96  return i->second;
97  }
98 
99  std::list<std::string> Object::getActionIds() const {
100  std::list<std::string> action_ids;
101  action_ids.clear();
102  if (m_actions) {
103  std::map<std::string, Action*>::const_iterator actions_it = m_actions->begin();
104  for(; actions_it != m_actions->end(); ++actions_it) {
105  action_ids.push_back(actions_it->first);
106  }
107  }
108  return action_ids;
109  }
110 
111  void Object::setPather(IPather* pather) {
112  m_pather = pather;
113  }
114 
115  bool Object::isBlocking() const {
116  if (m_blocking) {
117  return true;
118  }
119  if (m_inherited) {
120  return m_inherited->isBlocking();
121  }
122  return false;
123  }
124 
125  bool Object::isStatic() const {
126  if (m_static) {
127  return true;
128  }
129  if (m_inherited) {
130  return m_inherited->isStatic();
131  }
132  return false;
133  }
134 
135  bool Object::operator==(const Object& obj) const {
136  return m_id == obj.getId() && m_namespace == obj.getNamespace();
137  }
138 
139  bool Object::operator!=(const Object& obj) const {
140  return m_id != obj.getId() || m_namespace != obj.getNamespace();
141  }
142 
143 }
bool isStatic() const
Definition: object.cpp:125
Object(const std::string &identifier, const std::string &name_space, Object *inherited=NULL)
Definition: object.cpp:37
Action * createAction(const std::string &identifier, bool is_default=false)
Definition: object.cpp:62
Action * getAction(const std::string &identifier) const
Definition: object.cpp:85
void setPather(IPather *pather)
Definition: object.cpp:111
std::list< std::string > getActionIds() const
Definition: object.cpp:99
bool isBlocking() const
Definition: object.cpp:115
credit to phoku for his NodeDisplay example which the visitor code is adapted from ( he coded the qua...
Definition: soundclip.cpp:39