//--------------------------Private Class-------------------------------------// ParameterModelPrivate::ParameterModelPrivate(const std::string &name, AutoAnyReference defaultValue, bool inheritsFromParent, bool customChoice, bool password, const std::string &tooltip, unsigned int id, bool resource) : _metaProperty(id, name, defaultValue.signature()), _inheritsFromParent(inheritsFromParent), _customChoice(customChoice), _password(password), _tooltip(tooltip), _choices(), _isValid(true), _defaultValue(defaultValue.clone()) { if(resource) _metaProperty = MetaProperty(id, name, ParameterModel::signatureRessource()); Signature signature(defaultValue.signature()); //If defaultValue is int or double min and max are not defined so this object is not valid if(isIntegerOrDouble(defaultValue)) { qiLogError() << "Parameter.min and Parameter.max is not defined."; _isValid = false; } }
Ptr<const MetaInfo> getMetaInfo() { static auto meta = [] { auto meta = MetaInfo(); meta.setType(Type::Environment); meta.setPrettyName("environment"); meta.addProperty(MetaProperty(MetaProperty::Builtin::ScanFunction, static_cast<ScanFunction_t>(&scan))); meta.addProperty(MetaProperty(MetaProperty::Builtin::DestructorFunction, static_cast<DestructorFunction_t>(&destroy))); meta.addProperty(MetaProperty(MetaProperty::Builtin::IsEqualFunction, static_cast<IsEqualFunction_t>(&isEqual))); return meta; }(); // Note that this lambda is immediately called. return &meta; }
unsigned int MetaObjectPrivate::addProperty(const std::string& name, const qi::Signature& sig, int id) { boost::recursive_mutex::scoped_lock sl(_propertiesMutex); for (MetaObject::PropertyMap::iterator it = _properties.begin(); it != _properties.end(); ++it) { if (it->second.name() == name) { qiLogWarning() << "Property already exists: " << name; return it->second.uid() ; } } if (id == -1) id = ++_index; _properties[id] = MetaProperty(id, name, sig); _dirtyCache = true; return id; }
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); } } }
//-------------------------------Setter------------------------------------// void ParameterModel::setMetaProperty(unsigned int id, const std::string &name, const Signature &sig) { _p->_metaProperty = MetaProperty(id, name, sig.toString()); _p->_isValid = false; }