customer.cpp
Go to the documentation of this file.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 #define FREPPLE_CORE
00029 #include "frepple/model.h"
00030
00031 namespace frepple
00032 {
00033
00034 template<class Customer> DECLARE_EXPORT Tree utils::HasName<Customer>::st;
00035 DECLARE_EXPORT const MetaCategory* Customer::metadata;
00036 DECLARE_EXPORT const MetaClass* CustomerDefault::metadata;
00037
00038
00039 int Customer::initialize()
00040 {
00041
00042 metadata = new MetaCategory("customer", "customers", reader, writer);
00043
00044
00045 return FreppleCategory<Customer>::initialize();
00046 }
00047
00048
00049 int CustomerDefault::initialize()
00050 {
00051
00052 CustomerDefault::metadata = new MetaClass(
00053 "customer",
00054 "customer_default",
00055 Object::createString<CustomerDefault>, true);
00056
00057
00058 return FreppleClass<CustomerDefault,Customer>::initialize();
00059 }
00060
00061
00062 DECLARE_EXPORT void Customer::writeElement(XMLOutput* o, const Keyword& tag, mode m) const
00063 {
00064
00065 if (m == REFERENCE)
00066 {
00067 o->writeElement(tag, Tags::tag_name, getName());
00068 return;
00069 }
00070
00071
00072 if (m != NOHEADER) o->BeginObject(tag, Tags::tag_name, getName());
00073
00074
00075 HasDescription::writeElement(o, tag);
00076 HasHierarchy<Customer>::writeElement(o, tag);
00077 o->EndObject(tag);
00078 }
00079
00080
00081 DECLARE_EXPORT void Customer::beginElement(XMLInput& pIn, const Attribute& pAttr)
00082 {
00083 HasHierarchy<Customer>::beginElement(pIn, pAttr);
00084 }
00085
00086
00087 DECLARE_EXPORT void Customer::endElement(XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
00088 {
00089 HasDescription::endElement(pIn, pAttr, pElement);
00090 HasHierarchy<Customer>::endElement(pIn, pAttr, pElement);
00091 }
00092
00093
00094 DECLARE_EXPORT Customer::~Customer()
00095 {
00096
00097 for (Demand::iterator i = Demand::begin(); i != Demand::end(); ++i)
00098 if (i->getCustomer() == this) i->setCustomer(NULL);
00099 }
00100
00101
00102 DECLARE_EXPORT PyObject* Customer::getattro(const Attribute& attr)
00103 {
00104 if (attr.isA(Tags::tag_name))
00105 return PythonObject(getName());
00106 if (attr.isA(Tags::tag_description))
00107 return PythonObject(getDescription());
00108 if (attr.isA(Tags::tag_category))
00109 return PythonObject(getCategory());
00110 if (attr.isA(Tags::tag_subcategory))
00111 return PythonObject(getSubCategory());
00112 if (attr.isA(Tags::tag_owner))
00113 return PythonObject(getOwner());
00114 if (attr.isA(Tags::tag_hidden))
00115 return PythonObject(getHidden());
00116 return NULL;
00117 }
00118
00119
00120 DECLARE_EXPORT int Customer::setattro(const Attribute& attr, const PythonObject& field)
00121 {
00122 if (attr.isA(Tags::tag_name))
00123 setName(field.getString());
00124 else if (attr.isA(Tags::tag_description))
00125 setDescription(field.getString());
00126 else if (attr.isA(Tags::tag_category))
00127 setCategory(field.getString());
00128 else if (attr.isA(Tags::tag_subcategory))
00129 setSubCategory(field.getString());
00130 else if (attr.isA(Tags::tag_owner))
00131 {
00132 if (!field.check(Customer::metadata))
00133 {
00134 PyErr_SetString(PythonDataException, "customer owner must be of type customer");
00135 return -1;
00136 }
00137 Customer* y = static_cast<Customer*>(static_cast<PyObject*>(field));
00138 setOwner(y);
00139 }
00140 else if (attr.isA(Tags::tag_hidden))
00141 setHidden(field.getBool());
00142 else
00143 return -1;
00144 return 0;
00145 }
00146
00147
00148 }