00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include "util/base/exception.h"
00031
00032 #include "object.h"
00033 #include "action.h"
00034 #include "ipather.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_filename(""),
00041 m_inherited(inherited),
00042 m_actions(NULL),
00043 m_blocking(false),
00044 m_static(false),
00045 m_pather(NULL),
00046 m_visual(NULL),
00047 m_defaultaction(NULL) {
00048 }
00049
00050 Object::~Object() {
00051 if (m_actions) {
00052 std::map<std::string, Action*>::const_iterator i(m_actions->begin());
00053 while (i != m_actions->end()) {
00054 delete i->second;
00055 ++i;
00056 }
00057 delete m_actions;
00058 }
00059 delete m_visual;
00060 }
00061
00062 Action* Object::createAction(const std::string& identifier, bool is_default) {
00063 if (!m_actions) {
00064 m_actions = new std::map<std::string, Action*>;
00065 }
00066
00067 std::map<std::string, Action*>::const_iterator it = m_actions->begin();
00068 for(; it != m_actions->end(); ++it) {
00069 if(identifier == it->second->getId()) {
00070 throw NameClash(identifier);
00071 }
00072 }
00073
00074 Action* a = getAction(identifier);
00075 if (!a) {
00076 a = new Action(identifier);
00077 (*m_actions)[identifier] = a;
00078 if (is_default || (!m_defaultaction)) {
00079 m_defaultaction = a;
00080 }
00081 }
00082 return a;
00083 }
00084
00085 Action* Object::getAction(const std::string& identifier) const {
00086 std::map<std::string, Action*>::const_iterator i;
00087 if (m_actions) {
00088 i = m_actions->find(identifier);
00089 }
00090 if ((!m_actions) || (i == m_actions->end())) {
00091 if (m_inherited) {
00092 return m_inherited->getAction(identifier);
00093 }
00094 return NULL;
00095 }
00096 return i->second;
00097 }
00098
00099 std::list<std::string> Object::getActionIds() const {
00100 std::list<std::string> action_ids;
00101 action_ids.clear();
00102 if (m_actions) {
00103 std::map<std::string, Action*>::const_iterator actions_it = m_actions->begin();
00104 for(; actions_it != m_actions->end(); ++actions_it) {
00105 action_ids.push_back(actions_it->first);
00106 }
00107 }
00108 return action_ids;
00109 }
00110
00111 void Object::setPather(IPather* pather) {
00112 m_pather = pather;
00113 }
00114
00115 bool Object::isBlocking() const {
00116 if (m_blocking) {
00117 return true;
00118 }
00119 if (m_inherited) {
00120 return m_inherited->isBlocking();
00121 }
00122 return false;
00123 }
00124
00125 bool Object::isStatic() const {
00126 if (m_static) {
00127 return true;
00128 }
00129 if (m_inherited) {
00130 return m_inherited->isStatic();
00131 }
00132 return false;
00133 }
00134
00135 bool Object::operator==(const Object& obj) const {
00136 return m_id == obj.getId() && m_namespace == obj.getNamespace();
00137 }
00138
00139 bool Object::operator!=(const Object& obj) const {
00140 return m_id != obj.getId() || m_namespace != obj.getNamespace();
00141 }
00142
00143 }