Пример #1
0
 bool CFGParam::getProperty(CFGProperty *property) const {
   unsigned int state = property->getState();
   if( (state & CFGProperty::allSetButValue) == CFGProperty::allSetButValue ) {
     CFGProperty *tmpProperty = propertys.at(property->getPropertyIndex());
     if( tmpProperty->isSameAs(*property) && tmpProperty->isValueSet() ) {
       double dValue = 0.0;
       int iValue = 0;
       bool bValue = false;
       string sValue = "";
       switch( property->getPropertyType() ) {
       case doubleProperty:
         tmpProperty->getValue(&dValue);
         property->setValue(dValue);
         break;
       case intProperty:
         tmpProperty->getValue(&iValue);
         property->setValue(iValue);
         break;
       case boolProperty:
         tmpProperty->getValue(&bValue);
         property->setValue(bValue);
         break;
       case stringProperty:
         tmpProperty->getValue(&sValue);
         property->setValue(sValue);
         break;
       default:
         return false;
       } //switch
       return true;
     } //if
   } //if
   return false;
 }
Пример #2
0
    void CFGManager::insertParam(CFGParam *newParam) {
      mutexCFGParams.lock();
      cfgParamId id = newParam->getId();
      mapStringToParam::const_iterator iter;
      string stringID = newParam->getGroup() + ":" + newParam->getName();
      iter = cfgParamsByString.find(stringID);

      // is there already this param?
      if( iter != cfgParamsByString.end() ) {
        // then get the values of the properties and override the old ones
        CFGParam* oldParam = iter->second;
        unsigned int i = 0;
        for(i = 0; i < oldParam->getNrOfPropertys(); ++i) {
          CFGProperty myProperty;
          myProperty.setParamId(newParam->getId());
          myProperty.setPropertyIndex(i);
          myProperty.setPropertyType(newParam->getPropertyTypeByIndex(i));
          if( newParam->getProperty(&myProperty) ) {
            if( myProperty.isValueSet() ) {
              myProperty.changeParamId(oldParam->getId());
              oldParam->setProperty(myProperty);
            }
          } //if
        } //for
        // delete the new param which is no more needed
        deleteParam(newParam);
      } else {
        string stringId = newParam->getGroup() + ":" + newParam->getName();
        cfgParamsById.insert(pair<cfgParamId, CFGParam*>(id, newParam));
        cfgParamsByString.insert(pair<string, CFGParam*>(stringId, newParam));
      }
      mutexCFGParams.unlock();
    }
Пример #3
0
    void CFGParam::writeToYAML(YAML::Emitter &out) const {
      out << YAML::BeginMap;

      out << YAML::Key << "name";
      out << YAML::Value << paramName;

      out << YAML::Key << "type";
      out << YAML::Value << cfgParamTypeString[paramType];

      if (options & userSave) {
        out << YAML::Key << "userSave";
        out << YAML::Value << true;
      }

      if (options & saveOnClose) {
        out << YAML::Key << "saveOnClose";
        out << YAML::Value << true;
      }

      unsigned int i = 0;
      mutexPropertys.lock();
      for(i = 0; i < propertys.size(); ++i) {
        CFGProperty *prop = propertys.at(i);
        if(prop->isValueSet()) {
          out << YAML::Key << getPropertyNameByIndex(i);
          double dValue = 0.0;
          int iValue = 0;
          string sValue = "";
          bool bValue = false;
          switch (prop->getPropertyType()) {
          case intProperty:
            prop->getValue(&iValue);
            out << YAML::Value << iValue;
            break;
          case boolProperty:
            prop->getValue(&bValue);
            out << YAML::Value << bValue;
            break;
          case stringProperty:
            prop->getValue(&sValue);
            out << YAML::Value << sValue;
            break;
          case doubleProperty:
            prop->getValue(&dValue);
            out << YAML::Value << dValue;
            break;
          default:
            out << YAML::Value << "error";
            break;
          } //switch
        }
      }
      mutexPropertys.unlock();

      out << YAML::EndMap;
    }