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 #define FREPPLE_CORE
00028 #include "frepple/model.h"
00029
00030 namespace frepple
00031 {
00032
00033 template<class Location> DECLARE_EXPORT Tree utils::HasName<Location>::st;
00034
00035
00036 DECLARE_EXPORT void Location::writeElement(XMLOutput* o, const Keyword& tag, mode m) const
00037 {
00038
00039 if (m == REFERENCE)
00040 {
00041 o->writeElement(tag, Tags::tag_name, getName());
00042 return;
00043 }
00044
00045
00046 if (m != NOHEADER) o->BeginObject(tag, Tags::tag_name, getName());
00047
00048
00049 HasDescription::writeElement(o, tag);
00050 HasHierarchy<Location>::writeElement(o, tag);
00051 o->writeElement(Tags::tag_available, available);
00052 o->EndObject(tag);
00053 }
00054
00055
00056 DECLARE_EXPORT void Location::beginElement(XMLInput& pIn, const Attribute& pAttr)
00057 {
00058 if (pAttr.isA(Tags::tag_available) || pAttr.isA(Tags::tag_maximum))
00059 pIn.readto( Calendar::reader(Calendar::metadata,pIn.getAttributes()) );
00060 else
00061 HasHierarchy<Location>::beginElement(pIn, pAttr);
00062 }
00063
00064
00065 DECLARE_EXPORT void Location::endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
00066 {
00067 if (pAttr.isA(Tags::tag_available))
00068 {
00069 CalendarBool *cal = dynamic_cast<CalendarBool*>(pIn.getPreviousObject());
00070 if (cal)
00071 setAvailable(cal);
00072 else
00073 {
00074 Calendar *c = dynamic_cast<Calendar*>(pIn.getPreviousObject());
00075 if (!c)
00076 throw LogicException("Incorrect object type during read operation");
00077 throw DataException("Calendar '" + c->getName() +
00078 "' has invalid type for use as location calendar");
00079 }
00080 }
00081 else
00082 {
00083 HasDescription::endElement(pIn, pAttr, pElement);
00084 HasHierarchy<Location>::endElement(pIn, pAttr, pElement);
00085 }
00086 }
00087
00088
00089 DECLARE_EXPORT Location::~Location()
00090 {
00091
00092 for (Buffer::iterator buf = Buffer::begin();
00093 buf != Buffer::end(); ++buf)
00094 if (buf->getLocation() == this) buf->setLocation(NULL);
00095
00096
00097 for (Resource::iterator res = Resource::begin();
00098 res != Resource::end(); ++res)
00099 if (res->getLocation() == this) res->setLocation(NULL);
00100
00101
00102 for (Operation::iterator oper = Operation::begin();
00103 oper != Operation::end(); ++oper)
00104 if (oper->getLocation() == this) oper->setLocation(NULL);
00105 }
00106
00107
00108 DECLARE_EXPORT PyObject* PythonLocation::getattro(const Attribute& attr)
00109 {
00110 if (!obj) return Py_BuildValue("");
00111 if (attr.isA(Tags::tag_name))
00112 return PythonObject(obj->getName());
00113 if (attr.isA(Tags::tag_description))
00114 return PythonObject(obj->getDescription());
00115 if (attr.isA(Tags::tag_category))
00116 return PythonObject(obj->getCategory());
00117 if (attr.isA(Tags::tag_subcategory))
00118 return PythonObject(obj->getSubCategory());
00119 if (attr.isA(Tags::tag_owner))
00120 return PythonObject(obj->getOwner());
00121 if (attr.isA(Tags::tag_available))
00122 return PythonObject(obj->getAvailable());
00123 if (attr.isA(Tags::tag_hidden))
00124 return PythonObject(obj->getHidden());
00125 return NULL;
00126 }
00127
00128
00129 DECLARE_EXPORT int PythonLocation::setattro(const Attribute& attr, const PythonObject& field)
00130 {
00131 if (attr.isA(Tags::tag_name))
00132 obj->setName(field.getString());
00133 else if (attr.isA(Tags::tag_description))
00134 obj->setDescription(field.getString());
00135 else if (attr.isA(Tags::tag_category))
00136 obj->setCategory(field.getString());
00137 else if (attr.isA(Tags::tag_subcategory))
00138 obj->setSubCategory(field.getString());
00139 else if (attr.isA(Tags::tag_owner))
00140 {
00141 if (!field.check(PythonLocation::getType()))
00142 {
00143 PyErr_SetString(PythonDataException, "location owner must be of type location");
00144 return -1;
00145 }
00146 Location* y = static_cast<PythonLocation*>(static_cast<PyObject*>(field))->obj;
00147 obj->setOwner(y);
00148 }
00149 else if (attr.isA(Tags::tag_available))
00150 {
00151 if (!field.check(PythonCalendarBool::getType()))
00152 {
00153 PyErr_SetString(PythonDataException, "location calendar must be of type calendar_bool");
00154 return -1;
00155 }
00156 CalendarBool* y = static_cast<PythonCalendarBool*>(static_cast<PyObject*>(field))->obj;
00157 obj->setAvailable(y);
00158 }
00159 else if (attr.isA(Tags::tag_hidden))
00160 obj->setHidden(field.getBool());
00161 else
00162 return -1;
00163 return 0;
00164 }
00165
00166
00167 DECLARE_EXPORT PyObject* PythonLocationDefault::getattro(const Attribute& attr)
00168 {
00169 return PythonLocation(obj).getattro(attr);
00170 }
00171
00172
00173 DECLARE_EXPORT int PythonLocationDefault::setattro(const Attribute& attr, const PythonObject& field)
00174 {
00175 return PythonLocation(obj).setattro(attr, field);
00176 }
00177
00178 }