void PropertyNode::setStr( const std::string &name, const std::string &val ) const{ PropertyValue *property = getPropertyRecursively( name ); if (!property) { throw std::runtime_error( "Value not exists: " + name ); } return property->setStr(val); }
bool _IgnoreActorsToProp(const ClassDefinition *pClass, PCTSTR pszProp, PropertyValue& value) { const SendParam *pSendParam; bool fRet = _FindSelfSendParamInInit(pClass, SCIMETHOD_IGNOREACTORS, &pSendParam); if (fRet) { // See what the value is. if (pSendParam->HasValue()) { fRet = _GetFirstSimpleValueInCodeSegmentArray(pSendParam->GetSelectorParams(), value); } if (!fRet) { // "ignoreActors()" // No params means yes, ignore actors. value.SetValue(1); fRet = true; } } else { // We didn't find any call to ignoreActors. By default actors are not ignored. // (Actually, it would depend on bit $4000 of the signal property technically) value.SetValue(0); fRet = true; } return fRet; }
void shallowCopyDataBack(const std::vector<unsigned int> & stateful_prop_ids, MaterialProperties & data, MaterialProperties & data_from) { for (unsigned int i=0; i<stateful_prop_ids.size(); ++i) { PropertyValue * prop = data[i]; // do the look-up just once (OPT) PropertyValue * prop_from = data_from[stateful_prop_ids[i]]; // do the look-up just once (OPT) if (prop != NULL && prop_from != NULL) prop->swap(prop_from); } }
/** * Shallow copy the material properties * @param stateful_prop_ids List of IDs with properties to shallow copy * @param data Destination data * @param data_from Source data */ void shallowCopyData(const std::vector<unsigned int> & stateful_prop_ids, MaterialProperties & data, MaterialProperties & data_from) { for (unsigned int i = 0; i < stateful_prop_ids.size(); ++i) { if (i >= data_from.size() || stateful_prop_ids[i] >= data.size()) continue; PropertyValue * prop = data[stateful_prop_ids[i]]; // do the look-up just once (OPT) PropertyValue * prop_from = data_from[i]; // do the look-up just once (OPT) if (prop != nullptr && prop_from != nullptr) prop->swap(prop_from); } }
void FramePropertyTable::Set(nsIFrame* aFrame, const FramePropertyDescriptor* aProperty, void* aValue) { NS_ASSERTION(aFrame, "Null frame?"); NS_ASSERTION(aProperty, "Null property?"); if (mLastFrame != aFrame || !mLastEntry) { mLastFrame = aFrame; mLastEntry = mEntries.PutEntry(aFrame); } Entry* entry = mLastEntry; if (!entry->mProp.IsArray()) { if (!entry->mProp.mProperty) { // Empty entry, so we can just store our property in the empty slot entry->mProp.mProperty = aProperty; entry->mProp.mValue = aValue; return; } if (entry->mProp.mProperty == aProperty) { // Just overwrite the current value entry->mProp.DestroyValueFor(aFrame); entry->mProp.mValue = aValue; return; } // We need to expand the single current entry to an array PropertyValue current = entry->mProp; entry->mProp.mProperty = nullptr; static_assert(sizeof(nsTArray<PropertyValue>) <= sizeof(void *), "Property array must fit entirely within entry->mProp.mValue"); new (&entry->mProp.mValue) nsTArray<PropertyValue>(4); entry->mProp.ToArray()->AppendElement(current); } nsTArray<PropertyValue>* array = entry->mProp.ToArray(); nsTArray<PropertyValue>::index_type index = array->IndexOf(aProperty, 0, PropertyComparator()); if (index != nsTArray<PropertyValue>::NoIndex) { PropertyValue* pv = &array->ElementAt(index); pv->DestroyValueFor(aFrame); pv->mValue = aValue; return; } array->AppendElement(PropertyValue(aProperty, aValue)); }
bool _AddToPicToProp(const ClassDefinition *pClass, PCTSTR pszProp, PropertyValue& value) { const SendParam *pSendParam; // This only depends on whether we found an addToPic call value.SetValue(_FindSelfSendParamInInit(pClass, SCIMETHOD_ADDTOPIC, &pSendParam) ? 1 : 0); return true; }
void NotifConfig::load() throw (NotifConfig::GeneralConfigError) { string filename = get_storage_filename(); fstream file(filename.c_str(), ios::in); if (!file.good()) { string msg = "cannot open config file '"; msg.append(filename + "' for loading"); throw NotifConfig::GeneralConfigError(msg); } string line,head,tail; int n; getline(file, line); while (!file.eof()) { if (line == "") continue; n = line.find(" "); head = line.substr(0, n); tail = line.substr(n + 1); try { PropertyValue * value = find(head); value->from_string(tail); } catch (PropertyNotFound & e) { string msg = "cannot load config from disk: key '"; msg.append(e.property_name + "' not found"); throw GeneralConfigError(msg); } catch (PropertyValue::InvalidStringFormat & e) { string msg = "cannot load config from disk: key '"; msg.append(head + "' cannot be correctly interpreted"); throw GeneralConfigError(msg); } getline(file,line); } file.close(); }
static void setValue(void *dst, valuetype_t dstType, PropertyValue const &pvalue) { switch (dstType) { case DDVT_FIXED: *((fixed_t *) dst) = pvalue.asFixed(); break; case DDVT_FLOAT: *( (float *) dst) = pvalue.asFloat(); break; case DDVT_DOUBLE: *( (double *) dst) = pvalue.asDouble(); break; case DDVT_BYTE: *( (byte *) dst) = pvalue.asByte(); break; case DDVT_INT: *( (int *) dst) = pvalue.asInt32(); break; case DDVT_SHORT: *( (short *) dst) = pvalue.asInt16(); break; case DDVT_ANGLE: *((angle_t *) dst) = pvalue.asAngle(); break; default: throw Error("setValue", QString("Unknown value type %d").arg(dstType)); } }
void Portal::SetProp(PropertyKey key, PropertyValue value) { Trigger::SetProp(key, value); switch (key) { case PROP_DEST_ID: m_destId = value.GetInt(); } }
int main() { { testcallback tcb; string p("/a/bb/ccc/dddd/eeeee/ffffff"); cout << " print #1" << endl; mgr.print(); PropertyValue * p1 = mgr.addLeaf("/test/wholenumber"); p1->set(17); PropertyValue * p2; (p2 = mgr.addLeaf("/lesser/floatno"))->set(-0.334f); PropertyValue * p3; (p3 = mgr.addLeaf("/dict/text/str"))->set(string("laber")); //PropertyValue * nd = mgr.addLeaf("/i/am/notdefined"); PropertyValue * p4; (p4 = mgr.addLeaf("/logical/notlogic/MisterBoole"))->set(true); cout << " print #2" << endl; mgr.print(); p1->registerOnChange(&tcb); p1->set(99); cout << " print #3" << endl; mgr.print(); // PropertyValue * r0 = mgr.get("/this/does/not/exist"); PropertyValue * r1 = mgr.get("/test/wholenumber"); PropertyValue * notdef = mgr.get("/i/am/notdefined"); notdef->set(false); cout << "getPath test: " << p1->getPath() << endl; cout << "\\\\\\\\\\\\\\" << "comparing p1 and r1: p1=" << &p1 << " r1=" << r1 << endl; r1->set(23); PropertyValue * r3 = mgr.get("/dict/text/str"); r3->set(string("unit TESTING in progress...")); mgr.run(); cout << " print #4" << endl; mgr.print(); } exit(0); }
Variant GetDPByExpExpression::Evaluate(Expressive::EvalContext* context) { Object* obj = m_object->Evaluate(context); DependencyObject* depObj = dynamic_cast<DependencyObject*>(obj); if (depObj == NULL) { VERIFY(0); } Variant propertyRef = m_exp->Evaluate(context); PropertyValue* pProperty; if (propertyRef.IsString()) pProperty = depObj->GetProperty(depObj->GetClass()->GetLocalProperty(propertyRef.ToString())); else if (propertyRef.IsInt()) pProperty = depObj->GetProperty(depObj->GetClass()->GetLocalProperty((int)propertyRef)); else throw new Exception("property not found"); return pProperty->GetComputedValue(); }
bool GetDPByExpExpression::Set(Expressive::EvalContext* context, Variant value) { Object* obj = m_object->Evaluate(context); DependencyObject* depObj = dynamic_cast<DependencyObject*>(obj); if (depObj == NULL) { VERIFY(0); } Variant propertyRef = m_exp->Evaluate(context); PropertyValue* pProperty; if (propertyRef.IsString()) pProperty = depObj->GetProperty(depObj->GetClass()->GetLocalProperty(propertyRef.ToString())); else if (propertyRef.IsInt()) pProperty = depObj->GetProperty(depObj->GetClass()->GetLocalProperty(int(propertyRef))); else raise(Exception("property not found")); pProperty->UpdateValue(value); return true; }
bool _PriorityClassToProp(const ClassDefinition *pClass, PCTSTR pszProp, PropertyValue& value) { const SendParam *pSendParam; bool fRet = _FindSelfSendParamInInit(pClass, SCIMETHOD_SETPRI, &pSendParam); if (fRet) { // See what the value is. if (pSendParam->HasValue()) { fRet = _GetFirstSimpleValueInCodeSegmentArray(pSendParam->GetSelectorParams(), value); } } if (!fRet) { // We didn't find anything. The default value for priority tends to be zero, but that isn't // accurate. It depends on the signal property. // Instead we'll use -1 as a sentinel value indicating "default priority". value.SetValue((WORD)-1); fRet = true; } return fRet; }
std::vector<FontStack> Parser::fontStacks() const { std::set<FontStack> result; for (const auto& layer : layers) { if (layer->is<SymbolLayer>()) { PropertyValue<FontStack> textFont = layer->as<SymbolLayer>()->getTextFont(); if (textFont.isUndefined()) { result.insert({"Open Sans Regular", "Arial Unicode MS Regular"}); } else if (textFont.isConstant()) { result.insert(textFont.asConstant()); } else if (textFont.isFunction()) { for (const auto& stop : textFont.asFunction().getStops()) { result.insert(stop.second); } } } } return std::vector<FontStack>(result.begin(), result.end()); }
std::vector<FontStack> Parser::fontStacks() const { std::set<FontStack> optional; for (const auto& layer : layers) { if (layer->is<SymbolLayer>()) { PropertyValue<FontStack> textFont = layer->as<SymbolLayer>()->getTextFont(); if (textFont.isUndefined()) { optional.insert({"Open Sans Regular", "Arial Unicode MS Regular"}); } else if (textFont.isConstant()) { optional.insert(textFont.asConstant()); } else if (textFont.isCameraFunction()) { textFont.asCameraFunction().stops.match( [&] (const auto& stops) { for (const auto& stop : stops.stops) { optional.insert(stop.second); } } ); } } } return std::vector<FontStack>(optional.begin(), optional.end()); }
float evaluate(PropertyValue<float> value, float zoom) { return value.evaluate(PropertyEvaluator<float>(PropertyEvaluationParameters(zoom), 0)); }
bool evaluate(PropertyValue<bool> value, float zoom) { return value.evaluate(PropertyEvaluator<bool>(PropertyEvaluationParameters(zoom), false)); }
std::string evaluate(PropertyValue<std::string> value, float zoom) { return value.evaluate(PropertyEvaluator<std::string>(PropertyEvaluationParameters(zoom), "")); }
void stringify(Writer& writer, const PropertyValue<T>& v) { v.evaluate([&] (const auto& v_) { stringify(writer, v_); }); }
void TpMzScheme::evalDesign(Design::Ptr d){ DesignStore::Ptr ds = Game::getGame()->getDesignStore(); if (scheme_setjmp(scheme_error_buf)) { Logger::getLogger()->warning("MzScheme Error"); } else { Scheme_Object* temp; std::ostringstream formater; formater.str(""); formater << "(define-values (struct:designType make-designType designType? designType-ref designType-set!)(make-design-type " << ds->getMaxPropertyId() << "))"; temp = scheme_eval_string(formater.str().c_str(), env); temp = scheme_eval_string("(define property-designType-set! (lambda (design id val) (designType-set! design (- id 1) val)))", env); std::set<uint32_t> propids = ds->getPropertyIds(); for(std::set<uint32_t>::iterator propit = propids.begin(); propit != propids.end(); ++propit){ // for each property type Property::Ptr p = ds->getProperty(*propit); if(p){ formater.str(""); formater << "(define designType." << p->getName() << " (make-property-accessor designType-ref " << p->getPropertyId() << " \"" << p->getName() << "\" ))"; temp = scheme_eval_string(formater.str().c_str(), env); } } propids.clear(); IdMap complist = d->getComponents(); temp = scheme_eval_string("(define design (make-designType))", env); for(std::set<uint32_t>::iterator propit = propids.begin(); propit != propids.end(); ++propit){ formater.str(""); formater << "(property-designType-set! design " << *propit << " 0.0)"; temp = scheme_eval_string(formater.str().c_str(), env); } std::map<uint32_t, std::map<uint32_t, std::list<std::string> > > propranking; for(IdMap::iterator compit = complist.begin(); compit != complist.end(); ++compit){ Component::Ptr c = ds->getComponent(compit->first); std::map<uint32_t, std::string> pilist = c->getPropertyList(); for(std::map<uint32_t, std::string>::iterator piit = pilist.begin(); piit != pilist.end(); ++piit){ Property::Ptr p = ds->getProperty(piit->first); for(uint32_t i = 0; i < compit->second; i++){ propranking[p->getRank()][p->getPropertyId()].push_back(piit->second); } } } std::map<uint32_t, PropertyValue> propertyvalues; for(std::map<uint32_t, std::map<uint32_t, std::list<std::string> > >::iterator rpiit = propranking.begin(); rpiit != propranking.end(); ++rpiit){ std::map<uint32_t, std::list<std::string> > pilist = rpiit->second; std::set<PropertyValue> localvalues; for(std::map<uint32_t, std::list<std::string> >::iterator piit = pilist.begin(); piit != pilist.end(); ++piit){ PropertyValue propval(piit->first,0.0); std::list<double> listvals; std::list<std::string> lambdas = piit->second; for(std::list<std::string>::iterator itlamb = lambdas.begin(); itlamb != lambdas.end(); ++itlamb){ temp = scheme_eval_string((std::string("(") + (*itlamb) + " design)").c_str(), env); if(!SCHEME_NUMBERP(temp)){ Logger::getLogger()->warning("MzScheme: Return not a number"); }else{ listvals.push_back(scheme_real_to_double(temp)); } } Property::Ptr p = ds->getProperty(piit->first); formater.str(""); formater << "(" << p->getTpclDisplayFunction() << " design '("; for(std::list<double>::iterator itvals = listvals.begin(); itvals != listvals.end(); ++itvals){ formater << *itvals << " "; } formater << "))"; temp = scheme_eval_string(formater.str().c_str(), env); #ifdef HAVE_MZSCHEME20X if(!SCHEME_PAIRP(temp) || !SCHEME_NUMBERP(SCHEME_CAR(temp)) || !SCHEME_STRINGP(SCHEME_CDR(temp))){ #else if(!SCHEME_PAIRP(temp) || !SCHEME_NUMBERP(SCHEME_CAR(temp)) || !SCHEME_CHAR_STRINGP(SCHEME_CDR(temp))){ #endif Logger::getLogger()->warning("MzScheme: Return not a pair, or the wrong time in the pair"); }else{ propval.setValue(scheme_real_to_double(SCHEME_CAR(temp))); #ifdef HAVE_MZSCHEME20X propval.setDisplayString(std::string(SCHEME_STR_VAL(SCHEME_CDR(temp)))); #else propval.setDisplayString(std::string((char*)SCHEME_CHAR_STR_VAL(SCHEME_CDR(temp)))); #endif localvalues.insert(propval); } } for(std::set<PropertyValue>::iterator pvit = localvalues.begin(); pvit != localvalues.end(); ++pvit){ PropertyValue pv = *pvit; formater.str(""); formater << "(property-designType-set! design " << pv.getPropertyId() << " " << pv.getValue() << ")"; temp = scheme_eval_string(formater.str().c_str(), env); propertyvalues[pv.getPropertyId()] = pv; } } d->setPropertyValues(propertyvalues); // now check if the design is valid bool valid = true; std::string feedback = ""; Logger::getLogger()->debug("About to process requirement functions"); for(IdMap::iterator compit = complist.begin(); compit != complist.end(); ++compit){ uint32_t curval = compit->first; //for each component in the design temp = scheme_eval_string((std::string("(") + ds->getComponent(curval)->getTpclRequirementsFunction() + " design)").c_str(), env); #ifdef HAVE_MZSCHEME20X if(!SCHEME_PAIRP(temp) || !SCHEME_STRINGP(SCHEME_CDR(temp))){ #else if(!SCHEME_PAIRP(temp) || !SCHEME_CHAR_STRINGP(SCHEME_CDR(temp))){ #endif Logger::getLogger()->warning("MzScheme: (a) Return not a pair, or the wrong time in the pair"); }else{ valid &= SCHEME_TRUEP(SCHEME_CAR(temp)); #ifdef HAVE_MZSCHEME20X std::string strtemp = SCHEME_STR_VAL(SCHEME_CDR(temp)); #else std::string strtemp = (char*)SCHEME_CHAR_STR_VAL(SCHEME_CDR(temp)); #endif if(strtemp.length() > 0) feedback += strtemp + " "; } } for(std::map<uint32_t, std::map<uint32_t, std::list<std::string> > >::iterator rpiit = propranking.begin(); rpiit != propranking.end(); ++rpiit){ std::map<uint32_t, std::list<std::string> > pilist = rpiit->second; for(std::map<uint32_t, std::list<std::string> >::iterator piit = pilist.begin(); piit != pilist.end(); ++piit){ temp = scheme_eval_string((std::string("(") + ds->getProperty(piit->first)->getTpclRequirementsFunction() + " design)").c_str(), env); #ifdef HAVE_MZSCHEME20X if(!SCHEME_PAIRP(temp) || !SCHEME_STRINGP(SCHEME_CDR(temp))){ #else if(!SCHEME_PAIRP(temp) || !SCHEME_CHAR_STRINGP(SCHEME_CDR(temp))){ #endif Logger::getLogger()->warning("MzScheme: (a) Return not a pair, or the wrong time in the pair"); }else{ valid &= SCHEME_TRUEP(SCHEME_CAR(temp)); #ifdef HAVE_MZSCHEME20X std::string strtemp = SCHEME_STR_VAL(SCHEME_CDR(temp)); #else std::string strtemp = (char*)SCHEME_CHAR_STR_VAL(SCHEME_CDR(temp)); #endif if(strtemp.length() > 0) feedback += strtemp + " "; } } } propranking.clear(); d->setValid(valid, feedback); Logger::getLogger()->debug("Eval'ed design"); if(!valid){ Logger::getLogger()->debug("Design %s is not valid, reason: %s", d->getName().c_str(), feedback.c_str()); } } } TpMzScheme::TpMzScheme(){ //scheme_set_stack_base(NULL, 1); /* required for OS X, only. WILL NOT WORK HERE */ bool loaded = false; env = scheme_basic_env(); if (scheme_setjmp(scheme_error_buf)) { Logger::getLogger()->warning("MzScheme warning: could not load local file, trying installed file"); } else { scheme_eval_string("(load \"../modules/tpcl/mzscheme/designstruct.scm\")",env); loaded = true; } if(loaded == false){ if (scheme_setjmp(scheme_error_buf)) { Logger::getLogger()->warning("MzScheme warning: could not load installed file"); } else { scheme_eval_string("(load \"" DATADIR "/tpserver/tpscheme/mzscheme/designstruct.scm\")", env); loaded = true; } } if(loaded == false){ Logger::getLogger()->error("MzScheme Error: failed to load designstruct.scm file"); //throw exception? } }
int read_dwarf_object_property(Context * Ctx, int Frame, ObjectInfo * Obj, int Attr, PropertyValue * Value) { Trap trap; memset(Value, 0, sizeof(PropertyValue)); Value->mContext = Ctx; Value->mFrame = Frame; Value->mObject = Obj; Value->mAttr = Attr; Value->mBigEndian = Obj->mCompUnit->mFile->big_endian; if (Attr == AT_location && Obj->mLowPC != 0) { Value->mValue = Obj->mLowPC; return 0; } sCompUnit = Obj->mCompUnit; sCache = (DWARFCache *)sCompUnit->mFile->dwarf_dt_cache; sDebugSection = sCompUnit->mSection; dio_EnterDebugSection(&sCompUnit->mDesc, sDebugSection, Obj->mID - sDebugSection->addr); if (set_trap(&trap)) { gop_gAttr = Attr; gop_gForm = 0; dio_ReadEntry(get_object_property_callback); clear_trap(&trap); } dio_ExitSection(); sCompUnit = NULL; sCache = NULL; sDebugSection = NULL; if (trap.error) return -1; switch (Value->mForm = gop_gForm) { case FORM_REF : case FORM_REF_ADDR : case FORM_REF1 : case FORM_REF2 : case FORM_REF4 : case FORM_REF8 : case FORM_REF_UDATA : { ObjectInfo * RefObj = find_object(sCache, gop_gFormRef); PropertyValue ValueAddr; if (read_and_evaluate_dwarf_object_property(Ctx, Frame, 0, RefObj, AT_location, &ValueAddr) < 0) return -1; if (ValueAddr.mAccessFunc != NULL) { ValueAddr.mAccessFunc(&ValueAddr, 0, &Value->mValue); } else { static U1_T Buf[8]; PropertyValue ValueSize; ContextAddress Addr; size_t Size; Addr = (ContextAddress)get_numeric_property_value(&ValueAddr); if (read_and_evaluate_dwarf_object_property(Ctx, Frame, Addr, RefObj, AT_byte_size, &ValueSize) < 0) return -1; Size = (size_t)get_numeric_property_value(&ValueSize); if (Size < 1 || Size > sizeof(Buf)) { errno = ERR_INV_DATA_TYPE; return -1; } if (context_read_mem(Ctx, Addr, Buf, Size) < 0) return -1; check_breakpoints_on_memory_read(Ctx, Addr, Buf, Size); Value->mAddr = Buf; Value->mSize = Size; } } break; case FORM_DATA1 : case FORM_DATA2 : case FORM_DATA4 : case FORM_DATA8 : case FORM_FLAG : case FORM_BLOCK1 : case FORM_BLOCK2 : case FORM_BLOCK4 : case FORM_BLOCK : Value->mAddr = gop_gFormDataAddr; Value->mSize = gop_gFormDataSize; break; case FORM_SDATA : case FORM_UDATA : Value->mValue = gop_gFormData; break; default: errno = ENOENT; return -1; } return 0; }