plan.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
00035 DECLARE_EXPORT Plan* Plan::thePlan;
00036 DECLARE_EXPORT const MetaCategory* Plan::metadata;
00037
00038
00039 int Plan::initialize()
00040 {
00041
00042 metadata = new MetaCategory("plan","");
00043
00044
00045 PythonType& x = PythonExtension<Plan>::getType();
00046 x.setName("parameters");
00047 x.setDoc("frePPLe global settings");
00048 x.supportgetattro();
00049 x.supportsetattro();
00050 int tmp =x.typeReady();
00051 const_cast<MetaCategory*>(metadata)->pythonClass = x.type_object();
00052
00053
00054
00055
00056
00057 thePlan = new Plan();
00058
00059
00060 return PyModule_AddObject(PythonInterpreter::getModule(),
00061 "settings", &Plan::instance()) + tmp;
00062 }
00063
00064
00065 DECLARE_EXPORT Plan::~Plan()
00066 {
00067
00068 Environment::setLogFile("");
00069
00070
00071 thePlan = NULL;
00072 }
00073
00074
00075 DECLARE_EXPORT void Plan::setCurrent (Date l)
00076 {
00077
00078 cur_Date = l;
00079
00080
00081
00082 for (Operation::iterator i = Operation::begin(); i != Operation::end(); ++i)
00083 i->setChanged();
00084 }
00085
00086
00087 DECLARE_EXPORT void Plan::writeElement (XMLOutput *o, const Keyword& tag, mode m) const
00088 {
00089
00090 assert(m != REFERENCE);
00091
00092
00093 if (m!=NOHEADER) o->BeginObject(tag);
00094
00095
00096 o->writeElement(Tags::tag_name, name);
00097 o->writeElement(Tags::tag_description, descr);
00098 o->writeElement(Tags::tag_current, cur_Date);
00099 Plannable::writeElement(o, tag);
00100
00101
00102 MetaCategory::persist(o);
00103
00104 o->EndObject(tag);
00105 }
00106
00107
00108 DECLARE_EXPORT void Plan::endElement (XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
00109 {
00110 if (pAttr.isA(Tags::tag_current))
00111 setCurrent(pElement.getDate());
00112 else if (pAttr.isA(Tags::tag_description))
00113 pElement >> descr;
00114 else if (pAttr.isA(Tags::tag_name))
00115 pElement >> name;
00116 else if (pAttr.isA(Tags::tag_logfile))
00117 Environment::setLogFile(pElement.getString());
00118 else
00119 Plannable::endElement(pIn, pAttr, pElement);
00120 }
00121
00122
00123 DECLARE_EXPORT void Plan::beginElement(XMLInput& pIn, const Attribute& pAttr)
00124 {
00125 const MetaCategory *cat = MetaCategory::findCategoryByGroupTag(pIn.getParentElement().first.getHash());
00126 if (cat)
00127 {
00128 if (cat->readFunction)
00129
00130 pIn.readto(cat->readFunction(cat,pIn.getAttributes()));
00131 else
00132
00133
00134
00135 pIn.IgnoreElement();
00136 }
00137 }
00138
00139
00140 DECLARE_EXPORT PyObject* Plan::getattro(const Attribute& attr)
00141 {
00142 if (attr.isA(Tags::tag_name))
00143 return PythonObject(Plan::instance().getName());
00144 if (attr.isA(Tags::tag_description))
00145 return PythonObject(Plan::instance().getDescription());
00146 if (attr.isA(Tags::tag_current))
00147 return PythonObject(Plan::instance().getCurrent());
00148 if (attr.isA(Tags::tag_logfile))
00149 return PythonObject(Environment::getLogFile());
00150 return NULL;
00151 }
00152
00153
00154 DECLARE_EXPORT int Plan::setattro(const Attribute& attr, const PythonObject& field)
00155 {
00156 if (attr.isA(Tags::tag_name))
00157 Plan::instance().setName(field.getString());
00158 else if (attr.isA(Tags::tag_description))
00159 Plan::instance().setDescription(field.getString());
00160 else if (attr.isA(Tags::tag_current))
00161 Plan::instance().setCurrent(field.getDate());
00162 else if (attr.isA(Tags::tag_logfile))
00163 Environment::setLogFile(field.getString());
00164 else
00165 return -1;
00166 return 0;
00167 }
00168
00169 }