From 9626ab8fec34f73cd60822bd34376c1cb94e11d7 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 5 Apr 2012 16:10:07 -0700 Subject: CHUI-89 FIX Make nametags appear consistently next to avatar heads nametags now track avatar head avatar_skeleton now loaded as param block vector3 param block parsing support fixes for param block recursion --- indra/llxuixml/llinitparam.h | 227 ++++++++++++++++++++++++----------------- indra/llxuixml/llxuiparser.cpp | 27 +++++ indra/llxuixml/llxuiparser.h | 2 + 3 files changed, 162 insertions(+), 94 deletions(-) (limited to 'indra/llxuixml') diff --git a/indra/llxuixml/llinitparam.h b/indra/llxuixml/llinitparam.h index ab20957760..6fffb73acd 100644 --- a/indra/llxuixml/llinitparam.h +++ b/indra/llxuixml/llinitparam.h @@ -377,8 +377,9 @@ namespace LLInitParam class Lazy { public: + Lazy() - : mPtr(NULL) + : mPtr(NULL) {} ~Lazy() @@ -386,6 +387,11 @@ namespace LLInitParam delete mPtr; } + Lazy(const T& value) + { + mPtr = new T(value); + } + Lazy(const Lazy& other) { if (other.mPtr) @@ -424,12 +430,17 @@ namespace LLInitParam const T& get() const { - return ensureInstance(); + return *ensureInstance(); } T& get() { - return ensureInstance(); + return *ensureInstance(); + } + + operator const T&() const + { + return get(); } private: @@ -520,8 +531,8 @@ namespace LLInitParam void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const; bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const; - virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return selfBlockDescriptor(); } - virtual BlockDescriptor& mostDerivedBlockDescriptor() { return selfBlockDescriptor(); } + virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return getBlockDescriptor(); } + virtual BlockDescriptor& mostDerivedBlockDescriptor() { return getBlockDescriptor(); } // take all provided params from other and apply to self bool overwriteFrom(const BaseBlock& other) @@ -539,6 +550,15 @@ namespace LLInitParam ParamDescriptorPtr findParamDescriptor(const Param& param); + // take all provided params from other and apply to self + bool mergeBlock(BlockDescriptor& block_data, const BaseBlock& other, bool overwrite); + + static BlockDescriptor& getBlockDescriptor() + { + static BlockDescriptor sBlockDescriptor; + return sBlockDescriptor; + } + protected: void init(BlockDescriptor& descriptor, BlockDescriptor& base_descriptor, size_t block_size); @@ -547,25 +567,11 @@ namespace LLInitParam { return mergeBlock(block_data, source, overwrite); } - // take all provided params from other and apply to self - bool mergeBlock(BlockDescriptor& block_data, const BaseBlock& other, bool overwrite); - - static BlockDescriptor& selfBlockDescriptor() - { - static BlockDescriptor sBlockDescriptor; - return sBlockDescriptor; - } private: const std::string& getParamName(const BlockDescriptor& block_data, const Param* paramp) const; }; - template - struct ParamCompare, false > - { - static bool equals(const BaseBlock::Lazy& a, const BaseBlock::Lazy& b) { return !a.empty() || !b.empty(); } - }; - class Param { public: @@ -607,26 +613,16 @@ namespace LLInitParam // these templates allow us to distinguish between template parameters // that derive from BaseBlock and those that don't - template + template struct IsBlock { static const bool value = false; - struct EmptyBase {}; - typedef EmptyBase base_class_t; }; template struct IsBlock { static const bool value = true; - typedef BaseBlock base_class_t; - }; - - template - struct IsBlock, typename T::baseblock_base_class_t > - { - static const bool value = true; - typedef BaseBlock base_class_t; }; template::value> @@ -817,13 +813,13 @@ namespace LLInitParam public: typedef TypedParam self_t; typedef ParamValue param_value_t; - typedef typename param_value_t::value_assignment_t value_assignment_t; - typedef NAME_VALUE_LOOKUP name_value_lookup_t; + typedef typename param_value_t::value_assignment_t value_assignment_t; using param_value_t::operator(); - TypedParam(BlockDescriptor& block_descriptor, const char* name, value_assignment_t value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) - : Param(block_descriptor.mCurrentBlockPtr) + TypedParam(BlockDescriptor& block_descriptor, const char* name, const T& value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) + : Param(block_descriptor.mCurrentBlockPtr), + param_value_t(value) { if (LL_UNLIKELY(block_descriptor.mInitializationState == BlockDescriptor::INITIALIZING)) { @@ -837,8 +833,6 @@ namespace LLInitParam min_count, max_count)); BaseBlock::addParam(block_descriptor, param_descriptor, name); } - - setValue(value); } bool isProvided() const { return Param::anyProvided(); } @@ -857,14 +851,14 @@ namespace LLInitParam } // try to parse a known named value - if(name_value_lookup_t::valueNamesExist()) + if(param_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 (name_value_lookup_t::getValueFromName(name, typed_param.getValue())) + if (param_value_t::getValueFromName(name, typed_param.getValue())) { typed_param.setValueName(name); typed_param.setProvided(); @@ -917,9 +911,9 @@ 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 (name_value_lookup_t::getPossibleValues()) + if (param_value_t::getPossibleValues()) { - parser.inspectValue(name_stack, min_count, max_count, name_value_lookup_t::getPossibleValues()); + parser.inspectValue(name_stack, min_count, max_count, param_value_t::getPossibleValues()); } } @@ -969,11 +963,10 @@ namespace LLInitParam typedef ParamValue param_value_t; typedef typename param_value_t::value_assignment_t value_assignment_t; typedef TypedParam self_t; - typedef NAME_VALUE_LOOKUP name_value_lookup_t; using param_value_t::operator(); - TypedParam(BlockDescriptor& block_descriptor, const char* name, value_assignment_t value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) + TypedParam(BlockDescriptor& block_descriptor, const char* name, const T& value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) : Param(block_descriptor.mCurrentBlockPtr), param_value_t(value) { @@ -1002,14 +995,14 @@ namespace LLInitParam return true; } - if(name_value_lookup_t::valueNamesExist()) + if(param_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 (name_value_lookup_t::getValueFromName(name, typed_param.getValue())) + if (param_value_t::getValueFromName(name, typed_param.getValue())) { typed_param.setValueName(name); typed_param.setProvided(); @@ -1041,7 +1034,7 @@ namespace LLInitParam } else { - typed_param.serializeBlock(parser, name_stack, static_cast(diff_param)); + typed_param.serializeBlock(parser, name_stack, &static_cast(*static_cast(diff_param))); } } @@ -1115,7 +1108,7 @@ namespace LLInitParam if (src_typed_param.anyProvided()) { - if (dst_typed_param.mergeBlockParam(src_typed_param.isProvided(), dst_typed_param.isProvided(), param_value_t::selfBlockDescriptor(), src_typed_param, overwrite)) + if (dst_typed_param.mergeBlockParam(src_typed_param.isProvided(), dst_typed_param.isProvided(), param_value_t::getBlockDescriptor(), src_typed_param, overwrite)) { dst_typed_param.clearValueName(); dst_typed_param.setProvided(true); @@ -1138,9 +1131,8 @@ namespace LLInitParam typedef const container_t& value_assignment_t; typedef typename param_value_t::value_t value_t; - typedef NAME_VALUE_LOOKUP name_value_lookup_t; - TypedParam(BlockDescriptor& block_descriptor, const char* name, value_assignment_t value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) + TypedParam(BlockDescriptor& block_descriptor, const char* name, const container_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)); @@ -1176,14 +1168,14 @@ namespace LLInitParam } // try to parse a known named value - if(name_value_lookup_t::valueNamesExist()) + if(param_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 (name_value_lookup_t::getValueFromName(name, value)) + if (param_value_t::getValueFromName(name, value)) { typed_param.add(value); typed_param.mValues.back().setValueName(name); @@ -1234,9 +1226,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 (name_value_lookup_t::getPossibleValues()) + if (param_value_t::getPossibleValues()) { - parser.inspectValue(name_stack, min_count, max_count, name_value_lookup_t::getPossibleValues()); + parser.inspectValue(name_stack, min_count, max_count, param_value_t::getPossibleValues()); } } @@ -1261,12 +1253,12 @@ namespace LLInitParam setProvided(); } - void add(const typename name_value_lookup_t::name_t& name) + void add(const typename param_value_t::name_t& name) { value_t value; // try to parse a per type named value - if (name_value_lookup_t::getValueFromName(name, value)) + if (param_value_t::getValueFromName(name, value)) { add(value); mValues.back().setValueName(name); @@ -1330,9 +1322,8 @@ namespace LLInitParam typedef typename std::vector container_t; typedef const container_t& value_assignment_t; typedef typename param_value_t::value_t value_t; - typedef NAME_VALUE_LOOKUP name_value_lookup_t; - TypedParam(BlockDescriptor& block_descriptor, const char* name, value_assignment_t value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) + TypedParam(BlockDescriptor& block_descriptor, const char* name, const container_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)); @@ -1372,14 +1363,14 @@ namespace LLInitParam typed_param.setProvided(); return true; } - else if(name_value_lookup_t::valueNamesExist()) + else if(param_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 (name_value_lookup_t::getValueFromName(name, value.getValue())) + if (param_value_t::getValueFromName(name, value.getValue())) { typed_param.mValues.back().setValueName(name); typed_param.setProvided(); @@ -1447,12 +1438,12 @@ namespace LLInitParam setProvided(); } - void add(const typename name_value_lookup_t::name_t& name) + void add(const typename param_value_t::name_t& name) { value_t value; // try to parse a per type named value - if (name_value_lookup_t::getValueFromName(name, value)) + if (param_value_t::getValueFromName(name, value)) { add(value); mValues.back().setValueName(name); @@ -1526,13 +1517,13 @@ namespace LLInitParam // take all provided params from other and apply to self bool overwriteFrom(const self_t& other) { - return static_cast(this)->mergeBlock(selfBlockDescriptor(), other, true); + return static_cast(this)->mergeBlock(getBlockDescriptor(), other, true); } // take all provided params that are not already provided, and apply to self bool fillFrom(const self_t& other) { - return static_cast(this)->mergeBlock(selfBlockDescriptor(), other, false); + return static_cast(this)->mergeBlock(getBlockDescriptor(), other, false); } bool mergeBlockParam(bool source_provided, bool dest_provided, BlockDescriptor& block_data, const self_t& source, bool overwrite) @@ -1550,7 +1541,7 @@ namespace LLInitParam bool mergeBlock(BlockDescriptor& block_data, const self_t& other, bool overwrite) { mCurChoice = other.mCurChoice; - return base_block_t::mergeBlock(selfBlockDescriptor(), other, overwrite); + return base_block_t::mergeBlock(getBlockDescriptor(), other, overwrite); } // clear out old choice when param has changed @@ -1571,14 +1562,14 @@ namespace LLInitParam base_block_t::paramChanged(changed_param, user_provided); } - virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return selfBlockDescriptor(); } - virtual BlockDescriptor& mostDerivedBlockDescriptor() { return selfBlockDescriptor(); } + virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return getBlockDescriptor(); } + virtual BlockDescriptor& mostDerivedBlockDescriptor() { return getBlockDescriptor(); } protected: ChoiceBlock() : mCurChoice(0) { - BaseBlock::init(selfBlockDescriptor(), base_block_t::selfBlockDescriptor(), sizeof(DERIVED_BLOCK)); + BaseBlock::init(getBlockDescriptor(), base_block_t::getBlockDescriptor(), sizeof(DERIVED_BLOCK)); } // Alternatives are mutually exclusive wrt other Alternatives in the same block. @@ -1596,13 +1587,13 @@ namespace LLInitParam using super_t::operator =; - explicit Alternative(const char* name = "", value_assignment_t val = defaultValue()) - : super_t(DERIVED_BLOCK::selfBlockDescriptor(), name, val, NULL, 0, 1), + explicit Alternative(const char* name = "", const T& val = defaultValue()) + : super_t(DERIVED_BLOCK::getBlockDescriptor(), name, val, NULL, 0, 1), mOriginalValue(val) { // assign initial choice to first declared option - DERIVED_BLOCK* blockp = ((DERIVED_BLOCK*)DERIVED_BLOCK::selfBlockDescriptor().mCurrentBlockPtr); - if (LL_UNLIKELY(DERIVED_BLOCK::selfBlockDescriptor().mInitializationState == BlockDescriptor::INITIALIZING)) + DERIVED_BLOCK* blockp = ((DERIVED_BLOCK*)DERIVED_BLOCK::getBlockDescriptor().mCurrentBlockPtr); + if (LL_UNLIKELY(DERIVED_BLOCK::getBlockDescriptor().mInitializationState == BlockDescriptor::INITIALIZING)) { if(blockp->mCurChoice == 0) { @@ -1654,8 +1645,8 @@ namespace LLInitParam T mOriginalValue; }; - protected: - static BlockDescriptor& selfBlockDescriptor() + public: + static BlockDescriptor& getBlockDescriptor() { static BlockDescriptor sBlockDescriptor; return sBlockDescriptor; @@ -1683,23 +1674,23 @@ namespace LLInitParam // take all provided params from other and apply to self bool overwriteFrom(const self_t& other) { - return static_cast(this)->mergeBlock(selfBlockDescriptor(), other, true); + return static_cast(this)->mergeBlock(getBlockDescriptor(), other, true); } // take all provided params that are not already provided, and apply to self bool fillFrom(const self_t& other) { - return static_cast(this)->mergeBlock(selfBlockDescriptor(), other, false); + return static_cast(this)->mergeBlock(getBlockDescriptor(), other, false); } - virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return selfBlockDescriptor(); } - virtual BlockDescriptor& mostDerivedBlockDescriptor() { return selfBlockDescriptor(); } + virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return getBlockDescriptor(); } + virtual BlockDescriptor& mostDerivedBlockDescriptor() { return getBlockDescriptor(); } protected: Block() { //#pragma message("Parsing LLInitParam::Block") - BaseBlock::init(selfBlockDescriptor(), BASE_BLOCK::selfBlockDescriptor(), sizeof(DERIVED_BLOCK)); + BaseBlock::init(getBlockDescriptor(), BASE_BLOCK::getBlockDescriptor(), sizeof(DERIVED_BLOCK)); } // @@ -1715,8 +1706,8 @@ namespace LLInitParam using super_t::operator(); using super_t::operator =; - explicit Optional(const char* name = "", value_assignment_t val = defaultValue()) - : super_t(DERIVED_BLOCK::selfBlockDescriptor(), name, val, NULL, 0, 1) + explicit Optional(const char* name = "", const T& val = defaultValue()) + : super_t(DERIVED_BLOCK::getBlockDescriptor(), name, val, NULL, 0, 1) { //#pragma message("Parsing LLInitParam::Block::Optional") } @@ -1746,8 +1737,8 @@ namespace LLInitParam using super_t::operator =; // mandatory parameters require a name to be parseable - explicit Mandatory(const char* name = "", value_assignment_t val = defaultValue()) - : super_t(DERIVED_BLOCK::selfBlockDescriptor(), name, val, &validate, 1, 1) + explicit Mandatory(const char* name = "", const T& val = defaultValue()) + : super_t(DERIVED_BLOCK::getBlockDescriptor(), name, val, &validate, 1, 1) {} Mandatory& operator =(value_assignment_t val) @@ -1782,7 +1773,7 @@ namespace LLInitParam typedef typename super_t::const_iterator const_iterator; explicit Multiple(const char* name = "") - : super_t(DERIVED_BLOCK::selfBlockDescriptor(), name, container_t(), &validate, RANGE::minCount, RANGE::maxCount) + : super_t(DERIVED_BLOCK::getBlockDescriptor(), name, container_t(), &validate, RANGE::minCount, RANGE::maxCount) {} Multiple& operator =(value_assignment_t val) @@ -1808,9 +1799,9 @@ namespace LLInitParam { public: explicit Deprecated(const char* name) - : Param(DERIVED_BLOCK::selfBlockDescriptor().mCurrentBlockPtr) + : Param(DERIVED_BLOCK::getBlockDescriptor().mCurrentBlockPtr) { - BlockDescriptor& block_descriptor = DERIVED_BLOCK::selfBlockDescriptor(); + BlockDescriptor& block_descriptor = DERIVED_BLOCK::getBlockDescriptor(); if (LL_UNLIKELY(block_descriptor.mInitializationState == BlockDescriptor::INITIALIZING)) { ParamDescriptorPtr param_descriptor = ParamDescriptorPtr(new ParamDescriptor( @@ -1841,13 +1832,14 @@ namespace LLInitParam // different semantics for documentation purposes, but functionally identical typedef Deprecated Ignored; - protected: - static BlockDescriptor& selfBlockDescriptor() + public: + static BlockDescriptor& getBlockDescriptor() { static BlockDescriptor sBlockDescriptor; return sBlockDescriptor; } + protected: template void changeDefault(TypedParam& param, typename TypedParam::value_assignment_t value) @@ -1887,7 +1879,7 @@ namespace LLInitParam { *static_cast(this) = defaultBatchValue(); // merge individual parameters into destination - return super_t::mergeBlock(super_t::selfBlockDescriptor(), other, overwrite); + return super_t::mergeBlock(super_t::getBlockDescriptor(), other, overwrite); } return false; } @@ -1955,14 +1947,36 @@ namespace LLInitParam mutable bool mValidated; // lazy validation flag }; - template + template + struct IsBlock, TypeValues > > , BLOCK_IDENTIFIER> + { + static const bool value = true;//IsBlock::value; + }; + + template + struct ParamCompare, false> + { + static bool equals(const T&a, const T &b) + { + return a == b; + } + + static bool equals(const BaseBlock::Lazy& a, const BaseBlock::Lazy& b) + { + if (a.empty() || b.empty()) return false; + return a.get() == b.get(); + } + }; + + + template class ParamValue , - TypeValues, - IS_BLOCK> - : public IsBlock::base_class_t + TypeValues >, + VALUE_IS_BLOCK> + : public TypeValues { public: - typedef ParamValue , TypeValues, false> self_t; + typedef ParamValue , TypeValues >, false> self_t; typedef const T& value_assignment_t; typedef T value_t; @@ -1971,11 +1985,16 @@ namespace LLInitParam mValidated(false) {} - ParamValue(value_assignment_t other) + ParamValue(const BaseBlock::Lazy& other) : mValue(other), mValidated(false) {} + ParamValue(const T& value) + : mValue(value), + mValidated(false) + {} + void setValue(value_assignment_t val) { mValue.set(val); @@ -1991,6 +2010,11 @@ namespace LLInitParam return mValue.get(); } + operator const BaseBlock&() const + { + return mValue.get(); + } + operator value_assignment_t() const { return mValue.get(); @@ -2020,7 +2044,22 @@ namespace LLInitParam return mValue.get().inspectBlock(p, name_stack, min_count, max_count); } - protected: + bool mergeBlockParam(bool source_provided, bool dst_provided, BlockDescriptor& block_data, const self_t& source, bool overwrite) + { + return mValue.get().mergeBlock(block_data, source.getValue(), overwrite); + } + + bool validateBlock(bool emit_errors = true) const + { + return mValue.get().validateBlock(emit_errors); + } + + static BlockDescriptor& getBlockDescriptor() + { + return T::getBlockDescriptor(); + } + + mutable bool mValidated; // lazy validation flag private: diff --git a/indra/llxuixml/llxuiparser.cpp b/indra/llxuixml/llxuiparser.cpp index afc76024d1..3c89fa3aaf 100644 --- a/indra/llxuixml/llxuiparser.cpp +++ b/indra/llxuixml/llxuiparser.cpp @@ -42,6 +42,7 @@ #include #include "lluicolor.h" +#include "v3math.h" using namespace BOOST_SPIRIT_CLASSIC_NS; @@ -670,6 +671,7 @@ LLXUIParser::LLXUIParser() registerParserFuncs(readS32Value, writeS32Value); registerParserFuncs(readF32Value, writeF32Value); registerParserFuncs(readF64Value, writeF64Value); + registerParserFuncs(readVector3Value, writeVector3Value); registerParserFuncs(readColor4Value, writeColor4Value); registerParserFuncs(readUIColorValue, writeUIColorValue); registerParserFuncs(readUUIDValue, writeUUIDValue); @@ -1144,6 +1146,31 @@ bool LLXUIParser::writeF64Value(Parser& parser, const void* val_ptr, name_stack_ return false; } +bool LLXUIParser::readVector3Value(Parser& parser, void* val_ptr) +{ + LLXUIParser& self = static_cast(parser); + LLVector3* vecp = (LLVector3*)val_ptr; + if(self.mCurReadNode->getFloatValue(3, vecp->mV) >= 3) + { + return true; + } + + return false; +} + +bool LLXUIParser::writeVector3Value(Parser& parser, const void* val_ptr, name_stack_t& stack) +{ + LLXUIParser& self = static_cast(parser); + LLXMLNodePtr node = self.getNode(stack); + if (node.notNull()) + { + LLVector3 vector = *((LLVector3*)val_ptr); + node->setFloatValue(3, vector.mV); + return true; + } + return false; +} + bool LLXUIParser::readColor4Value(Parser& parser, void* val_ptr) { LLXUIParser& self = static_cast(parser); diff --git a/indra/llxuixml/llxuiparser.h b/indra/llxuixml/llxuiparser.h index d7cd256967..e48663e5cc 100644 --- a/indra/llxuixml/llxuiparser.h +++ b/indra/llxuixml/llxuiparser.h @@ -127,6 +127,7 @@ private: static bool readS32Value(Parser& parser, void* val_ptr); static bool readF32Value(Parser& parser, void* val_ptr); static bool readF64Value(Parser& parser, void* val_ptr); + static bool readVector3Value(Parser& parser, void* val_ptr); static bool readColor4Value(Parser& parser, void* val_ptr); static bool readUIColorValue(Parser& parser, void* val_ptr); static bool readUUIDValue(Parser& parser, void* val_ptr); @@ -144,6 +145,7 @@ private: static bool writeS32Value(Parser& parser, const void* val_ptr, name_stack_t&); static bool writeF32Value(Parser& parser, const void* val_ptr, name_stack_t&); static bool writeF64Value(Parser& parser, const void* val_ptr, name_stack_t&); + static bool writeVector3Value(Parser& parser, const void* val_ptr, name_stack_t&); static bool writeColor4Value(Parser& parser, const void* val_ptr, name_stack_t&); static bool writeUIColorValue(Parser& parser, const void* val_ptr, name_stack_t&); static bool writeUUIDValue(Parser& parser, const void* val_ptr, name_stack_t&); -- cgit v1.2.3 From 2eb0096dd7f173debc27c155c57969ae5cb67682 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 5 Apr 2012 17:50:22 -0700 Subject: added support for LLInitParam::Lazy to support lazy-initialized non-param-block values --- indra/llxuixml/llinitparam.h | 94 +++++++++++++++++++++++--------------------- 1 file changed, 50 insertions(+), 44 deletions(-) (limited to 'indra/llxuixml') diff --git a/indra/llxuixml/llinitparam.h b/indra/llxuixml/llinitparam.h index 6fffb73acd..6c054b934b 100644 --- a/indra/llxuixml/llinitparam.h +++ b/indra/llxuixml/llinitparam.h @@ -369,11 +369,30 @@ 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 + { + static const bool value = false; + typedef NOT_BLOCK value_t; + }; + + template + struct IsBlock + { + static const bool value = true; + typedef IS_BLOCK value_t; + }; + class BaseBlock { public: //TODO: implement in terms of owned_ptr - template + template class Lazy { public: @@ -404,7 +423,7 @@ namespace LLInitParam } } - Lazy& operator = (const Lazy& other) + Lazy& operator = (const Lazy& other) { if (other.mPtr) { @@ -462,6 +481,7 @@ namespace LLInitParam mutable T* mPtr; }; + // "Multiple" constraint types, put here in root class to avoid ambiguity during use struct AnyAmount { @@ -611,19 +631,6 @@ namespace LLInitParam }; - // these templates allow us to distinguish between template parameters - // that derive from BaseBlock and those that don't - template - struct IsBlock - { - static const bool value = false; - }; - - template - struct IsBlock - { - static const bool value = true; - }; template::value> class ParamValue : public NAME_VALUE_LOOKUP @@ -805,7 +812,7 @@ namespace LLInitParam template, bool HAS_MULTIPLE_VALUES = false, - bool VALUE_IS_BLOCK = IsBlock >::value> + bool VALUE_IS_BLOCK = IsBlock::value> class TypedParam : public Param, public ParamValue @@ -1034,7 +1041,7 @@ namespace LLInitParam } else { - typed_param.serializeBlock(parser, name_stack, &static_cast(*static_cast(diff_param))); + typed_param.serializeBlock(parser, name_stack, static_cast(diff_param)); } } @@ -1582,7 +1589,7 @@ namespace LLInitParam friend class ChoiceBlock; typedef Alternative self_t; - typedef TypedParam >::value> super_t; + typedef TypedParam::value> super_t; typedef typename super_t::value_assignment_t value_assignment_t; using super_t::operator =; @@ -1700,7 +1707,7 @@ namespace LLInitParam class Optional : public TypedParam { public: - typedef TypedParam >::value> super_t; + typedef TypedParam::value> super_t; typedef typename super_t::value_assignment_t value_assignment_t; using super_t::operator(); @@ -1729,7 +1736,7 @@ namespace LLInitParam class Mandatory : public TypedParam { public: - typedef TypedParam >::value> super_t; + typedef TypedParam::value> super_t; typedef Mandatory self_t; typedef typename super_t::value_assignment_t value_assignment_t; @@ -1765,7 +1772,7 @@ namespace LLInitParam class Multiple : public TypedParam { public: - typedef TypedParam >::value> super_t; + typedef TypedParam::value> super_t; typedef Multiple self_t; typedef typename super_t::container_t container_t; typedef typename super_t::value_assignment_t value_assignment_t; @@ -1948,20 +1955,21 @@ namespace LLInitParam }; template - struct IsBlock, TypeValues > > , BLOCK_IDENTIFIER> + struct IsBlock, BLOCK_IDENTIFIER> { - static const bool value = true;//IsBlock::value; + static const bool value = true; }; - template - struct ParamCompare, false> + template + struct IsBlock, BLOCK_IDENTIFIER> { - static bool equals(const T&a, const T &b) - { - return a == b; - } + static const bool value = false; + }; - static bool equals(const BaseBlock::Lazy& a, const BaseBlock::Lazy& b) + template + struct ParamCompare, false> + { + static bool equals(const BaseBlock::Lazy& a, const BaseBlock::Lazy& b) { if (a.empty() || b.empty()) return false; return a.get() == b.get(); @@ -1969,14 +1977,14 @@ namespace LLInitParam }; - template - class ParamValue , - TypeValues >, - VALUE_IS_BLOCK> + template + class ParamValue , + TypeValues >, + true> : public TypeValues { public: - typedef ParamValue , TypeValues >, false> self_t; + typedef ParamValue , TypeValues >, true> self_t; typedef const T& value_assignment_t; typedef T value_t; @@ -1985,7 +1993,7 @@ namespace LLInitParam mValidated(false) {} - ParamValue(const BaseBlock::Lazy& other) + ParamValue(const BaseBlock::Lazy& other) : mValue(other), mValidated(false) {} @@ -2010,11 +2018,6 @@ namespace LLInitParam return mValue.get(); } - operator const BaseBlock&() const - { - return mValue.get(); - } - operator value_assignment_t() const { return mValue.get(); @@ -2030,11 +2033,14 @@ namespace LLInitParam return mValue.get().deserializeBlock(p, name_stack_range, new_name); } - void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const + void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const self_t* diff_block = NULL) const { if (mValue.empty()) return; - mValue.get().serializeBlock(p, name_stack, diff_block); + const BaseBlock* base_block = (diff_block && !diff_block->mValue.empty()) + ? &(diff_block->mValue.get()) + : NULL; + mValue.get().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 @@ -2063,7 +2069,7 @@ namespace LLInitParam mutable bool mValidated; // lazy validation flag private: - BaseBlock::Lazy mValue; + BaseBlock::Lazy mValue; }; template <> -- cgit v1.2.3 From 6dd7029942dcc381d670657e0c4bb7d8dcd24594 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Thu, 5 Apr 2012 18:11:45 -0700 Subject: optimized Lazy params - don't generate block when checking validity or merging --- indra/llxuixml/llinitparam.h | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'indra/llxuixml') diff --git a/indra/llxuixml/llinitparam.h b/indra/llxuixml/llinitparam.h index 6c054b934b..1f0dec5d94 100644 --- a/indra/llxuixml/llinitparam.h +++ b/indra/llxuixml/llinitparam.h @@ -436,6 +436,12 @@ namespace LLInitParam return *this; } + bool operator==(const Lazy& other) const + { + if (empty() || other.empty()) return false; + return *mPtr == *other.mPtr; + } + bool empty() const { return mPtr == NULL; @@ -1966,17 +1972,6 @@ namespace LLInitParam static const bool value = false; }; - template - struct ParamCompare, false> - { - static bool equals(const BaseBlock::Lazy& a, const BaseBlock::Lazy& b) - { - if (a.empty() || b.empty()) return false; - return a.get() == b.get(); - } - }; - - template class ParamValue , TypeValues >, @@ -2045,19 +2040,17 @@ namespace LLInitParam bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const { - if (mValue.empty()) return false; - return mValue.get().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) { - return mValue.get().mergeBlock(block_data, source.getValue(), overwrite); + return source.mValue.empty() || mValue.get().mergeBlock(block_data, source.getValue(), overwrite); } bool validateBlock(bool emit_errors = true) const { - return mValue.get().validateBlock(emit_errors); + return mValue.empty() || mValue.get().validateBlock(emit_errors); } static BlockDescriptor& getBlockDescriptor() -- cgit v1.2.3 From fff9567a67ded34471fd17af9c50bc1d307e7b19 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 6 Apr 2012 09:40:59 -0700 Subject: 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 --- indra/llxuixml/llinitparam.cpp | 59 +++++++------- indra/llxuixml/llinitparam.h | 177 ++++++++++++++++++++++++----------------- 2 files changed, 132 insertions(+), 104 deletions(-) (limited to 'indra/llxuixml') 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" << 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" << 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 param_map_t; typedef std::vector param_list_t; @@ -377,22 +378,23 @@ namespace LLInitParam template struct IsBlock { - static const bool value = false; typedef NOT_BLOCK value_t; }; template struct IsBlock { - 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 + template 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::value> + template::value_t> class ParamValue : public NAME_VALUE_LOOKUP { public: @@ -694,14 +693,14 @@ namespace LLInitParam }; template - class ParamValue + class ParamValue : public T, public NAME_VALUE_LOOKUP { public: typedef const T& value_assignment_t; typedef T value_t; - typedef ParamValue self_t; + typedef ParamValue self_t; ParamValue() : T(), @@ -758,13 +757,13 @@ namespace LLInitParam }; template - class ParamValue + class ParamValue : public NAME_VALUE_LOOKUP { public: typedef const std::string& value_assignment_t; typedef std::string value_t; - typedef ParamValue self_t; + typedef ParamValue self_t; ParamValue(): mValue() {} ParamValue(value_assignment_t other) : mValue(other) {} @@ -818,7 +817,7 @@ namespace LLInitParam template, bool HAS_MULTIPLE_VALUES = false, - bool VALUE_IS_BLOCK = IsBlock::value> + typename VALUE_IS_BLOCK = typename IsBlock::value_t> class TypedParam : public Param, public ParamValue @@ -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 - class TypedParam + class TypedParam : public Param, public ParamValue { public: typedef ParamValue param_value_t; typedef typename param_value_t::value_assignment_t value_assignment_t; - typedef TypedParam self_t; + typedef TypedParam 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 - class TypedParam + class TypedParam : public Param { public: - typedef TypedParam self_t; + typedef TypedParam self_t; typedef ParamValue param_value_t; typedef typename std::vector 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 - class TypedParam + class TypedParam : public Param { public: - typedef TypedParam self_t; + typedef TypedParam self_t; typedef ParamValue param_value_t; typedef typename std::vector 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 @@ -1595,7 +1618,7 @@ namespace LLInitParam friend class ChoiceBlock; typedef Alternative self_t; - typedef TypedParam::value> super_t; + typedef TypedParam::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 { public: - typedef TypedParam::value> super_t; - typedef typename super_t::value_assignment_t value_assignment_t; + typedef TypedParam::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 { public: - typedef TypedParam::value> super_t; + typedef TypedParam::value_t> super_t; typedef Mandatory self_t; typedef typename super_t::value_assignment_t value_assignment_t; @@ -1778,7 +1801,7 @@ namespace LLInitParam class Multiple : public TypedParam { public: - typedef TypedParam::value> super_t; + 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; @@ -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 + template void changeDefault(TypedParam& param, typename TypedParam::value_assignment_t value) { @@ -1911,7 +1934,7 @@ namespace LLInitParam typename NAME_VALUE_LOOKUP> class ParamValue , NAME_VALUE_LOOKUP, - true> + IS_BLOCK> : public NAME_VALUE_LOOKUP, protected BatchBlock { @@ -1961,25 +1984,31 @@ namespace LLInitParam }; template - struct IsBlock, BLOCK_IDENTIFIER> + struct IsBlock, BLOCK_IDENTIFIER> { - static const bool value = true; + typedef IS_BLOCK value_t; }; template - struct IsBlock, BLOCK_IDENTIFIER> + struct IsBlock, BLOCK_IDENTIFIER> { - static const bool value = false; + typedef NOT_BLOCK value_t; }; + //template + //struct IsBlock, BLOCK_IDENTIFIER> + //{ + // typedef typename IsBlock::value_t value_t; + //}; + template - class ParamValue , - TypeValues >, - true> + class ParamValue , + TypeValues >, + IS_BLOCK> : public TypeValues { public: - typedef ParamValue , TypeValues >, true> self_t; + typedef ParamValue , TypeValues >, 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& other) + ParamValue(const BaseBlock::Lazy& other) : mValue(other), mValidated(false) {} @@ -2062,18 +2091,18 @@ namespace LLInitParam mutable bool mValidated; // lazy validation flag private: - BaseBlock::Lazy mValue; + BaseBlock::Lazy mValue; }; template <> class ParamValue , - false> + NOT_BLOCK> : public TypeValues, public BaseBlock { public: - typedef ParamValue, false> self_t; + typedef ParamValue, NOT_BLOCK> self_t; typedef const LLSD& value_assignment_t; ParamValue() -- cgit v1.2.3