From 82c9b0fbbca6f61e57464a6126ae36a59b13d6ed Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 13 Apr 2012 23:07:48 -0700 Subject: fixed build all param values now support named values uniformly --- indra/llui/llui.cpp | 24 +- indra/llui/llui.h | 8 +- indra/llui/lluiimage.cpp | 4 +- indra/llui/lluiimage.h | 2 +- indra/llui/tests/llurlentry_stub.cpp | 16 +- indra/llui/tests/llurlmatch_test.cpp | 16 +- indra/llxuixml/llinitparam.h | 690 +++++++++++++++-------------------- indra/llxuixml/llxuiparser.cpp | 24 +- indra/newview/llvoavatar.cpp | 2 +- 9 files changed, 345 insertions(+), 441 deletions(-) (limited to 'indra') diff --git a/indra/llui/llui.cpp b/indra/llui/llui.cpp index 6b74c5a6be..b52b0355fe 100644 --- a/indra/llui/llui.cpp +++ b/indra/llui/llui.cpp @@ -2107,7 +2107,7 @@ const LLView* LLUI::resolvePath(const LLView* context, const std::string& path) namespace LLInitParam { - ParamValue >::ParamValue(const LLUIColor& color) + ParamValue::ParamValue(const LLUIColor& color) : super_t(color), red("red"), green("green"), @@ -2118,7 +2118,7 @@ namespace LLInitParam updateBlockFromValue(false); } - void ParamValue >::updateValueFromBlock() + void ParamValue::updateValueFromBlock() { if (control.isProvided() && !control().empty()) { @@ -2130,7 +2130,7 @@ namespace LLInitParam } } - void ParamValue >::updateBlockFromValue(bool make_block_authoritative) + void ParamValue::updateBlockFromValue(bool make_block_authoritative) { LLColor4 color = getValue(); red.set(color.mV[VRED], make_block_authoritative); @@ -2146,7 +2146,7 @@ namespace LLInitParam && !(b->getFontDesc() < a->getFontDesc()); } - ParamValue >::ParamValue(const LLFontGL* fontp) + ParamValue::ParamValue(const LLFontGL* fontp) : super_t(fontp), name("name"), size("size"), @@ -2160,7 +2160,7 @@ namespace LLInitParam updateBlockFromValue(false); } - void ParamValue >::updateValueFromBlock() + void ParamValue::updateValueFromBlock() { const LLFontGL* res_fontp = LLFontGL::getFontByName(name); if (res_fontp) @@ -2183,7 +2183,7 @@ namespace LLInitParam } } - void ParamValue >::updateBlockFromValue(bool make_block_authoritative) + void ParamValue::updateBlockFromValue(bool make_block_authoritative) { if (getValue()) { @@ -2193,7 +2193,7 @@ namespace LLInitParam } } - ParamValue >::ParamValue(const LLRect& rect) + ParamValue::ParamValue(const LLRect& rect) : super_t(rect), left("left"), top("top"), @@ -2205,7 +2205,7 @@ namespace LLInitParam updateBlockFromValue(false); } - void ParamValue >::updateValueFromBlock() + void ParamValue::updateValueFromBlock() { LLRect rect; @@ -2269,7 +2269,7 @@ namespace LLInitParam updateValue(rect); } - void ParamValue >::updateBlockFromValue(bool make_block_authoritative) + void ParamValue::updateBlockFromValue(bool make_block_authoritative) { // because of the ambiguity in specifying a rect by position and/or dimensions // we use the lowest priority pairing so that any valid pairing in xui @@ -2286,7 +2286,7 @@ namespace LLInitParam height.set(value.getHeight(), make_block_authoritative); } - ParamValue >::ParamValue(const LLCoordGL& coord) + ParamValue::ParamValue(const LLCoordGL& coord) : super_t(coord), x("x"), y("y") @@ -2294,12 +2294,12 @@ namespace LLInitParam updateBlockFromValue(false); } - void ParamValue >::updateValueFromBlock() + void ParamValue::updateValueFromBlock() { updateValue(LLCoordGL(x, y)); } - void ParamValue >::updateBlockFromValue(bool make_block_authoritative) + void ParamValue::updateBlockFromValue(bool make_block_authoritative) { x.set(getValue().mX, make_block_authoritative); y.set(getValue().mY, make_block_authoritative); diff --git a/indra/llui/llui.h b/indra/llui/llui.h index 28e84fa444..618ed2fc42 100644 --- a/indra/llui/llui.h +++ b/indra/llui/llui.h @@ -512,7 +512,7 @@ public: namespace LLInitParam { template<> - class ParamValue > + class ParamValue : public CustomParamValue { typedef CustomParamValue super_t; @@ -531,7 +531,7 @@ namespace LLInitParam }; template<> - class ParamValue > + class ParamValue : public CustomParamValue { typedef CustomParamValue super_t; @@ -549,7 +549,7 @@ namespace LLInitParam }; template<> - class ParamValue > + class ParamValue : public CustomParamValue { typedef CustomParamValue super_t; @@ -589,7 +589,7 @@ namespace LLInitParam template<> - class ParamValue > + class ParamValue : public CustomParamValue { typedef CustomParamValue super_t; diff --git a/indra/llui/lluiimage.cpp b/indra/llui/lluiimage.cpp index 1d9ce29ba9..6ae42c8852 100644 --- a/indra/llui/lluiimage.cpp +++ b/indra/llui/lluiimage.cpp @@ -155,7 +155,7 @@ void LLUIImage::onImageLoaded() namespace LLInitParam { - void ParamValue >::updateValueFromBlock() + void ParamValue::updateValueFromBlock() { // The keyword "none" is specifically requesting a null image // do not default to current value. Used to overwrite template images. @@ -172,7 +172,7 @@ namespace LLInitParam } } - void ParamValue >::updateBlockFromValue(bool make_block_authoritative) + void ParamValue::updateBlockFromValue(bool make_block_authoritative) { if (getValue() == NULL) { diff --git a/indra/llui/lluiimage.h b/indra/llui/lluiimage.h index b9b90fee71..b86ea67505 100644 --- a/indra/llui/lluiimage.h +++ b/indra/llui/lluiimage.h @@ -92,7 +92,7 @@ protected: namespace LLInitParam { template<> - class ParamValue, NOT_BLOCK > + class ParamValue : public CustomParamValue { typedef boost::add_reference::type>::type T_const_ref; diff --git a/indra/llui/tests/llurlentry_stub.cpp b/indra/llui/tests/llurlentry_stub.cpp index 20bac5ff55..9cb6a89eee 100644 --- a/indra/llui/tests/llurlentry_stub.cpp +++ b/indra/llui/tests/llurlentry_stub.cpp @@ -127,14 +127,14 @@ namespace LLInitParam bool BaseBlock::mergeBlock(BlockDescriptor& block_data, const BaseBlock& other, bool overwrite) { return true; } bool BaseBlock::validateBlock(bool emit_errors) const { return true; } - ParamValue >::ParamValue(const LLUIColor& color) + ParamValue::ParamValue(const LLUIColor& color) : super_t(color) {} - void ParamValue >::updateValueFromBlock() + void ParamValue::updateValueFromBlock() {} - void ParamValue >::updateBlockFromValue(bool) + void ParamValue::updateBlockFromValue(bool) {} bool ParamCompare::equals(const LLFontGL* a, const LLFontGL* b) @@ -142,14 +142,14 @@ namespace LLInitParam return false; } - ParamValue >::ParamValue(const LLFontGL* fontp) + ParamValue::ParamValue(const LLFontGL* fontp) : super_t(fontp) {} - void ParamValue >::updateValueFromBlock() + void ParamValue::updateValueFromBlock() {} - void ParamValue >::updateBlockFromValue(bool) + void ParamValue::updateBlockFromValue(bool) {} void TypeValues::declareValues() @@ -161,10 +161,10 @@ namespace LLInitParam void TypeValues::declareValues() {} - void ParamValue >::updateValueFromBlock() + void ParamValue::updateValueFromBlock() {} - void ParamValue >::updateBlockFromValue(bool) + void ParamValue::updateBlockFromValue(bool) {} diff --git a/indra/llui/tests/llurlmatch_test.cpp b/indra/llui/tests/llurlmatch_test.cpp index 9119e7d1fe..36402f5b27 100644 --- a/indra/llui/tests/llurlmatch_test.cpp +++ b/indra/llui/tests/llurlmatch_test.cpp @@ -97,14 +97,14 @@ namespace LLInitParam bool BaseBlock::mergeBlock(BlockDescriptor& block_data, const BaseBlock& other, bool overwrite) { return true; } bool BaseBlock::validateBlock(bool emit_errors) const { return true; } - ParamValue >::ParamValue(const LLUIColor& color) + ParamValue::ParamValue(const LLUIColor& color) : super_t(color) {} - void ParamValue >::updateValueFromBlock() + void ParamValue::updateValueFromBlock() {} - void ParamValue >::updateBlockFromValue(bool) + void ParamValue::updateBlockFromValue(bool) {} bool ParamCompare::equals(const LLFontGL* a, const LLFontGL* b) @@ -113,14 +113,14 @@ namespace LLInitParam } - ParamValue >::ParamValue(const LLFontGL* fontp) + ParamValue::ParamValue(const LLFontGL* fontp) : super_t(fontp) {} - void ParamValue >::updateValueFromBlock() + void ParamValue::updateValueFromBlock() {} - void ParamValue >::updateBlockFromValue(bool) + void ParamValue::updateBlockFromValue(bool) {} void TypeValues::declareValues() @@ -132,10 +132,10 @@ namespace LLInitParam void TypeValues::declareValues() {} - void ParamValue >::updateValueFromBlock() + void ParamValue::updateValueFromBlock() {} - void ParamValue >::updateBlockFromValue(bool) + void ParamValue::updateBlockFromValue(bool) {} bool ParamCompare::equals( diff --git a/indra/llxuixml/llinitparam.h b/indra/llxuixml/llinitparam.h index 09617209a8..7e2dd3989a 100644 --- a/indra/llxuixml/llinitparam.h +++ b/indra/llxuixml/llinitparam.h @@ -77,24 +77,118 @@ namespace LLInitParam // helper functions and classes typedef ptrdiff_t param_handle_t; + struct IS_A_BLOCK {}; + struct NOT_BLOCK {}; + + // these templates allow us to distinguish between template parameters + // that derive from BaseBlock and those that don't + template + struct IsBlock + { + typedef NOT_BLOCK value_t; + }; + + template + struct IsBlock + { + typedef IS_A_BLOCK value_t; + }; + + + template::value_t> + class ParamValue + { + typedef ParamValue self_t; + + public: + typedef T default_value_t; + typedef T value_t; + + ParamValue(): mValue() {} + ParamValue(const default_value_t& other) : mValue(other) {} + + void setValue(const value_t& val) + { + mValue = val; + } + + const value_t& getValue() const + { + return mValue; + } + + T& getValue() + { + return mValue; + } + + protected: + T mValue; + }; + + template + class ParamValue + : public T + { + typedef ParamValue self_t; + public: + typedef T default_value_t; + typedef T value_t; + + ParamValue() + : T(), + mValidated(false) + {} + + ParamValue(const default_value_t& other) + : T(other), + mValidated(false) + {} + + void setValue(const value_t& val) + { + *this = val; + } + + const value_t& getValue() const + { + return *this; + } + + T& getValue() + { + return *this; + } + + protected: + mutable bool mValidated; // lazy validation flag + }; + // empty default implementation of key cache // leverages empty base class optimization template class TypeValues + : public ParamValue { private: struct Inaccessable{}; + typedef typename ParamValue::value_t value_t; public: typedef std::map value_name_map_t; typedef Inaccessable name_t; + typedef TypeValues type_value_t; + + TypeValues(const value_t& val) + : ParamValue(val) + {} void setValueName(const std::string& key) {} std::string getValueName() const { return ""; } - std::string calcValueName(const T& value) const { return ""; } + std::string calcValueName(const value_t& value) const { return ""; } void clearValueName() const {} - static bool getValueFromName(const std::string& name, T& value) + static bool getValueFromName(const std::string& name, value_t& value) { return false; } @@ -109,15 +203,36 @@ namespace LLInitParam return NULL; } + void assignNamedValue(const Inaccessable& name) + {} + + operator const value_t&() const + { + return getValue(); + } + + const value_t& operator()() const + { + return getValue(); + } + static value_name_map_t* getValueNames() {return NULL;} }; - template > + template , bool IS_SPECIALIZED = true > class TypeValuesHelper + : public ParamValue { + typedef TypeValuesHelper self_t; + typedef typename ParamValue::value_t value_t; public: typedef typename std::map value_name_map_t; typedef std::string name_t; + typedef self_t type_value_t; + + TypeValuesHelper(const value_t& val) + : ParamValue(val) + {} //TODO: cache key by index to save on param block size void setValueName(const std::string& value_name) @@ -130,7 +245,7 @@ namespace LLInitParam return mValueName; } - std::string calcValueName(const T& value) const + std::string calcValueName(const value_t& value) const { value_name_map_t* map = getValueNames(); for (typename value_name_map_t::iterator it = map->begin(), end_it = map->end(); @@ -151,7 +266,7 @@ namespace LLInitParam mValueName.clear(); } - static bool getValueFromName(const std::string& name, T& value) + static bool getValueFromName(const std::string& name, value_t& value) { value_name_map_t* map = getValueNames(); typename value_name_map_t::iterator found_it = map->find(name); @@ -193,18 +308,80 @@ namespace LLInitParam return &sValues; } - static void declare(const std::string& name, const T& value) + static void declare(const std::string& name, const value_t& value) { (*getValueNames())[name] = value; } + void operator ()(const std::string& name) + { + *this = name; + } + + void assignNamedValue(const std::string& name) + { + if (getValueFromName(name, getValue())) + { + setValueName(name); + } + } + + operator const value_t&() const + { + return getValue(); + } + + const value_t& operator()() const + { + return getValue(); + } + protected: - static void getName(const std::string& name, const T& value) + static void getName(const std::string& name, const value_t& value) {} mutable std::string mValueName; }; + template + class TypeValuesHelper + : public TypeValuesHelper + { + public: + TypeValuesHelper(const std::string& val) + : TypeValuesHelper(val) + {} + + void operator ()(const std::string& name) + { + *this = name; + } + + self_t& operator =(const std::string& name) + { + if (getValueFromName(name, getValue())) + { + setValueName(name); + } + else + { + setValue(name); + } + return *this; + } + + operator const value_t&() const + { + return getValue(); + } + + const value_t& operator()() const + { + return getValue(); + } + + }; + class Parser { LOG_CLASS(Parser); @@ -370,23 +547,6 @@ namespace LLInitParam class BaseBlock* mCurrentBlockPtr; // pointer to block currently being constructed }; - struct IS_BLOCK {}; - struct NOT_BLOCK {}; - - // these templates allow us to distinguish between template parameters - // that derive from BaseBlock and those that don't - template - struct IsBlock - { - typedef NOT_BLOCK value_t; - }; - - template - struct IsBlock - { - typedef IS_BLOCK value_t; - }; - //TODO: implement in terms of owned_ptr template class LazyValue @@ -483,8 +643,8 @@ namespace LLInitParam { public: // lift block tags into baseblock namespace so derived classes do not need to qualify them - typedef LLInitParam::IS_BLOCK IS_BLOCK; - typedef LLInitParam::NOT_BLOCK NOT_BLOCK; + typedef LLInitParam::IS_A_BLOCK IS_A_BLOCK; + typedef LLInitParam::NOT_BLOCK NOT_A_BLOCK; template class Atomic @@ -640,182 +800,12 @@ namespace LLInitParam U32 mIsProvided:1; }; - - - template::value_t> - class ParamValue : public NAME_VALUE_LOOKUP - { - typedef ParamValue self_t; - - public: - typedef T default_value_t; - typedef T value_t; - - ParamValue(): mValue() {} - ParamValue(const default_value_t& other) : mValue(other) {} - - void setValue(const value_t& val) - { - mValue = val; - } - - const value_t& getValue() const - { - return mValue; - } - - T& getValue() - { - return mValue; - } - - operator const value_t&() const - { - return mValue; - } - - const value_t& operator()() const - { - return mValue; - } - - void operator ()(const typename NAME_VALUE_LOOKUP::name_t& name) - { - *this = name; - } - - self_t& operator =(const typename NAME_VALUE_LOOKUP::name_t& name) - { - if (NAME_VALUE_LOOKUP::getValueFromName(name, mValue)) - { - setValueName(name); - } - - return *this; - } - - protected: - T mValue; - }; - - template - class ParamValue - : public T, - public NAME_VALUE_LOOKUP - { - typedef ParamValue self_t; - public: - typedef T default_value_t; - typedef T value_t; - - ParamValue() - : T(), - mValidated(false) - {} - - ParamValue(const default_value_t& other) - : T(other), - mValidated(false) - {} - - void setValue(const value_t& val) - { - *this = val; - } - - const value_t& getValue() const - { - return *this; - } - - T& getValue() - { - return *this; - } - - operator const value_t&() const - { - return *this; - } - - const value_t& operator()() const - { - return *this; - } - - void operator ()(const typename NAME_VALUE_LOOKUP::name_t& name) - { - *this = name; - } - - self_t& operator =(const typename NAME_VALUE_LOOKUP::name_t& name) - { - if (NAME_VALUE_LOOKUP::getValueFromName(name, *this)) - { - setValueName(name); - } - - return *this; - } - - protected: - mutable bool mValidated; // lazy validation flag - }; - - template - class ParamValue - : public NAME_VALUE_LOOKUP - { - typedef ParamValue self_t; - public: - typedef std::string default_value_t; - typedef std::string value_t; - - ParamValue(): mValue() {} - ParamValue(const default_value_t& other) : mValue(other) {} - - void setValue(const value_t& val) - { - if (NAME_VALUE_LOOKUP::getValueFromName(val, mValue)) - { - NAME_VALUE_LOOKUP::setValueName(val); - } - else - { - mValue = val; - } - } - - const value_t& getValue() const - { - return mValue; - } - - std::string& getValue() - { - return mValue; - } - - operator const value_t&() const - { - return mValue; - } - - const value_t& operator()() const - { - return mValue; - } - - protected: - std::string mValue; - }; - - + template > struct ParamIterator { - typedef typename std::vector >::const_iterator const_iterator; - typedef typename std::vector >::iterator iterator; + typedef typename std::vector::const_iterator const_iterator; + typedef typename std::vector::iterator iterator; }; // specialize for custom parsing/decomposition of specific classes @@ -823,22 +813,23 @@ namespace LLInitParam template, bool HAS_MULTIPLE_VALUES = false, - typename VALUE_IS_BLOCK = typename IsBlock >::value_t> + typename VALUE_IS_BLOCK = typename IsBlock >::value_t> class TypedParam : public Param, - public ParamValue + public NAME_VALUE_LOOKUP::type_value_t { protected: typedef TypedParam self_t; - typedef ParamValue param_value_t; + typedef ParamValue param_value_t; typedef typename param_value_t::value_t value_t; typedef typename param_value_t::default_value_t default_value_t; + typedef typename NAME_VALUE_LOOKUP::type_value_t named_value_t; public: - using param_value_t::operator(); + using named_value_t::operator(); TypedParam(BlockDescriptor& block_descriptor, const char* name, const default_value_t& value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) : Param(block_descriptor.mCurrentBlockPtr), - param_value_t(value) + named_value_t(value) { if (LL_UNLIKELY(block_descriptor.mInitializationState == BlockDescriptor::INITIALIZING)) { @@ -862,7 +853,7 @@ namespace LLInitParam } // try to parse a known named value - if(param_value_t::valueNamesExist()) + if(named_value_t::valueNamesExist()) { // try to parse a known named value std::string name; @@ -870,7 +861,7 @@ namespace LLInitParam { // try to parse a per type named value - if (param_value_t::getValueFromName(name, typed_param.getValue())) + if (named_value_t::getValueFromName(name, typed_param.getValue())) { typed_param.setValueName(name); typed_param.setProvided(); @@ -923,22 +914,23 @@ namespace LLInitParam // tell parser about our actual type parser.inspectValue(name_stack, min_count, max_count, NULL); // then tell it about string-based alternatives ("red", "blue", etc. for LLColor4) - if (param_value_t::getPossibleValues()) + if (named_value_t::getPossibleValues()) { - parser.inspectValue(name_stack, min_count, max_count, param_value_t::getPossibleValues()); + parser.inspectValue(name_stack, min_count, max_count, named_value_t::getPossibleValues()); } } void set(const value_t& val, bool flag_as_provided = true) { - param_value_t::clearValueName(); + named_value_t::clearValueName(); setValue(val); setProvided(flag_as_provided); } - self_t& operator =(const typename NAME_VALUE_LOOKUP::name_t& name) + self_t& operator =(const typename named_value_t::name_t& name) { - return static_cast(param_value_t::operator =(name)); + named_value_t::assignNamedValue(name); + return *this; } protected: @@ -980,21 +972,22 @@ namespace LLInitParam // parameter that is a block template - class TypedParam + class TypedParam : public Param, - public ParamValue + public NAME_VALUE_LOOKUP::type_value_t { protected: - typedef ParamValue param_value_t; + typedef ParamValue param_value_t; typedef typename param_value_t::value_t value_t; typedef typename param_value_t::default_value_t default_value_t; - typedef TypedParam self_t; + typedef TypedParam self_t; + typedef typename NAME_VALUE_LOOKUP::type_value_t named_value_t; public: - using param_value_t::operator(); + using named_value_t::operator(); TypedParam(BlockDescriptor& block_descriptor, const char* name, const default_value_t& value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) : Param(block_descriptor.mCurrentBlockPtr), - param_value_t(value) + named_value_t(value) { if (LL_UNLIKELY(block_descriptor.mInitializationState == BlockDescriptor::INITIALIZING)) { @@ -1013,14 +1006,14 @@ namespace LLInitParam return true; } - if(param_value_t::valueNamesExist()) + if(named_value_t::valueNamesExist()) { // try to parse a known named value std::string name; if (parser.readValue(name)) { // try to parse a per type named value - if (param_value_t::getValueFromName(name, typed_param.getValue())) + if (named_value_t::getValueFromName(name, typed_param.getValue())) { typed_param.setValueName(name); typed_param.setProvided(); @@ -1045,9 +1038,9 @@ namespace LLInitParam std::string key = typed_param.getValueName(); if (!key.empty()) { - if (!parser.writeValue(key, name_stack)) + if (!diff_param || !ParamCompare::equals(static_cast(diff_param)->getValueName(), key)) { - return; + parser.writeValue(key, name_stack); } } else @@ -1058,8 +1051,16 @@ namespace LLInitParam static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count) { - // I am a param that is also a block, so just recurse into my contents const self_t& typed_param = static_cast(param); + + // tell parser about our actual type + parser.inspectValue(name_stack, min_count, max_count, NULL); + // then tell it about string-based alternatives ("red", "blue", etc. for LLColor4) + if (named_value_t::getPossibleValues()) + { + parser.inspectValue(name_stack, min_count, max_count, named_value_t::getPossibleValues()); + } + typed_param.inspectBlock(parser, name_stack, min_count, max_count); } @@ -1080,29 +1081,31 @@ namespace LLInitParam void set(const value_t& val, bool flag_as_provided = true) { setValue(val); - param_value_t::clearValueName(); + named_value_t::clearValueName(); // force revalidation of block // next call to isProvided() will update provision status based on validity param_value_t::mValidated = false; setProvided(flag_as_provided); } - self_t& operator =(const typename NAME_VALUE_LOOKUP::name_t& name) + self_t& operator =(const typename named_value_t::name_t& name) { - return static_cast(param_value_t::operator =(name)); + named_value_t::assignNamedValue(name); + return *this; } // propagate changed status up to enclosing block /*virtual*/ void paramChanged(const Param& changed_param, bool user_provided) { param_value_t::paramChanged(changed_param, user_provided); + named_value_t::clearValueName(); + if (user_provided) { // a child param has been explicitly changed // so *some* aspect of this block is now provided param_value_t::mValidated = false; setProvided(); - param_value_t::clearValueName(); } else { @@ -1157,11 +1160,12 @@ namespace LLInitParam : public Param { protected: - typedef TypedParam self_t; - typedef ParamValue::value_t> param_value_t; - typedef typename std::vector container_t; - typedef container_t default_value_t; - typedef typename param_value_t::value_t value_t; + typedef TypedParam self_t; + typedef ParamValue param_value_t; + typedef typename std::vector container_t; + typedef container_t default_value_t; + typedef typename param_value_t::value_t value_t; + typedef typename NAME_VALUE_LOOKUP::type_value_t named_value_t; public: TypedParam(BlockDescriptor& block_descriptor, const char* name, const default_value_t& value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) @@ -1193,14 +1197,14 @@ namespace LLInitParam } // try to parse a known named value - if(param_value_t::valueNamesExist()) + if(named_value_t::valueNamesExist()) { // try to parse a known named value std::string name; if (parser.readValue(name)) { // try to parse a per type named value - if (param_value_t::getValueFromName(name, value)) + if (named_value_t::getValueFromName(name, value)) { typed_param.add(value); typed_param.mValues.back().setValueName(name); @@ -1251,9 +1255,9 @@ namespace LLInitParam static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count) { parser.inspectValue(name_stack, min_count, max_count, NULL); - if (param_value_t::getPossibleValues()) + if (named_value_t::getPossibleValues()) { - parser.inspectValue(name_stack, min_count, max_count, param_value_t::getPossibleValues()); + parser.inspectValue(name_stack, min_count, max_count, named_value_t::getPossibleValues()); } } @@ -1265,25 +1269,23 @@ namespace LLInitParam param_value_t& add() { - mValues.push_back(param_value_t(value_t())); + mValues.push_back(value_t()); Param::setProvided(); return mValues.back(); } void add(const value_t& item) { - param_value_t param_value; - param_value.setValue(item); - mValues.push_back(param_value); + mValues.push_back(item); setProvided(); } - void add(const typename param_value_t::name_t& name) + void add(const typename named_value_t::name_t& name) { value_t value; // try to parse a per type named value - if (param_value_t::getValueFromName(name, value)) + if (named_value_t::getValueFromName(name, value)) { add(value); mValues.back().setValueName(name); @@ -1352,17 +1354,18 @@ namespace LLInitParam // container of block parameters template - class TypedParam + class TypedParam : public Param { protected: - typedef TypedParam self_t; - typedef ParamValue::value_t> param_value_t; - typedef typename std::vector container_t; - typedef typename param_value_t::value_t value_t; - typedef container_t default_value_t; - typedef typename container_t::iterator iterator; - typedef typename container_t::const_iterator const_iterator; + typedef TypedParam self_t; + typedef ParamValue param_value_t; + typedef typename std::vector container_t; + typedef typename NAME_VALUE_LOOKUP::type_value_t named_value_t; + typedef typename param_value_t::value_t value_t; + typedef container_t default_value_t; + typedef typename container_t::iterator iterator; + typedef typename container_t::const_iterator const_iterator; public: TypedParam(BlockDescriptor& block_descriptor, const char* name, const default_value_t& value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) : Param(block_descriptor.mCurrentBlockPtr) @@ -1396,14 +1399,14 @@ namespace LLInitParam typed_param.setProvided(); return true; } - else if(param_value_t::valueNamesExist()) + else if(named_value_t::valueNamesExist()) { // try to parse a known named value std::string name; if (parser.readValue(name)) { // try to parse a per type named value - if (param_value_t::getValueFromName(name, value.getValue())) + if (named_value_t::getValueFromName(name, value.getValue())) { typed_param.mValues.back().setValueName(name); typed_param.setProvided(); @@ -1448,8 +1451,17 @@ namespace LLInitParam static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count) { - // I am a vector of blocks, so describe my contents recursively - param_value_t(value_t()).inspectBlock(parser, name_stack, min_count, max_count); + const param_value_t& value_param = param_value_t(value_t()); + + // tell parser about our actual type + parser.inspectValue(name_stack, min_count, max_count, NULL); + // then tell it about string-based alternatives ("red", "blue", etc. for LLColor4) + if (named_value_t::getPossibleValues()) + { + parser.inspectValue(name_stack, min_count, max_count, named_value_t::getPossibleValues()); + } + + value_param.inspectBlock(parser, name_stack, min_count, max_count); } void set(const container_t& val, bool flag_as_provided = true) @@ -1471,12 +1483,12 @@ namespace LLInitParam setProvided(); } - void add(const typename param_value_t::name_t& name) + void add(const typename named_value_t::name_t& name) { value_t value; // try to parse a per type named value - if (param_value_t::getValueFromName(name, value)) + if (named_value_t::getValueFromName(name, value)) { add(value); mValues.back().setValueName(name); @@ -1620,7 +1632,7 @@ namespace LLInitParam // Alternatives are mutually exclusive wrt other Alternatives in the same block. // One alternative in a block will always have isChosen() == true. // At most one alternative in a block will have isProvided() == true. - template > + template ::type_value_t > class Alternative : public TypedParam { typedef TypedParam super_t; @@ -1662,7 +1674,7 @@ namespace LLInitParam super_t::set(val); } - void operator()(typename const value_t& val) + void operator()(const value_t& val) { super_t::set(val); } @@ -1743,7 +1755,7 @@ namespace LLInitParam // // Nested classes for declaring parameters // - template > + template ::type_value_t > class Optional : public TypedParam { typedef TypedParam super_t; @@ -1773,7 +1785,7 @@ namespace LLInitParam } }; - template > + template ::type_value_t > class Mandatory : public TypedParam { typedef TypedParam super_t; @@ -1796,7 +1808,7 @@ namespace LLInitParam return *this; } - DERIVED_BLOCK& operator()(typename const value_t& val) + DERIVED_BLOCK& operator()(const value_t& val) { super_t::set(val); return static_cast(Param::enclosingBlock()); @@ -1810,14 +1822,13 @@ namespace LLInitParam }; - template > + template ::type_value_t > class Multiple : public TypedParam { typedef TypedParam super_t; typedef Multiple self_t; typedef typename super_t::container_t container_t; typedef typename super_t::value_t value_t; - typedef TypedParam super_t; public: typedef typename super_t::iterator iterator; @@ -1833,7 +1844,7 @@ namespace LLInitParam return *this; } - DERIVED_BLOCK& operator()(typename const container_t& val) + DERIVED_BLOCK& operator()(const container_t& val) { super_t::set(val); return static_cast(Param::enclosingBlock()); @@ -1904,30 +1915,27 @@ namespace LLInitParam }; template - struct IsBlock, TypeValues >, BLOCK_T >, void> + struct IsBlock, BLOCK_T >, void> { - typedef IS_BLOCK value_t; + typedef IS_A_BLOCK value_t; }; template - struct IsBlock, TypeValues >, BLOCK_T >, void> + struct IsBlock, BLOCK_T >, void> { typedef NOT_BLOCK value_t; }; template - struct IsBlock, TypeValues >, typename IsBlock >::value_t >, BLOCK_IDENTIFIER> + struct IsBlock, typename IsBlock >::value_t >, BLOCK_IDENTIFIER> { - typedef typename IsBlock > >::value_t value_t; + typedef typename IsBlock >::value_t value_t; }; template - class ParamValue , - TypeValues >, - BLOCK_T> - : public TypeValues + class ParamValue , BLOCK_T> { - typedef ParamValue , TypeValues >, BLOCK_T> self_t; + typedef ParamValue , BLOCK_T> self_t; public: typedef T value_t; @@ -1945,12 +1953,12 @@ namespace LLInitParam void setValue(const value_t& val) { - mValue.setValue(val); + mValue = val; } const T& getValue() const { - return mValue.getValue(); + return mValue; } T& getValue() @@ -1968,18 +1976,6 @@ namespace LLInitParam return mValue; } - void operator ()(const typename TypeValues::name_t& name) - { - *this = name; - } - - self_t& operator =(const typename TypeValues::name_t& name) - { - mValue = name; - - return *this; - } - bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name) { if (new_name) @@ -2036,12 +2032,9 @@ namespace LLInitParam }; template - class ParamValue , - TypeValues >, - BLOCK_T> - : public TypeValues + class ParamValue , BLOCK_T> { - typedef ParamValue , TypeValues >, BLOCK_T> self_t; + typedef ParamValue , BLOCK_T> self_t; public: typedef T value_t; @@ -2087,21 +2080,6 @@ namespace LLInitParam return mValue.get(); } - void operator ()(const typename TypeValues::name_t& name) - { - *this = name; - } - - self_t& operator =(const typename TypeValues::name_t& name) - { - if (TypeValues::getValueFromName(name, mValue.get())) - { - setValueName(name); - } - - return *this; - } - bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name) { return mValue.get().deserializeBlock(p, name_stack_range, new_name); @@ -2145,12 +2123,9 @@ namespace LLInitParam }; template - class ParamValue , - TypeValues >, - BLOCK_T> - : public TypeValues + class ParamValue , BLOCK_T> { - typedef ParamValue , TypeValues >, BLOCK_T> self_t; + typedef ParamValue , BLOCK_T> self_t; public: typedef T value_t; @@ -2196,21 +2171,6 @@ namespace LLInitParam return mValue.get(); } - void operator ()(const typename TypeValues::name_t& name) - { - *this = name; - } - - self_t& operator =(const typename TypeValues::name_t& name) - { - if (TypeValues::getValueFromName(name, mValue.get())) - { - setValueName(name); - } - - return *this; - } - mutable bool mValidated; // lazy validation flag private: @@ -2218,11 +2178,8 @@ namespace LLInitParam }; template <> - class ParamValue , - NOT_BLOCK> - : public TypeValues, - public BaseBlock + class ParamValue + : public BaseBlock { public: typedef LLSD value_t; @@ -2265,8 +2222,7 @@ namespace LLInitParam template class CustomParamValue - : public Block > >, - public TypeValues + : public Block > { public: typedef enum e_value_age @@ -2276,12 +2232,12 @@ namespace LLInitParam BLOCK_AUTHORITATIVE // mValue is derived from the block parameters, which are authoritative } EValueAge; - typedef ParamValue > derived_t; - typedef CustomParamValue self_t; - typedef Block block_t; - typedef T default_value_t; - typedef T value_t; - typedef void baseblock_base_class_t; + typedef ParamValue derived_t; + typedef CustomParamValue self_t; + typedef Block block_t; + typedef T default_value_t; + typedef T value_t; + typedef void baseblock_base_class_t; CustomParamValue(const default_value_t& value = T()) @@ -2301,8 +2257,6 @@ namespace LLInitParam typed_param.mValueAge = VALUE_AUTHORITATIVE; typed_param.updateBlockFromValue(false); - typed_param.clearValueName(); - return true; } } @@ -2316,18 +2270,8 @@ namespace LLInitParam const derived_t& typed_param = static_cast(*this); const derived_t* diff_param = static_cast(diff_block); - std::string key = typed_param.getValueName(); - - // first try to write out name of name/value pair - if (!key.empty()) - { - if (!diff_param || !ParamCompare::equals(diff_param->getValueName(), key)) - { - parser.writeValue(key, name_stack); - } - } // then try to serialize value directly - else if (!diff_param || !ParamCompare::equals(typed_param.getValue(), diff_param->getValue())) + if (!diff_param || !ParamCompare::equals(typed_param.getValue(), diff_param->getValue())) { if (!parser.writeValue(typed_param.getValue(), name_stack)) @@ -2357,19 +2301,6 @@ namespace LLInitParam } } - bool inspectBlock(Parser& parser, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const - { - // first, inspect with actual type... - parser.inspectValue(name_stack, min_count, max_count, NULL); - if (TypeValues::getPossibleValues()) - { - //...then inspect with possible string values... - parser.inspectValue(name_stack, min_count, max_count, TypeValues::getPossibleValues()); - } - // then recursively inspect contents... - return block_t::inspectBlock(parser, name_stack, min_count, max_count); - } - bool validateBlock(bool emit_errors = true) const { if (mValueAge == VALUE_NEEDS_UPDATE) @@ -2377,7 +2308,6 @@ namespace LLInitParam if (block_t::validateBlock(emit_errors)) { // clear stale keyword associated with old value - TypeValues::clearValueName(); mValueAge = BLOCK_AUTHORITATIVE; static_cast(const_cast(this))->updateValueFromBlock(); return true; @@ -2409,11 +2339,9 @@ namespace LLInitParam void setValue(const value_t& val) { - derived_t& typed_param = static_cast(*this); // set param version number to be up to date, so we ignore block contents mValueAge = VALUE_AUTHORITATIVE; mValue = val; - typed_param.clearValueName(); static_cast(this)->updateBlockFromValue(false); } @@ -2429,30 +2357,6 @@ namespace LLInitParam return mValue; } - operator const value_t&() const - { - return getValue(); - } - - const value_t& operator()() const - { - return getValue(); - } - - void operator ()(const typename TypeValues::name_t& name) - { - *this = name; - } - - self_t& operator =(const typename TypeValues::name_t& name) - { - if (TypeValues::getValueFromName(name, mValue)) - { - setValueName(name); - } - - return *this; - } protected: // use this from within updateValueFromBlock() to set the value without making it authoritative diff --git a/indra/llxuixml/llxuiparser.cpp b/indra/llxuixml/llxuiparser.cpp index 2e1f8888d0..58ed24b08b 100644 --- a/indra/llxuixml/llxuiparser.cpp +++ b/indra/llxuixml/llxuiparser.cpp @@ -130,7 +130,7 @@ struct Any : public LLInitParam::Block struct All : public LLInitParam::Block { - Multiple< Lazy > elements; + Multiple< Lazy > elements; All() : elements("element") @@ -141,11 +141,11 @@ struct All : public LLInitParam::Block struct Choice : public LLInitParam::ChoiceBlock { - Alternative< Lazy > element; - Alternative< Lazy > group; - Alternative< Lazy > choice; - Alternative< Lazy > sequence; - Alternative< Lazy > any; + Alternative< Lazy > element; + Alternative< Lazy > group; + Alternative< Lazy > choice; + Alternative< Lazy > sequence; + Alternative< Lazy > any; Choice() : element("element"), @@ -159,11 +159,11 @@ struct Choice : public LLInitParam::ChoiceBlock struct Sequence : public LLInitParam::ChoiceBlock { - Alternative< Lazy > element; - Alternative< Lazy > group; - Alternative< Lazy > choice; - Alternative< Lazy > sequence; - Alternative< Lazy > any; + Alternative< Lazy > element; + Alternative< Lazy > group; + Alternative< Lazy > choice; + Alternative< Lazy > sequence; + Alternative< Lazy > any; }; struct GroupContents : public LLInitParam::ChoiceBlock @@ -248,7 +248,7 @@ struct ComplexType : public LLInitParam::Block Optional mixed; Multiple attribute; - Multiple< Lazy > elements; + Multiple< Lazy > elements; ComplexType() : name("name"), diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp index c483aa58c9..b420812a3c 100644 --- a/indra/newview/llvoavatar.cpp +++ b/indra/newview/llvoavatar.cpp @@ -248,7 +248,7 @@ struct LLVOAvatarCollisionVolumeInfo : public LLInitParam::Block { - Alternative > bone; + Alternative > bone; Alternative collision_volume; LLVOAvatarChildJoint() -- cgit v1.2.3