bool IdfExtensibleGroup::setFields(const std::vector<std::string>& values, bool checkValidity) { if ((values.size() == 0) || (values.size() != numFields())) { return false; } unsigned n = numFields(); // save oldValues for rollback StringVector oldValues; for (unsigned i = 0; i < n; ++i) { OptionalString oValue = getString(i); OS_ASSERT(oValue); oldValues.push_back(*oValue); } // try to set values bool ok = true; for (unsigned i = 0; i < n; ++i) { ok = setString(i,values[i],checkValidity); if (!ok) { break; } } if (!ok) { // rollback for (unsigned i = 0; i < n; ++i) { bool rollbackOk = setString(i,oldValues[i],false); OS_ASSERT(rollbackOk); } } return ok; }
void _LSList::toLList_t(llist_t* L) { ll_init(L,Weight(),numFields()); L->numFields=numFields(); for (u32 i=0; i<_m_count(); ++i) { _LSListField* cField = fetchField(i); for (u32 j=0; j<cField->numEntries();++j) { L->data[L->index[i]+j]=cField->at(j); } L->index[i+1]=L->index[i]+cField->numEntries(); releaseField(cField); } }
static point *user_spline(attrsym_t * symptr, edge_t * e, int *np) { char *pos; int i, n, nc; point *ps = 0; point *pp; double x, y; if (symptr == NULL) return 0; pos = agxget(e, symptr->index); if (*pos == '\0') return 0; n = numFields(pos); *np = n; if (n > 1) { ps = ALLOC(n, 0, point); pp = ps; while (n) { i = sscanf(pos, "%lf,%lf%n", &x, &y, &nc); if (i < 2) { free(ps); ps = 0; break; } pos = pos + nc; pp->x = (int) x; pp->y = (int) y; pp++; n--; } } return ps; }
void PortList_Impl::removePort(unsigned port) { unsigned t_numFields = numFields(); for(unsigned i = port + 1; i < t_numFields; i++ ) { if( boost::optional<Connection> connection = getObject<ModelObject>().getModelObjectTarget<Connection>(i) ) { if( boost::optional<ModelObject> targetObject = connection->targetObject() ) { if( targetObject->handle() == handle() ) { connection->setTargetObjectPort(i - 1); continue; } } if( boost::optional<ModelObject> sourceObject = connection->sourceObject() ) { if( sourceObject->handle() == handle() ) { connection->setSourceObjectPort(i - 1); continue; } } } } eraseExtensibleGroup(port - numNonextensibleFields()); }
ClimateZone ClimateZones_Impl::getClimateZone(unsigned index) const { IdfExtensibleGroup eg = getExtensibleGroup(index); if (eg.empty()) { std::shared_ptr<ClimateZones_Impl> p; return ClimateZone(p,numFields()); } return eg.cast<ClimateZone>(); }
StringVector IdfExtensibleGroup::fields(bool returnDefault) const { StringVector result; for (unsigned i = 0, n = numFields(); i < n; ++i) { OptionalString str = getString(i,returnDefault); OS_ASSERT(str); result.push_back(*str); } return result; }
std::vector<T> getModelObjectTargets() const { std::vector<T> result; if (empty()) { return result; } for (unsigned fieldIndex = 0, n = numFields(); fieldIndex < n; ++fieldIndex) { boost::optional<T> oTarget = getModelObjectTarget<T>(fieldIndex); if (oTarget) { result.push_back(*oTarget); } } return result; }
WorkspaceObjectVector WorkspaceExtensibleGroup::getTargets() const { WorkspaceObjectVector result; if (empty()) { return result; } for (unsigned fieldIndex = 0, n = numFields(); fieldIndex < n; ++fieldIndex) { OptionalWorkspaceObject owo = getTarget(fieldIndex); if (owo) { result.push_back(*owo); } } return result; }
StringVector IdfExtensibleGroup::fieldComments(bool returnDefault) const { StringVector result; for (unsigned i = 0, n = numFields(); i < n; ++i) { OptionalString str = fieldComment(i,returnDefault); if (str) { result.push_back(*str); } else { break; } } return result; }
std::vector<unsigned> IdfExtensibleGroup::mf_indices() const { UnsignedVector result; if (!empty()) { for (unsigned i = 0, n = numFields(); i < n; ++i) { result.push_back(mf_toIndex(i)); } } return result; }
bool WorkspaceExtensibleGroup::canBeSource() const { bool result = false; if (empty()) { return result; } for (unsigned fieldIndex = 0, n = numFields(); fieldIndex < n; ++fieldIndex) { result = getImpl<detail::WorkspaceObject_Impl>()->canBeSource(mf_toIndex(fieldIndex)); if (result) { break; } } return result; }
IdfExtensibleGroup IdfExtensibleGroup::insertClone(unsigned groupIndex) const { if (empty()) { detail::IdfObject_ImplPtr p; return IdfExtensibleGroup(p,0); } StringVector values = fields(); OS_ASSERT(values.size() == numFields()); return m_impl->insertExtensibleGroup(groupIndex,values); }
IdfExtensibleGroup IdfExtensibleGroup::pushClone() const { if (empty()) { detail::IdfObject_ImplPtr p; return IdfExtensibleGroup(p,0); } StringVector values = fields(); OS_ASSERT(values.size() == numFields()); return m_impl->pushExtensibleGroup(values); }
std::vector<unsigned> IdfExtensibleGroup::requiredFields() const { UnsignedVector result; if (!empty()) { IddFieldVector iddExtFields = m_impl->iddObject().extensibleGroup(); for (unsigned fieldIndex = 0, n = numFields(); fieldIndex < n; ++fieldIndex) { if (iddExtFields[fieldIndex].properties().required) { result.push_back(fieldIndex); } } } return result; }
ClimateZone ClimateZones_Impl::getClimateZone(const std::string& institution,unsigned year) const { std::shared_ptr<ClimateZones_Impl> p; ClimateZone result(p,numFields()); ClimateZoneVector czs = climateZones(); for (const ClimateZone& cz : czs) { if ( istringEqual(cz.institution(),institution) && (cz.year() == year) ) { result = cz; break; } } return result; }
llist_t * _LBList<BTECOLL>::toLList_t() { llist_t* P = (llist_t *)lxmalloc(sizeof(llist_t),1); ll_init(P,Weight(),numFields()); for (u32 i=0; i<_count; ++i) { // do bulk load. Without any cache. _LBListField<BTECOLL>* cField = fetchField(i); for (u32 j=0; j<cField->info()->entries;++j) { P->data[P->index[i]+j]=cField->el[j]; } P->index[i+1]=P->index[i]+cField->info()->entries; releaseField(cField); } return P; }
ClimateZone ClimateZones_Impl::setClimateZone(const std::string& institution, unsigned year, const std::string& value) { std::shared_ptr<ClimateZones_Impl> p; ClimateZone result(p,numFields()); ClimateZone candidate = getClimateZone(institution,year); if (candidate.empty()) { return appendClimateZone(institution, ClimateZones::getDefaultDocumentName(institution), year, value); } bool ok = candidate.setValue(value); if (ok) { result = candidate; } return result; }
ClimateZone ClimateZones_Impl::appendClimateZone(const std::string& institution, const std::string documentName, unsigned year, const std::string& value) { StringVector values; values.push_back(institution); values.push_back(documentName); std::stringstream ss; ss << year; values.push_back(ss.str()); values.push_back(value); IdfExtensibleGroup eg = pushExtensibleGroup(values); if (eg.empty()) { std::shared_ptr<ClimateZones_Impl> p; return ClimateZone(p,numFields()); } return eg.cast<ClimateZone>(); }
/* ClimateZone ClimateZones_Impl::setActiveClimateZone(const std::string& institution) { std::shared_ptr<ClimateZones_Impl> p; ClimateZone result(p,numFields()); ClimateZoneVector czs = getClimateZones(institution); if (czs.empty()) { result = appendClimateZone(institution); } else { if (czs.size() > 1) { LOG(Warn,"Multiple climate zones have institution '" << institution << "'. Setting the first " << "to be active."); } result = czs[0]; } OS_ASSERT(!result.empty()); bool ok = setString(OS_ClimateZonesFields::ActiveInstitution,result.institution()); OS_ASSERT(ok); ok = setUnsigned(OS_ClimateZonesFields::ActiveYear,result.year()); OS_ASSERT(ok); return result; } ClimateZone ClimateZones_Impl::setActiveClimateZone(const std::string& institution, unsigned year) { ClimateZone result = getClimateZone(institution,year); if (result.empty()) { result = appendClimateZone(institution,year,""); } bool ok = setString(OS_ClimateZonesFields::ActiveInstitution,result.institution()); OS_ASSERT(ok); ok = setUnsigned(OS_ClimateZonesFields::ActiveYear,result.year()); OS_ASSERT(ok); return result; } */ ClimateZone ClimateZones_Impl::setClimateZone(const std::string& institution, const std::string& value) { std::shared_ptr<ClimateZones_Impl> p; ClimateZone result(p,numFields()); ClimateZoneVector candidates = getClimateZones(institution); if (candidates.size() > 1) { LOG(Warn,"Cannot set climate zone value for institutuion '" << institution << "', because there are " << candidates.size() << " such listings, not 1."); return result; } if (candidates.size() == 0) { return appendClimateZone(institution,value); } bool ok = candidates[0].setValue(value); if (ok) { result = candidates[0]; } return result; }