DECLARE_EXPORT void ResourceSkill::writeElement(XMLOutput *o, const Keyword& tag, mode m) const { // If the resourceskill has already been saved, no need to repeat it again // A 'reference' to a load is not useful to be saved. if (m == REFERENCE) return; assert(m != NOHEAD && m != NOHEADTAIL); o->BeginObject(tag); // If the resourceskill is defined inside of a resource tag, we don't need to save // the resource. Otherwise we do save it... if (!dynamic_cast<Resource*>(o->getPreviousObject())) o->writeElement(Tags::tag_resource, getResource()); // If the resourceskill is defined inside of a skill tag, we don't need to save // the skill. Otherwise we do save it... if (!dynamic_cast<Skill*>(o->getPreviousObject())) o->writeElement(Tags::tag_skill, getSkill()); // Write the priority and effective daterange if (getPriority()!=1) o->writeElement(Tags::tag_priority, getPriority()); if (getEffective().getStart() != Date::infinitePast) o->writeElement(Tags::tag_effective_start, getEffective().getStart()); if (getEffective().getEnd() != Date::infiniteFuture) o->writeElement(Tags::tag_effective_end, getEffective().getEnd()); // Write the tail if (m != NOHEADTAIL && m != NOTAIL) o->EndObject(tag); }
DECLARE_EXPORT PyObject* ResourceSkill::getattro(const Attribute& attr) { if (attr.isA(Tags::tag_resource)) return PythonObject(getResource()); if (attr.isA(Tags::tag_skill)) return PythonObject(getSkill()); if (attr.isA(Tags::tag_priority)) return PythonObject(getPriority()); if (attr.isA(Tags::tag_effective_end)) return PythonObject(getEffective().getEnd()); if (attr.isA(Tags::tag_effective_start)) return PythonObject(getEffective().getStart()); return NULL; }
DECLARE_EXPORT void Flow::validate(Action action) { // Catch null operation and buffer pointers Operation* oper = getOperation(); Buffer* buf = getBuffer(); if (!oper || !buf) { // This flow is not a valid one since it misses essential information if (!oper && !buf) throw DataException("Missing operation and buffer on a flow"); else if (!oper) throw DataException("Missing operation on a flow with buffer '" + buf->getName() + "'"); else throw DataException("Missing buffer on a flow with operation '" + oper->getName() + "'"); } // Check if a flow with 1) identical buffer, 2) identical operation and // 3) overlapping effectivity dates already exists, and 4) same // flow type. Operation::flowlist::const_iterator i = oper->getFlows().begin(); for (; i != oper->getFlows().end(); ++i) if (i->getBuffer() == buf && i->getEffective().overlap(getEffective()) && i->getType() == getType() && &*i != this) break; // Apply the appropriate action switch (action) { case ADD: if (i != oper->getFlows().end()) throw DataException("Flow of '" + oper->getName() + "' and '" + buf->getName() + "' already exists"); break; case CHANGE: throw DataException("Can't update a flow"); case ADD_CHANGE: // ADD is handled in the code after the switch statement if (i == oper->getFlows().end()) break; throw DataException("Can't update a flow between '" + oper->getName() + "' and '" + buf->getName() + "')"); case REMOVE: // Delete the temporary flow object delete this; // Nothing to delete if (i == oper->getFlows().end()) throw DataException("Can't remove nonexistent flow of '" + oper->getName() + "' and '" + buf->getName() + "'"); // Delete delete &*i; } // Set a flag to make sure the level computation is triggered again HasLevel::triggerLazyRecomputation(); }
DECLARE_EXPORT void ItemSupplier::validate(Action action) { // Catch null supplier and item pointers Supplier *sup = getSupplier(); Item *it = getItem(); Location *loc = getLocation(); if (!sup || !it) { // Invalid ItemSupplier model if (!sup && !it) throw DataException("Missing supplier and item on a itemsupplier"); else if (!sup) throw DataException("Missing supplier on a itemsupplier on item '" + it->getName() + "'"); else if (!it) throw DataException("Missing item on a itemsupplier on supplier '" + sup->getName() + "'"); } // Check if a ItemSupplier with 1) identical supplier, 2) identical item // 3) identical location, and 4) overlapping effectivity dates already exists Supplier::itemlist::const_iterator i = sup->getItems().begin(); for (; i != sup->getItems().end(); ++i) if (i->getItem() == it && i->getEffective().overlap(getEffective()) && i->getLocation() == loc && &*i != this) break; // Apply the appropriate action switch (action) { case ADD: if (i != sup->getItems().end()) { throw DataException("ItemSupplier of '" + sup->getName() + "' and '" + it->getName() + "' already exists"); } break; case CHANGE: throw DataException("Can't update a itemsupplier"); case ADD_CHANGE: // ADD is handled in the code after the switch statement if (i == sup->getItems().end()) break; throw DataException("Can't update a itemsupplier"); case REMOVE: // This ItemSupplier was only used temporarily during the reading process delete this; if (i == sup->getItems().end()) // Nothing to delete throw DataException("Can't remove nonexistent itemsupplier of '" + sup->getName() + "' and '" + it->getName() + "'"); delete &*i; return; } }
DECLARE_EXPORT void ResourceSkill::validate(Action action) { // Catch null operation and resource pointers Skill *skill = getSkill(); Resource *res = getResource(); if (!skill || !res) { // Invalid load model if (!skill && !res) throw DataException("Missing resource and kill on a resourceskill"); else if (!skill) throw DataException("Missing skill on a resourceskill on resource '" + res->getName() + "'"); else if (!res) throw DataException("Missing resource on a resourceskill on skill '" + skill->getName() + "'"); } // Check if a resourceskill with 1) identical resource, 2) identical skill and // 3) overlapping effectivity dates already exists Skill::resourcelist::const_iterator i = skill->getResources().begin(); for (; i != skill->getResources().end(); ++i) if (i->getResource() == res && i->getEffective().overlap(getEffective()) && &*i != this) break; // Apply the appropriate action switch (action) { case ADD: if (i != skill->getResources().end()) { throw DataException("Resourceskill of '" + res->getName() + "' and '" + skill->getName() + "' already exists"); } break; case CHANGE: throw DataException("Can't update a resourceskill"); case ADD_CHANGE: // ADD is handled in the code after the switch statement if (i == skill->getResources().end()) break; throw DataException("Can't update a resourceskill"); case REMOVE: // This resourceskill was only used temporarily during the reading process delete this; if (i == skill->getResources().end()) // Nothing to delete throw DataException("Can't remove nonexistent resourceskill of '" + res->getName() + "' and '" + skill->getName() + "'"); delete &*i; return; } }
pair<Date, double> FlowEnd::getFlowplanDateQuantity(const FlowPlan* fl) const { if (isConsumer() && !fl->getOperationPlan()->getConsumeMaterial()) return make_pair(fl->getOperationPlan()->getEnd(), 0.0); else if (isProducer() && !fl->getOperationPlan()->getProduceMaterial()) return make_pair(fl->getOperationPlan()->getEnd(), 0.0); else if (fl->getConfirmed()) return make_pair( fl->getOperationPlan()->getEnd(), fl->getQuantity() ); else return make_pair( fl->getOperationPlan()->getEnd(), getEffective().within(fl->getDate()) && fl->getOperationPlan()->getQuantity() ? getQuantityFixed() + fl->getOperationPlan()->getQuantity() * getQuantity() : 0.0 ); }
DECLARE_EXPORT void Load::validate(Action action) { // Catch null operation and resource pointers Operation *oper = getOperation(); Resource *res = getResource(); if (!oper || !res) { // Invalid load model if (!oper && !res) throw DataException("Missing operation and resource on a load"); else if (!oper) throw DataException("Missing operation on a load on resource '" + res->getName() + "'"); else if (!res) throw DataException("Missing resource on a load on operation '" + oper->getName() + "'"); } // Check if a load with 1) identical resource, 2) identical operation and // 3) overlapping effectivity dates already exists Operation::loadlist::const_iterator i = oper->getLoads().begin(); for (; i != oper->getLoads().end(); ++i) if (i->getResource() == res && i->getEffective().overlap(getEffective()) && &*i != this) break; // Apply the appropriate action switch (action) { case ADD: if (i != oper->getLoads().end()) { throw DataException("Load of '" + oper->getName() + "' and '" + res->getName() + "' already exists"); } break; case CHANGE: throw DataException("Can't update a load"); case ADD_CHANGE: // ADD is handled in the code after the switch statement if (i == oper->getLoads().end()) break; throw DataException("Can't update a load"); case REMOVE: // This load was only used temporarily during the reading process delete this; if (i == oper->getLoads().end()) // Nothing to delete throw DataException("Can't remove nonexistent load of '" + oper->getName() + "' and '" + res->getName() + "'"); delete &*i; // Set a flag to make sure the level computation is triggered again HasLevel::triggerLazyRecomputation(); return; } // The statements below should be executed only when a new load is created. // Set a flag to make sure the level computation is triggered again HasLevel::triggerLazyRecomputation(); }