Example #1
0
 bool ScheduleRule_Impl::setParent(ParentObject& newParent)
 {
   bool result = false;
   if (newParent.optionalCast<ScheduleRuleset>()){
     result = setPointer(OS_Schedule_RuleFields::ScheduleRulesetName, newParent.handle());
   }
   return result;
 }
Example #2
0
std::vector<ModelObject> getRecursiveChildren(const ParentObject& object, bool includeLifeCycleCosts) {
  std::set<Handle> resultSet;
  std::pair<HandleSet::const_iterator,bool> insertResult;
  std::vector<ModelObject> result;
  resultSet.insert(object.handle());
  result.push_back(object);

  if (includeLifeCycleCosts){
    for (const LifeCycleCost& lifeCycleCost : object.lifeCycleCosts()){
      result.push_back(lifeCycleCost);
    }
  }

  std::deque<ParentObject> parents;
  parents.push_back(object);

  while (parents.size() > 0) {
    ParentObject currentParent(parents[0]);
    parents.pop_front();

    // parent's costs have already been added
    
    for (const ModelObject& child : currentParent.children()) {
      insertResult = resultSet.insert(child.handle());
      if (insertResult.second) {
        result.push_back(child);

        if (includeLifeCycleCosts){
          for (const LifeCycleCost& lifeCycleCost : child.lifeCycleCosts()){
            result.push_back(lifeCycleCost);
          }
        }

        OptionalParentObject opo = child.optionalCast<ParentObject>();
        if (opo) { 
          parents.push_back(*opo); 
        }
      }
    }
  }

  return result;
}