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 Calendar> DECLARE_EXPORT Tree utils::HasName<Calendar>::st;
00034
00035
00036 template <> DECLARE_EXPORT bool CalendarValue<string>::getBool() const
00037 { return defaultValue.empty(); }
00038 template <> DECLARE_EXPORT bool CalendarValue<string>::BucketValue::getBool() const
00039 { return val.empty(); }
00040
00041
00042 DECLARE_EXPORT Calendar::~Calendar()
00043 {
00044
00045 while (firstBucket)
00046 {
00047 Bucket* tmp = firstBucket;
00048 firstBucket = firstBucket->nextBucket;
00049 delete tmp;
00050 }
00051 }
00052
00053
00054 DECLARE_EXPORT CalendarDouble::~CalendarDouble()
00055 {
00056
00057 for (Buffer::iterator b = Buffer::begin(); b != Buffer::end(); ++b)
00058 {
00059 if (b->getMinimum()==this) b->setMinimum(NULL);
00060 if (b->getMaximum()==this) b->setMaximum(NULL);
00061 }
00062
00063
00064 for (Resource::iterator r = Resource::begin(); r != Resource::end(); ++r)
00065 if (r->getMaximum()==this) r->setMaximum(NULL);
00066 }
00067
00068
00069 DECLARE_EXPORT CalendarBool::~CalendarBool()
00070 {
00071
00072 for (Location::iterator l = Location::begin(); l != Location::end(); ++l)
00073 {
00074 if (l->getAvailable() == this)
00075 l->setAvailable(NULL);
00076 }
00077 }
00078
00079
00080 DECLARE_EXPORT Calendar::Bucket* Calendar::addBucket
00081 (Date start, Date end, string name)
00082 {
00083
00084 if (start > end)
00085 {
00086
00087 Date tmp = end;
00088 end = start;
00089 start = end;
00090 }
00091
00092
00093 Bucket *next = firstBucket, *prev = NULL;
00094 while (next && next->startdate < start)
00095 {
00096 prev = next;
00097 next = next->nextBucket;
00098 }
00099
00100
00101 Bucket *c = createNewBucket(start,end,name);
00102 c->nextBucket = next;
00103 c->prevBucket = prev;
00104
00105
00106 if (prev) prev->nextBucket = c;
00107 else firstBucket = c;
00108 if (next) next->prevBucket = c;
00109
00110
00111 return c;
00112 }
00113
00114
00115 DECLARE_EXPORT void Calendar::removeBucket(Calendar::Bucket* bkt)
00116 {
00117
00118 Bucket *b = firstBucket;
00119 while (b && b != bkt) b = b->nextBucket;
00120
00121
00122 if (!b)
00123 throw DataException("Trying to remove unavailable bucket from calendar '"
00124 + getName() + "'");
00125
00126
00127 if (bkt->prevBucket)
00128
00129 bkt->prevBucket->nextBucket = bkt->nextBucket;
00130 else
00131
00132 firstBucket = bkt->nextBucket;
00133 if (bkt->nextBucket)
00134
00135 bkt->nextBucket->prevBucket = bkt->prevBucket;
00136
00137
00138 delete bkt;
00139 }
00140
00141
00142 DECLARE_EXPORT Calendar::Bucket* Calendar::findBucket(Date d, bool fwd) const
00143 {
00144 Calendar::Bucket *curBucket = NULL;
00145 double curPriority = DBL_MAX;
00146 for (Bucket *b = firstBucket; b; b = b->nextBucket)
00147 {
00148 if (b->getStart() > d)
00149
00150
00151 break;
00152 else if (curPriority > b->getPriority() && b->checkValid(d)
00153 && ( (fwd && d >= b->getStart() && d < b->getEnd()) ||
00154 (!fwd && d > b->getStart() && d <= b->getEnd())
00155 ))
00156 {
00157
00158 curPriority = b->getPriority();
00159 curBucket = &*b;
00160 }
00161 }
00162 return curBucket;
00163 }
00164
00165
00166 DECLARE_EXPORT Calendar::Bucket* Calendar::findBucket(const string& d) const
00167 {
00168 for (Bucket *b = firstBucket; b; b = b->nextBucket)
00169 if (b->getName() == d) return b;
00170 return NULL;
00171 }
00172
00173
00174 DECLARE_EXPORT void Calendar::writeElement(XMLOutput *o, const Keyword& tag, mode m) const
00175 {
00176
00177 if (m == REFERENCE)
00178 {
00179 o->writeElement
00180 (tag, Tags::tag_name, getName(), Tags::tag_type, getType().type);
00181 return;
00182 }
00183
00184
00185 if (m != NOHEADER) o->BeginObject
00186 (tag, Tags::tag_name, getName(), Tags::tag_type, getType().type);
00187
00188
00189 o->BeginObject (Tags::tag_buckets);
00190 for (BucketIterator i = beginBuckets(); i != endBuckets(); ++i)
00191
00192
00193 o->writeElement(Tags::tag_bucket, *i, FULL);
00194 o->EndObject(Tags::tag_buckets);
00195
00196 o->EndObject(tag);
00197 }
00198
00199
00200 DECLARE_EXPORT Calendar::Bucket* Calendar::createBucket(const AttributeList& atts)
00201 {
00202
00203 Date startdate = atts.get(Tags::tag_start)->getDate();
00204 const DataElement* d = atts.get(Tags::tag_end);
00205 Date enddate = *d ? d->getDate() : Date::infiniteFuture;
00206 string name = atts.get(Tags::tag_name)->getString();
00207
00208
00209 Calendar::Bucket* result = NULL;
00210 for (BucketIterator x = beginBuckets(); x!=endBuckets(); ++x)
00211 {
00212 if ((!name.empty() && x->nm==name)
00213 || (name.empty() && x->startdate==startdate && x->enddate==enddate))
00214 {
00215
00216 result = &*x;
00217 break;
00218 }
00219 }
00220
00221
00222 switch (MetaClass::decodeAction(atts))
00223 {
00224 case ADD:
00225
00226 if (result)
00227 throw("Bucket " + string(startdate) + " " + string(enddate) + " " + name
00228 + " already exists in calendar '" + getName() + "'");
00229 result = addBucket(startdate, enddate, name);
00230 return result;
00231 case CHANGE:
00232
00233 if (!result)
00234 throw DataException("Bucket " + string(startdate) + " " + string(enddate)
00235 + " " + name + " doesn't exist in calendar '" + getName() + "'");
00236 return result;
00237 case REMOVE:
00238
00239 if (!result)
00240 throw DataException("Bucket " + string(startdate) + " " + string(enddate)
00241 + " " + name + " doesn't exist in calendar '" + getName() + "'");
00242 else
00243 {
00244
00245 removeBucket(result);
00246 return NULL;
00247 }
00248 case ADD_CHANGE:
00249 if (!result)
00250
00251 result = addBucket(startdate, enddate, name);
00252 return result;
00253 }
00254
00255
00256 throw LogicException("Unreachable code reached");
00257 }
00258
00259
00260 DECLARE_EXPORT void Calendar::beginElement (XMLInput& pIn, const Attribute& pAttr)
00261 {
00262 if (pAttr.isA (Tags::tag_bucket)
00263 && pIn.getParentElement().first.isA(Tags::tag_buckets))
00264
00265 pIn.readto(createBucket(pIn.getAttributes()));
00266 }
00267
00268
00269 DECLARE_EXPORT void Calendar::Bucket::writeHeader(XMLOutput *o) const
00270 {
00271
00272 if (startdate != Date::infinitePast)
00273 {
00274 if (enddate != Date::infiniteFuture)
00275 {
00276 if (!nm.empty())
00277 o->BeginObject(Tags::tag_bucket, Tags::tag_start, string(startdate), Tags::tag_end, string(enddate), Tags::tag_name, nm);
00278 else
00279 o->BeginObject(Tags::tag_bucket, Tags::tag_start, string(startdate), Tags::tag_end, string(enddate));
00280 }
00281 else
00282 {
00283 if (!nm.empty())
00284 o->BeginObject(Tags::tag_bucket, Tags::tag_start, string(startdate), Tags::tag_name, nm);
00285 else
00286 o->BeginObject(Tags::tag_bucket, Tags::tag_start, string(startdate));
00287 }
00288 }
00289 else
00290 {
00291 if (enddate != Date::infiniteFuture)
00292 {
00293 if (!nm.empty())
00294 o->BeginObject(Tags::tag_bucket, Tags::tag_end, string(enddate), Tags::tag_name, nm);
00295 else
00296 o->BeginObject(Tags::tag_bucket, Tags::tag_end, string(enddate));
00297 }
00298 else
00299 {
00300 if (!nm.empty())
00301 o->BeginObject(Tags::tag_bucket, Tags::tag_name, nm);
00302 else
00303 o->BeginObject(Tags::tag_bucket);
00304 }
00305 }
00306 }
00307
00308
00309 DECLARE_EXPORT void Calendar::Bucket::writeElement
00310 (XMLOutput *o, const Keyword& tag, mode m) const
00311 {
00312 assert(m == DEFAULT || m == FULL);
00313 writeHeader(o);
00314 if (priority) o->writeElement(Tags::tag_priority, priority);
00315 o->EndObject(tag);
00316 }
00317
00318
00319 DECLARE_EXPORT void Calendar::Bucket::endElement (XMLInput& pIn, const Attribute& pAttr, const DataElement& pElement)
00320 {
00321 if (pAttr.isA(Tags::tag_priority))
00322 pElement >> priority;
00323 }
00324
00325
00326 DECLARE_EXPORT Calendar::EventIterator& Calendar::EventIterator::operator++()
00327 {
00328
00329 Date d = curDate;
00330 curDate = Date::infiniteFuture;
00331 curBucket = NULL;
00332 curPriority = DBL_MAX;
00333 for (const Calendar::Bucket *b = theCalendar->firstBucket; b; b = b->nextBucket)
00334 b->nextEvent(this, d);
00335 return *this;
00336 }
00337
00338
00339 DECLARE_EXPORT Calendar::EventIterator& Calendar::EventIterator::operator--()
00340 {
00341
00342 Date d = curDate;
00343 curDate = Date::infinitePast;
00344 curBucket = NULL;
00345 curPriority = DBL_MAX;
00346 for (const Calendar::Bucket *b = theCalendar->firstBucket; b; b = b->nextBucket)
00347 b->prevEvent(this, d);
00348 return *this;
00349 }
00350
00351
00352 DECLARE_EXPORT void Calendar::Bucket::nextEvent(EventIterator* iter, Date refDate) const
00353 {
00354 if (iter->curPriority < priority)
00355
00356 return;
00357
00358 if (refDate < startdate && startdate <= iter->curDate)
00359 {
00360
00361 iter->curDate = startdate;
00362 iter->curBucket = this;
00363 iter->curPriority = priority;
00364 return;
00365 }
00366
00367 if (refDate < enddate && enddate < iter->curDate)
00368 {
00369
00370 iter->curDate = enddate;
00371 iter->curBucket = iter->theCalendar->findBucket(enddate);
00372 iter->curPriority = priority;
00373 return;
00374 }
00375 }
00376
00377
00378 DECLARE_EXPORT void Calendar::Bucket::prevEvent(EventIterator* iter, Date refDate) const
00379 {
00380 if (iter->curPriority < priority)
00381
00382 return;
00383
00384 if (refDate > enddate && enddate >= iter->curDate)
00385 {
00386
00387 iter->curDate = enddate;
00388 iter->curBucket = this;
00389 iter->curPriority = priority;
00390 return;
00391 }
00392
00393 if (refDate > startdate && startdate > iter->curDate)
00394 {
00395
00396 iter->curDate = startdate;
00397 iter->curBucket = iter->theCalendar->findBucket(startdate,false);
00398 iter->curPriority = priority;
00399 return;
00400 }
00401
00402 }
00403
00404
00405 DECLARE_EXPORT PyObject* PythonCalendar::getattro(const Attribute& attr)
00406 {
00407 if (!obj) return Py_BuildValue("");
00408 if (attr.isA(Tags::tag_name))
00409 return PythonObject(obj->getName());
00410 if (attr.isA(Tags::tag_buckets))
00411 return new PythonCalendarBucketIterator(obj);
00412 return NULL;
00413 }
00414
00415
00416 DECLARE_EXPORT int PythonCalendar::setattro(const Attribute& attr, const PythonObject& field)
00417 {
00418 if (attr.isA(Tags::tag_name))
00419 obj->setName(field.getString());
00420 else
00421 return -1;
00422 return 0;
00423 }
00424
00425
00426 DECLARE_EXPORT PyObject* PythonCalendarVoid::getattro(const Attribute& attr)
00427 {
00428 return PythonCalendar(obj).getattro(attr);
00429 }
00430
00431
00432 DECLARE_EXPORT int PythonCalendarVoid::setattro(const Attribute& attr, const PythonObject& field)
00433 {
00434 return PythonCalendar(obj).setattro(attr, field);
00435 }
00436
00437
00438 DECLARE_EXPORT PyObject* PythonCalendarVoid::setValue(PyObject* self, PyObject* args, PyObject* kwdict)
00439 {
00440 try
00441 {
00442
00443 CalendarVoid *cal = static_cast<PythonCalendarVoid*>(self)->obj;
00444 if (!cal) throw LogicException("Can't set value of a NULL calendar");
00445
00446
00447 PyObject *pystart, *pyend, *pyval = NULL;
00448 if (!PyArg_ParseTuple(args, "OO|O", &pystart, &pyend, &pyval))
00449 return NULL;
00450
00451
00452 PythonObject start(pystart), end(pyend);
00453 cal->addBucket(start.getDate(), end.getDate(), "");
00454 }
00455 catch(...)
00456 {
00457 PythonType::evalException();
00458 return NULL;
00459 }
00460 return Py_BuildValue("");
00461 }
00462
00463
00464 DECLARE_EXPORT PyObject* PythonCalendarBool::getattro(const Attribute& attr)
00465 {
00466 if (!obj) return Py_BuildValue("");
00467 if (attr.isA(Tags::tag_default))
00468 return PythonObject(obj->getDefault());
00469 return PythonCalendar(obj).getattro(attr);
00470 }
00471
00472
00473 DECLARE_EXPORT int PythonCalendarBool::setattro(const Attribute& attr, const PythonObject& field)
00474 {
00475 if (attr.isA(Tags::tag_default))
00476 obj->setDefault(field.getBool());
00477 else
00478 return PythonCalendar(obj).setattro(attr, field);
00479 return 0;
00480 }
00481
00482
00483 DECLARE_EXPORT PyObject* PythonCalendarBool::setValue(PyObject* self, PyObject* args, PyObject* kwdict)
00484 {
00485 try
00486 {
00487
00488 CalendarBool *cal = static_cast<PythonCalendarBool*>(self)->obj;
00489 if (!cal) throw LogicException("Can't set value of a NULL calendar");
00490
00491
00492 PyObject *pystart, *pyend, *pyval;
00493 if (!PyArg_ParseTuple(args, "OOO", &pystart, &pyend, &pyval))
00494 return NULL;
00495
00496
00497 PythonObject start(pystart), end(pyend), val(pyval);
00498 cal->setValue(start.getDate(), end.getDate(), val.getBool());
00499 }
00500 catch(...)
00501 {
00502 PythonType::evalException();
00503 return NULL;
00504 }
00505 return Py_BuildValue("");
00506 }
00507
00508
00509 DECLARE_EXPORT PyObject* PythonCalendarDouble::getattro(const Attribute& attr)
00510 {
00511 if (!obj) return Py_BuildValue("");
00512 if (attr.isA(Tags::tag_default))
00513 return PythonObject(obj->getDefault());
00514 return PythonCalendar(obj).getattro(attr);
00515 }
00516
00517
00518 DECLARE_EXPORT int PythonCalendarDouble::setattro(const Attribute& attr, const PythonObject& field)
00519 {
00520 if (attr.isA(Tags::tag_default))
00521 obj->setDefault(field.getDouble());
00522 else
00523 return PythonCalendar(obj).setattro(attr, field);
00524 return 0;
00525 }
00526
00527
00528 DECLARE_EXPORT PyObject* PythonCalendarDouble::setValue(PyObject* self, PyObject* args, PyObject* kwdict)
00529 {
00530 try
00531 {
00532
00533 CalendarDouble *cal = static_cast<PythonCalendarDouble*>(self)->obj;
00534 if (!cal) throw LogicException("Can't set value of a NULL calendar");
00535
00536
00537 PyObject *pystart, *pyend, *pyval;
00538 if (!PyArg_ParseTuple(args, "OOO", &pystart, &pyend, &pyval))
00539 return NULL;
00540
00541
00542 PythonObject start(pystart), end(pyend), val(pyval);
00543 cal->setValue(start.getDate(), end.getDate(), val.getDouble());
00544 }
00545 catch(...)
00546 {
00547 PythonType::evalException();
00548 return NULL;
00549 }
00550 return Py_BuildValue("");
00551 }
00552
00553
00554 DECLARE_EXPORT PyObject* PythonCalendarString::getattro(const Attribute& attr)
00555 {
00556 if (!obj) return Py_BuildValue("");
00557 if (attr.isA(Tags::tag_default))
00558 return PythonObject(obj->getDefault());
00559 return PythonCalendar(obj).getattro(attr);
00560 }
00561
00562
00563 DECLARE_EXPORT int PythonCalendarString::setattro(const Attribute& attr, const PythonObject& field)
00564 {
00565 if (attr.isA(Tags::tag_default))
00566 obj->setDefault(field.getString());
00567 else
00568 return PythonCalendar(obj).setattro(attr, field);
00569 return 0;
00570 }
00571
00572
00573 DECLARE_EXPORT PyObject* PythonCalendarString::setValue(PyObject* self, PyObject* args, PyObject* kwdict)
00574 {
00575 try
00576 {
00577
00578 CalendarString *cal = static_cast<PythonCalendarString*>(self)->obj;
00579 if (!cal) throw LogicException("Can't set value of a NULL calendar");
00580
00581
00582 PyObject *pystart, *pyend, *pyval;
00583 if (!PyArg_ParseTuple(args, "OOO", &pystart, &pyend, &pyval))
00584 return NULL;
00585
00586
00587 PythonObject start(pystart), end(pyend), val(pyval);
00588 cal->setValue(start.getDate(), end.getDate(), val.getString());
00589 }
00590 catch(...)
00591 {
00592 PythonType::evalException();
00593 return NULL;
00594 }
00595 return Py_BuildValue("");
00596 }
00597
00598
00599 DECLARE_EXPORT PyObject* PythonCalendarInt::getattro(const Attribute& attr)
00600 {
00601 if (!obj) return Py_BuildValue("");
00602 if (attr.isA(Tags::tag_default))
00603 return PythonObject(obj->getDefault());
00604 return PythonCalendar(obj).getattro(attr);
00605 }
00606
00607
00608 DECLARE_EXPORT int PythonCalendarInt::setattro(const Attribute& attr, const PythonObject& field)
00609 {
00610 if (attr.isA(Tags::tag_default))
00611 obj->setDefault(field.getInt());
00612 else
00613 return PythonCalendar(obj).setattro(attr, field);
00614 return 0;
00615 }
00616
00617
00618 DECLARE_EXPORT PyObject* PythonCalendarInt::setValue(PyObject* self, PyObject* args, PyObject* kwdict)
00619 {
00620 try
00621 {
00622
00623 CalendarInt *cal = static_cast<PythonCalendarInt*>(self)->obj;
00624 if (!cal) throw LogicException("Can't set value of a NULL calendar");
00625
00626
00627 PyObject *pystart, *pyend, *pyval;
00628 if (!PyArg_ParseTuple(args, "OOO", &pystart, &pyend, &pyval))
00629 return NULL;
00630
00631
00632 PythonObject start(pystart), end(pyend), val(pyval);
00633 cal->setValue(start.getDate(), end.getDate(), val.getInt());
00634 }
00635 catch(...)
00636 {
00637 PythonType::evalException();
00638 return NULL;
00639 }
00640 return Py_BuildValue("");
00641 }
00642
00643
00644 DECLARE_EXPORT PyObject* PythonCalendarOperation::getattro(const Attribute& attr)
00645 {
00646 if (!obj) return Py_BuildValue("");
00647 if (attr.isA(Tags::tag_default))
00648 return PythonObject(obj->getDefault());
00649 return PythonCalendar(obj).getattro(attr);
00650 }
00651
00652
00653 DECLARE_EXPORT int PythonCalendarOperation::setattro(const Attribute& attr, const PythonObject& field)
00654 {
00655 if (attr.isA(Tags::tag_default))
00656 {
00657 if (!field.check(PythonOperation::getType()))
00658 {
00659 PyErr_SetString(PythonDataException, "calendar_operation stores values of type operation");
00660 return -1;
00661 }
00662 Operation* y = static_cast<PythonOperation*>(static_cast<PyObject*>(field))->obj;
00663 obj->setDefault(y);
00664 }
00665 else
00666 return PythonCalendar(obj).setattro(attr, field);
00667 return 0;
00668 }
00669
00670
00671 DECLARE_EXPORT PyObject* PythonCalendarOperation::setValue(PyObject* self, PyObject* args, PyObject* kwdict)
00672 {
00673 try
00674 {
00675
00676 CalendarOperation *cal = static_cast<PythonCalendarOperation*>(self)->obj;
00677 if (!cal) throw LogicException("Can't set value of a NULL calendar");
00678
00679
00680 PyObject *pystart, *pyend, *pyval;
00681 if (!PyArg_ParseTuple(args, "OOO", &pystart, &pyend, &pyval))
00682 return NULL;
00683
00684
00685 PythonObject start(pystart), end(pyend), val(pyval);
00686 if (!val.check(PythonOperation::getType()))
00687 {
00688 PyErr_SetString(PythonDataException, "calendar_operation stores values of type operation");
00689 return NULL;
00690 }
00691 Operation* y = static_cast<PythonOperation*>(static_cast<PyObject*>(val))->obj;
00692 cal->setValue(start.getDate(), end.getDate(), y);
00693 }
00694 catch(...)
00695 {
00696 PythonType::evalException();
00697 return NULL;
00698 }
00699 return Py_BuildValue("");
00700 }
00701
00702
00703 int PythonCalendarBucketIterator::initialize(PyObject* m)
00704 {
00705
00706 PythonType& x = PythonExtension<PythonCalendarBucketIterator>::getType();
00707 x.setName("calendarBucketIterator");
00708 x.setDoc("frePPLe iterator for calendar buckets");
00709 x.supportiter();
00710 return x.typeReady(m);
00711 }
00712
00713
00714 PyObject* PythonCalendarBucketIterator::iternext()
00715 {
00716 if (i == cal->endBuckets()) return NULL;
00717 return new PythonCalendarBucket(cal, &*(i++));
00718 }
00719
00720
00721 int PythonCalendarBucket::initialize(PyObject* m)
00722 {
00723
00724 PythonType& x = PythonExtension<PythonCalendarBucket>::getType();
00725 x.setName("calendarBucket");
00726 x.setDoc("frePPLe calendar bucket");
00727 x.supportgetattro();
00728 x.supportsetattro();
00729 return x.typeReady(m);
00730 }
00731
00732
00733 DECLARE_EXPORT PyObject* PythonCalendarBucket::getattro(const Attribute& attr)
00734 {
00735 if (!obj) return Py_BuildValue("");
00736 if (attr.isA(Tags::tag_start))
00737 return PythonObject(obj->getStart());
00738 if (attr.isA(Tags::tag_end))
00739 return PythonObject(obj->getEnd());
00740 if (attr.isA(Tags::tag_value))
00741 {
00742 if (cal->getType() == *CalendarDouble::metadata)
00743 return PythonObject(dynamic_cast< CalendarValue<double>::BucketValue* >(obj)->getValue());
00744 if (cal->getType() == *CalendarBool::metadata)
00745 return PythonObject(dynamic_cast< CalendarValue<bool>::BucketValue* >(obj)->getValue());
00746 if (cal->getType() == *CalendarInt::metadata)
00747 return PythonObject(dynamic_cast< CalendarValue<int>::BucketValue* >(obj)->getValue());
00748 if (cal->getType() == *CalendarString::metadata)
00749 return PythonObject(dynamic_cast< CalendarValue<string>::BucketValue* >(obj)->getValue());
00750 if (cal->getType() == *CalendarOperation::metadata)
00751 return PythonObject(dynamic_cast< CalendarPointer<Operation>::BucketPointer* >(obj)->getValue());
00752 if (cal->getType() == *CalendarVoid::metadata)
00753 return Py_BuildValue("");
00754 PyErr_SetString(PythonLogicException, "calendar type not recognized");
00755 return NULL;
00756 }
00757 if (attr.isA(Tags::tag_priority))
00758 return PythonObject(obj->getPriority());
00759 if (attr.isA(Tags::tag_name))
00760 return PythonObject(obj->getName());
00761 return NULL;
00762 }
00763
00764
00765 DECLARE_EXPORT int PythonCalendarBucket::setattro(const Attribute& attr, const PythonObject& field)
00766 {
00767 if (attr.isA(Tags::tag_name))
00768 obj->setName(field.getString());
00769 else if (attr.isA(Tags::tag_start))
00770 obj->setStart(field.getDate());
00771 else if (attr.isA(Tags::tag_end))
00772 obj->setEnd(field.getDate());
00773 else if (attr.isA(Tags::tag_priority))
00774 obj->setPriority(field.getInt());
00775 else if (attr.isA(Tags::tag_value))
00776 {
00777 if (cal->getType() == *CalendarDouble::metadata)
00778 dynamic_cast< CalendarValue<double>::BucketValue* >(obj)->setValue(field.getDouble());
00779 else if (cal->getType() == *CalendarBool::metadata)
00780 dynamic_cast< CalendarValue<bool>::BucketValue* >(obj)->setValue(field.getBool());
00781 else if (cal->getType() == *CalendarInt::metadata)
00782 dynamic_cast< CalendarValue<int>::BucketValue* >(obj)->setValue(field.getInt());
00783 else if (cal->getType() == *CalendarString::metadata)
00784 dynamic_cast< CalendarValue<string>::BucketValue* >(obj)->setValue(field.getString());
00785 else if (cal->getType() == *CalendarOperation::metadata)
00786 {
00787 if (!field.check(PythonOperation::getType()))
00788 {
00789 PyErr_SetString(PythonDataException, "calendar_operation stores values of type operation");
00790 return -1;
00791 }
00792 Operation* y = static_cast<PythonOperation*>(static_cast<PyObject*>(field))->obj;
00793 dynamic_cast< CalendarPointer<Operation>::BucketPointer* >(obj)->setValue(y);
00794 }
00795 else if (cal->getType() == *CalendarVoid::metadata)
00796 return -1;
00797 else
00798 {
00799 PyErr_SetString(PythonLogicException, "calendar type not recognized");
00800 return -1;
00801 }
00802 }
00803 else
00804 return -1;
00805 return 0;
00806 }
00807
00808
00809 }