From 5b4990ce6a7fbf5d757e86362d134061fa54a1e9 Mon Sep 17 00:00:00 2001 From: Richard Linden Date: Fri, 13 Apr 2012 12:51:34 -0700 Subject: more LLInitParam cleanup cleaned up typedefs, and hid those that aren't part of the interface --- indra/llxuixml/llinitparam.h | 387 ++++++++++++++++++++--------------------- indra/llxuixml/llxuiparser.cpp | 2 +- 2 files changed, 193 insertions(+), 196 deletions(-) diff --git a/indra/llxuixml/llinitparam.h b/indra/llxuixml/llinitparam.h index dcbbf9f0a7..09617209a8 100644 --- a/indra/llxuixml/llinitparam.h +++ b/indra/llxuixml/llinitparam.h @@ -387,111 +387,112 @@ namespace LLInitParam typedef IS_BLOCK value_t; }; - class BaseBlock + //TODO: implement in terms of owned_ptr + template + class LazyValue { 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; + LazyValue() + : mPtr(NULL) + {} - template - class Atomic - {}; + ~LazyValue() + { + delete mPtr; + } - //TODO: implement in terms of owned_ptr - template::value_t > - class Lazy + LazyValue(const T& value) { - public: - Lazy() - : mPtr(NULL) - {} + mPtr = new T(value); + } - ~Lazy() + LazyValue(const LazyValue& other) + { + if (other.mPtr) { - delete mPtr; + mPtr = new T(*other.mPtr); } - - Lazy(const T& value) + else { - mPtr = new T(value); + mPtr = NULL; } + } - Lazy(const Lazy& other) + LazyValue& operator = (const LazyValue& other) + { + if (other.mPtr) { - if (other.mPtr) - { - mPtr = new T(*other.mPtr); - } - else - { - mPtr = NULL; - } + mPtr = new T(*other.mPtr); } - - Lazy& operator = (const Lazy& other) + else { - if (other.mPtr) - { - mPtr = new T(*other.mPtr); - } - else - { - mPtr = NULL; - } - return *this; + mPtr = NULL; } + return *this; + } - bool operator==(const Lazy& other) const - { - if (empty() || other.empty()) return false; - return *mPtr == *other.mPtr; - } + bool operator==(const LazyValue& other) const + { + if (empty() || other.empty()) return false; + return *mPtr == *other.mPtr; + } - bool empty() const - { - return mPtr == NULL; - } + bool empty() const + { + return mPtr == NULL; + } - void set(const T& other) - { - delete mPtr; - mPtr = new T(other); - } + void set(const T& other) + { + delete mPtr; + mPtr = new T(other); + } - const T& get() const - { - return *ensureInstance(); - } + const T& get() const + { + return *ensureInstance(); + } - T& get() - { - return *ensureInstance(); - } + T& get() + { + return *ensureInstance(); + } - operator const T&() const - { - return get(); - } + operator const T&() const + { + return get(); + } - private: - // lazily allocate an instance of T - T* ensureInstance() const + private: + // lazily allocate an instance of T + T* ensureInstance() const + { + if (mPtr == NULL) { - if (mPtr == NULL) - { - mPtr = new T(); - } - return mPtr; + mPtr = new T(); } + return mPtr; + } - private: - // if you get a compilation error with this, that means you are using a forward declared struct for T - // unfortunately, the type traits we rely on don't work with forward declared typed - //static const int dummy = sizeof(T); + private: - mutable T* mPtr; - }; + mutable T* mPtr; + }; + + class BaseBlock + { + 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; + + template + class Atomic + {}; + + template::value_t > + class Lazy + {}; // "Multiple" constraint types, put here in root class to avoid ambiguity during use struct AnyAmount @@ -644,21 +645,21 @@ namespace LLInitParam template::value_t> class ParamValue : public NAME_VALUE_LOOKUP { + typedef ParamValue self_t; + public: - typedef const T& value_assignment_t; typedef T default_value_t; typedef T value_t; - typedef ParamValue self_t; ParamValue(): mValue() {} ParamValue(const default_value_t& other) : mValue(other) {} - void setValue(value_assignment_t val) + void setValue(const value_t& val) { mValue = val; } - value_assignment_t getValue() const + const value_t& getValue() const { return mValue; } @@ -668,12 +669,12 @@ namespace LLInitParam return mValue; } - operator value_assignment_t() const + operator const value_t&() const { return mValue; } - value_assignment_t operator()() const + const value_t& operator()() const { return mValue; } @@ -702,11 +703,10 @@ namespace LLInitParam : public T, public NAME_VALUE_LOOKUP { + typedef ParamValue self_t; public: - typedef const T& value_assignment_t; typedef T default_value_t; typedef T value_t; - typedef ParamValue self_t; ParamValue() : T(), @@ -718,12 +718,12 @@ namespace LLInitParam mValidated(false) {} - void setValue(value_assignment_t val) + void setValue(const value_t& val) { *this = val; } - value_assignment_t getValue() const + const value_t& getValue() const { return *this; } @@ -733,12 +733,12 @@ namespace LLInitParam return *this; } - operator value_assignment_t() const + operator const value_t&() const { return *this; } - value_assignment_t operator()() const + const value_t& operator()() const { return *this; } @@ -766,16 +766,15 @@ namespace LLInitParam class ParamValue : public NAME_VALUE_LOOKUP { + typedef ParamValue self_t; 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(const default_value_t& other) : mValue(other) {} - void setValue(value_assignment_t val) + void setValue(const value_t& val) { if (NAME_VALUE_LOOKUP::getValueFromName(val, mValue)) { @@ -787,7 +786,7 @@ namespace LLInitParam } } - value_assignment_t getValue() const + const value_t& getValue() const { return mValue; } @@ -797,12 +796,12 @@ namespace LLInitParam return mValue; } - operator value_assignment_t() const + operator const value_t&() const { return mValue; } - value_assignment_t operator()() const + const value_t& operator()() const { return mValue; } @@ -829,12 +828,12 @@ namespace LLInitParam : public Param, public ParamValue { - public: + protected: typedef TypedParam self_t; typedef ParamValue param_value_t; - typedef typename param_value_t::value_assignment_t value_assignment_t; + typedef typename param_value_t::value_t value_t; typedef typename param_value_t::default_value_t default_value_t; - + public: using param_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) @@ -930,7 +929,7 @@ namespace LLInitParam } } - void set(value_assignment_t val, bool flag_as_provided = true) + void set(const value_t& val, bool flag_as_provided = true) { param_value_t::clearValueName(); setValue(val); @@ -985,12 +984,12 @@ namespace LLInitParam : public Param, public ParamValue { - public: - typedef ParamValue 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; + protected: + 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; - + public: using param_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) @@ -1078,7 +1077,7 @@ namespace LLInitParam } // assign block contents to this param-that-is-a-block - void set(value_assignment_t val, bool flag_as_provided = true) + void set(const value_t& val, bool flag_as_provided = true) { setValue(val); param_value_t::clearValueName(); @@ -1157,15 +1156,14 @@ namespace LLInitParam class TypedParam : public Param { - public: - typedef TypedParam self_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; + 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; + 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) { @@ -1259,7 +1257,7 @@ namespace LLInitParam } } - void set(value_assignment_t val, bool flag_as_provided = true) + void set(const container_t& val, bool flag_as_provided = true) { mValues = val; setProvided(flag_as_provided); @@ -1293,9 +1291,9 @@ namespace LLInitParam } // implicit conversion - operator value_assignment_t() const { return mValues; } + operator const container_t&() const { return mValues; } // explicit conversion - value_assignment_t operator()() const { return mValues; } + const container_t& operator()() const { return mValues; } typedef typename container_t::iterator iterator; typedef typename container_t::const_iterator const_iterator; @@ -1357,14 +1355,15 @@ namespace LLInitParam 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; public: - typedef TypedParam self_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 default_value_t& value, ParamDescriptor::validation_func_t validate_func, S32 min_count, S32 max_count) : Param(block_descriptor.mCurrentBlockPtr) { @@ -1453,7 +1452,7 @@ namespace LLInitParam param_value_t(value_t()).inspectBlock(parser, name_stack, min_count, max_count); } - void set(value_assignment_t val, bool flag_as_provided = true) + void set(const container_t& val, bool flag_as_provided = true) { mValues = val; setProvided(flag_as_provided); @@ -1485,12 +1484,10 @@ namespace LLInitParam } // implicit conversion - operator value_assignment_t() const { return mValues; } + operator const container_t&() const { return mValues; } // explicit conversion - value_assignment_t operator()() const { return mValues; } + const container_t& operator()() const { return mValues; } - typedef typename container_t::iterator iterator; - typedef typename container_t::const_iterator const_iterator; iterator begin() { return mValues.begin(); } iterator end() { return mValues.end(); } const_iterator begin() const { return mValues.begin(); } @@ -1626,14 +1623,13 @@ namespace LLInitParam template > class Alternative : public TypedParam { - public: - friend class ChoiceBlock; - - typedef Alternative self_t; typedef TypedParam super_t; - typedef typename super_t::value_assignment_t value_assignment_t; + typedef typename super_t::value_t value_t; typedef typename super_t::default_value_t default_value_t; + public: + friend class ChoiceBlock; + using super_t::operator =; explicit Alternative(const char* name = "", const default_value_t& val = defaultValue()) @@ -1656,27 +1652,27 @@ namespace LLInitParam static_cast(Param::enclosingBlock()).paramChanged(*this, true); } - void chooseAs(value_assignment_t val) + void chooseAs(const value_t& val) { super_t::set(val); } - void operator =(value_assignment_t val) + void operator =(const value_t& val) { super_t::set(val); } - void operator()(typename super_t::value_assignment_t val) + void operator()(typename const value_t& val) { super_t::set(val); } - operator value_assignment_t() const + operator const value_t&() const { return (*this)(); } - value_assignment_t operator()() const + const value_t& operator()() const { if (static_cast(Param::enclosingBlock()).getCurrentChoice() == this) { @@ -1691,7 +1687,7 @@ namespace LLInitParam } private: - T mOriginalValue; + default_value_t mOriginalValue; }; public: @@ -1715,6 +1711,8 @@ namespace LLInitParam : public BASE_BLOCK { typedef Block self_t; + + protected: typedef Block block_t; public: @@ -1748,11 +1746,11 @@ namespace LLInitParam template > class Optional : public TypedParam { - public: typedef TypedParam super_t; - typedef typename super_t::value_assignment_t value_assignment_t; + typedef typename super_t::value_t value_t; typedef typename super_t::default_value_t default_value_t; + public: using super_t::operator(); using super_t::operator =; @@ -1762,13 +1760,13 @@ namespace LLInitParam //#pragma message("Parsing LLInitParam::Block::Optional") } - Optional& operator =(value_assignment_t val) + Optional& operator =(const value_t& val) { set(val); return *this; } - DERIVED_BLOCK& operator()(value_assignment_t val) + DERIVED_BLOCK& operator()(const value_t& val) { super_t::set(val); return static_cast(Param::enclosingBlock()); @@ -1778,12 +1776,12 @@ namespace LLInitParam template > class Mandatory : public TypedParam { - public: typedef TypedParam super_t; typedef Mandatory self_t; - typedef typename super_t::value_assignment_t value_assignment_t; + typedef typename super_t::value_t value_t; typedef typename super_t::default_value_t default_value_t; + public: using super_t::operator(); using super_t::operator =; @@ -1792,13 +1790,13 @@ namespace LLInitParam : super_t(DERIVED_BLOCK::getBlockDescriptor(), name, val, &validate, 1, 1) {} - Mandatory& operator =(value_assignment_t val) + Mandatory& operator =(const value_t& val) { set(val); return *this; } - DERIVED_BLOCK& operator()(typename super_t::value_assignment_t val) + DERIVED_BLOCK& operator()(typename const value_t& val) { super_t::set(val); return static_cast(Param::enclosingBlock()); @@ -1815,25 +1813,27 @@ namespace LLInitParam template > class Multiple : public TypedParam { - public: 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; + typedef typename super_t::value_t value_t; + typedef TypedParam super_t; + + public: + 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) {} - Multiple& operator =(value_assignment_t val) + Multiple& operator =(const container_t& val) { set(val); return *this; } - DERIVED_BLOCK& operator()(typename super_t::value_assignment_t val) + DERIVED_BLOCK& operator()(typename const container_t& val) { super_t::set(val); return static_cast(Param::enclosingBlock()); @@ -1893,7 +1893,7 @@ namespace LLInitParam protected: template void changeDefault(TypedParam& param, - typename TypedParam::value_assignment_t value) + const typename TypedParam::value_t& value) { if (!param.isProvided()) { @@ -1927,12 +1927,11 @@ namespace LLInitParam BLOCK_T> : public TypeValues { - public: typedef ParamValue , TypeValues >, BLOCK_T> self_t; - typedef ParamValue > param_value_t; - typedef const T& value_assignment_t; - typedef T value_t; - typedef T default_value_t; + + public: + typedef T value_t; + typedef T default_value_t; ParamValue() : mValue(), @@ -1944,7 +1943,7 @@ namespace LLInitParam mValidated(false) {} - void setValue(value_assignment_t val) + void setValue(const value_t& val) { mValue.setValue(val); } @@ -1959,12 +1958,12 @@ namespace LLInitParam return mValue; } - operator value_assignment_t() const + operator const value_t&() const { return mValue; } - value_assignment_t operator()() const + const value_t& operator()() const { return mValue; } @@ -2042,11 +2041,11 @@ namespace LLInitParam 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; + + public: + typedef T value_t; + typedef LazyValue default_value_t; ParamValue() : mValue(), @@ -2063,12 +2062,12 @@ namespace LLInitParam mValidated(false) {} - void setValue(value_assignment_t val) + void setValue(const value_t& val) { mValue.set(val); } - value_assignment_t getValue() const + const value_t& getValue() const { return mValue.get(); } @@ -2078,12 +2077,12 @@ namespace LLInitParam return mValue.get(); } - operator value_assignment_t() const + operator const value_t&() const { return mValue.get(); } - value_assignment_t operator()() const + const value_t& operator()() const { return mValue.get(); } @@ -2142,7 +2141,7 @@ namespace LLInitParam mutable bool mValidated; // lazy validation flag private: - BaseBlock::Lazy mValue; + LazyValue mValue; }; template @@ -2151,11 +2150,11 @@ namespace LLInitParam 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; + + public: + typedef T value_t; + typedef LazyValue default_value_t; ParamValue() : mValue(), @@ -2172,12 +2171,12 @@ namespace LLInitParam mValidated(false) {} - void setValue(value_assignment_t val) + void setValue(const value_t& val) { mValue.set(val); } - value_assignment_t getValue() const + const value_t& getValue() const { return mValue.get(); } @@ -2187,12 +2186,12 @@ namespace LLInitParam return mValue.get(); } - operator value_assignment_t() const + operator const value_t&() const { return mValue.get(); } - value_assignment_t operator()() const + const value_t& operator()() const { return mValue.get(); } @@ -2215,7 +2214,7 @@ namespace LLInitParam mutable bool mValidated; // lazy validation flag private: - BaseBlock::Lazy mValue; + LazyValue mValue; }; template <> @@ -2226,9 +2225,8 @@ namespace LLInitParam public BaseBlock { public: - typedef ParamValue, NOT_BLOCK> self_t; - typedef const LLSD& value_assignment_t; - typedef LLSD default_value_t; + typedef LLSD value_t; + typedef LLSD default_value_t; ParamValue() : mValidated(false) @@ -2239,13 +2237,13 @@ namespace LLInitParam mValidated(false) {} - void setValue(value_assignment_t val) { mValue = val; } + void setValue(const value_t& val) { mValue = val; } - value_assignment_t getValue() const { return mValue; } + const value_t& getValue() const { return mValue; } LLSD& getValue() { return mValue; } - operator value_assignment_t() const { return mValue; } - value_assignment_t operator()() const { return mValue; } + operator const value_t&() const { return mValue; } + const value_t& operator()() const { return mValue; } // block param interface bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name); @@ -2281,7 +2279,6 @@ namespace LLInitParam typedef ParamValue > 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; @@ -2410,7 +2407,7 @@ namespace LLInitParam } } - void setValue(value_assignment_t val) + 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 @@ -2420,7 +2417,7 @@ namespace LLInitParam static_cast(this)->updateBlockFromValue(false); } - value_assignment_t getValue() const + const value_t& getValue() const { validateBlock(true); return mValue; @@ -2432,12 +2429,12 @@ namespace LLInitParam return mValue; } - operator value_assignment_t() const + operator const value_t&() const { return getValue(); } - value_assignment_t operator()() const + const value_t& operator()() const { return getValue(); } @@ -2459,7 +2456,7 @@ namespace LLInitParam protected: // use this from within updateValueFromBlock() to set the value without making it authoritative - void updateValue(value_assignment_t value) + void updateValue(const value_t& value) { mValue = value; } diff --git a/indra/llxuixml/llxuiparser.cpp b/indra/llxuixml/llxuiparser.cpp index ce8c8411ea..2e1f8888d0 100644 --- a/indra/llxuixml/llxuiparser.cpp +++ b/indra/llxuixml/llxuiparser.cpp @@ -343,7 +343,7 @@ void LLXSDWriter::writeXSD(const std::string& type_name, LLXMLNodePtr node, cons { Schema schema(xml_namespace); - schema.root_element.super_t::param_value_t::name = type_name; + schema.root_element.name = type_name; Choice& choice = schema.root_element.complexType.choice; choice.minOccurs = 0; -- cgit v1.2.3