diff options
Diffstat (limited to 'indra/llxuixml')
-rw-r--r-- | indra/llxuixml/llinitparam.cpp | 41 | ||||
-rw-r--r-- | indra/llxuixml/llinitparam.h | 144 | ||||
-rw-r--r-- | indra/llxuixml/lltrans.cpp | 4 | ||||
-rw-r--r-- | indra/llxuixml/lluicolor.cpp | 16 | ||||
-rw-r--r-- | indra/llxuixml/lluicolor.h | 8 | ||||
-rw-r--r-- | indra/llxuixml/llxuiparser.cpp | 36 |
6 files changed, 115 insertions, 134 deletions
diff --git a/indra/llxuixml/llinitparam.cpp b/indra/llxuixml/llinitparam.cpp index 318a0348a2..2ead5a4a57 100644 --- a/indra/llxuixml/llinitparam.cpp +++ b/indra/llxuixml/llinitparam.cpp @@ -46,7 +46,7 @@ namespace LLInitParam { const U8* my_addr = reinterpret_cast<const U8*>(this); const U8* block_addr = reinterpret_cast<const U8*>(enclosing_block); - mEnclosingBlockOffset = (S16)(block_addr - my_addr); + mEnclosingBlockOffset = (U16)(my_addr - block_addr); } // @@ -84,8 +84,8 @@ namespace LLInitParam // BaseBlock // BaseBlock::BaseBlock() - : mLastChangedParam(0), - mChangeVersion(0) + : mChangeVersion(0), + mBlockDescriptor(NULL) {} BaseBlock::~BaseBlock() @@ -137,7 +137,7 @@ namespace LLInitParam } - bool BaseBlock::validateBlock(bool silent) const + bool BaseBlock::validateBlock(bool emit_errors) const { const BlockDescriptor& block_data = getBlockDescriptor(); for (BlockDescriptor::param_validation_list_t::const_iterator it = block_data.mValidationList.begin(); it != block_data.mValidationList.end(); ++it) @@ -145,7 +145,7 @@ namespace LLInitParam const Param* param = getParamFromHandle(it->first); if (!it->second(param)) { - if (!silent) + if (emit_errors) { llwarns << "Invalid param \"" << getParamName(block_data, param) << "\"" << llendl; } @@ -347,7 +347,6 @@ namespace LLInitParam if (deserialize_func && deserialize_func(*paramp, p, name_stack, name_stack.first == name_stack.second ? -1 : name_stack.first->second)) { - mLastChangedParam = (*it)->mParamHandle; return true; } } @@ -416,9 +415,11 @@ namespace LLInitParam void BaseBlock::setLastChangedParam(const Param& last_param, bool user_provided) { - mLastChangedParam = getHandleFromParam(&last_param); + if (user_provided) + { mChangeVersion++; } + } const std::string& BaseBlock::getParamName(const BlockDescriptor& block_data, const Param* paramp) const { @@ -457,28 +458,7 @@ namespace LLInitParam // take all provided params from other and apply to self // NOTE: this requires that "other" is of the same derived type as this - bool BaseBlock::overwriteFromImpl(BlockDescriptor& block_data, const BaseBlock& other) - { - bool param_changed = false; - BlockDescriptor::all_params_list_t::const_iterator end_it = block_data.mAllParams.end(); - for (BlockDescriptor::all_params_list_t::const_iterator it = block_data.mAllParams.begin(); - it != end_it; - ++it) - { - const Param* other_paramp = other.getParamFromHandle(it->mParamHandle); - ParamDescriptor::merge_func_t merge_func = it->mMergeFunc; - if (merge_func) - { - Param* paramp = getParamFromHandle(it->mParamHandle); - param_changed |= merge_func(*paramp, *other_paramp, true); - mLastChangedParam = it->mParamHandle; - } - } - return param_changed; - } - - // take all provided params that are not already provided, and apply to self - bool BaseBlock::fillFromImpl(BlockDescriptor& block_data, const BaseBlock& other) + bool BaseBlock::merge(BlockDescriptor& block_data, const BaseBlock& other, bool overwrite) { bool param_changed = false; BlockDescriptor::all_params_list_t::const_iterator end_it = block_data.mAllParams.end(); @@ -491,8 +471,7 @@ namespace LLInitParam if (merge_func) { Param* paramp = getParamFromHandle(it->mParamHandle); - param_changed |= merge_func(*paramp, *other_paramp, false); - mLastChangedParam = it->mParamHandle; + param_changed |= merge_func(*paramp, *other_paramp, overwrite); } } return param_changed; diff --git a/indra/llxuixml/llinitparam.h b/indra/llxuixml/llinitparam.h index 9fb464ca7b..c9c1d4af90 100644 --- a/indra/llxuixml/llinitparam.h +++ b/indra/llxuixml/llinitparam.h @@ -1,5 +1,5 @@ /** - * @file llinitparam.h +f * @file llinitparam.h * @brief parameter block abstraction for creating complex objects and * parsing construction parameters from xml and LLSD * @@ -300,14 +300,14 @@ namespace LLInitParam const U8* my_addr = reinterpret_cast<const U8*>(this); // get address of enclosing BLOCK class using stored offset to enclosing BaseBlock class return *const_cast<BaseBlock*>( - reinterpret_cast<const BaseBlock*>(my_addr + (ptrdiff_t)mEnclosingBlockOffset)); + reinterpret_cast<const BaseBlock*>(my_addr - (ptrdiff_t)(S32)mEnclosingBlockOffset)); } private: friend class BaseBlock; bool mIsProvided; - S16 mEnclosingBlockOffset; + U16 mEnclosingBlockOffset; }; // various callbacks and constraints associated with an individual param @@ -321,13 +321,13 @@ namespace LLInitParam typedef bool(*validation_func_t)(const Param*); ParamDescriptor(param_handle_t p, - merge_func_t merge_func, - deserialize_func_t deserialize_func, - serialize_func_t serialize_func, - validation_func_t validation_func, - inspect_func_t inspect_func, - S32 min_count, - S32 max_count) + merge_func_t merge_func, + deserialize_func_t deserialize_func, + serialize_func_t serialize_func, + validation_func_t validation_func, + inspect_func_t inspect_func, + S32 min_count, + S32 max_count) : mParamHandle(p), mMergeFunc(merge_func), mDeserializeFunc(deserialize_func), @@ -336,6 +336,7 @@ namespace LLInitParam mInspectFunc(inspect_func), mMinCount(min_count), mMaxCount(max_count), + mGeneration(0), mNumRefs(0) {} @@ -371,7 +372,8 @@ namespace LLInitParam public: BlockDescriptor() : mMaxParamOffset(0), - mInitializationState(UNINITIALIZED) + mInitializationState(UNINITIALIZED), + mCurrentBlockPtr(NULL) {} typedef enum e_initialization_state @@ -405,6 +407,41 @@ namespace LLInitParam class BaseBlock { public: + // "Multiple" constraint types, put here in root class to avoid ambiguity during use + struct AnyAmount + { + static U32 minCount() { return 0; } + static U32 maxCount() { return U32_MAX; } + }; + + template<U32 MIN_AMOUNT> + struct AtLeast + { + static U32 minCount() { return MIN_AMOUNT; } + static U32 maxCount() { return U32_MAX; } + }; + + template<U32 MAX_AMOUNT> + struct AtMost + { + static U32 minCount() { return 0; } + static U32 maxCount() { return MAX_AMOUNT; } + }; + + template<U32 MIN_AMOUNT, U32 MAX_AMOUNT> + struct Between + { + static U32 minCount() { return MIN_AMOUNT; } + static U32 maxCount() { return MAX_AMOUNT; } + }; + + template<U32 EXACT_COUNT> + struct Exactly + { + static U32 minCount() { return EXACT_COUNT; } + static U32 maxCount() { return EXACT_COUNT; } + }; + // this typedef identifies derived classes as being blocks typedef void baseblock_base_class_t; LOG_CLASS(BaseBlock); @@ -415,7 +452,7 @@ namespace LLInitParam bool submitValue(const Parser::name_stack_t& name_stack, Parser& p, bool silent=false); param_handle_t getHandleFromParam(const Param* param) const; - bool validateBlock(bool silent = false) const; + bool validateBlock(bool emit_errors = true) const; Param* getParamFromHandle(const param_handle_t param_handle) { @@ -435,7 +472,6 @@ namespace LLInitParam // Blocks can override this to do custom tracking of changes virtual void setLastChangedParam(const Param& last_param, bool user_provided); - const Param* getLastChangedParam() const { return mLastChangedParam ? getParamFromHandle(mLastChangedParam) : NULL; } S32 getLastChangeVersion() const { return mChangeVersion; } bool isDefault() const { return mChangeVersion == 0; } @@ -464,13 +500,9 @@ namespace LLInitParam // take all provided params from other and apply to self - bool overwriteFromImpl(BlockDescriptor& block_data, const BaseBlock& other); - - // take all provided params that are not already provided, and apply to self - bool fillFromImpl(BlockDescriptor& block_data, const BaseBlock& other); + bool merge(BlockDescriptor& block_data, const BaseBlock& other, bool overwrite); // can be updated in getters - mutable param_handle_t mLastChangedParam; mutable S32 mChangeVersion; BlockDescriptor* mBlockDescriptor; // most derived block descriptor @@ -770,7 +802,7 @@ namespace LLInitParam if (Param::getProvided() && mData.mValidatedVersion < T::getLastChangeVersion()) { // a sub-block is "provided" when it has been filled in enough to be valid - mData.mValidated = T::validateBlock(true); + mData.mValidated = T::validateBlock(false); mData.mValidatedVersion = T::getLastChangeVersion(); } return Param::getProvided() && mData.mValidated; @@ -1201,7 +1233,7 @@ namespace LLInitParam it != mValues.end(); ++it) { - if(it->validateBlock(true)) count++; + if(it->validateBlock(false)) count++; } return count; } @@ -1251,7 +1283,7 @@ namespace LLInitParam bool overwriteFrom(const self_t& other) { mCurChoice = other.mCurChoice; - return BaseBlock::overwriteFromImpl(blockDescriptor(), other); + return BaseBlock::merge(blockDescriptor(), other, true); } // take all provided params that are not already provided, and apply to self @@ -1365,40 +1397,6 @@ namespace LLInitParam } }; - struct AnyAmount - { - static U32 minCount() { return 0; } - static U32 maxCount() { return U32_MAX; } - }; - - template<U32 MIN_AMOUNT> - struct AtLeast - { - static U32 minCount() { return MIN_AMOUNT; } - static U32 maxCount() { return U32_MAX; } - }; - - template<U32 MAX_AMOUNT> - struct AtMost - { - static U32 minCount() { return 0; } - static U32 maxCount() { return MAX_AMOUNT; } - }; - - template<U32 MIN_AMOUNT, U32 MAX_AMOUNT> - struct Between - { - static U32 minCount() { return MIN_AMOUNT; } - static U32 maxCount() { return MAX_AMOUNT; } - }; - - template<U32 EXACT_COUNT> - struct Exactly - { - static U32 minCount() { return EXACT_COUNT; } - static U32 maxCount() { return EXACT_COUNT; } - }; - template <typename DERIVED_BLOCK, typename BASE_BLOCK = BaseBlock> class Block : public BASE_BLOCK @@ -1412,13 +1410,13 @@ namespace LLInitParam // take all provided params from other and apply to self bool overwriteFrom(const self_t& other) { - return BaseBlock::overwriteFromImpl(blockDescriptor(), other); + return BaseBlock::merge(blockDescriptor(), other, true); } // take all provided params that are not already provided, and apply to self bool fillFrom(const self_t& other) { - return BaseBlock::fillFromImpl(blockDescriptor(), other); + return BaseBlock::merge(blockDescriptor(), other, false); } protected: Block() @@ -1491,7 +1489,7 @@ namespace LLInitParam }; - template <typename T, typename RANGE = AnyAmount, typename NAME_VALUE_LOOKUP = TypeValues<T> > + template <typename T, typename RANGE = BaseBlock::AnyAmount, typename NAME_VALUE_LOOKUP = TypeValues<T> > class Multiple : public TypedParam<T, NAME_VALUE_LOOKUP, true> { public: @@ -1709,9 +1707,9 @@ namespace LLInitParam // if cached value is stale, regenerate from params if (Param::getProvided() && mData.mLastParamVersion < BaseBlock::getLastChangeVersion()) { - if (block_t::validateBlock(true)) + if (block_t::validateBlock(false)) { - mData.mValue = static_cast<const DERIVED*>(this)->getValueFromBlock(); + static_cast<const DERIVED*>(this)->setValueFromBlock(); // clear stale keyword associated with old value mData.clearKey(); mData.mLastParamVersion = BaseBlock::getLastChangeVersion(); @@ -1731,12 +1729,14 @@ namespace LLInitParam void set(value_assignment_t val, bool flag_as_provided = true) { Param::enclosingBlock().setLastChangedParam(*this, flag_as_provided); + // set param version number to be up to date, so we ignore block contents mData.mLastParamVersion = BaseBlock::getLastChangeVersion(); mData.mValue = val; mData.clearKey(); setProvided(flag_as_provided); + static_cast<DERIVED*>(this)->setBlockFromValue(); } void setIfNotProvided(value_assignment_t val, bool flag_as_provided = true) @@ -1766,9 +1766,9 @@ namespace LLInitParam if (Param::getProvided() && (mData.mLastParamVersion < BaseBlock::getLastChangeVersion())) { // go ahead and issue warnings at this point if any param is invalid - if(block_t::validateBlock(false)) + if(block_t::validateBlock(true)) { - mData.mValue = static_cast<const DERIVED*>(this)->getValueFromBlock(); + static_cast<const DERIVED*>(this)->setValueFromBlock(); mData.clearKey(); mData.mLastParamVersion = BaseBlock::getLastChangeVersion(); } @@ -1794,25 +1794,23 @@ namespace LLInitParam private: static bool mergeWith(Param& dst, const Param& src, bool overwrite) { - const self_t& src_param = static_cast<const self_t&>(src); + const self_t& src_typed_param = static_cast<const self_t&>(src); self_t& dst_typed_param = static_cast<self_t&>(dst); - if (src_param.isProvided() + if (src_typed_param.isProvided() && (overwrite || !dst_typed_param.isProvided())) { // assign individual parameters - if (overwrite) - { - dst_typed_param.BaseBlock::overwriteFromImpl(block_t::blockDescriptor(), src_param); - } - else - { - dst_typed_param.BaseBlock::fillFromImpl(block_t::blockDescriptor(), src_param); - } + dst_typed_param.BaseBlock::merge(block_t::blockDescriptor(), src_typed_param, overwrite); + // then copy actual value - dst_typed_param.mData.mValue = src_param.get(); + dst_typed_param.mData.mValue = src_typed_param.get(); dst_typed_param.mData.clearKey(); dst_typed_param.setProvided(true); + + // Propagate value back to block params since the value was updated during this merge. + // This will result in mData.mValue and the block params being in sync. + static_cast<DERIVED&>(dst_typed_param).setBlockFromValue(); return true; } return false; diff --git a/indra/llxuixml/lltrans.cpp b/indra/llxuixml/lltrans.cpp index 4c800a502d..d6f17dbb08 100644 --- a/indra/llxuixml/lltrans.cpp +++ b/indra/llxuixml/lltrans.cpp @@ -162,7 +162,7 @@ std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil:: args["STRING_NAME"] = xml_desc; LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL; - //LLNotifications::instance().add("MissingString", args); // *TODO: resurrect + //LLNotificationsUtil::add("MissingString", args); // *TODO: resurrect //return xml_desc; return "MissingString("+xml_desc+")"; @@ -189,7 +189,7 @@ bool LLTrans::findString(std::string &result, const std::string &xml_desc, const LLSD args; args["STRING_NAME"] = xml_desc; LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL; - //LLNotifications::instance().add("MissingString", args); + //LLNotificationsUtil::add("MissingString", args); return false; } diff --git a/indra/llxuixml/lluicolor.cpp b/indra/llxuixml/lluicolor.cpp index 856c05cf4a..0049ec055c 100644 --- a/indra/llxuixml/lluicolor.cpp +++ b/indra/llxuixml/lluicolor.cpp @@ -7,6 +7,8 @@ * $/LicenseInfo$ */ +#include "linden_common.h" + #include "lluicolor.h" LLUIColor::LLUIColor() @@ -14,13 +16,15 @@ LLUIColor::LLUIColor() { } -LLUIColor::LLUIColor(const LLColor4* color) - :mColorPtr(color) + +LLUIColor::LLUIColor(const LLColor4& color) +: mColor(color), + mColorPtr(NULL) { } -LLUIColor::LLUIColor(const LLColor4& color) - :mColor(color), mColorPtr(NULL) +LLUIColor::LLUIColor(const LLUIColor* color) +: mColorPtr(color) { } @@ -30,14 +34,14 @@ void LLUIColor::set(const LLColor4& color) mColorPtr = NULL; } -void LLUIColor::set(const LLColor4* color) +void LLUIColor::set(const LLUIColor* color) { mColorPtr = color; } const LLColor4& LLUIColor::get() const { - return (mColorPtr == NULL ? mColor : *mColorPtr); + return (mColorPtr == NULL ? mColor : mColorPtr->get()); } LLUIColor::operator const LLColor4& () const diff --git a/indra/llxuixml/lluicolor.h b/indra/llxuixml/lluicolor.h index bb0f786326..0ef2f78b24 100644 --- a/indra/llxuixml/lluicolor.h +++ b/indra/llxuixml/lluicolor.h @@ -22,11 +22,11 @@ class LLUIColor { public: LLUIColor(); - LLUIColor(const LLColor4* color); LLUIColor(const LLColor4& color); + LLUIColor(const LLUIColor* color); void set(const LLColor4& color); - void set(const LLColor4* color); + void set(const LLUIColor* color); const LLColor4& get() const; @@ -38,7 +38,7 @@ public: private: friend struct LLInitParam::ParamCompare<LLUIColor, false>; - const LLColor4* mColorPtr; + const LLUIColor* mColorPtr; LLColor4 mColor; }; @@ -47,7 +47,7 @@ namespace LLInitParam template<> struct ParamCompare<LLUIColor, false> { - static bool equals(const class LLUIColor& a, const class LLUIColor& b); + static bool equals(const LLUIColor& a, const LLUIColor& b); }; } diff --git a/indra/llxuixml/llxuiparser.cpp b/indra/llxuixml/llxuiparser.cpp index 17399865e5..dbc20a5a1e 100644 --- a/indra/llxuixml/llxuiparser.cpp +++ b/indra/llxuixml/llxuiparser.cpp @@ -324,33 +324,33 @@ void LLXUIXSDWriter::writeXSD(const std::string& type_name, const std::string& p // add includes for all possible children const std::type_info* type = *LLWidgetTypeRegistry::instance().getValue(type_name); const widget_registry_t* widget_registryp = LLChildRegistryRegistry::instance().getValue(type); - - // add include declarations for all valid children - for (widget_registry_t::Registrar::registry_map_t::const_iterator it = widget_registryp->currentRegistrar().beginItems(); - it != widget_registryp->currentRegistrar().endItems(); - ++it) - { - std::string widget_name = it->first; - if (widget_name == type_name) - { - continue; - } - LLXMLNodePtr nodep = new LLXMLNode("xs:include", false); - nodep->createChild("schemaLocation", true)->setStringValue(widget_name + ".xsd"); - - // add to front of schema - mSchemaNode->addChild(nodep, mSchemaNode); - } // add choices for valid children if (widget_registryp) { + // add include declarations for all valid children + for (widget_registry_t::Registrar::registry_map_t::const_iterator it = widget_registryp->currentRegistrar().beginItems(); + it != widget_registryp->currentRegistrar().endItems(); + ++it) + { + std::string widget_name = it->first; + if (widget_name == type_name) + { + continue; + } + LLXMLNodePtr nodep = new LLXMLNode("xs:include", false); + nodep->createChild("schemaLocation", true)->setStringValue(widget_name + ".xsd"); + + // add to front of schema + mSchemaNode->addChild(nodep, mSchemaNode); + } + for (widget_registry_t::Registrar::registry_map_t::const_iterator it = widget_registryp->currentRegistrar().beginItems(); it != widget_registryp->currentRegistrar().endItems(); ++it) { std::string widget_name = it->first; - //<xs:element name="widget_name" type="widget_name"> + //<xs:element name="widget_name" type="widget_name"> LLXMLNodePtr widget_node = mElementNode->createChild("xs:element", false); widget_node->createChild("name", true)->setStringValue(widget_name); widget_node->createChild("type", true)->setStringValue(widget_name); |