FIFE
2008.0
|
00001 /*************************************************************************** 00002 * Copyright (C) 2005-2008 by the FIFE team * 00003 * http://www.fifengine.de * 00004 * This file is part of FIFE. * 00005 * * 00006 * FIFE is free software; you can redistribute it and/or * 00007 * modify it under the terms of the GNU Lesser General Public * 00008 * License as published by the Free Software Foundation; either * 00009 * version 2.1 of the License, or (at your option) any later version. * 00010 * * 00011 * This library is distributed in the hope that it will be useful, * 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00014 * Lesser General Public License for more details. * 00015 * * 00016 * You should have received a copy of the GNU Lesser General Public * 00017 * License along with this library; if not, write to the * 00018 * Free Software Foundation, Inc., * 00019 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 00020 ***************************************************************************/ 00021 00022 // Standard C++ library includes 00023 00024 // 3rd party library includes 00025 00026 // FIFE includes 00027 // These includes are split up in two parts, separated by one empty line 00028 // First block: files included from the FIFE root src directory 00029 // Second block: files included from the same folder 00030 #include "util/base/exception.h" 00031 00032 #include "object.h" 00033 #include "action.h" 00034 #include "abstractpather.h" 00035 00036 namespace FIFE { 00037 Object::Object(const std::string& identifier, const std::string& name_space, Object* inherited): 00038 m_id(identifier), 00039 m_namespace(name_space), 00040 m_inherited(inherited), 00041 m_actions(NULL), 00042 m_blocking(false), 00043 m_static(false), 00044 m_pather(NULL), 00045 m_visual(NULL), 00046 m_defaultaction(NULL) { 00047 } 00048 00049 Object::~Object() { 00050 if (m_actions) { 00051 std::map<std::string, Action*>::const_iterator i(m_actions->begin()); 00052 while (i != m_actions->end()) { 00053 delete i->second; 00054 ++i; 00055 } 00056 delete m_actions; 00057 } 00058 delete m_visual; 00059 } 00060 00061 Action* Object::createAction(const std::string& identifier, bool is_default) { 00062 if (!m_actions) { 00063 m_actions = new std::map<std::string, Action*>; 00064 } 00065 00066 std::map<std::string, Action*>::const_iterator it = m_actions->begin(); 00067 for(; it != m_actions->end(); ++it) { 00068 if(identifier == it->second->getId()) { 00069 throw NameClash(identifier); 00070 } 00071 } 00072 00073 Action* a = getAction(identifier); 00074 if (!a) { 00075 a = new Action(identifier); 00076 (*m_actions)[identifier] = a; 00077 if (is_default || (!m_defaultaction)) { 00078 m_defaultaction = a; 00079 } 00080 } 00081 return a; 00082 } 00083 00084 Action* Object::getAction(const std::string& identifier) const { 00085 std::map<std::string, Action*>::const_iterator i; 00086 if (m_actions) { 00087 i = m_actions->find(identifier); 00088 } 00089 if ((!m_actions) || (i == m_actions->end())) { 00090 if (m_inherited) { 00091 return m_inherited->getAction(identifier); 00092 } 00093 return NULL; 00094 } 00095 return i->second; 00096 } 00097 00098 std::list<std::string> Object::getActionIds() const { 00099 std::list<std::string> action_ids; 00100 action_ids.clear(); 00101 if (m_actions) { 00102 std::map<std::string, Action*>::const_iterator actions_it = m_actions->begin(); 00103 for(; actions_it != m_actions->end(); ++actions_it) { 00104 action_ids.push_back(actions_it->first); 00105 } 00106 } 00107 return action_ids; 00108 } 00109 00110 void Object::setPather(AbstractPather* pather) { 00111 m_pather = pather; 00112 } 00113 00114 bool Object::isBlocking() const { 00115 if (m_blocking) { 00116 return true; 00117 } 00118 if (m_inherited) { 00119 return m_inherited->isBlocking(); 00120 } 00121 return false; 00122 } 00123 00124 bool Object::isStatic() const { 00125 if (m_static) { 00126 return true; 00127 } 00128 if (m_inherited) { 00129 return m_inherited->isStatic(); 00130 } 00131 return false; 00132 } 00133 00134 bool Object::operator==(const Object& obj) const { 00135 return m_id == obj.getId() && m_namespace == obj.getNamespace(); 00136 } 00137 00138 bool Object::operator!=(const Object& obj) const { 00139 return m_id != obj.getId() || m_namespace != obj.getNamespace(); 00140 } 00141 00142 }