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 Customer> DECLARE_EXPORT Tree utils::HasName<Customer>::st;
00034
00035
00036 DECLARE_EXPORT void Customer::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<Customer>::writeElement(o, tag);
00051 o->EndObject(tag);
00052 }
00053
00054
00055 DECLARE_EXPORT void Customer::beginElement(XMLInput& pIn, const Attribute& pAttr)
00056 {
00057 HasHierarchy<Customer>::beginElement(pIn, pAttr);
00058 }
00059
00060
00061 DECLARE_EXPORT void Customer::endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
00062 {
00063 HasDescription::endElement(pIn, pAttr, pElement);
00064 HasHierarchy<Customer>::endElement(pIn, pAttr, pElement);
00065 }
00066
00067
00068 DECLARE_EXPORT Customer::~Customer()
00069 {
00070
00071 for (Demand::iterator i = Demand::begin(); i != Demand::end(); ++i)
00072 if (i->getCustomer() == this) i->setCustomer(NULL);
00073 }
00074
00075
00076 DECLARE_EXPORT PyObject* PythonCustomer::getattro(const Attribute& attr)
00077 {
00078 if (!obj) return Py_BuildValue("");
00079 if (attr.isA(Tags::tag_name))
00080 return PythonObject(obj->getName());
00081 if (attr.isA(Tags::tag_description))
00082 return PythonObject(obj->getDescription());
00083 if (attr.isA(Tags::tag_category))
00084 return PythonObject(obj->getCategory());
00085 if (attr.isA(Tags::tag_subcategory))
00086 return PythonObject(obj->getSubCategory());
00087 if (attr.isA(Tags::tag_owner))
00088 return PythonObject(obj->getOwner());
00089 if (attr.isA(Tags::tag_hidden))
00090 return PythonObject(obj->getHidden());
00091 return NULL;
00092 }
00093
00094
00095 DECLARE_EXPORT int PythonCustomer::setattro(const Attribute& attr, const PythonObject& field)
00096 {
00097 if (attr.isA(Tags::tag_name))
00098 obj->setName(field.getString());
00099 else if (attr.isA(Tags::tag_description))
00100 obj->setDescription(field.getString());
00101 else if (attr.isA(Tags::tag_category))
00102 obj->setCategory(field.getString());
00103 else if (attr.isA(Tags::tag_subcategory))
00104 obj->setSubCategory(field.getString());
00105 else if (attr.isA(Tags::tag_owner))
00106 {
00107 if (!field.check(PythonCustomer::getType()))
00108 {
00109 PyErr_SetString(PythonDataException, "customer owner must be of type customer");
00110 return -1;
00111 }
00112 Customer* y = static_cast<PythonCustomer*>(static_cast<PyObject*>(field))->obj;
00113 obj->setOwner(y);
00114 }
00115 else if (attr.isA(Tags::tag_hidden))
00116 obj->setHidden(field.getBool());
00117 else
00118 return -1;
00119 return 0;
00120 }
00121
00122
00123 DECLARE_EXPORT PyObject* PythonCustomerDefault::getattro(const Attribute& attr)
00124 {
00125 return PythonCustomer(obj).getattro(attr);
00126 }
00127
00128
00129 DECLARE_EXPORT int PythonCustomerDefault::setattro(const Attribute& attr, const PythonObject& field)
00130 {
00131 return PythonCustomer(obj).setattro(attr, field);
00132 }
00133
00134
00135 }