From 855fbc0bf331c116d20d402f427535f060f70345 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 12 Apr 2012 17:18:34 -0700 Subject: fixed UI not working at all due to bad param blocks --- indra/llui/llloadingindicator.cpp | 2 +- indra/llui/llloadingindicator.h | 6 +- indra/llxuixml/llinitparam.h | 391 ++++++++++++++++++++++++++------------ indra/llxuixml/llxuiparser.cpp | 26 +-- indra/newview/llvoavatar.cpp | 2 +- 5 files changed, 284 insertions(+), 143 deletions(-) (limited to 'indra') diff --git a/indra/llui/llloadingindicator.cpp b/indra/llui/llloadingindicator.cpp index 6ac38f5ad4..1ede5b706f 100644 --- a/indra/llui/llloadingindicator.cpp +++ b/indra/llui/llloadingindicator.cpp @@ -52,7 +52,7 @@ LLLoadingIndicator::LLLoadingIndicator(const Params& p) void LLLoadingIndicator::initFromParams(const Params& p) { - BOOST_FOREACH(LLUIImage* image, p.images.image) + BOOST_FOREACH(LLUIImage* image, p.images().image) { mImages.push_back(image); } diff --git a/indra/llui/llloadingindicator.h b/indra/llui/llloadingindicator.h index c1f979c111..4998a57263 100644 --- a/indra/llui/llloadingindicator.h +++ b/indra/llui/llloadingindicator.h @@ -51,7 +51,7 @@ class LLLoadingIndicator LOG_CLASS(LLLoadingIndicator); public: - struct Images : public LLInitParam::BatchBlock + struct Images : public LLInitParam::Block { Multiple image; @@ -62,8 +62,8 @@ public: struct Params : public LLInitParam::Block { - Optional images_per_sec; - Optional images; + Optional images_per_sec; + Optional > images; Params() : images_per_sec("images_per_sec", 1.0f), diff --git a/indra/llxuixml/llinitparam.h b/indra/llxuixml/llinitparam.h index dbf2fdaa73..0c53b36bad 100644 --- a/indra/llxuixml/llinitparam.h +++ b/indra/llxuixml/llinitparam.h @@ -390,15 +390,19 @@ namespace LLInitParam class BaseBlock { public: - typedef IS_BLOCK IS_BLOCK; - typedef NOT_BLOCK NOT_BLOCK; + // 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; + + template + class Batch + {}; //TODO: implement in terms of owned_ptr - template + template::value_t > class Lazy { public: - Lazy() : mPtr(NULL) {} @@ -470,7 +474,7 @@ namespace LLInitParam return get(); } - private: + private: // lazily allocate an instance of T T* ensureInstance() const { @@ -642,11 +646,12 @@ namespace LLInitParam { public: typedef const T& value_assignment_t; + typedef T default_value_t; typedef T value_t; typedef ParamValue self_t; ParamValue(): mValue() {} - ParamValue(value_assignment_t other) : mValue(other) {} + ParamValue(const default_value_t& other) : mValue(other) {} void setValue(value_assignment_t val) { @@ -699,6 +704,7 @@ namespace LLInitParam { public: typedef const T& value_assignment_t; + typedef T default_value_t; typedef T value_t; typedef ParamValue self_t; @@ -707,7 +713,7 @@ namespace LLInitParam mValidated(false) {} - ParamValue(value_assignment_t other) + ParamValue(const default_value_t& other) : T(other), mValidated(false) {} @@ -762,11 +768,12 @@ namespace LLInitParam { public: typedef const std::string& value_assignment_t; + typedef std::string default_value_t; typedef std::string value_t; typedef ParamValue self_t; ParamValue(): mValue() {} - ParamValue(value_assignment_t other) : mValue(other) {} + ParamValue(const default_value_t& other) : mValue(other) {} void setValue(value_assignment_t val) { @@ -808,8 +815,8 @@ namespace LLInitParam template > struct ParamIterator { - typedef typename std::vector >::const_iterator const_iterator; - typedef typename std::vector >::iterator iterator; + typedef typename std::vector::value_t> >::const_iterator const_iterator; + typedef typename std::vector::value_t> >::iterator iterator; }; // specialize for custom parsing/decomposition of specific classes @@ -817,19 +824,20 @@ namespace LLInitParam template, bool HAS_MULTIPLE_VALUES = false, - typename VALUE_IS_BLOCK = typename IsBlock::value_t> + typename VALUE_IS_BLOCK = typename IsBlock::value_t> >::value_t> class TypedParam : public Param, - public ParamValue + public ParamValue::value_t> { public: - typedef TypedParam self_t; - typedef ParamValue param_value_t; - typedef typename param_value_t::value_assignment_t value_assignment_t; + typedef TypedParam self_t; + typedef ParamValue::value_t> param_value_t; + typedef typename param_value_t::value_assignment_t value_assignment_t; + typedef typename param_value_t::default_value_t default_value_t; using param_value_t::operator(); - TypedParam(BlockDescriptor& block_descriptor, const char* name, const T& value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) + 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) { @@ -862,6 +870,7 @@ namespace LLInitParam if (parser.readValue(name)) { // try to parse a per type named value + if (param_value_t::getValueFromName(name, typed_param.getValue())) { typed_param.setValueName(name); @@ -974,16 +983,17 @@ namespace LLInitParam template class TypedParam : public Param, - public ParamValue + public ParamValue::value_t> { public: - typedef ParamValue param_value_t; + typedef ParamValue::value_t> param_value_t; typedef typename param_value_t::value_assignment_t value_assignment_t; + typedef typename param_value_t::default_value_t default_value_t; typedef TypedParam self_t; using param_value_t::operator(); - TypedParam(BlockDescriptor& block_descriptor, const char* name, const T& value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) + 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) { @@ -1149,13 +1159,14 @@ namespace LLInitParam { public: typedef TypedParam self_t; - typedef ParamValue param_value_t; + typedef ParamValue::value_t> param_value_t; typedef typename std::vector container_t; typedef const container_t& value_assignment_t; + typedef container_t default_value_t; typedef typename param_value_t::value_t value_t; - TypedParam(BlockDescriptor& block_descriptor, const char* name, const container_t& value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) + 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) { std::copy(value.begin(), value.end(), std::back_inserter(mValues)); @@ -1348,12 +1359,13 @@ namespace LLInitParam { public: typedef TypedParam self_t; - typedef ParamValue param_value_t; + typedef ParamValue::value_t> param_value_t; typedef typename std::vector container_t; typedef const container_t& value_assignment_t; typedef typename param_value_t::value_t value_t; + typedef container_t default_value_t; - TypedParam(BlockDescriptor& block_descriptor, const char* name, const container_t& value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) + 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) { std::copy(value.begin(), value.end(), back_inserter(mValues)); @@ -1617,13 +1629,14 @@ namespace LLInitParam public: friend class ChoiceBlock; - typedef Alternative self_t; - typedef TypedParam::value_t> super_t; - typedef typename super_t::value_assignment_t value_assignment_t; + typedef Alternative self_t; + typedef TypedParam super_t; + typedef typename super_t::value_assignment_t value_assignment_t; + typedef typename super_t::default_value_t default_value_t; using super_t::operator =; - explicit Alternative(const char* name = "", const T& val = defaultValue()) + explicit Alternative(const char* name = "", const default_value_t& val = defaultValue()) : super_t(DERIVED_BLOCK::getBlockDescriptor(), name, val, NULL, 0, 1), mOriginalValue(val) { @@ -1736,13 +1749,14 @@ namespace LLInitParam class Optional : public TypedParam { public: - typedef TypedParam::value_t> super_t; - typedef typename super_t::value_assignment_t value_assignment_t; + typedef TypedParam super_t; + typedef typename super_t::value_assignment_t value_assignment_t; + typedef typename super_t::default_value_t default_value_t; using super_t::operator(); using super_t::operator =; - explicit Optional(const char* name = "", const T& val = defaultValue()) + explicit Optional(const char* name = "", const default_value_t& val = defaultValue()) : super_t(DERIVED_BLOCK::getBlockDescriptor(), name, val, NULL, 0, 1) { //#pragma message("Parsing LLInitParam::Block::Optional") @@ -1765,15 +1779,16 @@ namespace LLInitParam class Mandatory : public TypedParam { public: - typedef TypedParam::value_t> super_t; - typedef Mandatory self_t; - typedef typename super_t::value_assignment_t value_assignment_t; + typedef TypedParam super_t; + typedef Mandatory self_t; + typedef typename super_t::value_assignment_t value_assignment_t; + typedef typename super_t::default_value_t default_value_t; using super_t::operator(); using super_t::operator =; // mandatory parameters require a name to be parseable - explicit Mandatory(const char* name = "", const T& val = defaultValue()) + explicit Mandatory(const char* name = "", const default_value_t& val = defaultValue()) : super_t(DERIVED_BLOCK::getBlockDescriptor(), name, val, &validate, 1, 1) {} @@ -1801,12 +1816,12 @@ namespace LLInitParam class Multiple : public TypedParam { public: - typedef TypedParam::value_t> super_t; - typedef Multiple self_t; - typedef typename super_t::container_t container_t; - typedef typename super_t::value_assignment_t value_assignment_t; - typedef typename super_t::iterator iterator; - typedef typename super_t::const_iterator const_iterator; + typedef TypedParam super_t; + typedef Multiple self_t; + typedef typename super_t::container_t container_t; + typedef typename super_t::value_assignment_t value_assignment_t; + typedef typename super_t::iterator iterator; + typedef typename super_t::const_iterator const_iterator; explicit Multiple(const char* name = "") : super_t(DERIVED_BLOCK::getBlockDescriptor(), name, container_t(), &validate, RANGE::minCount, RANGE::maxCount) @@ -1888,136 +1903,158 @@ namespace LLInitParam }; - template - class BatchBlock - : public Block + template + struct IsBlock, TypeValues >, BLOCK_T >, void> { - public: - typedef BatchBlock self_t; - typedef Block super_t; - - BatchBlock() - {} + typedef IS_BLOCK value_t; + }; - bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name) - { - if (new_name) - { - // reset block - *static_cast(this) = defaultBatchValue(); - } - return super_t::deserializeBlock(p, name_stack_range, new_name); - } + template + struct IsBlock, TypeValues >, BLOCK_T >, void> + { + typedef NOT_BLOCK value_t; + }; - bool mergeBlock(BlockDescriptor& block_data, const BaseBlock& other, bool overwrite) - { - if (overwrite) - { - *static_cast(this) = defaultBatchValue(); - // merge individual parameters into destination - return super_t::mergeBlock(super_t::getBlockDescriptor(), other, overwrite); - } - return false; - } - protected: - static const DERIVED_BLOCK& defaultBatchValue() - { - static DERIVED_BLOCK default_value; - return default_value; - } + template + struct IsBlock, TypeValues >, typename IsBlock >::value_t >, BLOCK_IDENTIFIER> + { + typedef typename IsBlock, typename IsBlock::value_t > >::value_t value_t; }; - // FIXME: this specialization is not currently used, as it only matches against the BatchBlock base class - // and not the derived class with the actual params - template - class ParamValue , - NAME_VALUE_LOOKUP, - IS_BLOCK> - : public NAME_VALUE_LOOKUP, - protected BatchBlock + template + class ParamValue , + TypeValues >, + BLOCK_T> + : public TypeValues { public: - typedef BatchBlock block_t; - typedef const BatchBlock& value_assignment_t; - typedef block_t value_t; + typedef ParamValue , TypeValues >, BLOCK_T> self_t; + typedef ParamValue, typename IsBlock::value_t > param_value_t; + typedef const T& value_assignment_t; + typedef T value_t; + typedef T default_value_t; ParamValue() - : block_t(), + : mValue(), mValidated(false) {} - ParamValue(value_assignment_t other) - : block_t(other), + ParamValue(const default_value_t& value) + : mValue(value), mValidated(false) - { - } + {} void setValue(value_assignment_t val) { - *this = val; + mValue.setValue(val); } - value_assignment_t getValue() const + const T& getValue() const { - return *this; + return mValue.getValue(); } - BatchBlock& getValue() + T& getValue() { - return *this; + return mValue; } operator value_assignment_t() const { - return *this; + return mValue; } value_assignment_t operator()() const { + 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; } - protected: + bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name) + { + if (new_name) + { + // reset block + mValue = defaultBatchValue(); + } + return mValue.deserializeBlock(p, name_stack_range, new_name); + } + + void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const self_t* diff_block = NULL) const + { + const BaseBlock* base_block = diff_block + ? &(diff_block->mValue) + : NULL; + mValue.serializeBlock(p, name_stack, base_block); + } + + bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const + { + return mValue.inspectBlock(p, name_stack, min_count, max_count); + } + + bool mergeBlockParam(bool source_provided, bool dst_provided, BlockDescriptor& block_data, const self_t& source, bool overwrite) + { + if (overwrite) + { + mValue = defaultBatchValue(); + return mValue.mergeBlock(block_data, source, overwrite); + } + return false; + } + + bool validateBlock(bool emit_errors = true) const + { + return mValue.validateBlock(emit_errors); + } + + static BlockDescriptor& getBlockDescriptor() + { + return T::getBlockDescriptor(); + } + + mutable bool mValidated; // lazy validation flag - }; - template - struct IsBlock, BLOCK_IDENTIFIER> - { - typedef IS_BLOCK value_t; - }; + private: + static const T& defaultBatchValue() + { + static T default_value; + return default_value; + } - template - struct IsBlock, BLOCK_IDENTIFIER> - { - typedef NOT_BLOCK value_t; + T mValue; }; - //template - //struct IsBlock, BLOCK_IDENTIFIER> - //{ - // typedef typename IsBlock::value_t value_t; - //}; - - template + template class ParamValue , TypeValues >, - IS_BLOCK> + BLOCK_T> : public TypeValues { public: - typedef ParamValue , TypeValues >, IS_BLOCK> self_t; + typedef ParamValue , TypeValues >, BLOCK_T> self_t; typedef const T& value_assignment_t; typedef T value_t; + typedef BaseBlock::Lazy default_value_t; ParamValue() : mValue(), mValidated(false) {} - ParamValue(const BaseBlock::Lazy& other) + ParamValue(const default_value_t& other) : mValue(other), mValidated(false) {} @@ -2052,6 +2089,21 @@ 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); @@ -2074,7 +2126,7 @@ namespace LLInitParam bool mergeBlockParam(bool source_provided, bool dst_provided, BlockDescriptor& block_data, const self_t& source, bool overwrite) { - return source.mValue.empty() || mValue.get().mergeBlock(block_data, source.getValue(), overwrite); + return source.mValue.empty() || mValue.get().mergeBlock(block_data, source, overwrite); } bool validateBlock(bool emit_errors = true) const @@ -2094,6 +2146,79 @@ namespace LLInitParam BaseBlock::Lazy mValue; }; + template + class ParamValue , + TypeValues >, + BLOCK_T> + : public TypeValues + { + public: + typedef ParamValue , TypeValues >, BLOCK_T> self_t; + typedef const T& value_assignment_t; + typedef T value_t; + typedef BaseBlock::Lazy default_value_t; + + ParamValue() + : mValue(), + mValidated(false) + {} + + ParamValue(const default_value_t& other) + : mValue(other), + mValidated(false) + {} + + ParamValue(const T& value) + : mValue(value), + mValidated(false) + {} + + void setValue(value_assignment_t val) + { + mValue.set(val); + } + + value_assignment_t getValue() const + { + return mValue.get(); + } + + T& getValue() + { + return mValue.get(); + } + + operator value_assignment_t() const + { + return mValue.get(); + } + + value_assignment_t operator()() const + { + 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: + BaseBlock::Lazy mValue; + }; + template <> class ParamValue , @@ -2104,12 +2229,13 @@ namespace LLInitParam public: typedef ParamValue, NOT_BLOCK> self_t; typedef const LLSD& value_assignment_t; + typedef LLSD default_value_t; ParamValue() : mValidated(false) {} - ParamValue(value_assignment_t other) + ParamValue(const default_value_t& other) : mValue(other), mValidated(false) {} @@ -2122,7 +2248,6 @@ namespace LLInitParam operator value_assignment_t() const { return mValue; } value_assignment_t operator()() const { return mValue; } - // block param interface bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name); void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const; @@ -2143,7 +2268,7 @@ namespace LLInitParam template class CustomParamValue - : public Block > >, + : public Block, typename IsBlock::value_t > >, public TypeValues { public: @@ -2154,14 +2279,16 @@ namespace LLInitParam BLOCK_AUTHORITATIVE // mValue is derived from the block parameters, which are authoritative } EValueAge; - typedef ParamValue > derived_t; + typedef ParamValue, typename IsBlock::value_t > derived_t; typedef CustomParamValue self_t; typedef Block block_t; typedef const T& value_assignment_t; + typedef T default_value_t; typedef T value_t; + typedef void baseblock_base_class_t; - CustomParamValue(const T& value = T()) + CustomParamValue(const default_value_t& value = T()) : mValue(value), mValueAge(VALUE_AUTHORITATIVE), mValidated(false) @@ -2316,6 +2443,20 @@ namespace LLInitParam 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 3c89fa3aaf..ce8c8411ea 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"), @@ -343,7 +343,7 @@ void LLXSDWriter::writeXSD(const std::string& type_name, LLXMLNodePtr node, cons { Schema schema(xml_namespace); - schema.root_element.name = type_name; + schema.root_element.super_t::param_value_t::name = type_name; Choice& choice = schema.root_element.complexType.choice; choice.minOccurs = 0; diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp index f47cce9a4d..c483aa58c9 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