Пример #1
0
		AnyValue JsonSerializer::toAny(const Json::Value & val)
		{
			std::vector<AnyValue> arr;
			Bundle b;
			switch (val.type())
			{
			case Json::ValueType::arrayValue:
				for (auto e : val) arr.push_back(this->toAny(e));
				return arr;
			case Json::ValueType::booleanValue:
				return val.asBool();
			case Json::ValueType::intValue:
				return (int64_t)val.asInt64();
			case Json::ValueType::nullValue:
				return nullptr;
			case Json::ValueType::objectValue:
				for (Json::ValueConstIterator it = val.begin(); it != val.end(); it++)
				{
					std::string name = it.name();
					b.set(name, this->toAny(*it));
				}
				return b;
			case Json::ValueType::realValue:
				return val.asDouble();
			case Json::ValueType::stringValue:
				return val.asString();
			case Json::ValueType::uintValue:
				return (uint64_t)val.asUInt64();
			}
			return AnyValue();
		}
Пример #2
0
 static AnyValue from(const T& r) {
   //explicit AutoAnyReference to avoid ambiguous call for object implementing cast to AnyValue
   return AnyValue(AutoAnyReference(r));
 }
Пример #3
0
  ParameterModelPrivate::ParameterModelPrivate(boost::shared_ptr<const AL::XmlElement> elt)
  {
    std::string signature;
    std::string name;
    int id;
    elt->getAttribute("name", name);
    elt->getAttribute("type", signature);
    elt->getAttribute("id", id);
    _metaProperty = MetaProperty(id, name, signature);
    elt->getAttribute("inherits_from_parent", _inheritsFromParent);

    Signature sig = Signature(signature);

    _isValid = true;
    if(sig.isConvertibleTo(Signature::fromType(Signature::Type_Bool)) == 1.0f)
    {
      bool default_value_bool;
      elt->getAttribute("default_value",    default_value_bool);
      _defaultValue = AnyValue(default_value_bool).clone();
    }
    else if(sig.isConvertibleTo(Signature::fromType(Signature::Type_Int32)) == 1.0f)
    {
      int default_value_int, min_int, max_int;
      elt->getAttribute("default_value",    default_value_int);
      elt->getAttribute("min",              min_int, 0);
      elt->getAttribute("max",              max_int, 0);
      _defaultValue  = AnyValue(default_value_int).clone();
      _min           = AnyValue(min_int).clone();
      _max           = AnyValue(max_int).clone();
    }
    else if(sig.isConvertibleTo(Signature::fromType(Signature::Type_Double)) == 1.0f )
    {
      double default_value_double, min_double, max_double;
      elt->getAttribute("default_value",    default_value_double);
      elt->getAttribute("min",              min_double, 0.0);
      elt->getAttribute("max",              max_double, 0.0);
      _defaultValue  = AnyValue(default_value_double).clone();
      _min           = AnyValue(min_double).clone();
      _max           = AnyValue(max_double).clone();
    }
    else if(sig.isConvertibleTo(Signature::fromType(Signature::Type_String)) == 1.0f)
    {
      std::string default_value_string;
      elt->getAttribute("default_value", default_value_string, std::string(""));
      _defaultValue = AnyValue(default_value_string).clone();
    }
    else
    {
      _isValid = false;
    }

    elt->getAttribute("custom_choice",        _customChoice, false);
    elt->getAttribute("password",             _password, false);
    elt->getAttribute("tooltip",              _tooltip);

    AL::XmlElement::CList choices = elt->children("Choice", "");

    if(!choices.empty())
    {
      for (AL::XmlElement::CList::const_iterator it=choices.begin(), itEnd=choices.end(); it!=itEnd; ++it)
      {
        boost::shared_ptr<const AL::XmlElement> elt = *it;
        boost::shared_ptr<ChoiceModel> choice(new ChoiceModel(elt, Signature(_defaultValue.signature())));
        _choices.push_front(choice);
      }
    }
  }
Пример #4
0
 FutureSync<void> setValue(AutoAnyReference value) override { return set(AnyValue(value, false, false));}