diff options
author | Richard Linden <none@none> | 2012-04-06 09:40:59 -0700 |
---|---|---|
committer | Richard Linden <none@none> | 2012-04-06 09:40:59 -0700 |
commit | fff9567a67ded34471fd17af9c50bc1d307e7b19 (patch) | |
tree | 9a3f4e3d0c99163f1c81e4018ae93393fdbea87b | |
parent | 6dd7029942dcc381d670657e0c4bb7d8dcd24594 (diff) |
further LLInitParam cleanup
changed bool template parameter to IS_BLOCK and NOT_BLOCK types
moved addParam to BlockDescriptor
moved init outside of param element constructors for faster construction
-rw-r--r-- | indra/llui/llsdparam.cpp | 6 | ||||
-rw-r--r-- | indra/llui/lluiimage.h | 4 | ||||
-rw-r--r-- | indra/llxuixml/llinitparam.cpp | 59 | ||||
-rw-r--r-- | indra/llxuixml/llinitparam.h | 177 |
4 files changed, 137 insertions, 109 deletions
diff --git a/indra/llui/llsdparam.cpp b/indra/llui/llsdparam.cpp index 0e29873bb0..828f809452 100644 --- a/indra/llui/llsdparam.cpp +++ b/indra/llui/llsdparam.cpp @@ -313,7 +313,7 @@ namespace LLInitParam { // LLSD specialization // block param interface - bool ParamValue<LLSD, TypeValues<LLSD>, false>::deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack, bool new_name) + bool ParamValue<LLSD, TypeValues<LLSD>, NOT_BLOCK>::deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack, bool new_name) { LLSD& sd = LLParamSDParserUtilities::getSDWriteNode(mValue, name_stack); @@ -328,12 +328,12 @@ namespace LLInitParam } //static - void ParamValue<LLSD, TypeValues<LLSD>, false>::serializeElement(Parser& p, const LLSD& sd, Parser::name_stack_t& name_stack) + void ParamValue<LLSD, TypeValues<LLSD>, NOT_BLOCK>::serializeElement(Parser& p, const LLSD& sd, Parser::name_stack_t& name_stack) { p.writeValue<LLSD::String>(sd.asString(), name_stack); } - void ParamValue<LLSD, TypeValues<LLSD>, false>::serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block) const + void ParamValue<LLSD, TypeValues<LLSD>, NOT_BLOCK>::serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block) const { // read from LLSD value and serialize out to parser (which could be LLSD, XUI, etc) Parser::name_stack_t stack; diff --git a/indra/llui/lluiimage.h b/indra/llui/lluiimage.h index f07e8fa746..b9b90fee71 100644 --- a/indra/llui/lluiimage.h +++ b/indra/llui/lluiimage.h @@ -92,7 +92,7 @@ protected: namespace LLInitParam { template<> - class ParamValue<LLUIImage*, TypeValues<LLUIImage*> > + class ParamValue<LLUIImage*, TypeValues<LLUIImage*>, NOT_BLOCK > : public CustomParamValue<LLUIImage*> { typedef boost::add_reference<boost::add_const<LLUIImage*>::type>::type T_const_ref; @@ -100,7 +100,7 @@ namespace LLInitParam public: Optional<std::string> name; - ParamValue(LLUIImage* const& image) + ParamValue(LLUIImage* const& image = NULL) : super_t(image) { updateBlockFromValue(false); diff --git a/indra/llxuixml/llinitparam.cpp b/indra/llxuixml/llinitparam.cpp index db72aa19b9..3cf145cdde 100644 --- a/indra/llxuixml/llinitparam.cpp +++ b/indra/llxuixml/llinitparam.cpp @@ -112,6 +112,35 @@ namespace LLInitParam std::copy(src_block_data.mAllParams.begin(), src_block_data.mAllParams.end(), std::back_inserter(mAllParams)); } + void BlockDescriptor::addParam(const ParamDescriptorPtr in_param, const char* char_name) + { + // create a copy of the param descriptor in mAllParams + // so other data structures can store a pointer to it + mAllParams.push_back(in_param); + ParamDescriptorPtr param(mAllParams.back()); + + std::string name(char_name); + if ((size_t)param->mParamHandle > mMaxParamOffset) + { + llerrs << "Attempted to register param with block defined for parent class, make sure to derive from LLInitParam::Block<YOUR_CLASS, PARAM_BLOCK_BASE_CLASS>" << llendl; + } + + if (name.empty()) + { + mUnnamedParams.push_back(param); + } + else + { + // don't use insert, since we want to overwrite existing entries + mNamedParams[name] = param; + } + + if (param->mValidationFunc) + { + mValidationList.push_back(std::make_pair(param->mParamHandle, param->mValidationFunc)); + } + } + BlockDescriptor::BlockDescriptor() : mMaxParamOffset(0), mInitializationState(UNINITIALIZED), @@ -358,36 +387,6 @@ namespace LLInitParam return false; } - //static - void BaseBlock::addParam(BlockDescriptor& block_data, const ParamDescriptorPtr in_param, const char* char_name) - { - // create a copy of the param descriptor in mAllParams - // so other data structures can store a pointer to it - block_data.mAllParams.push_back(in_param); - ParamDescriptorPtr param(block_data.mAllParams.back()); - - std::string name(char_name); - if ((size_t)param->mParamHandle > block_data.mMaxParamOffset) - { - llerrs << "Attempted to register param with block defined for parent class, make sure to derive from LLInitParam::Block<YOUR_CLASS, PARAM_BLOCK_BASE_CLASS>" << llendl; - } - - if (name.empty()) - { - block_data.mUnnamedParams.push_back(param); - } - else - { - // don't use insert, since we want to overwrite existing entries - block_data.mNamedParams[name] = param; - } - - if (param->mValidationFunc) - { - block_data.mValidationList.push_back(std::make_pair(param->mParamHandle, param->mValidationFunc)); - } - } - void BaseBlock::addSynonym(Param& param, const std::string& synonym) { BlockDescriptor& block_data = mostDerivedBlockDescriptor(); diff --git a/indra/llxuixml/llinitparam.h b/indra/llxuixml/llinitparam.h index 1f0dec5d94..dbf2fdaa73 100644 --- a/indra/llxuixml/llinitparam.h +++ b/indra/llxuixml/llinitparam.h @@ -354,6 +354,7 @@ namespace LLInitParam } EInitializationState; void aggregateBlockData(BlockDescriptor& src_block_data); + void addParam(ParamDescriptorPtr param, const char* name); typedef boost::unordered_map<const std::string, ParamDescriptorPtr> param_map_t; typedef std::vector<ParamDescriptorPtr> param_list_t; @@ -377,22 +378,23 @@ namespace LLInitParam template<typename T, typename BLOCK_IDENTIFIER = void> struct IsBlock { - static const bool value = false; typedef NOT_BLOCK value_t; }; template<typename T> struct IsBlock<T, typename T::baseblock_base_class_t> { - static const bool value = true; typedef IS_BLOCK value_t; }; class BaseBlock { public: + typedef IS_BLOCK IS_BLOCK; + typedef NOT_BLOCK NOT_BLOCK; + //TODO: implement in terms of owned_ptr - template<typename T, bool IS_BLOCK = true> + template<typename T, typename BLOCK_T = IS_BLOCK> class Lazy { public: @@ -487,7 +489,6 @@ namespace LLInitParam mutable T* mPtr; }; - // "Multiple" constraint types, put here in root class to avoid ambiguity during use struct AnyAmount { @@ -572,8 +573,6 @@ namespace LLInitParam return false; } - static void addParam(BlockDescriptor& block_data, ParamDescriptorPtr param, const char* name); - ParamDescriptorPtr findParamDescriptor(const Param& param); // take all provided params from other and apply to self @@ -638,7 +637,7 @@ namespace LLInitParam }; - template<typename T, typename NAME_VALUE_LOOKUP, bool VALUE_IS_BLOCK = IsBlock<T>::value> + template<typename T, typename NAME_VALUE_LOOKUP, typename VALUE_IS_BLOCK = typename IsBlock<T>::value_t> class ParamValue : public NAME_VALUE_LOOKUP { public: @@ -694,14 +693,14 @@ namespace LLInitParam }; template<typename T, typename NAME_VALUE_LOOKUP> - class ParamValue<T, NAME_VALUE_LOOKUP, true> + class ParamValue<T, NAME_VALUE_LOOKUP, IS_BLOCK> : public T, public NAME_VALUE_LOOKUP { public: typedef const T& value_assignment_t; typedef T value_t; - typedef ParamValue<T, NAME_VALUE_LOOKUP, true> self_t; + typedef ParamValue<T, NAME_VALUE_LOOKUP, IS_BLOCK> self_t; ParamValue() : T(), @@ -758,13 +757,13 @@ namespace LLInitParam }; template<typename NAME_VALUE_LOOKUP> - class ParamValue<std::string, NAME_VALUE_LOOKUP, false> + class ParamValue<std::string, NAME_VALUE_LOOKUP, NOT_BLOCK> : public NAME_VALUE_LOOKUP { public: typedef const std::string& value_assignment_t; typedef std::string value_t; - typedef ParamValue<std::string, NAME_VALUE_LOOKUP, false> self_t; + typedef ParamValue<std::string, NAME_VALUE_LOOKUP, NOT_BLOCK> self_t; ParamValue(): mValue() {} ParamValue(value_assignment_t other) : mValue(other) {} @@ -818,7 +817,7 @@ namespace LLInitParam template<typename T, typename NAME_VALUE_LOOKUP = TypeValues<T>, bool HAS_MULTIPLE_VALUES = false, - bool VALUE_IS_BLOCK = IsBlock<T>::value> + typename VALUE_IS_BLOCK = typename IsBlock<T>::value_t> class TypedParam : public Param, public ParamValue<T, NAME_VALUE_LOOKUP> @@ -836,15 +835,7 @@ namespace LLInitParam { if (LL_UNLIKELY(block_descriptor.mInitializationState == BlockDescriptor::INITIALIZING)) { - ParamDescriptorPtr param_descriptor = ParamDescriptorPtr(new ParamDescriptor( - block_descriptor.mCurrentBlockPtr->getHandleFromParam(this), - &mergeWith, - &deserializeParam, - &serializeParam, - validate_func, - &inspectParam, - min_count, max_count)); - BaseBlock::addParam(block_descriptor, param_descriptor, name); + init(block_descriptor, validate_func, min_count, max_count, name); } } @@ -964,18 +955,31 @@ namespace LLInitParam } return false; } + private: + void init( BlockDescriptor &block_descriptor, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count, const char* name ) + { + ParamDescriptorPtr param_descriptor = ParamDescriptorPtr(new ParamDescriptor( + block_descriptor.mCurrentBlockPtr->getHandleFromParam(this), + &mergeWith, + &deserializeParam, + &serializeParam, + validate_func, + &inspectParam, + min_count, max_count)); + block_descriptor.addParam(param_descriptor, name); + } }; // parameter that is a block template <typename T, typename NAME_VALUE_LOOKUP> - class TypedParam<T, NAME_VALUE_LOOKUP, false, true> + class TypedParam<T, NAME_VALUE_LOOKUP, false, IS_BLOCK> : public Param, public ParamValue<T, NAME_VALUE_LOOKUP> { public: typedef ParamValue<T, NAME_VALUE_LOOKUP> param_value_t; typedef typename param_value_t::value_assignment_t value_assignment_t; - typedef TypedParam<T, NAME_VALUE_LOOKUP, false, true> self_t; + typedef TypedParam<T, NAME_VALUE_LOOKUP, false, IS_BLOCK> self_t; using param_value_t::operator(); @@ -985,15 +989,7 @@ namespace LLInitParam { if (LL_UNLIKELY(block_descriptor.mInitializationState == BlockDescriptor::INITIALIZING)) { - ParamDescriptorPtr param_descriptor = ParamDescriptorPtr(new ParamDescriptor( - block_descriptor.mCurrentBlockPtr->getHandleFromParam(this), - &mergeWith, - &deserializeParam, - &serializeParam, - validate_func, - &inspectParam, - min_count, max_count)); - BaseBlock::addParam(block_descriptor, param_descriptor, name); + init(block_descriptor, validate_func, min_count, max_count, name); } } @@ -1130,15 +1126,29 @@ namespace LLInitParam } return false; } + + private: + void init( BlockDescriptor &block_descriptor, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count, const char* name ) + { + ParamDescriptorPtr param_descriptor = ParamDescriptorPtr(new ParamDescriptor( + block_descriptor.mCurrentBlockPtr->getHandleFromParam(this), + &mergeWith, + &deserializeParam, + &serializeParam, + validate_func, + &inspectParam, + min_count, max_count)); + block_descriptor.addParam(param_descriptor, name); + } }; // container of non-block parameters template <typename VALUE_TYPE, typename NAME_VALUE_LOOKUP> - class TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, false> + class TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, NOT_BLOCK> : public Param { public: - typedef TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, false> self_t; + typedef TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, NOT_BLOCK> self_t; typedef ParamValue<VALUE_TYPE, NAME_VALUE_LOOKUP> param_value_t; typedef typename std::vector<param_value_t> container_t; typedef const container_t& value_assignment_t; @@ -1152,15 +1162,8 @@ namespace LLInitParam if (LL_UNLIKELY(block_descriptor.mInitializationState == BlockDescriptor::INITIALIZING)) { - ParamDescriptorPtr param_descriptor = ParamDescriptorPtr(new ParamDescriptor( - block_descriptor.mCurrentBlockPtr->getHandleFromParam(this), - &mergeWith, - &deserializeParam, - &serializeParam, - validate_func, - &inspectParam, - min_count, max_count)); - BaseBlock::addParam(block_descriptor, param_descriptor, name); + init(block_descriptor, validate_func, min_count, max_count, name); + } } @@ -1322,15 +1325,29 @@ namespace LLInitParam } container_t mValues; + + private: + void init( BlockDescriptor &block_descriptor, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count, const char* name ) + { + ParamDescriptorPtr param_descriptor = ParamDescriptorPtr(new ParamDescriptor( + block_descriptor.mCurrentBlockPtr->getHandleFromParam(this), + &mergeWith, + &deserializeParam, + &serializeParam, + validate_func, + &inspectParam, + min_count, max_count)); + block_descriptor.addParam(param_descriptor, name); + } }; // container of block parameters template <typename VALUE_TYPE, typename NAME_VALUE_LOOKUP> - class TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, true> + class TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, IS_BLOCK> : public Param { public: - typedef TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, true> self_t; + typedef TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, IS_BLOCK> self_t; typedef ParamValue<VALUE_TYPE, NAME_VALUE_LOOKUP> param_value_t; typedef typename std::vector<param_value_t> container_t; typedef const container_t& value_assignment_t; @@ -1343,15 +1360,7 @@ namespace LLInitParam if (LL_UNLIKELY(block_descriptor.mInitializationState == BlockDescriptor::INITIALIZING)) { - ParamDescriptorPtr param_descriptor = ParamDescriptorPtr(new ParamDescriptor( - block_descriptor.mCurrentBlockPtr->getHandleFromParam(this), - &mergeWith, - &deserializeParam, - &serializeParam, - validate_func, - &inspectParam, - min_count, max_count)); - BaseBlock::addParam(block_descriptor, param_descriptor, name); + init(block_descriptor, validate_func, min_count, max_count, name); } } @@ -1516,6 +1525,20 @@ namespace LLInitParam } container_t mValues; + + private: + void init( BlockDescriptor &block_descriptor, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count, const char* name ) + { + ParamDescriptorPtr param_descriptor = ParamDescriptorPtr(new ParamDescriptor( + block_descriptor.mCurrentBlockPtr->getHandleFromParam(this), + &mergeWith, + &deserializeParam, + &serializeParam, + validate_func, + &inspectParam, + min_count, max_count)); + block_descriptor.addParam(param_descriptor, name); + } }; template <typename DERIVED_BLOCK, typename BASE_BLOCK = BaseBlock> @@ -1595,7 +1618,7 @@ namespace LLInitParam friend class ChoiceBlock<DERIVED_BLOCK>; typedef Alternative<T, NAME_VALUE_LOOKUP> self_t; - typedef TypedParam<T, NAME_VALUE_LOOKUP, false, IsBlock<T>::value> super_t; + typedef TypedParam<T, NAME_VALUE_LOOKUP, false, typename IsBlock<T>::value_t> super_t; typedef typename super_t::value_assignment_t value_assignment_t; using super_t::operator =; @@ -1713,8 +1736,8 @@ namespace LLInitParam class Optional : public TypedParam<T, NAME_VALUE_LOOKUP, false> { public: - typedef TypedParam<T, NAME_VALUE_LOOKUP, false, IsBlock<T>::value> super_t; - typedef typename super_t::value_assignment_t value_assignment_t; + typedef TypedParam<T, NAME_VALUE_LOOKUP, false, typename IsBlock<T>::value_t> super_t; + typedef typename super_t::value_assignment_t value_assignment_t; using super_t::operator(); using super_t::operator =; @@ -1742,7 +1765,7 @@ namespace LLInitParam class Mandatory : public TypedParam<T, NAME_VALUE_LOOKUP, false> { public: - typedef TypedParam<T, NAME_VALUE_LOOKUP, false, IsBlock<T>::value> super_t; + typedef TypedParam<T, NAME_VALUE_LOOKUP, false, typename IsBlock<T>::value_t> super_t; typedef Mandatory<T, NAME_VALUE_LOOKUP> self_t; typedef typename super_t::value_assignment_t value_assignment_t; @@ -1778,7 +1801,7 @@ namespace LLInitParam class Multiple : public TypedParam<T, NAME_VALUE_LOOKUP, true> { public: - typedef TypedParam<T, NAME_VALUE_LOOKUP, true, IsBlock<T>::value> super_t; + typedef TypedParam<T, NAME_VALUE_LOOKUP, true, typename IsBlock<T>::value_t> super_t; typedef Multiple<T, RANGE, NAME_VALUE_LOOKUP> self_t; typedef typename super_t::container_t container_t; typedef typename super_t::value_assignment_t value_assignment_t; @@ -1825,7 +1848,7 @@ namespace LLInitParam NULL, NULL, 0, S32_MAX)); - BaseBlock::addParam(block_descriptor, param_descriptor, name); + block_descriptor.addParam(param_descriptor, name); } } @@ -1853,7 +1876,7 @@ namespace LLInitParam } protected: - template <typename T, typename NAME_VALUE_LOOKUP, bool multiple, bool is_block> + template <typename T, typename NAME_VALUE_LOOKUP, bool multiple, typename is_block> void changeDefault(TypedParam<T, NAME_VALUE_LOOKUP, multiple, is_block>& param, typename TypedParam<T, NAME_VALUE_LOOKUP, multiple, is_block>::value_assignment_t value) { @@ -1911,7 +1934,7 @@ namespace LLInitParam typename NAME_VALUE_LOOKUP> class ParamValue <BatchBlock<DERIVED_BLOCK, BASE_BLOCK>, NAME_VALUE_LOOKUP, - true> + IS_BLOCK> : public NAME_VALUE_LOOKUP, protected BatchBlock<DERIVED_BLOCK, BASE_BLOCK> { @@ -1961,25 +1984,31 @@ namespace LLInitParam }; template<typename T, typename BLOCK_IDENTIFIER> - struct IsBlock<BaseBlock::Lazy<T, true>, BLOCK_IDENTIFIER> + struct IsBlock<BaseBlock::Lazy<T, IS_BLOCK>, BLOCK_IDENTIFIER> { - static const bool value = true; + typedef IS_BLOCK value_t; }; template<typename T, typename BLOCK_IDENTIFIER> - struct IsBlock<BaseBlock::Lazy<T, false>, BLOCK_IDENTIFIER> + struct IsBlock<BaseBlock::Lazy<T, NOT_BLOCK>, BLOCK_IDENTIFIER> { - static const bool value = false; + typedef NOT_BLOCK value_t; }; + //template<typename T, typename BLOCK_IDENTIFIER> + //struct IsBlock<BaseBlock::Lazy<T, void>, BLOCK_IDENTIFIER> + //{ + // typedef typename IsBlock<T>::value_t value_t; + //}; + template<typename T> - class ParamValue <BaseBlock::Lazy<T, true>, - TypeValues<BaseBlock::Lazy<T, true> >, - true> + class ParamValue <BaseBlock::Lazy<T, IS_BLOCK>, + TypeValues<BaseBlock::Lazy<T, IS_BLOCK> >, + IS_BLOCK> : public TypeValues<T> { public: - typedef ParamValue <BaseBlock::Lazy<T, true>, TypeValues<BaseBlock::Lazy<T, true> >, true> self_t; + typedef ParamValue <BaseBlock::Lazy<T, IS_BLOCK>, TypeValues<BaseBlock::Lazy<T, IS_BLOCK> >, IS_BLOCK> self_t; typedef const T& value_assignment_t; typedef T value_t; @@ -1988,7 +2017,7 @@ namespace LLInitParam mValidated(false) {} - ParamValue(const BaseBlock::Lazy<T, true>& other) + ParamValue(const BaseBlock::Lazy<T, IS_BLOCK>& other) : mValue(other), mValidated(false) {} @@ -2062,18 +2091,18 @@ namespace LLInitParam mutable bool mValidated; // lazy validation flag private: - BaseBlock::Lazy<T, true> mValue; + BaseBlock::Lazy<T, IS_BLOCK> mValue; }; template <> class ParamValue <LLSD, TypeValues<LLSD>, - false> + NOT_BLOCK> : public TypeValues<LLSD>, public BaseBlock { public: - typedef ParamValue<LLSD, TypeValues<LLSD>, false> self_t; + typedef ParamValue<LLSD, TypeValues<LLSD>, NOT_BLOCK> self_t; typedef const LLSD& value_assignment_t; ParamValue() |