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