summaryrefslogtreecommitdiff
path: root/indra/llxuixml
diff options
context:
space:
mode:
authorRichard Linden <none@none>2012-01-20 13:51:46 -0800
committerRichard Linden <none@none>2012-01-20 13:51:46 -0800
commit057da807ac55f9b0583ff334cd12b3568ab81a18 (patch)
treea6cbbc7e151c9e409dd29172d562221ae9b77901 /indra/llxuixml
parentb022ebf13c9a227f87a112419e237894a1231c8c (diff)
removed LLXUIXML library
moved LLInitParam, and LLRegistry to llcommon moved LLUIColor, LLTrans, and LLXUIParser to llui reviewed by Nat
Diffstat (limited to 'indra/llxuixml')
-rw-r--r--indra/llxuixml/CMakeLists.txt45
-rw-r--r--indra/llxuixml/llinitparam.cpp469
-rw-r--r--indra/llxuixml/llinitparam.h2294
-rw-r--r--indra/llxuixml/llregistry.h351
-rw-r--r--indra/llxuixml/lltrans.cpp295
-rw-r--r--indra/llxuixml/lltrans.h133
-rw-r--r--indra/llxuixml/lluicolor.cpp87
-rw-r--r--indra/llxuixml/lluicolor.h71
-rw-r--r--indra/llxuixml/llxuiparser.cpp1756
-rw-r--r--indra/llxuixml/llxuiparser.h242
10 files changed, 0 insertions, 5743 deletions
diff --git a/indra/llxuixml/CMakeLists.txt b/indra/llxuixml/CMakeLists.txt
deleted file mode 100644
index daed4de6ce..0000000000
--- a/indra/llxuixml/CMakeLists.txt
+++ /dev/null
@@ -1,45 +0,0 @@
-# -*- cmake -*-
-
-project(llxuixml)
-
-include(00-Common)
-include(LLCommon)
-include(LLMath)
-include(LLXML)
-
-include_directories(
- ${LLCOMMON_INCLUDE_DIRS}
- ${LLMATH_INCLUDE_DIRS}
- ${LLXML_INCLUDE_DIRS}
- )
-
-set(llxuixml_SOURCE_FILES
- llinitparam.cpp
- lltrans.cpp
- lluicolor.cpp
- llxuiparser.cpp
- )
-
-set(llxuixml_HEADER_FILES
- CMakeLists.txt
-
- llinitparam.h
- lltrans.h
- llregistry.h
- lluicolor.h
- llxuiparser.h
- )
-
-set_source_files_properties(${llxuixml_HEADER_FILES}
- PROPERTIES HEADER_FILE_ONLY TRUE)
-
-list(APPEND llxuixml_SOURCE_FILES ${llxuixml_HEADER_FILES})
-
-add_library (llxuixml ${llxuixml_SOURCE_FILES})
-# Libraries on which this library depends, needed for Linux builds
-# Sort by high-level to low-level
-target_link_libraries(llxuixml
- llxml
- llcommon
- llmath
- )
diff --git a/indra/llxuixml/llinitparam.cpp b/indra/llxuixml/llinitparam.cpp
deleted file mode 100644
index db72aa19b9..0000000000
--- a/indra/llxuixml/llinitparam.cpp
+++ /dev/null
@@ -1,469 +0,0 @@
-/**
- * @file llinitparam.cpp
- * @brief parameter block abstraction for creating complex objects and
- * parsing construction parameters from xml and LLSD
- *
- * $LicenseInfo:firstyear=2008&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include "linden_common.h"
-
-#include "llinitparam.h"
-
-
-namespace LLInitParam
-{
- //
- // Param
- //
- Param::Param(BaseBlock* enclosing_block)
- : mIsProvided(false)
- {
- const U8* my_addr = reinterpret_cast<const U8*>(this);
- const U8* block_addr = reinterpret_cast<const U8*>(enclosing_block);
- mEnclosingBlockOffset = 0x7FFFffff & (U32)(my_addr - block_addr);
- }
-
- //
- // ParamDescriptor
- //
- ParamDescriptor::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)
- : mParamHandle(p),
- mMergeFunc(merge_func),
- mDeserializeFunc(deserialize_func),
- mSerializeFunc(serialize_func),
- mValidationFunc(validation_func),
- mInspectFunc(inspect_func),
- mMinCount(min_count),
- mMaxCount(max_count),
- mUserData(NULL)
- {}
-
- ParamDescriptor::ParamDescriptor()
- : mParamHandle(0),
- mMergeFunc(NULL),
- mDeserializeFunc(NULL),
- mSerializeFunc(NULL),
- mValidationFunc(NULL),
- mInspectFunc(NULL),
- mMinCount(0),
- mMaxCount(0),
- mUserData(NULL)
- {}
-
- ParamDescriptor::~ParamDescriptor()
- {
- delete mUserData;
- }
-
- //
- // Parser
- //
- Parser::~Parser()
- {}
-
- void Parser::parserWarning(const std::string& message)
- {
- if (mParseSilently) return;
- llwarns << message << llendl;
- }
-
- void Parser::parserError(const std::string& message)
- {
- if (mParseSilently) return;
- llerrs << message << llendl;
- }
-
-
- //
- // BlockDescriptor
- //
- void BlockDescriptor::aggregateBlockData(BlockDescriptor& src_block_data)
- {
- mNamedParams.insert(src_block_data.mNamedParams.begin(), src_block_data.mNamedParams.end());
- std::copy(src_block_data.mUnnamedParams.begin(), src_block_data.mUnnamedParams.end(), std::back_inserter(mUnnamedParams));
- std::copy(src_block_data.mValidationList.begin(), src_block_data.mValidationList.end(), std::back_inserter(mValidationList));
- std::copy(src_block_data.mAllParams.begin(), src_block_data.mAllParams.end(), std::back_inserter(mAllParams));
- }
-
- BlockDescriptor::BlockDescriptor()
- : mMaxParamOffset(0),
- mInitializationState(UNINITIALIZED),
- mCurrentBlockPtr(NULL)
- {}
-
- // called by each derived class in least to most derived order
- void BaseBlock::init(BlockDescriptor& descriptor, BlockDescriptor& base_descriptor, size_t block_size)
- {
- descriptor.mCurrentBlockPtr = this;
- descriptor.mMaxParamOffset = block_size;
-
- switch(descriptor.mInitializationState)
- {
- case BlockDescriptor::UNINITIALIZED:
- // copy params from base class here
- descriptor.aggregateBlockData(base_descriptor);
-
- descriptor.mInitializationState = BlockDescriptor::INITIALIZING;
- break;
- case BlockDescriptor::INITIALIZING:
- descriptor.mInitializationState = BlockDescriptor::INITIALIZED;
- break;
- case BlockDescriptor::INITIALIZED:
- // nothing to do
- break;
- }
- }
-
- param_handle_t BaseBlock::getHandleFromParam(const Param* param) const
- {
- const U8* param_address = reinterpret_cast<const U8*>(param);
- const U8* baseblock_address = reinterpret_cast<const U8*>(this);
- return (param_address - baseblock_address);
- }
-
- bool BaseBlock::submitValue(Parser::name_stack_t& name_stack, Parser& p, bool silent)
- {
- if (!deserializeBlock(p, std::make_pair(name_stack.begin(), name_stack.end()), true))
- {
- if (!silent)
- {
- p.parserWarning(llformat("Failed to parse parameter \"%s\"", p.getCurrentElementName().c_str()));
- }
- return false;
- }
- return true;
- }
-
-
- bool BaseBlock::validateBlock(bool emit_errors) const
- {
- const BlockDescriptor& block_data = mostDerivedBlockDescriptor();
- for (BlockDescriptor::param_validation_list_t::const_iterator it = block_data.mValidationList.begin(); it != block_data.mValidationList.end(); ++it)
- {
- const Param* param = getParamFromHandle(it->first);
- if (!it->second(param))
- {
- if (emit_errors)
- {
- llwarns << "Invalid param \"" << getParamName(block_data, param) << "\"" << llendl;
- }
- return false;
- }
- }
- return true;
- }
-
- void BaseBlock::serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const LLInitParam::BaseBlock* diff_block) const
- {
- // named param is one like LLView::Params::follows
- // unnamed param is like LLView::Params::rect - implicit
- const BlockDescriptor& block_data = mostDerivedBlockDescriptor();
-
- for (BlockDescriptor::param_list_t::const_iterator it = block_data.mUnnamedParams.begin();
- it != block_data.mUnnamedParams.end();
- ++it)
- {
- param_handle_t param_handle = (*it)->mParamHandle;
- const Param* param = getParamFromHandle(param_handle);
- ParamDescriptor::serialize_func_t serialize_func = (*it)->mSerializeFunc;
- if (serialize_func)
- {
- const Param* diff_param = diff_block ? diff_block->getParamFromHandle(param_handle) : NULL;
- // each param descriptor remembers its serial number
- // so we can inspect the same param under different names
- // and see that it has the same number
- name_stack.push_back(std::make_pair("", true));
- serialize_func(*param, parser, name_stack, diff_param);
- name_stack.pop_back();
- }
- }
-
- for(BlockDescriptor::param_map_t::const_iterator it = block_data.mNamedParams.begin();
- it != block_data.mNamedParams.end();
- ++it)
- {
- param_handle_t param_handle = it->second->mParamHandle;
- const Param* param = getParamFromHandle(param_handle);
- ParamDescriptor::serialize_func_t serialize_func = it->second->mSerializeFunc;
- if (serialize_func && param->anyProvided())
- {
- // Ensure this param has not already been serialized
- // Prevents <rect> from being serialized as its own tag.
- bool duplicate = false;
- for (BlockDescriptor::param_list_t::const_iterator it2 = block_data.mUnnamedParams.begin();
- it2 != block_data.mUnnamedParams.end();
- ++it2)
- {
- if (param_handle == (*it2)->mParamHandle)
- {
- duplicate = true;
- break;
- }
- }
-
- //FIXME: for now, don't attempt to serialize values under synonyms, as current parsers
- // don't know how to detect them
- if (duplicate)
- {
- continue;
- }
-
- name_stack.push_back(std::make_pair(it->first, !duplicate));
- const Param* diff_param = diff_block ? diff_block->getParamFromHandle(param_handle) : NULL;
- serialize_func(*param, parser, name_stack, diff_param);
- name_stack.pop_back();
- }
- }
- }
-
- bool BaseBlock::inspectBlock(Parser& parser, Parser::name_stack_t name_stack, S32 min_count, S32 max_count) const
- {
- // named param is one like LLView::Params::follows
- // unnamed param is like LLView::Params::rect - implicit
- const BlockDescriptor& block_data = mostDerivedBlockDescriptor();
-
- for (BlockDescriptor::param_list_t::const_iterator it = block_data.mUnnamedParams.begin();
- it != block_data.mUnnamedParams.end();
- ++it)
- {
- param_handle_t param_handle = (*it)->mParamHandle;
- const Param* param = getParamFromHandle(param_handle);
- ParamDescriptor::inspect_func_t inspect_func = (*it)->mInspectFunc;
- if (inspect_func)
- {
- name_stack.push_back(std::make_pair("", true));
- inspect_func(*param, parser, name_stack, (*it)->mMinCount, (*it)->mMaxCount);
- name_stack.pop_back();
- }
- }
-
- for(BlockDescriptor::param_map_t::const_iterator it = block_data.mNamedParams.begin();
- it != block_data.mNamedParams.end();
- ++it)
- {
- param_handle_t param_handle = it->second->mParamHandle;
- const Param* param = getParamFromHandle(param_handle);
- ParamDescriptor::inspect_func_t inspect_func = it->second->mInspectFunc;
- if (inspect_func)
- {
- // Ensure this param has not already been inspected
- bool duplicate = false;
- for (BlockDescriptor::param_list_t::const_iterator it2 = block_data.mUnnamedParams.begin();
- it2 != block_data.mUnnamedParams.end();
- ++it2)
- {
- if (param_handle == (*it2)->mParamHandle)
- {
- duplicate = true;
- break;
- }
- }
-
- name_stack.push_back(std::make_pair(it->first, !duplicate));
- inspect_func(*param, parser, name_stack, it->second->mMinCount, it->second->mMaxCount);
- name_stack.pop_back();
- }
- }
-
- return true;
- }
-
- bool BaseBlock::deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool ignored)
- {
- BlockDescriptor& block_data = mostDerivedBlockDescriptor();
- bool names_left = name_stack_range.first != name_stack_range.second;
-
- bool new_name = names_left
- ? name_stack_range.first->second
- : true;
-
- if (names_left)
- {
- const std::string& top_name = name_stack_range.first->first;
-
- ParamDescriptor::deserialize_func_t deserialize_func = NULL;
- Param* paramp = NULL;
-
- BlockDescriptor::param_map_t::iterator found_it = block_data.mNamedParams.find(top_name);
- if (found_it != block_data.mNamedParams.end())
- {
- // find pointer to member parameter from offset table
- paramp = getParamFromHandle(found_it->second->mParamHandle);
- deserialize_func = found_it->second->mDeserializeFunc;
-
- Parser::name_stack_range_t new_name_stack(name_stack_range.first, name_stack_range.second);
- ++new_name_stack.first;
- if (deserialize_func(*paramp, p, new_name_stack, new_name))
- {
- // value is no longer new, we know about it now
- name_stack_range.first->second = false;
- return true;
- }
- else
- {
- return false;
- }
- }
- }
-
- // try to parse unnamed parameters, in declaration order
- for ( BlockDescriptor::param_list_t::iterator it = block_data.mUnnamedParams.begin();
- it != block_data.mUnnamedParams.end();
- ++it)
- {
- Param* paramp = getParamFromHandle((*it)->mParamHandle);
- ParamDescriptor::deserialize_func_t deserialize_func = (*it)->mDeserializeFunc;
-
- if (deserialize_func && deserialize_func(*paramp, p, name_stack_range, new_name))
- {
- return true;
- }
- }
-
- // if no match, and no names left on stack, this is just an existence assertion of this block
- // verify by calling readValue with NoParamValue type, an inherently unparseable type
- if (!names_left)
- {
- Flag no_value;
- return p.readValue(no_value);
- }
-
- 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();
- if (block_data.mInitializationState == BlockDescriptor::INITIALIZING)
- {
- param_handle_t handle = getHandleFromParam(&param);
-
- // check for invalid derivation from a paramblock (i.e. without using
- // Block<T, Base_Class>
- if ((size_t)handle > 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;
- }
-
- ParamDescriptorPtr param_descriptor = findParamDescriptor(param);
- if (param_descriptor)
- {
- if (synonym.empty())
- {
- block_data.mUnnamedParams.push_back(param_descriptor);
- }
- else
- {
- block_data.mNamedParams[synonym] = param_descriptor;
- }
- }
- }
- }
-
- const std::string& BaseBlock::getParamName(const BlockDescriptor& block_data, const Param* paramp) const
- {
- param_handle_t handle = getHandleFromParam(paramp);
- for (BlockDescriptor::param_map_t::const_iterator it = block_data.mNamedParams.begin(); it != block_data.mNamedParams.end(); ++it)
- {
- if (it->second->mParamHandle == handle)
- {
- return it->first;
- }
- }
-
- return LLStringUtil::null;
- }
-
- ParamDescriptorPtr BaseBlock::findParamDescriptor(const Param& param)
- {
- param_handle_t handle = getHandleFromParam(&param);
- BlockDescriptor& descriptor = mostDerivedBlockDescriptor();
- BlockDescriptor::all_params_list_t::iterator end_it = descriptor.mAllParams.end();
- for (BlockDescriptor::all_params_list_t::iterator it = descriptor.mAllParams.begin();
- it != end_it;
- ++it)
- {
- if ((*it)->mParamHandle == handle) return *it;
- }
- return ParamDescriptorPtr();
- }
-
- // 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::mergeBlock(BlockDescriptor& block_data, const BaseBlock& other, bool overwrite)
- {
- bool some_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);
- llassert(paramp->mEnclosingBlockOffset == (*it)->mParamHandle);
- some_param_changed |= merge_func(*paramp, *other_paramp, overwrite);
- }
- }
- return some_param_changed;
- }
-}
diff --git a/indra/llxuixml/llinitparam.h b/indra/llxuixml/llinitparam.h
deleted file mode 100644
index ab20957760..0000000000
--- a/indra/llxuixml/llinitparam.h
+++ /dev/null
@@ -1,2294 +0,0 @@
-/**
- * @file llinitparam.h
- * @brief parameter block abstraction for creating complex objects and
- * parsing construction parameters from xml and LLSD
- *
- * $LicenseInfo:firstyear=2008&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#ifndef LL_LLPARAM_H
-#define LL_LLPARAM_H
-
-#include <vector>
-#include <boost/function.hpp>
-#include <boost/type_traits/is_convertible.hpp>
-#include <boost/unordered_map.hpp>
-#include <boost/shared_ptr.hpp>
-
-#include "llerror.h"
-
-namespace LLInitParam
-{
- // used to indicate no matching value to a given name when parsing
- struct Flag{};
-
- template<typename T> const T& defaultValue() { static T value; return value; }
-
- template <typename T, bool IS_BOOST_FUNCTION = boost::is_convertible<T, boost::function_base>::value >
- struct ParamCompare
- {
- static bool equals(const T &a, const T &b)
- {
- return a == b;
- }
- };
-
- // boost function types are not comparable
- template<typename T>
- struct ParamCompare<T, true>
- {
- static bool equals(const T&a, const T &b)
- {
- return false;
- }
- };
-
- template<>
- struct ParamCompare<LLSD, false>
- {
- static bool equals(const LLSD &a, const LLSD &b) { return false; }
- };
-
- template<>
- struct ParamCompare<Flag, false>
- {
- static bool equals(const Flag& a, const Flag& b) { return false; }
- };
-
-
- // helper functions and classes
- typedef ptrdiff_t param_handle_t;
-
- // empty default implementation of key cache
- // leverages empty base class optimization
- template <typename T>
- class TypeValues
- {
- private:
- struct Inaccessable{};
- public:
- typedef std::map<std::string, T> value_name_map_t;
- typedef Inaccessable name_t;
-
- void setValueName(const std::string& key) {}
- std::string getValueName() const { return ""; }
- std::string calcValueName(const T& value) const { return ""; }
- void clearValueName() const {}
-
- static bool getValueFromName(const std::string& name, T& value)
- {
- return false;
- }
-
- static bool valueNamesExist()
- {
- return false;
- }
-
- static std::vector<std::string>* getPossibleValues()
- {
- return NULL;
- }
-
- static value_name_map_t* getValueNames() {return NULL;}
- };
-
- template <typename T, typename DERIVED_TYPE = TypeValues<T> >
- class TypeValuesHelper
- {
- public:
- typedef typename std::map<std::string, T> value_name_map_t;
- typedef std::string name_t;
-
- //TODO: cache key by index to save on param block size
- void setValueName(const std::string& value_name)
- {
- mValueName = value_name;
- }
-
- std::string getValueName() const
- {
- return mValueName;
- }
-
- std::string calcValueName(const T& value) const
- {
- value_name_map_t* map = getValueNames();
- for (typename value_name_map_t::iterator it = map->begin(), end_it = map->end();
- it != end_it;
- ++it)
- {
- if (ParamCompare<T>::equals(it->second, value))
- {
- return it->first;
- }
- }
-
- return "";
- }
-
- void clearValueName() const
- {
- mValueName.clear();
- }
-
- static bool getValueFromName(const std::string& name, T& value)
- {
- value_name_map_t* map = getValueNames();
- typename value_name_map_t::iterator found_it = map->find(name);
- if (found_it == map->end()) return false;
-
- value = found_it->second;
- return true;
- }
-
- static bool valueNamesExist()
- {
- return !getValueNames()->empty();
- }
-
- static value_name_map_t* getValueNames()
- {
- static value_name_map_t sMap;
- static bool sInitialized = false;
-
- if (!sInitialized)
- {
- sInitialized = true;
- DERIVED_TYPE::declareValues();
- }
- return &sMap;
- }
-
- static std::vector<std::string>* getPossibleValues()
- {
- static std::vector<std::string> sValues;
-
- value_name_map_t* map = getValueNames();
- for (typename value_name_map_t::iterator it = map->begin(), end_it = map->end();
- it != end_it;
- ++it)
- {
- sValues.push_back(it->first);
- }
- return &sValues;
- }
-
- static void declare(const std::string& name, const T& value)
- {
- (*getValueNames())[name] = value;
- }
-
- protected:
- static void getName(const std::string& name, const T& value)
- {}
-
- mutable std::string mValueName;
- };
-
- class Parser
- {
- LOG_CLASS(Parser);
-
- public:
-
- struct CompareTypeID
- {
- bool operator()(const std::type_info* lhs, const std::type_info* rhs) const
- {
- return lhs->before(*rhs);
- }
- };
-
- typedef std::vector<std::pair<std::string, bool> > name_stack_t;
- typedef std::pair<name_stack_t::iterator, name_stack_t::iterator> name_stack_range_t;
- typedef std::vector<std::string> possible_values_t;
-
- typedef bool (*parser_read_func_t)(Parser& parser, void* output);
- typedef bool (*parser_write_func_t)(Parser& parser, const void*, name_stack_t&);
- typedef boost::function<void (name_stack_t&, S32, S32, const possible_values_t*)> parser_inspect_func_t;
-
- typedef std::map<const std::type_info*, parser_read_func_t, CompareTypeID> parser_read_func_map_t;
- typedef std::map<const std::type_info*, parser_write_func_t, CompareTypeID> parser_write_func_map_t;
- typedef std::map<const std::type_info*, parser_inspect_func_t, CompareTypeID> parser_inspect_func_map_t;
-
- Parser(parser_read_func_map_t& read_map, parser_write_func_map_t& write_map, parser_inspect_func_map_t& inspect_map)
- : mParseSilently(false),
- mParserReadFuncs(&read_map),
- mParserWriteFuncs(&write_map),
- mParserInspectFuncs(&inspect_map)
- {}
- virtual ~Parser();
-
- template <typename T> bool readValue(T& param)
- {
- parser_read_func_map_t::iterator found_it = mParserReadFuncs->find(&typeid(T));
- if (found_it != mParserReadFuncs->end())
- {
- return found_it->second(*this, (void*)&param);
- }
- return false;
- }
-
- template <typename T> bool writeValue(const T& param, name_stack_t& name_stack)
- {
- parser_write_func_map_t::iterator found_it = mParserWriteFuncs->find(&typeid(T));
- if (found_it != mParserWriteFuncs->end())
- {
- return found_it->second(*this, (const void*)&param, name_stack);
- }
- return false;
- }
-
- // dispatch inspection to registered inspection functions, for each parameter in a param block
- template <typename T> bool inspectValue(name_stack_t& name_stack, S32 min_count, S32 max_count, const possible_values_t* possible_values)
- {
- parser_inspect_func_map_t::iterator found_it = mParserInspectFuncs->find(&typeid(T));
- if (found_it != mParserInspectFuncs->end())
- {
- found_it->second(name_stack, min_count, max_count, possible_values);
- return true;
- }
- return false;
- }
-
- virtual std::string getCurrentElementName() = 0;
- virtual void parserWarning(const std::string& message);
- virtual void parserError(const std::string& message);
- void setParseSilently(bool silent) { mParseSilently = silent; }
-
- protected:
- template <typename T>
- void registerParserFuncs(parser_read_func_t read_func, parser_write_func_t write_func = NULL)
- {
- mParserReadFuncs->insert(std::make_pair(&typeid(T), read_func));
- mParserWriteFuncs->insert(std::make_pair(&typeid(T), write_func));
- }
-
- template <typename T>
- void registerInspectFunc(parser_inspect_func_t inspect_func)
- {
- mParserInspectFuncs->insert(std::make_pair(&typeid(T), inspect_func));
- }
-
- bool mParseSilently;
-
- private:
- parser_read_func_map_t* mParserReadFuncs;
- parser_write_func_map_t* mParserWriteFuncs;
- parser_inspect_func_map_t* mParserInspectFuncs;
- };
-
- class Param;
-
- // various callbacks and constraints associated with an individual param
- struct ParamDescriptor
- {
- struct UserData
- {
- virtual ~UserData() {}
- };
-
- typedef bool(*merge_func_t)(Param&, const Param&, bool);
- typedef bool(*deserialize_func_t)(Param&, Parser&, const Parser::name_stack_range_t&, bool);
- typedef void(*serialize_func_t)(const Param&, Parser&, Parser::name_stack_t&, const Param* diff_param);
- typedef void(*inspect_func_t)(const Param&, Parser&, Parser::name_stack_t&, S32 min_count, S32 max_count);
- 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);
-
- ParamDescriptor();
- ~ParamDescriptor();
-
- param_handle_t mParamHandle;
- merge_func_t mMergeFunc;
- deserialize_func_t mDeserializeFunc;
- serialize_func_t mSerializeFunc;
- inspect_func_t mInspectFunc;
- validation_func_t mValidationFunc;
- S32 mMinCount;
- S32 mMaxCount;
- S32 mNumRefs;
- UserData* mUserData;
- };
-
- typedef boost::shared_ptr<ParamDescriptor> ParamDescriptorPtr;
-
- // each derived Block class keeps a static data structure maintaining offsets to various params
- class BlockDescriptor
- {
- public:
- BlockDescriptor();
-
- typedef enum e_initialization_state
- {
- UNINITIALIZED,
- INITIALIZING,
- INITIALIZED
- } EInitializationState;
-
- void aggregateBlockData(BlockDescriptor& src_block_data);
-
- typedef boost::unordered_map<const std::string, ParamDescriptorPtr> param_map_t;
- typedef std::vector<ParamDescriptorPtr> param_list_t;
- typedef std::list<ParamDescriptorPtr> all_params_list_t;
- typedef std::vector<std::pair<param_handle_t, ParamDescriptor::validation_func_t> > param_validation_list_t;
-
- param_map_t mNamedParams; // parameters with associated names
- param_list_t mUnnamedParams; // parameters with_out_ associated names
- param_validation_list_t mValidationList; // parameters that must be validated
- all_params_list_t mAllParams; // all parameters, owns descriptors
- size_t mMaxParamOffset;
- EInitializationState mInitializationState; // whether or not static block data has been initialized
- class BaseBlock* mCurrentBlockPtr; // pointer to block currently being constructed
- };
-
- class BaseBlock
- {
- public:
- //TODO: implement in terms of owned_ptr
- template<typename T>
- class Lazy
- {
- public:
- Lazy()
- : mPtr(NULL)
- {}
-
- ~Lazy()
- {
- delete mPtr;
- }
-
- Lazy(const Lazy& other)
- {
- if (other.mPtr)
- {
- mPtr = new T(*other.mPtr);
- }
- else
- {
- mPtr = NULL;
- }
- }
-
- Lazy<T>& operator = (const Lazy<T>& other)
- {
- if (other.mPtr)
- {
- mPtr = new T(*other.mPtr);
- }
- else
- {
- mPtr = NULL;
- }
- return *this;
- }
-
- bool empty() const
- {
- return mPtr == NULL;
- }
-
- void set(const T& other)
- {
- delete mPtr;
- mPtr = new T(other);
- }
-
- const T& get() const
- {
- return ensureInstance();
- }
-
- T& get()
- {
- return ensureInstance();
- }
-
- private:
- // lazily allocate an instance of T
- T* ensureInstance() const
- {
- if (mPtr == NULL)
- {
- 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);
-
- mutable T* mPtr;
- };
-
- // "Multiple" constraint types, put here in root class to avoid ambiguity during use
- struct AnyAmount
- {
- enum { minCount = 0 };
- enum { maxCount = U32_MAX };
- };
-
- template<U32 MIN_AMOUNT>
- struct AtLeast
- {
- enum { minCount = MIN_AMOUNT };
- enum { maxCount = U32_MAX };
- };
-
- template<U32 MAX_AMOUNT>
- struct AtMost
- {
- enum { minCount = 0 };
- enum { maxCount = MAX_AMOUNT };
- };
-
- template<U32 MIN_AMOUNT, U32 MAX_AMOUNT>
- struct Between
- {
- enum { minCount = MIN_AMOUNT };
- enum { maxCount = MAX_AMOUNT };
- };
-
- template<U32 EXACT_COUNT>
- struct Exactly
- {
- enum { minCount = EXACT_COUNT };
- enum { maxCount = EXACT_COUNT };
- };
-
- // this typedef identifies derived classes as being blocks
- typedef void baseblock_base_class_t;
- LOG_CLASS(BaseBlock);
- friend class Param;
-
- virtual ~BaseBlock() {}
- bool submitValue(Parser::name_stack_t& name_stack, Parser& p, bool silent=false);
-
- param_handle_t getHandleFromParam(const Param* param) const;
- bool validateBlock(bool emit_errors = true) const;
-
- Param* getParamFromHandle(const param_handle_t param_handle)
- {
- if (param_handle == 0) return NULL;
-
- U8* baseblock_address = reinterpret_cast<U8*>(this);
- return reinterpret_cast<Param*>(baseblock_address + param_handle);
- }
-
- const Param* getParamFromHandle(const param_handle_t param_handle) const
- {
- const U8* baseblock_address = reinterpret_cast<const U8*>(this);
- return reinterpret_cast<const Param*>(baseblock_address + param_handle);
- }
-
- void addSynonym(Param& param, const std::string& synonym);
-
- // Blocks can override this to do custom tracking of changes
- virtual void paramChanged(const Param& changed_param, bool user_provided) {}
-
- bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name);
- void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const;
- 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(); }
-
- // take all provided params from other and apply to self
- bool overwriteFrom(const BaseBlock& other)
- {
- return false;
- }
-
- // take all provided params that are not already provided, and apply to self
- bool fillFrom(const BaseBlock& other)
- {
- return false;
- }
-
- static void addParam(BlockDescriptor& block_data, ParamDescriptorPtr param, const char* name);
-
- ParamDescriptorPtr findParamDescriptor(const Param& param);
-
- protected:
- void init(BlockDescriptor& descriptor, BlockDescriptor& base_descriptor, size_t block_size);
-
-
- bool mergeBlockParam(bool source_provided, bool dst_provided, BlockDescriptor& block_data, const BaseBlock& source, bool overwrite)
- {
- 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<typename T>
- struct ParamCompare<BaseBlock::Lazy<T>, false >
- {
- static bool equals(const BaseBlock::Lazy<T>& a, const BaseBlock::Lazy<T>& b) { return !a.empty() || !b.empty(); }
- };
-
- class Param
- {
- public:
- void setProvided(bool is_provided = true)
- {
- mIsProvided = is_provided;
- enclosingBlock().paramChanged(*this, is_provided);
- }
-
- Param& operator =(const Param& other)
- {
- mIsProvided = other.mIsProvided;
- // don't change mEnclosingblockoffset
- return *this;
- }
- protected:
-
- bool anyProvided() const { return mIsProvided; }
-
- Param(BaseBlock* enclosing_block);
-
- // store pointer to enclosing block as offset to reduce space and allow for quick copying
- BaseBlock& enclosingBlock() const
- {
- 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)(S32)mEnclosingBlockOffset));
- }
-
- private:
- friend class BaseBlock;
-
- U32 mEnclosingBlockOffset:31;
- U32 mIsProvided:1;
-
- };
-
- // these templates allow us to distinguish between template parameters
- // that derive from BaseBlock and those that don't
- template<typename T, typename Void = void>
- struct IsBlock
- {
- static const bool value = false;
- struct EmptyBase {};
- typedef EmptyBase base_class_t;
- };
-
- template<typename T>
- struct IsBlock<T, typename T::baseblock_base_class_t>
- {
- static const bool value = true;
- typedef BaseBlock base_class_t;
- };
-
- template<typename T>
- struct IsBlock<BaseBlock::Lazy<T>, typename T::baseblock_base_class_t >
- {
- static const bool value = true;
- typedef BaseBlock base_class_t;
- };
-
- template<typename T, typename NAME_VALUE_LOOKUP, bool VALUE_IS_BLOCK = IsBlock<T>::value>
- class ParamValue : public NAME_VALUE_LOOKUP
- {
- public:
- typedef const T& value_assignment_t;
- typedef T value_t;
- typedef ParamValue<T, NAME_VALUE_LOOKUP, VALUE_IS_BLOCK> self_t;
-
- ParamValue(): mValue() {}
- ParamValue(value_assignment_t other) : mValue(other) {}
-
- void setValue(value_assignment_t val)
- {
- mValue = val;
- }
-
- value_assignment_t getValue() const
- {
- return mValue;
- }
-
- T& getValue()
- {
- return mValue;
- }
-
- operator value_assignment_t() const
- {
- return mValue;
- }
-
- value_assignment_t operator()() const
- {
- return mValue;
- }
-
- void operator ()(const typename NAME_VALUE_LOOKUP::name_t& name)
- {
- *this = name;
- }
-
- self_t& operator =(const typename NAME_VALUE_LOOKUP::name_t& name)
- {
- if (NAME_VALUE_LOOKUP::getValueFromName(name, mValue))
- {
- setValueName(name);
- }
-
- return *this;
- }
-
- protected:
- T mValue;
- };
-
- template<typename T, typename NAME_VALUE_LOOKUP>
- class ParamValue<T, NAME_VALUE_LOOKUP, true>
- : 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;
-
- ParamValue()
- : T(),
- mValidated(false)
- {}
-
- ParamValue(value_assignment_t other)
- : T(other),
- mValidated(false)
- {}
-
- void setValue(value_assignment_t val)
- {
- *this = val;
- }
-
- value_assignment_t getValue() const
- {
- return *this;
- }
-
- T& getValue()
- {
- return *this;
- }
-
- operator value_assignment_t() const
- {
- return *this;
- }
-
- value_assignment_t operator()() const
- {
- return *this;
- }
-
- void operator ()(const typename NAME_VALUE_LOOKUP::name_t& name)
- {
- *this = name;
- }
-
- self_t& operator =(const typename NAME_VALUE_LOOKUP::name_t& name)
- {
- if (NAME_VALUE_LOOKUP::getValueFromName(name, *this))
- {
- setValueName(name);
- }
-
- return *this;
- }
-
- protected:
- mutable bool mValidated; // lazy validation flag
- };
-
- template<typename NAME_VALUE_LOOKUP>
- class ParamValue<std::string, NAME_VALUE_LOOKUP, false>
- : 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;
-
- ParamValue(): mValue() {}
- ParamValue(value_assignment_t other) : mValue(other) {}
-
- void setValue(value_assignment_t val)
- {
- if (NAME_VALUE_LOOKUP::getValueFromName(val, mValue))
- {
- NAME_VALUE_LOOKUP::setValueName(val);
- }
- else
- {
- mValue = val;
- }
- }
-
- value_assignment_t getValue() const
- {
- return mValue;
- }
-
- std::string& getValue()
- {
- return mValue;
- }
-
- operator value_assignment_t() const
- {
- return mValue;
- }
-
- value_assignment_t operator()() const
- {
- return mValue;
- }
-
- protected:
- std::string mValue;
- };
-
-
- template<typename T, typename NAME_VALUE_LOOKUP = TypeValues<T> >
- struct ParamIterator
- {
- typedef typename std::vector<ParamValue<T, NAME_VALUE_LOOKUP> >::const_iterator const_iterator;
- typedef typename std::vector<ParamValue<T, NAME_VALUE_LOOKUP> >::iterator iterator;
- };
-
- // specialize for custom parsing/decomposition of specific classes
- // e.g. TypedParam<LLRect> has left, top, right, bottom, etc...
- template<typename T,
- typename NAME_VALUE_LOOKUP = TypeValues<T>,
- bool HAS_MULTIPLE_VALUES = false,
- bool VALUE_IS_BLOCK = IsBlock<ParamValue<T, NAME_VALUE_LOOKUP> >::value>
- class TypedParam
- : public Param,
- public ParamValue<T, NAME_VALUE_LOOKUP>
- {
- public:
- typedef TypedParam<T, NAME_VALUE_LOOKUP, HAS_MULTIPLE_VALUES, VALUE_IS_BLOCK> self_t;
- typedef ParamValue<T, NAME_VALUE_LOOKUP> param_value_t;
- typedef typename param_value_t::value_assignment_t value_assignment_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)
- : Param(block_descriptor.mCurrentBlockPtr)
- {
- 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);
- }
-
- setValue(value);
- }
-
- bool isProvided() const { return Param::anyProvided(); }
-
- static bool deserializeParam(Param& param, Parser& parser, const Parser::name_stack_range_t& name_stack_range, bool new_name)
- {
- self_t& typed_param = static_cast<self_t&>(param);
- // no further names in stack, attempt to parse value now
- if (name_stack_range.first == name_stack_range.second)
- {
- if (parser.readValue(typed_param.getValue()))
- {
- typed_param.clearValueName();
- typed_param.setProvided();
- return true;
- }
-
- // try to parse a known named value
- if(name_value_lookup_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()))
- {
- typed_param.setValueName(name);
- typed_param.setProvided();
- return true;
- }
-
- }
- }
- }
- return false;
- }
-
- static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param)
- {
- const self_t& typed_param = static_cast<const self_t&>(param);
- if (!typed_param.isProvided()) return;
-
- if (!name_stack.empty())
- {
- name_stack.back().second = true;
- }
-
- std::string key = typed_param.getValueName();
-
- // first try to write out name of name/value pair
-
- if (!key.empty())
- {
- if (!diff_param || !ParamCompare<std::string>::equals(static_cast<const self_t*>(diff_param)->getValueName(), key))
- {
- parser.writeValue(key, name_stack);
- }
- }
- // then try to serialize value directly
- else if (!diff_param || !ParamCompare<T>::equals(typed_param.getValue(), static_cast<const self_t*>(diff_param)->getValue()))
- {
- if (!parser.writeValue(typed_param.getValue(), name_stack))
- {
- std::string calculated_key = typed_param.calcValueName(typed_param.getValue());
- if (!diff_param || !ParamCompare<std::string>::equals(static_cast<const self_t*>(diff_param)->getValueName(), calculated_key))
- {
- parser.writeValue(calculated_key, name_stack);
- }
- }
- }
- }
-
- static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count)
- {
- // tell parser about our actual type
- parser.inspectValue<T>(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())
- {
- parser.inspectValue<std::string>(name_stack, min_count, max_count, name_value_lookup_t::getPossibleValues());
- }
- }
-
- void set(value_assignment_t val, bool flag_as_provided = true)
- {
- param_value_t::clearValueName();
- setValue(val);
- setProvided(flag_as_provided);
- }
-
- self_t& operator =(const typename NAME_VALUE_LOOKUP::name_t& name)
- {
- return static_cast<self_t&>(param_value_t::operator =(name));
- }
-
- protected:
-
- self_t& operator =(const self_t& other)
- {
- param_value_t::operator =(other);
- Param::operator =(other);
- return *this;
- }
-
- static bool mergeWith(Param& dst, const Param& src, bool overwrite)
- {
- const self_t& src_typed_param = static_cast<const self_t&>(src);
- self_t& dst_typed_param = static_cast<self_t&>(dst);
-
- if (src_typed_param.isProvided()
- && (overwrite || !dst_typed_param.isProvided()))
- {
- dst_typed_param.set(src_typed_param.getValue());
- return true;
- }
- return false;
- }
- };
-
- // parameter that is a block
- template <typename T, typename NAME_VALUE_LOOKUP>
- class TypedParam<T, NAME_VALUE_LOOKUP, false, true>
- : 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 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)
- : Param(block_descriptor.mCurrentBlockPtr),
- param_value_t(value)
- {
- 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);
- }
- }
-
- static bool deserializeParam(Param& param, Parser& parser, const Parser::name_stack_range_t& name_stack_range, bool new_name)
- {
- self_t& typed_param = static_cast<self_t&>(param);
- // attempt to parse block...
- if(typed_param.deserializeBlock(parser, name_stack_range, new_name))
- {
- typed_param.clearValueName();
- typed_param.setProvided();
- return true;
- }
-
- if(name_value_lookup_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()))
- {
- typed_param.setValueName(name);
- typed_param.setProvided();
- return true;
- }
-
- }
- }
- return false;
- }
-
- static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param)
- {
- const self_t& typed_param = static_cast<const self_t&>(param);
- if (!typed_param.isProvided()) return;
-
- if (!name_stack.empty())
- {
- name_stack.back().second = true;
- }
-
- std::string key = typed_param.getValueName();
- if (!key.empty())
- {
- if (!parser.writeValue(key, name_stack))
- {
- return;
- }
- }
- else
- {
- typed_param.serializeBlock(parser, name_stack, static_cast<const self_t*>(diff_param));
- }
- }
-
- static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count)
- {
- // I am a param that is also a block, so just recurse into my contents
- const self_t& typed_param = static_cast<const self_t&>(param);
- typed_param.inspectBlock(parser, name_stack, min_count, max_count);
- }
-
- // a param-that-is-a-block is provided when the user has set one of its child params
- // *and* the block as a whole validates
- bool isProvided() const
- {
- // only validate block when it hasn't already passed validation with current data
- if (Param::anyProvided() && !param_value_t::mValidated)
- {
- // a sub-block is "provided" when it has been filled in enough to be valid
- param_value_t::mValidated = param_value_t::validateBlock(false);
- }
- return Param::anyProvided() && param_value_t::mValidated;
- }
-
- // assign block contents to this param-that-is-a-block
- void set(value_assignment_t val, bool flag_as_provided = true)
- {
- setValue(val);
- param_value_t::clearValueName();
- // force revalidation of block
- // next call to isProvided() will update provision status based on validity
- param_value_t::mValidated = false;
- setProvided(flag_as_provided);
- }
-
- self_t& operator =(const typename NAME_VALUE_LOOKUP::name_t& name)
- {
- return static_cast<self_t&>(param_value_t::operator =(name));
- }
-
- // propagate changed status up to enclosing block
- /*virtual*/ void paramChanged(const Param& changed_param, bool user_provided)
- {
- param_value_t::paramChanged(changed_param, user_provided);
- if (user_provided)
- {
- // a child param has been explicitly changed
- // so *some* aspect of this block is now provided
- param_value_t::mValidated = false;
- setProvided();
- param_value_t::clearValueName();
- }
- else
- {
- Param::enclosingBlock().paramChanged(*this, user_provided);
- }
- }
-
- protected:
-
- self_t& operator =(const self_t& other)
- {
- param_value_t::operator =(other);
- Param::operator =(other);
- return *this;
- }
-
- static bool mergeWith(Param& dst, const Param& src, bool overwrite)
- {
- const self_t& src_typed_param = static_cast<const self_t&>(src);
- self_t& dst_typed_param = static_cast<self_t&>(dst);
-
- 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))
- {
- dst_typed_param.clearValueName();
- dst_typed_param.setProvided(true);
- return true;
- }
- }
- return false;
- }
- };
-
- // container of non-block parameters
- template <typename VALUE_TYPE, typename NAME_VALUE_LOOKUP>
- class TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, false>
- : public Param
- {
- public:
- typedef TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, false> 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;
-
- 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)
- : Param(block_descriptor.mCurrentBlockPtr)
- {
- std::copy(value.begin(), value.end(), std::back_inserter(mValues));
-
- 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);
- }
- }
-
- bool isProvided() const { return Param::anyProvided(); }
-
- static bool deserializeParam(Param& param, Parser& parser, const Parser::name_stack_range_t& name_stack_range, bool new_name)
- {
- self_t& typed_param = static_cast<self_t&>(param);
- value_t value;
- // no further names in stack, attempt to parse value now
- if (name_stack_range.first == name_stack_range.second)
- {
- // attempt to read value directly
- if (parser.readValue(value))
- {
- typed_param.add(value);
- return true;
- }
-
- // try to parse a known named value
- if(name_value_lookup_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))
- {
- typed_param.add(value);
- typed_param.mValues.back().setValueName(name);
- return true;
- }
-
- }
- }
- }
- return false;
- }
-
- static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param)
- {
- const self_t& typed_param = static_cast<const self_t&>(param);
- if (!typed_param.isProvided() || name_stack.empty()) return;
-
- for (const_iterator it = typed_param.mValues.begin(), end_it = typed_param.mValues.end();
- it != end_it;
- ++it)
- {
- std::string key = it->getValueName();
- name_stack.back().second = true;
-
- if(key.empty())
- // not parsed via name values, write out value directly
- {
- bool value_written = parser.writeValue(*it, name_stack);
- if (!value_written)
- {
- std::string calculated_key = it->calcValueName(it->getValue());
- if (!parser.writeValue(calculated_key, name_stack))
- {
- break;
- }
- }
- }
- else
- {
- if(!parser.writeValue(key, name_stack))
- {
- break;
- }
- }
- }
- }
-
- static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count)
- {
- parser.inspectValue<VALUE_TYPE>(name_stack, min_count, max_count, NULL);
- if (name_value_lookup_t::getPossibleValues())
- {
- parser.inspectValue<std::string>(name_stack, min_count, max_count, name_value_lookup_t::getPossibleValues());
- }
- }
-
- void set(value_assignment_t val, bool flag_as_provided = true)
- {
- mValues = val;
- setProvided(flag_as_provided);
- }
-
- param_value_t& add()
- {
- mValues.push_back(param_value_t(value_t()));
- Param::setProvided();
- return mValues.back();
- }
-
- void add(const value_t& item)
- {
- param_value_t param_value;
- param_value.setValue(item);
- mValues.push_back(param_value);
- setProvided();
- }
-
- void add(const typename name_value_lookup_t::name_t& name)
- {
- value_t value;
-
- // try to parse a per type named value
- if (name_value_lookup_t::getValueFromName(name, value))
- {
- add(value);
- mValues.back().setValueName(name);
- }
- }
-
- // implicit conversion
- operator value_assignment_t() const { return mValues; }
- // explicit conversion
- value_assignment_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(); }
- const_iterator end() const { return mValues.end(); }
- bool empty() const { return mValues.empty(); }
- size_t size() const { return mValues.size(); }
-
- U32 numValidElements() const
- {
- return mValues.size();
- }
-
- protected:
- static bool mergeWith(Param& dst, const Param& src, bool overwrite)
- {
- const self_t& src_typed_param = static_cast<const self_t&>(src);
- self_t& dst_typed_param = static_cast<self_t&>(dst);
-
- if (overwrite)
- {
- std::copy(src_typed_param.begin(), src_typed_param.end(), std::back_inserter(dst_typed_param.mValues));
- }
- else
- {
- container_t new_values(src_typed_param.mValues);
- std::copy(dst_typed_param.begin(), dst_typed_param.end(), std::back_inserter(new_values));
- std::swap(dst_typed_param.mValues, new_values);
- }
-
- if (src_typed_param.begin() != src_typed_param.end())
- {
- dst_typed_param.setProvided();
- }
- return true;
- }
-
- container_t mValues;
- };
-
- // container of block parameters
- template <typename VALUE_TYPE, typename NAME_VALUE_LOOKUP>
- class TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, true>
- : public Param
- {
- public:
- typedef TypedParam<VALUE_TYPE, NAME_VALUE_LOOKUP, true, true> 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;
- 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)
- : Param(block_descriptor.mCurrentBlockPtr)
- {
- std::copy(value.begin(), value.end(), back_inserter(mValues));
-
- 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);
- }
- }
-
- bool isProvided() const { return Param::anyProvided(); }
-
- static bool deserializeParam(Param& param, Parser& parser, const Parser::name_stack_range_t& name_stack_range, bool new_name)
- {
- self_t& typed_param = static_cast<self_t&>(param);
- bool new_value = false;
-
- if (new_name || typed_param.mValues.empty())
- {
- new_value = true;
- typed_param.mValues.push_back(value_t());
- }
-
- param_value_t& value = typed_param.mValues.back();
-
- // attempt to parse block...
- if(value.deserializeBlock(parser, name_stack_range, new_name))
- {
- typed_param.setProvided();
- return true;
- }
- else if(name_value_lookup_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()))
- {
- typed_param.mValues.back().setValueName(name);
- typed_param.setProvided();
- return true;
- }
-
- }
- }
-
- if (new_value)
- { // failed to parse new value, pop it off
- typed_param.mValues.pop_back();
- }
-
- return false;
- }
-
- static void serializeParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, const Param* diff_param)
- {
- const self_t& typed_param = static_cast<const self_t&>(param);
- if (!typed_param.isProvided() || name_stack.empty()) return;
-
- for (const_iterator it = typed_param.mValues.begin(), end_it = typed_param.mValues.end();
- it != end_it;
- ++it)
- {
- name_stack.back().second = true;
-
- std::string key = it->getValueName();
- if (!key.empty())
- {
- parser.writeValue(key, name_stack);
- }
- // Not parsed via named values, write out value directly
- // NOTE: currently we don't worry about removing default values in Multiple
- else
- {
- it->serializeBlock(parser, name_stack, NULL);
- }
- }
- }
-
- static void inspectParam(const Param& param, Parser& parser, Parser::name_stack_t& name_stack, S32 min_count, S32 max_count)
- {
- // I am a vector of blocks, so describe my contents recursively
- param_value_t(value_t()).inspectBlock(parser, name_stack, min_count, max_count);
- }
-
- void set(value_assignment_t val, bool flag_as_provided = true)
- {
- mValues = val;
- setProvided(flag_as_provided);
- }
-
- param_value_t& add()
- {
- mValues.push_back(value_t());
- setProvided();
- return mValues.back();
- }
-
- void add(const value_t& item)
- {
- mValues.push_back(item);
- setProvided();
- }
-
- void add(const typename name_value_lookup_t::name_t& name)
- {
- value_t value;
-
- // try to parse a per type named value
- if (name_value_lookup_t::getValueFromName(name, value))
- {
- add(value);
- mValues.back().setValueName(name);
- }
- }
-
- // implicit conversion
- operator value_assignment_t() const { return mValues; }
- // explicit conversion
- value_assignment_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(); }
- const_iterator end() const { return mValues.end(); }
- bool empty() const { return mValues.empty(); }
- size_t size() const { return mValues.size(); }
-
- U32 numValidElements() const
- {
- U32 count = 0;
- for (const_iterator it = mValues.begin(), end_it = mValues.end();
- it != end_it;
- ++it)
- {
- if(it->validateBlock(false)) count++;
- }
- return count;
- }
-
- protected:
-
- static bool mergeWith(Param& dst, const Param& src, bool overwrite)
- {
- const self_t& src_typed_param = static_cast<const self_t&>(src);
- self_t& dst_typed_param = static_cast<self_t&>(dst);
-
- if (overwrite)
- {
- std::copy(src_typed_param.begin(), src_typed_param.end(), std::back_inserter(dst_typed_param.mValues));
- }
- else
- {
- container_t new_values(src_typed_param.mValues);
- std::copy(dst_typed_param.begin(), dst_typed_param.end(), std::back_inserter(new_values));
- std::swap(dst_typed_param.mValues, new_values);
- }
-
- if (src_typed_param.begin() != src_typed_param.end())
- {
- dst_typed_param.setProvided();
- }
-
- return true;
- }
-
- container_t mValues;
- };
-
- template <typename DERIVED_BLOCK, typename BASE_BLOCK = BaseBlock>
- class ChoiceBlock : public BASE_BLOCK
- {
- typedef ChoiceBlock<DERIVED_BLOCK, BASE_BLOCK> self_t;
- typedef ChoiceBlock<DERIVED_BLOCK, BASE_BLOCK> enclosing_block_t;
- typedef BASE_BLOCK base_block_t;
-
- LOG_CLASS(self_t);
- public:
- // take all provided params from other and apply to self
- bool overwriteFrom(const self_t& other)
- {
- return static_cast<DERIVED_BLOCK*>(this)->mergeBlock(selfBlockDescriptor(), other, true);
- }
-
- // take all provided params that are not already provided, and apply to self
- bool fillFrom(const self_t& other)
- {
- return static_cast<DERIVED_BLOCK*>(this)->mergeBlock(selfBlockDescriptor(), other, false);
- }
-
- bool mergeBlockParam(bool source_provided, bool dest_provided, BlockDescriptor& block_data, const self_t& source, bool overwrite)
- {
- bool source_override = source_provided && (overwrite || !dest_provided);
-
- if (source_override || source.mCurChoice == mCurChoice)
- {
- return mergeBlock(block_data, source, overwrite);
- }
- return false;
- }
-
- // merge with other block
- bool mergeBlock(BlockDescriptor& block_data, const self_t& other, bool overwrite)
- {
- mCurChoice = other.mCurChoice;
- return base_block_t::mergeBlock(selfBlockDescriptor(), other, overwrite);
- }
-
- // clear out old choice when param has changed
- /*virtual*/ void paramChanged(const Param& changed_param, bool user_provided)
- {
- param_handle_t changed_param_handle = base_block_t::getHandleFromParam(&changed_param);
- // if we have a new choice...
- if (changed_param_handle != mCurChoice)
- {
- // clear provided flag on previous choice
- Param* previous_choice = base_block_t::getParamFromHandle(mCurChoice);
- if (previous_choice)
- {
- previous_choice->setProvided(false);
- }
- mCurChoice = changed_param_handle;
- }
- base_block_t::paramChanged(changed_param, user_provided);
- }
-
- virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return selfBlockDescriptor(); }
- virtual BlockDescriptor& mostDerivedBlockDescriptor() { return selfBlockDescriptor(); }
-
- protected:
- ChoiceBlock()
- : mCurChoice(0)
- {
- BaseBlock::init(selfBlockDescriptor(), base_block_t::selfBlockDescriptor(), sizeof(DERIVED_BLOCK));
- }
-
- // Alternatives are mutually exclusive wrt other Alternatives in the same block.
- // One alternative in a block will always have isChosen() == true.
- // At most one alternative in a block will have isProvided() == true.
- template <typename T, typename NAME_VALUE_LOOKUP = TypeValues<T> >
- class Alternative : public TypedParam<T, NAME_VALUE_LOOKUP, false>
- {
- public:
- friend class ChoiceBlock<DERIVED_BLOCK>;
-
- typedef Alternative<T, NAME_VALUE_LOOKUP> self_t;
- typedef TypedParam<T, NAME_VALUE_LOOKUP, false, IsBlock<ParamValue<T, NAME_VALUE_LOOKUP> >::value> super_t;
- typedef typename super_t::value_assignment_t value_assignment_t;
-
- using super_t::operator =;
-
- explicit Alternative(const char* name = "", value_assignment_t val = defaultValue<T>())
- : super_t(DERIVED_BLOCK::selfBlockDescriptor(), 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))
- {
- if(blockp->mCurChoice == 0)
- {
- blockp->mCurChoice = Param::enclosingBlock().getHandleFromParam(this);
- }
- }
- }
-
- void choose()
- {
- static_cast<enclosing_block_t&>(Param::enclosingBlock()).paramChanged(*this, true);
- }
-
- void chooseAs(value_assignment_t val)
- {
- super_t::set(val);
- }
-
- void operator =(value_assignment_t val)
- {
- super_t::set(val);
- }
-
- void operator()(typename super_t::value_assignment_t val)
- {
- super_t::set(val);
- }
-
- operator value_assignment_t() const
- {
- return (*this)();
- }
-
- value_assignment_t operator()() const
- {
- if (static_cast<enclosing_block_t&>(Param::enclosingBlock()).getCurrentChoice() == this)
- {
- return super_t::getValue();
- }
- return mOriginalValue;
- }
-
- bool isChosen() const
- {
- return static_cast<enclosing_block_t&>(Param::enclosingBlock()).getCurrentChoice() == this;
- }
-
- private:
- T mOriginalValue;
- };
-
- protected:
- static BlockDescriptor& selfBlockDescriptor()
- {
- static BlockDescriptor sBlockDescriptor;
- return sBlockDescriptor;
- }
-
- private:
- param_handle_t mCurChoice;
-
- const Param* getCurrentChoice() const
- {
- return base_block_t::getParamFromHandle(mCurChoice);
- }
- };
-
- template <typename DERIVED_BLOCK, typename BASE_BLOCK = BaseBlock>
- class Block
- : public BASE_BLOCK
- {
- typedef Block<DERIVED_BLOCK, BASE_BLOCK> self_t;
- typedef Block<DERIVED_BLOCK, BASE_BLOCK> block_t;
-
- public:
- typedef BASE_BLOCK base_block_t;
-
- // take all provided params from other and apply to self
- bool overwriteFrom(const self_t& other)
- {
- return static_cast<DERIVED_BLOCK*>(this)->mergeBlock(selfBlockDescriptor(), other, true);
- }
-
- // take all provided params that are not already provided, and apply to self
- bool fillFrom(const self_t& other)
- {
- return static_cast<DERIVED_BLOCK*>(this)->mergeBlock(selfBlockDescriptor(), other, false);
- }
-
- virtual const BlockDescriptor& mostDerivedBlockDescriptor() const { return selfBlockDescriptor(); }
- virtual BlockDescriptor& mostDerivedBlockDescriptor() { return selfBlockDescriptor(); }
-
- protected:
- Block()
- {
- //#pragma message("Parsing LLInitParam::Block")
- BaseBlock::init(selfBlockDescriptor(), BASE_BLOCK::selfBlockDescriptor(), sizeof(DERIVED_BLOCK));
- }
-
- //
- // Nested classes for declaring parameters
- //
- template <typename T, typename NAME_VALUE_LOOKUP = TypeValues<T> >
- class Optional : public TypedParam<T, NAME_VALUE_LOOKUP, false>
- {
- public:
- typedef TypedParam<T, NAME_VALUE_LOOKUP, false, IsBlock<ParamValue<T, NAME_VALUE_LOOKUP> >::value> super_t;
- typedef typename super_t::value_assignment_t value_assignment_t;
-
- using super_t::operator();
- using super_t::operator =;
-
- explicit Optional(const char* name = "", value_assignment_t val = defaultValue<T>())
- : super_t(DERIVED_BLOCK::selfBlockDescriptor(), name, val, NULL, 0, 1)
- {
- //#pragma message("Parsing LLInitParam::Block::Optional")
- }
-
- Optional& operator =(value_assignment_t val)
- {
- set(val);
- return *this;
- }
-
- DERIVED_BLOCK& operator()(value_assignment_t val)
- {
- super_t::set(val);
- return static_cast<DERIVED_BLOCK&>(Param::enclosingBlock());
- }
- };
-
- template <typename T, typename NAME_VALUE_LOOKUP = TypeValues<T> >
- class Mandatory : public TypedParam<T, NAME_VALUE_LOOKUP, false>
- {
- public:
- typedef TypedParam<T, NAME_VALUE_LOOKUP, false, IsBlock<ParamValue<T, NAME_VALUE_LOOKUP> >::value> super_t;
- typedef Mandatory<T, NAME_VALUE_LOOKUP> self_t;
- typedef typename super_t::value_assignment_t value_assignment_t;
-
- using super_t::operator();
- using super_t::operator =;
-
- // mandatory parameters require a name to be parseable
- explicit Mandatory(const char* name = "", value_assignment_t val = defaultValue<T>())
- : super_t(DERIVED_BLOCK::selfBlockDescriptor(), name, val, &validate, 1, 1)
- {}
-
- Mandatory& operator =(value_assignment_t val)
- {
- set(val);
- return *this;
- }
-
- DERIVED_BLOCK& operator()(typename super_t::value_assignment_t val)
- {
- super_t::set(val);
- return static_cast<DERIVED_BLOCK&>(Param::enclosingBlock());
- }
-
- static bool validate(const Param* p)
- {
- // valid only if provided
- return static_cast<const self_t*>(p)->isProvided();
- }
-
- };
-
- template <typename T, typename RANGE = BaseBlock::AnyAmount, typename NAME_VALUE_LOOKUP = TypeValues<T> >
- class Multiple : public TypedParam<T, NAME_VALUE_LOOKUP, true>
- {
- public:
- typedef TypedParam<T, NAME_VALUE_LOOKUP, true, IsBlock<ParamValue<T, NAME_VALUE_LOOKUP> >::value> 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;
- typedef typename super_t::iterator iterator;
- 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)
- {}
-
- Multiple& operator =(value_assignment_t val)
- {
- set(val);
- return *this;
- }
-
- DERIVED_BLOCK& operator()(typename super_t::value_assignment_t val)
- {
- super_t::set(val);
- return static_cast<DERIVED_BLOCK&>(Param::enclosingBlock());
- }
-
- static bool validate(const Param* paramp)
- {
- U32 num_valid = ((super_t*)paramp)->numValidElements();
- return RANGE::minCount <= num_valid && num_valid <= RANGE::maxCount;
- }
- };
-
- class Deprecated : public Param
- {
- public:
- explicit Deprecated(const char* name)
- : Param(DERIVED_BLOCK::selfBlockDescriptor().mCurrentBlockPtr)
- {
- BlockDescriptor& block_descriptor = DERIVED_BLOCK::selfBlockDescriptor();
- if (LL_UNLIKELY(block_descriptor.mInitializationState == BlockDescriptor::INITIALIZING))
- {
- ParamDescriptorPtr param_descriptor = ParamDescriptorPtr(new ParamDescriptor(
- block_descriptor.mCurrentBlockPtr->getHandleFromParam(this),
- NULL,
- &deserializeParam,
- NULL,
- NULL,
- NULL,
- 0, S32_MAX));
- BaseBlock::addParam(block_descriptor, param_descriptor, name);
- }
- }
-
- static bool deserializeParam(Param& param, Parser& parser, const Parser::name_stack_range_t& name_stack_range, bool new_name)
- {
- if (name_stack_range.first == name_stack_range.second)
- {
- //std::string message = llformat("Deprecated value %s ignored", getName().c_str());
- //parser.parserWarning(message);
- return true;
- }
-
- return false;
- }
- };
-
- // different semantics for documentation purposes, but functionally identical
- typedef Deprecated Ignored;
-
- protected:
- static BlockDescriptor& selfBlockDescriptor()
- {
- static BlockDescriptor sBlockDescriptor;
- return sBlockDescriptor;
- }
-
- template <typename T, typename NAME_VALUE_LOOKUP, bool multiple, bool 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)
- {
- if (!param.isProvided())
- {
- param.set(value, false);
- }
- }
-
- };
-
- template <typename DERIVED_BLOCK, typename BASE_BLOCK = BaseBlock>
- class BatchBlock
- : public Block<DERIVED_BLOCK, BASE_BLOCK>
- {
- public:
- typedef BatchBlock<DERIVED_BLOCK, BASE_BLOCK> self_t;
- typedef Block<DERIVED_BLOCK, BASE_BLOCK> super_t;
-
- BatchBlock()
- {}
-
- bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name)
- {
- if (new_name)
- {
- // reset block
- *static_cast<DERIVED_BLOCK*>(this) = defaultBatchValue();
- }
- return super_t::deserializeBlock(p, name_stack_range, new_name);
- }
-
- bool mergeBlock(BlockDescriptor& block_data, const BaseBlock& other, bool overwrite)
- {
- if (overwrite)
- {
- *static_cast<DERIVED_BLOCK*>(this) = defaultBatchValue();
- // merge individual parameters into destination
- return super_t::mergeBlock(super_t::selfBlockDescriptor(), other, overwrite);
- }
- return false;
- }
- protected:
- static const DERIVED_BLOCK& defaultBatchValue()
- {
- static DERIVED_BLOCK default_value;
- return default_value;
- }
- };
-
- // FIXME: this specialization is not currently used, as it only matches against the BatchBlock base class
- // and not the derived class with the actual params
- template<typename DERIVED_BLOCK,
- typename BASE_BLOCK,
- typename NAME_VALUE_LOOKUP>
- class ParamValue <BatchBlock<DERIVED_BLOCK, BASE_BLOCK>,
- NAME_VALUE_LOOKUP,
- true>
- : public NAME_VALUE_LOOKUP,
- protected BatchBlock<DERIVED_BLOCK, BASE_BLOCK>
- {
- public:
- typedef BatchBlock<DERIVED_BLOCK, BASE_BLOCK> block_t;
- typedef const BatchBlock<DERIVED_BLOCK, BASE_BLOCK>& value_assignment_t;
- typedef block_t value_t;
-
- ParamValue()
- : block_t(),
- mValidated(false)
- {}
-
- ParamValue(value_assignment_t other)
- : block_t(other),
- mValidated(false)
- {
- }
-
- void setValue(value_assignment_t val)
- {
- *this = val;
- }
-
- value_assignment_t getValue() const
- {
- return *this;
- }
-
- BatchBlock<DERIVED_BLOCK, BASE_BLOCK>& getValue()
- {
- return *this;
- }
-
- operator value_assignment_t() const
- {
- return *this;
- }
-
- value_assignment_t operator()() const
- {
- return *this;
- }
-
- protected:
- mutable bool mValidated; // lazy validation flag
- };
-
- template<typename T, bool IS_BLOCK>
- class ParamValue <BaseBlock::Lazy<T>,
- TypeValues<T>,
- IS_BLOCK>
- : public IsBlock<T>::base_class_t
- {
- public:
- typedef ParamValue <BaseBlock::Lazy<T>, TypeValues<T>, false> self_t;
- typedef const T& value_assignment_t;
- typedef T value_t;
-
- ParamValue()
- : mValue(),
- mValidated(false)
- {}
-
- ParamValue(value_assignment_t other)
- : mValue(other),
- mValidated(false)
- {}
-
- void setValue(value_assignment_t val)
- {
- mValue.set(val);
- }
-
- value_assignment_t getValue() const
- {
- return mValue.get();
- }
-
- T& getValue()
- {
- return mValue.get();
- }
-
- operator value_assignment_t() const
- {
- return mValue.get();
- }
-
- value_assignment_t operator()() const
- {
- return mValue.get();
- }
-
- bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name)
- {
- return mValue.get().deserializeBlock(p, name_stack_range, new_name);
- }
-
- void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const
- {
- if (mValue.empty()) return;
-
- mValue.get().serializeBlock(p, name_stack, diff_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
- {
- if (mValue.empty()) return false;
-
- return mValue.get().inspectBlock(p, name_stack, min_count, max_count);
- }
-
- protected:
- mutable bool mValidated; // lazy validation flag
-
- private:
- BaseBlock::Lazy<T> mValue;
- };
-
- template <>
- class ParamValue <LLSD,
- TypeValues<LLSD>,
- false>
- : public TypeValues<LLSD>,
- public BaseBlock
- {
- public:
- typedef ParamValue<LLSD, TypeValues<LLSD>, false> self_t;
- typedef const LLSD& value_assignment_t;
-
- ParamValue()
- : mValidated(false)
- {}
-
- ParamValue(value_assignment_t other)
- : mValue(other),
- mValidated(false)
- {}
-
- void setValue(value_assignment_t val) { mValue = val; }
-
- value_assignment_t getValue() const { return mValue; }
- LLSD& getValue() { return mValue; }
-
- operator value_assignment_t() const { return mValue; }
- value_assignment_t operator()() const { return mValue; }
-
-
- // block param interface
- bool deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack_range, bool new_name);
- void serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const;
- bool inspectBlock(Parser& p, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const
- {
- //TODO: implement LLSD params as schema type Any
- return true;
- }
-
- protected:
- mutable bool mValidated; // lazy validation flag
-
- private:
- static void serializeElement(Parser& p, const LLSD& sd, Parser::name_stack_t& name_stack);
-
- LLSD mValue;
- };
-
- template<typename T>
- class CustomParamValue
- : public Block<ParamValue<T, TypeValues<T> > >,
- public TypeValues<T>
- {
- public:
- typedef enum e_value_age
- {
- VALUE_NEEDS_UPDATE, // mValue needs to be refreshed from the block parameters
- VALUE_AUTHORITATIVE, // mValue holds the authoritative value (which has been replicated to the block parameters via updateBlockFromValue)
- BLOCK_AUTHORITATIVE // mValue is derived from the block parameters, which are authoritative
- } EValueAge;
-
- typedef ParamValue<T, TypeValues<T> > derived_t;
- typedef CustomParamValue<T> self_t;
- typedef Block<derived_t> block_t;
- typedef const T& value_assignment_t;
- typedef T value_t;
-
-
- CustomParamValue(const T& value = T())
- : mValue(value),
- mValueAge(VALUE_AUTHORITATIVE),
- mValidated(false)
- {}
-
- bool deserializeBlock(Parser& parser, Parser::name_stack_range_t name_stack_range, bool new_name)
- {
- derived_t& typed_param = static_cast<derived_t&>(*this);
- // try to parse direct value T
- if (name_stack_range.first == name_stack_range.second)
- {
- if(parser.readValue(typed_param.mValue))
- {
- typed_param.mValueAge = VALUE_AUTHORITATIVE;
- typed_param.updateBlockFromValue(false);
-
- typed_param.clearValueName();
-
- return true;
- }
- }
-
- // fall back on parsing block components for T
- return typed_param.BaseBlock::deserializeBlock(parser, name_stack_range, new_name);
- }
-
- void serializeBlock(Parser& parser, Parser::name_stack_t& name_stack, const BaseBlock* diff_block = NULL) const
- {
- const derived_t& typed_param = static_cast<const derived_t&>(*this);
- const derived_t* diff_param = static_cast<const derived_t*>(diff_block);
-
- std::string key = typed_param.getValueName();
-
- // first try to write out name of name/value pair
- if (!key.empty())
- {
- if (!diff_param || !ParamCompare<std::string>::equals(diff_param->getValueName(), key))
- {
- parser.writeValue(key, name_stack);
- }
- }
- // then try to serialize value directly
- else if (!diff_param || !ParamCompare<T>::equals(typed_param.getValue(), diff_param->getValue()))
- {
-
- if (!parser.writeValue(typed_param.getValue(), name_stack))
- {
- //RN: *always* serialize provided components of BlockValue (don't pass diff_param on),
- // since these tend to be viewed as the constructor arguments for the value T. It seems
- // cleaner to treat the uniqueness of a BlockValue according to the generated value, and
- // not the individual components. This way <color red="0" green="1" blue="0"/> will not
- // be exported as <color green="1"/>, since it was probably the intent of the user to
- // be specific about the RGB color values. This also fixes an issue where we distinguish
- // between rect.left not being provided and rect.left being explicitly set to 0 (same as default)
-
- if (typed_param.mValueAge == VALUE_AUTHORITATIVE)
- {
- // if the value is authoritative but the parser doesn't accept the value type
- // go ahead and make a copy, and splat the value out to its component params
- // and serialize those params
- derived_t copy(typed_param);
- copy.updateBlockFromValue(true);
- copy.block_t::serializeBlock(parser, name_stack, NULL);
- }
- else
- {
- block_t::serializeBlock(parser, name_stack, NULL);
- }
- }
- }
- }
-
- bool inspectBlock(Parser& parser, Parser::name_stack_t name_stack = Parser::name_stack_t(), S32 min_count = 0, S32 max_count = S32_MAX) const
- {
- // first, inspect with actual type...
- parser.inspectValue<T>(name_stack, min_count, max_count, NULL);
- if (TypeValues<T>::getPossibleValues())
- {
- //...then inspect with possible string values...
- parser.inspectValue<std::string>(name_stack, min_count, max_count, TypeValues<T>::getPossibleValues());
- }
- // then recursively inspect contents...
- return block_t::inspectBlock(parser, name_stack, min_count, max_count);
- }
-
- bool validateBlock(bool emit_errors = true) const
- {
- if (mValueAge == VALUE_NEEDS_UPDATE)
- {
- if (block_t::validateBlock(emit_errors))
- {
- // clear stale keyword associated with old value
- TypeValues<T>::clearValueName();
- mValueAge = BLOCK_AUTHORITATIVE;
- static_cast<derived_t*>(const_cast<self_t*>(this))->updateValueFromBlock();
- return true;
- }
- else
- {
- //block value incomplete, so not considered provided
- // will attempt to revalidate on next call to isProvided()
- return false;
- }
- }
- else
- {
- // we have a valid value in hand
- return true;
- }
- }
-
- // propagate change status up to enclosing block
- /*virtual*/ void paramChanged(const Param& changed_param, bool user_provided)
- {
- BaseBlock::paramChanged(changed_param, user_provided);
- if (user_provided)
- {
- // a parameter changed, so our value is out of date
- mValueAge = VALUE_NEEDS_UPDATE;
- }
- }
-
- void setValue(value_assignment_t val)
- {
- derived_t& typed_param = static_cast<derived_t&>(*this);
- // set param version number to be up to date, so we ignore block contents
- mValueAge = VALUE_AUTHORITATIVE;
- mValue = val;
- typed_param.clearValueName();
- static_cast<derived_t*>(this)->updateBlockFromValue(false);
- }
-
- value_assignment_t getValue() const
- {
- validateBlock(true);
- return mValue;
- }
-
- T& getValue()
- {
- validateBlock(true);
- return mValue;
- }
-
- operator value_assignment_t() const
- {
- return getValue();
- }
-
- value_assignment_t operator()() const
- {
- return getValue();
- }
-
- protected:
-
- // use this from within updateValueFromBlock() to set the value without making it authoritative
- void updateValue(value_assignment_t value)
- {
- mValue = value;
- }
-
- bool mergeBlockParam(bool source_provided, bool dst_provided, BlockDescriptor& block_data, const BaseBlock& source, bool overwrite)
- {
- bool source_override = source_provided && (overwrite || !dst_provided);
-
- const derived_t& src_typed_param = static_cast<const derived_t&>(source);
-
- if (source_override && src_typed_param.mValueAge == VALUE_AUTHORITATIVE)
- {
- // copy value over
- setValue(src_typed_param.getValue());
- return true;
- }
- // merge individual parameters into destination
- if (mValueAge == VALUE_AUTHORITATIVE)
- {
- static_cast<derived_t*>(this)->updateBlockFromValue(dst_provided);
- }
- return mergeBlock(block_data, source, overwrite);
- }
-
- bool mergeBlock(BlockDescriptor& block_data, const BaseBlock& source, bool overwrite)
- {
- return block_t::mergeBlock(block_data, source, overwrite);
- }
-
- mutable bool mValidated; // lazy validation flag
-
- private:
- mutable T mValue;
- mutable EValueAge mValueAge;
- };
-}
-
-
-#endif // LL_LLPARAM_H
diff --git a/indra/llxuixml/llregistry.h b/indra/llxuixml/llregistry.h
deleted file mode 100644
index 36ce6a97b7..0000000000
--- a/indra/llxuixml/llregistry.h
+++ /dev/null
@@ -1,351 +0,0 @@
-/**
- * @file llregistry.h
- * @brief template classes for registering name, value pairs in nested scopes, statically, etc.
- *
- * $LicenseInfo:firstyear=2001&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#ifndef LL_LLREGISTRY_H
-#define LL_LLREGISTRY_H
-
-#include <list>
-
-#include <boost/type_traits.hpp>
-#include "llsingleton.h"
-
-template <typename T>
-class LLRegistryDefaultComparator
-{
- bool operator()(const T& lhs, const T& rhs) { return lhs < rhs; }
-};
-
-template <typename KEY, typename VALUE, typename COMPARATOR = LLRegistryDefaultComparator<KEY> >
-class LLRegistry
-{
-public:
- typedef LLRegistry<KEY, VALUE, COMPARATOR> registry_t;
- typedef typename boost::add_reference<typename boost::add_const<KEY>::type>::type ref_const_key_t;
- typedef typename boost::add_reference<typename boost::add_const<VALUE>::type>::type ref_const_value_t;
- typedef typename boost::add_reference<VALUE>::type ref_value_t;
- typedef typename boost::add_pointer<typename boost::add_const<VALUE>::type>::type ptr_const_value_t;
- typedef typename boost::add_pointer<VALUE>::type ptr_value_t;
-
- class Registrar
- {
- friend class LLRegistry<KEY, VALUE, COMPARATOR>;
- public:
- typedef typename std::map<KEY, VALUE> registry_map_t;
-
- bool add(ref_const_key_t key, ref_const_value_t value)
- {
- if (mMap.insert(std::make_pair(key, value)).second == false)
- {
- llwarns << "Tried to register " << key << " but it was already registered!" << llendl;
- return false;
- }
- return true;
- }
-
- void remove(ref_const_key_t key)
- {
- mMap.erase(key);
- }
-
- void replace(ref_const_key_t key, ref_const_value_t value)
- {
- mMap[key] = value;
- }
-
- typename registry_map_t::const_iterator beginItems() const
- {
- return mMap.begin();
- }
-
- typename registry_map_t::const_iterator endItems() const
- {
- return mMap.end();
- }
-
- protected:
- ptr_value_t getValue(ref_const_key_t key)
- {
- typename registry_map_t::iterator found_it = mMap.find(key);
- if (found_it != mMap.end())
- {
- return &(found_it->second);
- }
- return NULL;
- }
-
- ptr_const_value_t getValue(ref_const_key_t key) const
- {
- typename registry_map_t::const_iterator found_it = mMap.find(key);
- if (found_it != mMap.end())
- {
- return &(found_it->second);
- }
- return NULL;
- }
-
- // if the registry is used to store pointers, and null values are valid entries
- // then use this function to check the existence of an entry
- bool exists(ref_const_key_t key) const
- {
- return mMap.find(key) != mMap.end();
- }
-
- bool empty() const
- {
- return mMap.empty();
- }
-
- protected:
- // use currentRegistrar() or defaultRegistrar()
- Registrar() {}
- ~Registrar() {}
-
- private:
- registry_map_t mMap;
- };
-
- typedef typename std::list<Registrar*> scope_list_t;
- typedef typename std::list<Registrar*>::iterator scope_list_iterator_t;
- typedef typename std::list<Registrar*>::const_iterator scope_list_const_iterator_t;
-
- LLRegistry()
- {}
-
- ~LLRegistry() {}
-
- ptr_value_t getValue(ref_const_key_t key)
- {
- for(scope_list_iterator_t it = mActiveScopes.begin();
- it != mActiveScopes.end();
- ++it)
- {
- ptr_value_t valuep = (*it)->getValue(key);
- if (valuep != NULL) return valuep;
- }
- return mDefaultRegistrar.getValue(key);
- }
-
- ptr_const_value_t getValue(ref_const_key_t key) const
- {
- for(scope_list_const_iterator_t it = mActiveScopes.begin();
- it != mActiveScopes.end();
- ++it)
- {
- ptr_value_t valuep = (*it)->getValue(key);
- if (valuep != NULL) return valuep;
- }
- return mDefaultRegistrar.getValue(key);
- }
-
- bool exists(ref_const_key_t key) const
- {
- for(scope_list_const_iterator_t it = mActiveScopes.begin();
- it != mActiveScopes.end();
- ++it)
- {
- if ((*it)->exists(key)) return true;
- }
-
- return mDefaultRegistrar.exists(key);
- }
-
- bool empty() const
- {
- for(scope_list_const_iterator_t it = mActiveScopes.begin();
- it != mActiveScopes.end();
- ++it)
- {
- if (!(*it)->empty()) return false;
- }
-
- return mDefaultRegistrar.empty();
- }
-
-
- Registrar& defaultRegistrar()
- {
- return mDefaultRegistrar;
- }
-
- const Registrar& defaultRegistrar() const
- {
- return mDefaultRegistrar;
- }
-
-
- Registrar& currentRegistrar()
- {
- if (!mActiveScopes.empty())
- {
- return *mActiveScopes.front();
- }
-
- return mDefaultRegistrar;
- }
-
- const Registrar& currentRegistrar() const
- {
- if (!mActiveScopes.empty())
- {
- return *mActiveScopes.front();
- }
-
- return mDefaultRegistrar;
- }
-
-
-protected:
- void addScope(Registrar* scope)
- {
- // newer scopes go up front
- mActiveScopes.insert(mActiveScopes.begin(), scope);
- }
-
- void removeScope(Registrar* scope)
- {
- // O(N) but should be near the beggining and N should be small and this is safer than storing iterators
- scope_list_iterator_t iter = std::find(mActiveScopes.begin(), mActiveScopes.end(), scope);
- if (iter != mActiveScopes.end())
- {
- mActiveScopes.erase(iter);
- }
- }
-
-private:
- scope_list_t mActiveScopes;
- Registrar mDefaultRegistrar;
-};
-
-template <typename KEY, typename VALUE, typename DERIVED_TYPE, typename COMPARATOR = LLRegistryDefaultComparator<KEY> >
-class LLRegistrySingleton
- : public LLRegistry<KEY, VALUE, COMPARATOR>,
- public LLSingleton<DERIVED_TYPE>
-{
- friend class LLSingleton<DERIVED_TYPE>;
-public:
- typedef LLRegistry<KEY, VALUE, COMPARATOR> registry_t;
- typedef const KEY& ref_const_key_t;
- typedef const VALUE& ref_const_value_t;
- typedef VALUE* ptr_value_t;
- typedef const VALUE* ptr_const_value_t;
- typedef LLSingleton<DERIVED_TYPE> singleton_t;
-
- class ScopedRegistrar : public registry_t::Registrar
- {
- public:
- ScopedRegistrar(bool push_scope = true)
- {
- if (push_scope)
- {
- pushScope();
- }
- }
-
- ~ScopedRegistrar()
- {
- if (!singleton_t::destroyed())
- {
- popScope();
- }
- }
-
- void pushScope()
- {
- singleton_t::instance().addScope(this);
- }
-
- void popScope()
- {
- singleton_t::instance().removeScope(this);
- }
-
- ptr_value_t getValueFromScope(ref_const_key_t key)
- {
- return getValue(key);
- }
-
- ptr_const_value_t getValueFromScope(ref_const_key_t key) const
- {
- return getValue(key);
- }
-
- private:
- typename std::list<typename registry_t::Registrar*>::iterator mListIt;
- };
-
- class StaticRegistrar : public registry_t::Registrar
- {
- public:
- virtual ~StaticRegistrar() {}
- StaticRegistrar(ref_const_key_t key, ref_const_value_t value)
- {
- singleton_t::instance().mStaticScope->add(key, value);
- }
- };
-
- // convenience functions
- typedef typename LLRegistry<KEY, VALUE, COMPARATOR>::Registrar& ref_registrar_t;
- static ref_registrar_t currentRegistrar()
- {
- return singleton_t::instance().registry_t::currentRegistrar();
- }
-
- static ref_registrar_t defaultRegistrar()
- {
- return singleton_t::instance().registry_t::defaultRegistrar();
- }
-
- static ptr_value_t getValue(ref_const_key_t key)
- {
- return singleton_t::instance().registry_t::getValue(key);
- }
-
-protected:
- // DERIVED_TYPE needs to derive from LLRegistrySingleton
- LLRegistrySingleton()
- : mStaticScope(NULL)
- {}
-
- virtual void initSingleton()
- {
- mStaticScope = new ScopedRegistrar();
- }
-
- virtual ~LLRegistrySingleton()
- {
- delete mStaticScope;
- }
-
-private:
- ScopedRegistrar* mStaticScope;
-};
-
-// helper macro for doing static registration
-#define GLUED_TOKEN(x, y) x ## y
-#define GLUE_TOKENS(x, y) GLUED_TOKEN(x, y)
-#define LLREGISTER_STATIC(REGISTRY, KEY, VALUE) static REGISTRY::StaticRegistrar GLUE_TOKENS(reg, __LINE__)(KEY, VALUE);
-
-#endif
diff --git a/indra/llxuixml/lltrans.cpp b/indra/llxuixml/lltrans.cpp
deleted file mode 100644
index 5388069c24..0000000000
--- a/indra/llxuixml/lltrans.cpp
+++ /dev/null
@@ -1,295 +0,0 @@
-/**
- * @file lltrans.cpp
- * @brief LLTrans implementation
- *
- * $LicenseInfo:firstyear=2000&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include "linden_common.h"
-
-#include "lltrans.h"
-
-#include "llfasttimer.h" // for call count statistics
-#include "llxuiparser.h"
-#include "llsd.h"
-#include "llxmlnode.h"
-
-#include <map>
-
-LLTrans::template_map_t LLTrans::sStringTemplates;
-LLStringUtil::format_map_t LLTrans::sDefaultArgs;
-
-struct StringDef : public LLInitParam::Block<StringDef>
-{
- Mandatory<std::string> name;
- Mandatory<std::string> value;
-
- StringDef()
- : name("name"),
- value("value")
- {}
-};
-
-struct StringTable : public LLInitParam::Block<StringTable>
-{
- Multiple<StringDef> strings;
- StringTable()
- : strings("string")
- {}
-};
-
-//static
-bool LLTrans::parseStrings(LLXMLNodePtr &root, const std::set<std::string>& default_args)
-{
- std::string xml_filename = "(strings file)";
- if (!root->hasName("strings"))
- {
- llerrs << "Invalid root node name in " << xml_filename
- << ": was " << root->getName() << ", expected \"strings\"" << llendl;
- }
-
- StringTable string_table;
- LLXUIParser parser;
- parser.readXUI(root, string_table, xml_filename);
-
- if (!string_table.validateBlock())
- {
- llerrs << "Problem reading strings: " << xml_filename << llendl;
- return false;
- }
-
- sStringTemplates.clear();
- sDefaultArgs.clear();
-
- for(LLInitParam::ParamIterator<StringDef>::const_iterator it = string_table.strings.begin();
- it != string_table.strings.end();
- ++it)
- {
- LLTransTemplate xml_template(it->name, it->value);
- sStringTemplates[xml_template.mName] = xml_template;
-
- std::set<std::string>::const_iterator iter = default_args.find(xml_template.mName);
- if (iter != default_args.end())
- {
- std::string name = *iter;
- if (name[0] != '[')
- name = llformat("[%s]",name.c_str());
- sDefaultArgs[name] = xml_template.mText;
- }
- }
-
- return true;
-}
-
-
-//static
-bool LLTrans::parseLanguageStrings(LLXMLNodePtr &root)
-{
- std::string xml_filename = "(language strings file)";
- if (!root->hasName("strings"))
- {
- llerrs << "Invalid root node name in " << xml_filename
- << ": was " << root->getName() << ", expected \"strings\"" << llendl;
- }
-
- StringTable string_table;
- LLXUIParser parser;
- parser.readXUI(root, string_table, xml_filename);
-
- if (!string_table.validateBlock())
- {
- llerrs << "Problem reading strings: " << xml_filename << llendl;
- return false;
- }
-
- for(LLInitParam::ParamIterator<StringDef>::const_iterator it = string_table.strings.begin();
- it != string_table.strings.end();
- ++it)
- {
- // share the same map with parseStrings() so we can search the strings using the same getString() function.- angela
- LLTransTemplate xml_template(it->name, it->value);
- sStringTemplates[xml_template.mName] = xml_template;
- }
-
- return true;
-}
-
-
-
-static LLFastTimer::DeclareTimer FTM_GET_TRANS("Translate string");
-
-//static
-std::string LLTrans::getString(const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args)
-{
- // Don't care about time as much as call count. Make sure we're not
- // calling LLTrans::getString() in an inner loop. JC
- LLFastTimer timer(FTM_GET_TRANS);
-
- template_map_t::iterator iter = sStringTemplates.find(xml_desc);
- if (iter != sStringTemplates.end())
- {
- std::string text = iter->second.mText;
- LLStringUtil::format_map_t args = sDefaultArgs;
- args.insert(msg_args.begin(), msg_args.end());
- LLStringUtil::format(text, args);
-
- return text;
- }
- else
- {
- LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
- return "MissingString("+xml_desc+")";
- }
-}
-
-//static
-std::string LLTrans::getString(const std::string &xml_desc, const LLSD& msg_args)
-{
- // Don't care about time as much as call count. Make sure we're not
- // calling LLTrans::getString() in an inner loop. JC
- LLFastTimer timer(FTM_GET_TRANS);
-
- template_map_t::iterator iter = sStringTemplates.find(xml_desc);
- if (iter != sStringTemplates.end())
- {
- std::string text = iter->second.mText;
- LLStringUtil::format(text, msg_args);
- return text;
- }
- else
- {
- LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
- return "MissingString("+xml_desc+")";
- }
-}
-
-//static
-bool LLTrans::findString(std::string &result, const std::string &xml_desc, const LLStringUtil::format_map_t& msg_args)
-{
- LLFastTimer timer(FTM_GET_TRANS);
-
- template_map_t::iterator iter = sStringTemplates.find(xml_desc);
- if (iter != sStringTemplates.end())
- {
- std::string text = iter->second.mText;
- LLStringUtil::format_map_t args = sDefaultArgs;
- args.insert(msg_args.begin(), msg_args.end());
- LLStringUtil::format(text, args);
- result = text;
- return true;
- }
- else
- {
- LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
- return false;
- }
-}
-
-//static
-bool LLTrans::findString(std::string &result, const std::string &xml_desc, const LLSD& msg_args)
-{
- LLFastTimer timer(FTM_GET_TRANS);
-
- template_map_t::iterator iter = sStringTemplates.find(xml_desc);
- if (iter != sStringTemplates.end())
- {
- std::string text = iter->second.mText;
- LLStringUtil::format(text, msg_args);
- result = text;
- return true;
- }
- else
- {
- LL_WARNS_ONCE("configuration") << "Missing String in strings.xml: [" << xml_desc << "]" << LL_ENDL;
- return false;
- }
-}
-
-//static
-std::string LLTrans::getCountString(const std::string& language, const std::string& xml_desc, S32 count)
-{
- // Compute which string identifier to use
- const char* form = "";
- if (language == "ru") // Russian
- {
- // From GNU ngettext()
- // Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;
- if (count % 10 == 1
- && count % 100 != 11)
- {
- // singular, "1 item"
- form = "A";
- }
- else if (count % 10 >= 2
- && count % 10 <= 4
- && (count % 100 < 10 || count % 100 >= 20) )
- {
- // special case "2 items", "23 items", but not "13 items"
- form = "B";
- }
- else
- {
- // English-style plural, "5 items"
- form = "C";
- }
- }
- else if (language == "fr" || language == "pt") // French, Brazilian Portuguese
- {
- // French and Portuguese treat zero as a singular "0 item" not "0 items"
- if (count == 0 || count == 1)
- {
- form = "A";
- }
- else
- {
- // English-style plural
- form = "B";
- }
- }
- else // default
- {
- // languages like English with 2 forms, singular and plural
- if (count == 1)
- {
- // "1 item"
- form = "A";
- }
- else
- {
- // "2 items", also use plural for "0 items"
- form = "B";
- }
- }
-
- // Translate that string
- LLStringUtil::format_map_t args;
- args["[COUNT]"] = llformat("%d", count);
-
- // Look up "AgeYearsB" or "AgeWeeksC" including the "form"
- std::string key = llformat("%s%s", xml_desc.c_str(), form);
- return getString(key, args);
-}
-
-void LLTrans::setDefaultArg(const std::string& name, const std::string& value)
-{
- sDefaultArgs[name] = value;
-}
diff --git a/indra/llxuixml/lltrans.h b/indra/llxuixml/lltrans.h
deleted file mode 100644
index 128b51d383..0000000000
--- a/indra/llxuixml/lltrans.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/**
- * @file lltrans.h
- * @brief LLTrans definition
- *
- * $LicenseInfo:firstyear=2000&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#ifndef LL_TRANS_H
-#define LL_TRANS_H
-
-#include <map>
-
-#include "llpointer.h"
-#include "llstring.h"
-
-class LLXMLNode;
-
-class LLSD;
-
-/**
- * @brief String template loaded from strings.xml
- */
-class LLTransTemplate
-{
-public:
- LLTransTemplate(const std::string& name = LLStringUtil::null, const std::string& text = LLStringUtil::null) : mName(name), mText(text) {}
-
- std::string mName;
- std::string mText;
-};
-
-/**
- * @brief Localized strings class
- * This class is used to retrieve translations of strings used to build larger ones, as well as
- * strings with a general usage that don't belong to any specific floater. For example,
- * "Owner:", "Retrieving..." used in the place of a not yet known name, etc.
- */
-class LLTrans
-{
-public:
- LLTrans();
-
- /**
- * @brief Parses the xml root that holds the strings. Used once on startup
-// *FIXME * @param xml_filename Filename to parse
- * @param default_args Set of strings (expected to be in the file) to use as default replacement args, e.g. "SECOND_LIFE"
- * @returns true if the file was parsed successfully, true if something went wrong
- */
- static bool parseStrings(LLPointer<LLXMLNode> & root, const std::set<std::string>& default_args);
-
- static bool parseLanguageStrings(LLPointer<LLXMLNode> & root);
-
- /**
- * @brief Returns a translated string
- * @param xml_desc String's description
- * @param args A list of substrings to replace in the string
- * @returns Translated string
- */
- static std::string getString(const std::string &xml_desc, const LLStringUtil::format_map_t& args);
- static std::string getString(const std::string &xml_desc, const LLSD& args);
- static bool findString(std::string &result, const std::string &xml_desc, const LLStringUtil::format_map_t& args);
- static bool findString(std::string &result, const std::string &xml_desc, const LLSD& args);
-
- // Returns translated string with [COUNT] replaced with a number, following
- // special per-language logic for plural nouns. For example, some languages
- // may have different plurals for 0, 1, 2 and > 2.
- // See "AgeWeeksA", "AgeWeeksB", etc. in strings.xml for examples.
- static std::string getCountString(const std::string& language, const std::string& xml_desc, S32 count);
-
- /**
- * @brief Returns a translated string
- * @param xml_desc String's description
- * @returns Translated string
- */
- static std::string getString(const std::string &xml_desc)
- {
- LLStringUtil::format_map_t empty;
- return getString(xml_desc, empty);
- }
-
- static bool findString(std::string &result, const std::string &xml_desc)
- {
- LLStringUtil::format_map_t empty;
- return findString(result, xml_desc, empty);
- }
-
- static std::string getKeyboardString(const char* keystring)
- {
- std::string key_str(keystring);
- std::string trans_str;
- return findString(trans_str, key_str) ? trans_str : key_str;
- }
-
- // get the default args
- static const LLStringUtil::format_map_t& getDefaultArgs()
- {
- return sDefaultArgs;
- }
-
- static void setDefaultArg(const std::string& name, const std::string& value);
-
- // insert default args into an arg list
- static void getArgs(LLStringUtil::format_map_t& args)
- {
- args.insert(sDefaultArgs.begin(), sDefaultArgs.end());
- }
-
-private:
- typedef std::map<std::string, LLTransTemplate > template_map_t;
- static template_map_t sStringTemplates;
- static LLStringUtil::format_map_t sDefaultArgs;
-};
-
-#endif
diff --git a/indra/llxuixml/lluicolor.cpp b/indra/llxuixml/lluicolor.cpp
deleted file mode 100644
index f9bb80f8c5..0000000000
--- a/indra/llxuixml/lluicolor.cpp
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * @file lluicolor.cpp
- * @brief brief LLUIColor class implementation file
- *
- * $LicenseInfo:firstyear=2009&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include "linden_common.h"
-
-#include "lluicolor.h"
-
-LLUIColor::LLUIColor()
- :mColorPtr(NULL)
-{
-}
-
-
-LLUIColor::LLUIColor(const LLColor4& color)
-: mColor(color),
- mColorPtr(NULL)
-{
-}
-
-LLUIColor::LLUIColor(const LLUIColor* color)
-: mColorPtr(color)
-{
-}
-
-void LLUIColor::set(const LLColor4& color)
-{
- mColor = color;
- mColorPtr = NULL;
-}
-
-void LLUIColor::set(const LLUIColor* color)
-{
- mColorPtr = color;
-}
-
-const LLColor4& LLUIColor::get() const
-{
- return (mColorPtr == NULL ? mColor : mColorPtr->get());
-}
-
-LLUIColor::operator const LLColor4& () const
-{
- return get();
-}
-
-const LLColor4& LLUIColor::operator()() const
-{
- return get();
-}
-
-bool LLUIColor::isReference() const
-{
- return mColorPtr != NULL;
-}
-
-namespace LLInitParam
-{
- // used to detect equivalence with default values on export
- bool ParamCompare<LLUIColor, false>::equals(const LLUIColor &a, const LLUIColor &b)
- {
- // do not detect value equivalence, treat pointers to colors as distinct from color values
- return (a.mColorPtr == NULL && b.mColorPtr == NULL ? a.mColor == b.mColor : a.mColorPtr == b.mColorPtr);
- }
-}
diff --git a/indra/llxuixml/lluicolor.h b/indra/llxuixml/lluicolor.h
deleted file mode 100644
index 97ebea854a..0000000000
--- a/indra/llxuixml/lluicolor.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * @file lluicolor.h
- * @brief brief LLUIColor class header file
- *
- * $LicenseInfo:firstyear=2009&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#ifndef LL_LLUICOLOR_H_
-#define LL_LLUICOLOR_H_
-
-#include "v4color.h"
-
-namespace LLInitParam
-{
- template<typename T, bool>
- struct ParamCompare;
-}
-
-class LLUIColor
-{
-public:
- LLUIColor();
- LLUIColor(const LLColor4& color);
- LLUIColor(const LLUIColor* color);
-
- void set(const LLColor4& color);
- void set(const LLUIColor* color);
-
- const LLColor4& get() const;
-
- operator const LLColor4& () const;
- const LLColor4& operator()() const;
-
- bool isReference() const;
-
-private:
- friend struct LLInitParam::ParamCompare<LLUIColor, false>;
-
- const LLUIColor* mColorPtr;
- LLColor4 mColor;
-};
-
-namespace LLInitParam
-{
- template<>
- struct ParamCompare<LLUIColor, false>
- {
- static bool equals(const LLUIColor& a, const LLUIColor& b);
- };
-}
-
-#endif
diff --git a/indra/llxuixml/llxuiparser.cpp b/indra/llxuixml/llxuiparser.cpp
deleted file mode 100644
index afc76024d1..0000000000
--- a/indra/llxuixml/llxuiparser.cpp
+++ /dev/null
@@ -1,1756 +0,0 @@
-/**
- * @file llxuiparser.cpp
- * @brief Utility functions for handling XUI structures in XML
- *
- * $LicenseInfo:firstyear=2003&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#include "linden_common.h"
-
-#include "llxuiparser.h"
-
-#include "llxmlnode.h"
-
-#ifdef LL_STANDALONE
-#include <expat.h>
-#else
-#include "expat/expat.h"
-#endif
-
-#include <fstream>
-#include <boost/tokenizer.hpp>
-//#include <boost/spirit/include/qi.hpp>
-#include <boost/spirit/include/classic_core.hpp>
-
-#include "lluicolor.h"
-
-using namespace BOOST_SPIRIT_CLASSIC_NS;
-
-const S32 MAX_STRING_ATTRIBUTE_SIZE = 40;
-
-static LLInitParam::Parser::parser_read_func_map_t sXSDReadFuncs;
-static LLInitParam::Parser::parser_write_func_map_t sXSDWriteFuncs;
-static LLInitParam::Parser::parser_inspect_func_map_t sXSDInspectFuncs;
-
-static LLInitParam::Parser::parser_read_func_map_t sSimpleXUIReadFuncs;
-static LLInitParam::Parser::parser_write_func_map_t sSimpleXUIWriteFuncs;
-static LLInitParam::Parser::parser_inspect_func_map_t sSimpleXUIInspectFuncs;
-
-const char* NO_VALUE_MARKER = "no_value";
-
-const S32 LINE_NUMBER_HERE = 0;
-
-struct MaxOccursValues : public LLInitParam::TypeValuesHelper<U32, MaxOccursValues>
-{
- static void declareValues()
- {
- declare("unbounded", U32_MAX);
- }
-};
-
-struct Occurs : public LLInitParam::Block<Occurs>
-{
- Optional<U32> minOccurs;
- Optional<U32, MaxOccursValues> maxOccurs;
-
- Occurs()
- : minOccurs("minOccurs", 0),
- maxOccurs("maxOccurs", U32_MAX)
-
- {}
-};
-
-
-typedef enum
-{
- USE_REQUIRED,
- USE_OPTIONAL
-} EUse;
-
-namespace LLInitParam
-{
- template<>
- struct TypeValues<EUse> : public TypeValuesHelper<EUse>
- {
- static void declareValues()
- {
- declare("required", USE_REQUIRED);
- declare("optional", USE_OPTIONAL);
- }
- };
-}
-
-struct Element;
-struct Group;
-struct Choice;
-struct Sequence;
-struct Any;
-
-struct Attribute : public LLInitParam::Block<Attribute>
-{
- Mandatory<std::string> name;
- Mandatory<std::string> type;
- Mandatory<EUse> use;
-
- Attribute()
- : name("name"),
- type("type"),
- use("use")
- {}
-};
-
-struct Any : public LLInitParam::Block<Any, Occurs>
-{
- Optional<std::string> _namespace;
-
- Any()
- : _namespace("namespace")
- {}
-};
-
-struct All : public LLInitParam::Block<All, Occurs>
-{
- Multiple< Lazy<Element> > elements;
-
- All()
- : elements("element")
- {
- maxOccurs = 1;
- }
-};
-
-struct Choice : public LLInitParam::ChoiceBlock<Choice, Occurs>
-{
- Alternative< Lazy<Element> > element;
- Alternative< Lazy<Group> > group;
- Alternative< Lazy<Choice> > choice;
- Alternative< Lazy<Sequence> > sequence;
- Alternative< Lazy<Any> > any;
-
- Choice()
- : element("element"),
- group("group"),
- choice("choice"),
- sequence("sequence"),
- any("any")
- {}
-
-};
-
-struct Sequence : public LLInitParam::ChoiceBlock<Sequence, Occurs>
-{
- Alternative< Lazy<Element> > element;
- Alternative< Lazy<Group> > group;
- Alternative< Lazy<Choice> > choice;
- Alternative< Lazy<Sequence> > sequence;
- Alternative< Lazy<Any> > any;
-};
-
-struct GroupContents : public LLInitParam::ChoiceBlock<GroupContents, Occurs>
-{
- Alternative<All> all;
- Alternative<Choice> choice;
- Alternative<Sequence> sequence;
-
- GroupContents()
- : all("all"),
- choice("choice"),
- sequence("sequence")
- {}
-};
-
-struct Group : public LLInitParam::Block<Group, GroupContents>
-{
- Optional<std::string> name,
- ref;
-
- Group()
- : name("name"),
- ref("ref")
- {}
-};
-
-struct Restriction : public LLInitParam::Block<Restriction>
-{
-};
-
-struct Extension : public LLInitParam::Block<Extension>
-{
-};
-
-struct SimpleContent : public LLInitParam::ChoiceBlock<SimpleContent>
-{
- Alternative<Restriction> restriction;
- Alternative<Extension> extension;
-
- SimpleContent()
- : restriction("restriction"),
- extension("extension")
- {}
-};
-
-struct SimpleType : public LLInitParam::Block<SimpleType>
-{
- // TODO
-};
-
-struct ComplexContent : public LLInitParam::Block<ComplexContent, SimpleContent>
-{
- Optional<bool> mixed;
-
- ComplexContent()
- : mixed("mixed", true)
- {}
-};
-
-struct ComplexTypeContents : public LLInitParam::ChoiceBlock<ComplexTypeContents>
-{
- Alternative<SimpleContent> simple_content;
- Alternative<ComplexContent> complex_content;
- Alternative<Group> group;
- Alternative<All> all;
- Alternative<Choice> choice;
- Alternative<Sequence> sequence;
-
- ComplexTypeContents()
- : simple_content("simpleContent"),
- complex_content("complexContent"),
- group("group"),
- all("all"),
- choice("choice"),
- sequence("sequence")
- {}
-};
-
-struct ComplexType : public LLInitParam::Block<ComplexType, ComplexTypeContents>
-{
- Optional<std::string> name;
- Optional<bool> mixed;
-
- Multiple<Attribute> attribute;
- Multiple< Lazy<Element> > elements;
-
- ComplexType()
- : name("name"),
- attribute("xs:attribute"),
- elements("xs:element"),
- mixed("mixed")
- {
- }
-};
-
-struct ElementContents : public LLInitParam::ChoiceBlock<ElementContents, Occurs>
-{
- Alternative<SimpleType> simpleType;
- Alternative<ComplexType> complexType;
-
- ElementContents()
- : simpleType("simpleType"),
- complexType("complexType")
- {}
-};
-
-struct Element : public LLInitParam::Block<Element, ElementContents>
-{
- Optional<std::string> name,
- ref,
- type;
-
- Element()
- : name("xs:name"),
- ref("xs:ref"),
- type("xs:type")
- {}
-};
-
-struct Schema : public LLInitParam::Block<Schema>
-{
-private:
- Mandatory<std::string> targetNamespace,
- xmlns,
- xs;
-
-public:
- Optional<std::string> attributeFormDefault,
- elementFormDefault;
-
- Mandatory<Element> root_element;
-
- void setNameSpace(const std::string& ns) {targetNamespace = ns; xmlns = ns;}
-
- Schema(const std::string& ns = LLStringUtil::null)
- : attributeFormDefault("attributeFormDefault"),
- elementFormDefault("elementFormDefault"),
- xs("xmlns:xs"),
- targetNamespace("targetNamespace"),
- xmlns("xmlns"),
- root_element("xs:element")
- {
- attributeFormDefault = "unqualified";
- elementFormDefault = "qualified";
- xs = "http://www.w3.org/2001/XMLSchema";
- if (!ns.empty())
- {
- setNameSpace(ns);
- };
- }
-
-};
-
-//
-// LLXSDWriter
-//
-LLXSDWriter::LLXSDWriter()
-: Parser(sXSDReadFuncs, sXSDWriteFuncs, sXSDInspectFuncs)
-{
- registerInspectFunc<bool>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:boolean", _1, _2, _3, _4));
- registerInspectFunc<std::string>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:string", _1, _2, _3, _4));
- registerInspectFunc<U8>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:unsignedByte", _1, _2, _3, _4));
- registerInspectFunc<S8>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:signedByte", _1, _2, _3, _4));
- registerInspectFunc<U16>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:unsignedShort", _1, _2, _3, _4));
- registerInspectFunc<S16>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:signedShort", _1, _2, _3, _4));
- registerInspectFunc<U32>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:unsignedInt", _1, _2, _3, _4));
- registerInspectFunc<S32>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:integer", _1, _2, _3, _4));
- registerInspectFunc<F32>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:float", _1, _2, _3, _4));
- registerInspectFunc<F64>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:double", _1, _2, _3, _4));
- registerInspectFunc<LLColor4>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:string", _1, _2, _3, _4));
- registerInspectFunc<LLUIColor>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:string", _1, _2, _3, _4));
- registerInspectFunc<LLUUID>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:string", _1, _2, _3, _4));
- registerInspectFunc<LLSD>(boost::bind(&LLXSDWriter::writeAttribute, this, "xs:string", _1, _2, _3, _4));
-}
-
-void LLXSDWriter::writeXSD(const std::string& type_name, LLXMLNodePtr node, const LLInitParam::BaseBlock& block, const std::string& xml_namespace)
-{
- Schema schema(xml_namespace);
-
- schema.root_element.name = type_name;
- Choice& choice = schema.root_element.complexType.choice;
-
- choice.minOccurs = 0;
- choice.maxOccurs = "unbounded";
-
- mSchemaNode = node;
- //node->setName("xs:schema");
- //node->createChild("attributeFormDefault", true)->setStringValue("unqualified");
- //node->createChild("elementFormDefault", true)->setStringValue("qualified");
- //node->createChild("targetNamespace", true)->setStringValue(xml_namespace);
- //node->createChild("xmlns:xs", true)->setStringValue("http://www.w3.org/2001/XMLSchema");
- //node->createChild("xmlns", true)->setStringValue(xml_namespace);
-
- //node = node->createChild("xs:complexType", false);
- //node->createChild("name", true)->setStringValue(type_name);
- //node->createChild("mixed", true)->setStringValue("true");
-
- //mAttributeNode = node;
- //mElementNode = node->createChild("xs:choice", false);
- //mElementNode->createChild("minOccurs", true)->setStringValue("0");
- //mElementNode->createChild("maxOccurs", true)->setStringValue("unbounded");
- block.inspectBlock(*this);
-
- // duplicate element choices
- LLXMLNodeList children;
- mElementNode->getChildren("xs:element", children, FALSE);
- for (LLXMLNodeList::iterator child_it = children.begin(); child_it != children.end(); ++child_it)
- {
- LLXMLNodePtr child_copy = child_it->second->deepCopy();
- std::string child_name;
- child_copy->getAttributeString("name", child_name);
- child_copy->setAttributeString("name", type_name + "." + child_name);
- mElementNode->addChild(child_copy);
- }
-
- LLXMLNodePtr element_declaration_node = mSchemaNode->createChild("xs:element", false);
- element_declaration_node->createChild("name", true)->setStringValue(type_name);
- element_declaration_node->createChild("type", true)->setStringValue(type_name);
-}
-
-void LLXSDWriter::writeAttribute(const std::string& type, const Parser::name_stack_t& stack, S32 min_count, S32 max_count, const std::vector<std::string>* possible_values)
-{
- name_stack_t non_empty_names;
- std::string attribute_name;
- for (name_stack_t::const_iterator it = stack.begin();
- it != stack.end();
- ++it)
- {
- const std::string& name = it->first;
- if (!name.empty())
- {
- non_empty_names.push_back(*it);
- }
- }
-
- for (name_stack_t::const_iterator it = non_empty_names.begin();
- it != non_empty_names.end();
- ++it)
- {
- if (!attribute_name.empty())
- {
- attribute_name += ".";
- }
- attribute_name += it->first;
- }
-
- // only flag non-nested attributes as mandatory, nested attributes have variant syntax
- // that can't be properly constrained in XSD
- // e.g. <foo mandatory.value="bar"/> vs <foo><mandatory value="bar"/></foo>
- bool attribute_mandatory = min_count == 1 && max_count == 1 && non_empty_names.size() == 1;
-
- // don't bother supporting "Multiple" params as xml attributes
- if (max_count <= 1)
- {
- // add compound attribute to root node
- addAttributeToSchema(mAttributeNode, attribute_name, type, attribute_mandatory, possible_values);
- }
-
- // now generated nested elements for compound attributes
- if (non_empty_names.size() > 1 && !attribute_mandatory)
- {
- std::string element_name;
-
- // traverse all but last element, leaving that as an attribute name
- name_stack_t::const_iterator end_it = non_empty_names.end();
- end_it--;
-
- for (name_stack_t::const_iterator it = non_empty_names.begin();
- it != end_it;
- ++it)
- {
- if (it != non_empty_names.begin())
- {
- element_name += ".";
- }
- element_name += it->first;
- }
-
- std::string short_attribute_name = non_empty_names.back().first;
-
- LLXMLNodePtr complex_type_node;
-
- // find existing element node here, starting at tail of child list
- if (mElementNode->mChildren.notNull())
- {
- for(LLXMLNodePtr element = mElementNode->mChildren->tail;
- element.notNull();
- element = element->mPrev)
- {
- std::string name;
- if(element->getAttributeString("name", name) && name == element_name)
- {
- complex_type_node = element->mChildren->head;
- break;
- }
- }
- }
- //create complex_type node
- //
- //<xs:element
- // maxOccurs="1"
- // minOccurs="0"
- // name="name">
- // <xs:complexType>
- // </xs:complexType>
- //</xs:element>
- if(complex_type_node.isNull())
- {
- complex_type_node = mElementNode->createChild("xs:element", false);
-
- complex_type_node->createChild("minOccurs", true)->setIntValue(min_count);
- complex_type_node->createChild("maxOccurs", true)->setIntValue(max_count);
- complex_type_node->createChild("name", true)->setStringValue(element_name);
- complex_type_node = complex_type_node->createChild("xs:complexType", false);
- }
-
- addAttributeToSchema(complex_type_node, short_attribute_name, type, false, possible_values);
- }
-}
-
-void LLXSDWriter::addAttributeToSchema(LLXMLNodePtr type_declaration_node, const std::string& attribute_name, const std::string& type, bool mandatory, const std::vector<std::string>* possible_values)
-{
- if (!attribute_name.empty())
- {
- LLXMLNodePtr new_enum_type_node;
- if (possible_values != NULL)
- {
- // custom attribute type, for example
- //<xs:simpleType>
- // <xs:restriction
- // base="xs:string">
- // <xs:enumeration
- // value="a" />
- // <xs:enumeration
- // value="b" />
- // </xs:restriction>
- // </xs:simpleType>
- new_enum_type_node = new LLXMLNode("xs:simpleType", false);
-
- LLXMLNodePtr restriction_node = new_enum_type_node->createChild("xs:restriction", false);
- restriction_node->createChild("base", true)->setStringValue("xs:string");
-
- for (std::vector<std::string>::const_iterator it = possible_values->begin();
- it != possible_values->end();
- ++it)
- {
- LLXMLNodePtr enum_node = restriction_node->createChild("xs:enumeration", false);
- enum_node->createChild("value", true)->setStringValue(*it);
- }
- }
-
- string_set_t& attributes_written = mAttributesWritten[type_declaration_node];
-
- string_set_t::iterator found_it = attributes_written.lower_bound(attribute_name);
-
- // attribute not yet declared
- if (found_it == attributes_written.end() || attributes_written.key_comp()(attribute_name, *found_it))
- {
- attributes_written.insert(found_it, attribute_name);
-
- LLXMLNodePtr attribute_node = type_declaration_node->createChild("xs:attribute", false);
-
- // attribute name
- attribute_node->createChild("name", true)->setStringValue(attribute_name);
-
- if (new_enum_type_node.notNull())
- {
- attribute_node->addChild(new_enum_type_node);
- }
- else
- {
- // simple attribute type
- attribute_node->createChild("type", true)->setStringValue(type);
- }
-
- // required or optional
- attribute_node->createChild("use", true)->setStringValue(mandatory ? "required" : "optional");
- }
- // attribute exists...handle collision of same name attributes with potentially different types
- else
- {
- LLXMLNodePtr attribute_declaration;
- if (type_declaration_node.notNull())
- {
- for(LLXMLNodePtr node = type_declaration_node->mChildren->tail;
- node.notNull();
- node = node->mPrev)
- {
- std::string name;
- if (node->getAttributeString("name", name) && name == attribute_name)
- {
- attribute_declaration = node;
- break;
- }
- }
- }
-
- bool new_type_is_enum = new_enum_type_node.notNull();
- bool existing_type_is_enum = !attribute_declaration->hasAttribute("type");
-
- // either type is enum, revert to string in collision
- // don't bother to check for enum equivalence
- if (new_type_is_enum || existing_type_is_enum)
- {
- if (attribute_declaration->hasAttribute("type"))
- {
- attribute_declaration->setAttributeString("type", "xs:string");
- }
- else
- {
- attribute_declaration->createChild("type", true)->setStringValue("xs:string");
- }
- attribute_declaration->deleteChildren("xs:simpleType");
- }
- else
- {
- // check for collision of different standard types
- std::string existing_type;
- attribute_declaration->getAttributeString("type", existing_type);
- // if current type is not the same as the new type, revert to strnig
- if (existing_type != type)
- {
- // ...than use most general type, string
- attribute_declaration->setAttributeString("type", "string");
- }
- }
- }
- }
-}
-
-//
-// LLXUIXSDWriter
-//
-void LLXUIXSDWriter::writeXSD(const std::string& type_name, const std::string& path, const LLInitParam::BaseBlock& block)
-{
- std::string file_name(path);
- file_name += type_name + ".xsd";
- LLXMLNodePtr root_nodep = new LLXMLNode();
-
- LLXSDWriter::writeXSD(type_name, root_nodep, block, "http://www.lindenlab.com/xui");
-
- // 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 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">
- LLXMLNodePtr widget_node = mElementNode->createChild("xs:element", false);
- widget_node->createChild("name", true)->setStringValue(widget_name);
- widget_node->createChild("type", true)->setStringValue(widget_name);
- }
- }
-
- LLFILE* xsd_file = LLFile::fopen(file_name.c_str(), "w");
- LLXMLNode::writeHeaderToFile(xsd_file);
- root_nodep->writeToFile(xsd_file);
- fclose(xsd_file);
-}
-
-static LLInitParam::Parser::parser_read_func_map_t sXUIReadFuncs;
-static LLInitParam::Parser::parser_write_func_map_t sXUIWriteFuncs;
-static LLInitParam::Parser::parser_inspect_func_map_t sXUIInspectFuncs;
-
-//
-// LLXUIParser
-//
-LLXUIParser::LLXUIParser()
-: Parser(sXUIReadFuncs, sXUIWriteFuncs, sXUIInspectFuncs),
- mCurReadDepth(0)
-{
- if (sXUIReadFuncs.empty())
- {
- registerParserFuncs<LLInitParam::Flag>(readFlag, writeFlag);
- registerParserFuncs<bool>(readBoolValue, writeBoolValue);
- registerParserFuncs<std::string>(readStringValue, writeStringValue);
- registerParserFuncs<U8>(readU8Value, writeU8Value);
- registerParserFuncs<S8>(readS8Value, writeS8Value);
- registerParserFuncs<U16>(readU16Value, writeU16Value);
- registerParserFuncs<S16>(readS16Value, writeS16Value);
- registerParserFuncs<U32>(readU32Value, writeU32Value);
- registerParserFuncs<S32>(readS32Value, writeS32Value);
- registerParserFuncs<F32>(readF32Value, writeF32Value);
- registerParserFuncs<F64>(readF64Value, writeF64Value);
- registerParserFuncs<LLColor4>(readColor4Value, writeColor4Value);
- registerParserFuncs<LLUIColor>(readUIColorValue, writeUIColorValue);
- registerParserFuncs<LLUUID>(readUUIDValue, writeUUIDValue);
- registerParserFuncs<LLSD>(readSDValue, writeSDValue);
- }
-}
-
-static LLFastTimer::DeclareTimer FTM_PARSE_XUI("XUI Parsing");
-const LLXMLNodePtr DUMMY_NODE = new LLXMLNode();
-
-void LLXUIParser::readXUI(LLXMLNodePtr node, LLInitParam::BaseBlock& block, const std::string& filename, bool silent)
-{
- LLFastTimer timer(FTM_PARSE_XUI);
- mNameStack.clear();
- mRootNodeName = node->getName()->mString;
- mCurFileName = filename;
- mCurReadDepth = 0;
- setParseSilently(silent);
-
- if (node.isNull())
- {
- parserWarning("Invalid node");
- }
- else
- {
- readXUIImpl(node, block);
- }
-}
-
-bool LLXUIParser::readXUIImpl(LLXMLNodePtr nodep, LLInitParam::BaseBlock& block)
-{
- typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
- boost::char_separator<char> sep(".");
-
- bool values_parsed = false;
- bool silent = mCurReadDepth > 0;
-
- if (nodep->getFirstChild().isNull()
- && nodep->mAttributes.empty()
- && nodep->getSanitizedValue().empty())
- {
- // empty node, just parse as flag
- mCurReadNode = DUMMY_NODE;
- return block.submitValue(mNameStack, *this, silent);
- }
-
- // submit attributes for current node
- values_parsed |= readAttributes(nodep, block);
-
- // treat text contents of xml node as "value" parameter
- std::string text_contents = nodep->getSanitizedValue();
- if (!text_contents.empty())
- {
- mCurReadNode = nodep;
- mNameStack.push_back(std::make_pair(std::string("value"), true));
- // child nodes are not necessarily valid parameters (could be a child widget)
- // so don't complain once we've recursed
- if (!block.submitValue(mNameStack, *this, true))
- {
- mNameStack.pop_back();
- block.submitValue(mNameStack, *this, silent);
- }
- else
- {
- mNameStack.pop_back();
- }
- }
-
- // then traverse children
- // child node must start with last name of parent node (our "scope")
- // for example: "<button><button.param nested_param1="foo"><param.nested_param2 nested_param3="bar"/></button.param></button>"
- // which equates to the following nesting:
- // button
- // param
- // nested_param1
- // nested_param2
- // nested_param3
- mCurReadDepth++;
- for(LLXMLNodePtr childp = nodep->getFirstChild(); childp.notNull();)
- {
- std::string child_name(childp->getName()->mString);
- S32 num_tokens_pushed = 0;
-
- // for non "dotted" child nodes check to see if child node maps to another widget type
- // and if not, treat as a child element of the current node
- // e.g. <button><rect left="10"/></button> will interpret <rect> as "button.rect"
- // since there is no widget named "rect"
- if (child_name.find(".") == std::string::npos)
- {
- mNameStack.push_back(std::make_pair(child_name, true));
- num_tokens_pushed++;
- }
- else
- {
- // parse out "dotted" name into individual tokens
- tokenizer name_tokens(child_name, sep);
-
- tokenizer::iterator name_token_it = name_tokens.begin();
- if(name_token_it == name_tokens.end())
- {
- childp = childp->getNextSibling();
- continue;
- }
-
- // check for proper nesting
- if (mNameStack.empty())
- {
- if (*name_token_it != mRootNodeName)
- {
- childp = childp->getNextSibling();
- continue;
- }
- }
- else if(mNameStack.back().first != *name_token_it)
- {
- childp = childp->getNextSibling();
- continue;
- }
-
- // now ignore first token
- ++name_token_it;
-
- // copy remaining tokens on to our running token list
- for(tokenizer::iterator token_to_push = name_token_it; token_to_push != name_tokens.end(); ++token_to_push)
- {
- mNameStack.push_back(std::make_pair(*token_to_push, true));
- num_tokens_pushed++;
- }
- }
-
- // recurse and visit children XML nodes
- if(readXUIImpl(childp, block))
- {
- // child node successfully parsed, remove from DOM
-
- values_parsed = true;
- LLXMLNodePtr node_to_remove = childp;
- childp = childp->getNextSibling();
-
- nodep->deleteChild(node_to_remove);
- }
- else
- {
- childp = childp->getNextSibling();
- }
-
- while(num_tokens_pushed-- > 0)
- {
- mNameStack.pop_back();
- }
- }
- mCurReadDepth--;
- return values_parsed;
-}
-
-bool LLXUIParser::readAttributes(LLXMLNodePtr nodep, LLInitParam::BaseBlock& block)
-{
- typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
- boost::char_separator<char> sep(".");
-
- bool any_parsed = false;
- bool silent = mCurReadDepth > 0;
-
- for(LLXMLAttribList::const_iterator attribute_it = nodep->mAttributes.begin();
- attribute_it != nodep->mAttributes.end();
- ++attribute_it)
- {
- S32 num_tokens_pushed = 0;
- std::string attribute_name(attribute_it->first->mString);
- mCurReadNode = attribute_it->second;
-
- tokenizer name_tokens(attribute_name, sep);
- // copy remaining tokens on to our running token list
- for(tokenizer::iterator token_to_push = name_tokens.begin(); token_to_push != name_tokens.end(); ++token_to_push)
- {
- mNameStack.push_back(std::make_pair(*token_to_push, true));
- num_tokens_pushed++;
- }
-
- // child nodes are not necessarily valid attributes, so don't complain once we've recursed
- any_parsed |= block.submitValue(mNameStack, *this, silent);
-
- while(num_tokens_pushed-- > 0)
- {
- mNameStack.pop_back();
- }
- }
-
- return any_parsed;
-}
-
-void LLXUIParser::writeXUI(LLXMLNodePtr node, const LLInitParam::BaseBlock &block, const LLInitParam::BaseBlock* diff_block)
-{
- mWriteRootNode = node;
- name_stack_t name_stack = Parser::name_stack_t();
- block.serializeBlock(*this, name_stack, diff_block);
- mOutNodes.clear();
-}
-
-// go from a stack of names to a specific XML node
-LLXMLNodePtr LLXUIParser::getNode(name_stack_t& stack)
-{
- LLXMLNodePtr out_node = mWriteRootNode;
-
- name_stack_t::iterator next_it = stack.begin();
- for (name_stack_t::iterator it = stack.begin();
- it != stack.end();
- it = next_it)
- {
- ++next_it;
- if (it->first.empty())
- {
- it->second = false;
- continue;
- }
-
- out_nodes_t::iterator found_it = mOutNodes.find(it->first);
-
- // node with this name not yet written
- if (found_it == mOutNodes.end() || it->second)
- {
- // make an attribute if we are the last element on the name stack
- bool is_attribute = next_it == stack.end();
- LLXMLNodePtr new_node = new LLXMLNode(it->first.c_str(), is_attribute);
- out_node->addChild(new_node);
- mOutNodes[it->first] = new_node;
- out_node = new_node;
- it->second = false;
- }
- else
- {
- out_node = found_it->second;
- }
- }
-
- return (out_node == mWriteRootNode ? LLXMLNodePtr(NULL) : out_node);
-}
-
-bool LLXUIParser::readFlag(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- return self.mCurReadNode == DUMMY_NODE;
-}
-
-bool LLXUIParser::writeFlag(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- // just create node
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- return node.notNull();
-}
-
-bool LLXUIParser::readBoolValue(Parser& parser, void* val_ptr)
-{
- S32 value;
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- bool success = self.mCurReadNode->getBoolValue(1, &value);
- *((bool*)val_ptr) = (value != FALSE);
- return success;
-}
-
-bool LLXUIParser::writeBoolValue(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- node->setBoolValue(*((bool*)val_ptr));
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readStringValue(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- *((std::string*)val_ptr) = self.mCurReadNode->getSanitizedValue();
- return true;
-}
-
-bool LLXUIParser::writeStringValue(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- const std::string* string_val = reinterpret_cast<const std::string*>(val_ptr);
- if (string_val->find('\n') != std::string::npos
- || string_val->size() > MAX_STRING_ATTRIBUTE_SIZE)
- {
- // don't write strings with newlines into attributes
- std::string attribute_name = node->getName()->mString;
- LLXMLNodePtr parent_node = node->mParent;
- parent_node->deleteChild(node);
- // write results in text contents of node
- if (attribute_name == "value")
- {
- // "value" is implicit, just write to parent
- node = parent_node;
- }
- else
- {
- // create a child that is not an attribute, but with same name
- node = parent_node->createChild(attribute_name.c_str(), false);
- }
- }
- node->setStringValue(*string_val);
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readU8Value(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- return self.mCurReadNode->getByteValue(1, (U8*)val_ptr);
-}
-
-bool LLXUIParser::writeU8Value(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- node->setUnsignedValue(*((U8*)val_ptr));
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readS8Value(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- S32 value;
- if(self.mCurReadNode->getIntValue(1, &value))
- {
- *((S8*)val_ptr) = value;
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::writeS8Value(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- node->setIntValue(*((S8*)val_ptr));
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readU16Value(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- U32 value;
- if(self.mCurReadNode->getUnsignedValue(1, &value))
- {
- *((U16*)val_ptr) = value;
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::writeU16Value(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- node->setUnsignedValue(*((U16*)val_ptr));
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readS16Value(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- S32 value;
- if(self.mCurReadNode->getIntValue(1, &value))
- {
- *((S16*)val_ptr) = value;
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::writeS16Value(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- node->setIntValue(*((S16*)val_ptr));
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readU32Value(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- return self.mCurReadNode->getUnsignedValue(1, (U32*)val_ptr);
-}
-
-bool LLXUIParser::writeU32Value(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- node->setUnsignedValue(*((U32*)val_ptr));
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readS32Value(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- return self.mCurReadNode->getIntValue(1, (S32*)val_ptr);
-}
-
-bool LLXUIParser::writeS32Value(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- node->setIntValue(*((S32*)val_ptr));
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readF32Value(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- return self.mCurReadNode->getFloatValue(1, (F32*)val_ptr);
-}
-
-bool LLXUIParser::writeF32Value(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- node->setFloatValue(*((F32*)val_ptr));
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readF64Value(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- return self.mCurReadNode->getDoubleValue(1, (F64*)val_ptr);
-}
-
-bool LLXUIParser::writeF64Value(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- node->setDoubleValue(*((F64*)val_ptr));
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readColor4Value(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLColor4* colorp = (LLColor4*)val_ptr;
- if(self.mCurReadNode->getFloatValue(4, colorp->mV) >= 3)
- {
- return true;
- }
-
- return false;
-}
-
-bool LLXUIParser::writeColor4Value(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- LLColor4 color = *((LLColor4*)val_ptr);
- node->setFloatValue(4, color.mV);
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readUIColorValue(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLUIColor* param = (LLUIColor*)val_ptr;
- LLColor4 color;
- bool success = self.mCurReadNode->getFloatValue(4, color.mV) >= 3;
- if (success)
- {
- param->set(color);
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::writeUIColorValue(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- LLUIColor color = *((LLUIColor*)val_ptr);
- //RN: don't write out the color that is represented by a function
- // rely on param block exporting to get the reference to the color settings
- if (color.isReference()) return false;
- node->setFloatValue(4, color.get().mV);
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readUUIDValue(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLUUID temp_id;
- // LLUUID::set is destructive, so use temporary value
- if (temp_id.set(self.mCurReadNode->getSanitizedValue()))
- {
- *(LLUUID*)(val_ptr) = temp_id;
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::writeUUIDValue(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- node->setStringValue(((LLUUID*)val_ptr)->asString());
- return true;
- }
- return false;
-}
-
-bool LLXUIParser::readSDValue(Parser& parser, void* val_ptr)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
- *((LLSD*)val_ptr) = LLSD(self.mCurReadNode->getSanitizedValue());
- return true;
-}
-
-bool LLXUIParser::writeSDValue(Parser& parser, const void* val_ptr, name_stack_t& stack)
-{
- LLXUIParser& self = static_cast<LLXUIParser&>(parser);
-
- LLXMLNodePtr node = self.getNode(stack);
- if (node.notNull())
- {
- std::string string_val = ((LLSD*)val_ptr)->asString();
- if (string_val.find('\n') != std::string::npos || string_val.size() > MAX_STRING_ATTRIBUTE_SIZE)
- {
- // don't write strings with newlines into attributes
- std::string attribute_name = node->getName()->mString;
- LLXMLNodePtr parent_node = node->mParent;
- parent_node->deleteChild(node);
- // write results in text contents of node
- if (attribute_name == "value")
- {
- // "value" is implicit, just write to parent
- node = parent_node;
- }
- else
- {
- node = parent_node->createChild(attribute_name.c_str(), false);
- }
- }
-
- node->setStringValue(string_val);
- return true;
- }
- return false;
-}
-
-/*virtual*/ std::string LLXUIParser::getCurrentElementName()
-{
- std::string full_name;
- for (name_stack_t::iterator it = mNameStack.begin();
- it != mNameStack.end();
- ++it)
- {
- full_name += it->first + "."; // build up dotted names: "button.param.nestedparam."
- }
-
- return full_name;
-}
-
-void LLXUIParser::parserWarning(const std::string& message)
-{
-#ifdef LL_WINDOWS
- // use Visual Studo friendly formatting of output message for easy access to originating xml
- llutf16string utf16str = utf8str_to_utf16str(llformat("%s(%d):\t%s", mCurFileName.c_str(), mCurReadNode->getLineNumber(), message.c_str()).c_str());
- utf16str += '\n';
- OutputDebugString(utf16str.c_str());
-#else
- Parser::parserWarning(message);
-#endif
-}
-
-void LLXUIParser::parserError(const std::string& message)
-{
-#ifdef LL_WINDOWS
- llutf16string utf16str = utf8str_to_utf16str(llformat("%s(%d):\t%s", mCurFileName.c_str(), mCurReadNode->getLineNumber(), message.c_str()).c_str());
- utf16str += '\n';
- OutputDebugString(utf16str.c_str());
-#else
- Parser::parserError(message);
-#endif
-}
-
-
-//
-// LLSimpleXUIParser
-//
-
-struct ScopedFile
-{
- ScopedFile( const std::string& filename, const char* accessmode )
- {
- mFile = LLFile::fopen(filename, accessmode);
- }
-
- ~ScopedFile()
- {
- fclose(mFile);
- mFile = NULL;
- }
-
- S32 getRemainingBytes()
- {
- if (!isOpen()) return 0;
-
- S32 cur_pos = ftell(mFile);
- fseek(mFile, 0L, SEEK_END);
- S32 file_size = ftell(mFile);
- fseek(mFile, cur_pos, SEEK_SET);
- return file_size - cur_pos;
- }
-
- bool isOpen() { return mFile != NULL; }
-
- LLFILE* mFile;
-};
-LLSimpleXUIParser::LLSimpleXUIParser(LLSimpleXUIParser::element_start_callback_t element_cb)
-: Parser(sSimpleXUIReadFuncs, sSimpleXUIWriteFuncs, sSimpleXUIInspectFuncs),
- mCurReadDepth(0),
- mElementCB(element_cb)
-{
- if (sSimpleXUIReadFuncs.empty())
- {
- registerParserFuncs<LLInitParam::Flag>(readFlag);
- registerParserFuncs<bool>(readBoolValue);
- registerParserFuncs<std::string>(readStringValue);
- registerParserFuncs<U8>(readU8Value);
- registerParserFuncs<S8>(readS8Value);
- registerParserFuncs<U16>(readU16Value);
- registerParserFuncs<S16>(readS16Value);
- registerParserFuncs<U32>(readU32Value);
- registerParserFuncs<S32>(readS32Value);
- registerParserFuncs<F32>(readF32Value);
- registerParserFuncs<F64>(readF64Value);
- registerParserFuncs<LLColor4>(readColor4Value);
- registerParserFuncs<LLUIColor>(readUIColorValue);
- registerParserFuncs<LLUUID>(readUUIDValue);
- registerParserFuncs<LLSD>(readSDValue);
- }
-}
-
-LLSimpleXUIParser::~LLSimpleXUIParser()
-{
-}
-
-
-bool LLSimpleXUIParser::readXUI(const std::string& filename, LLInitParam::BaseBlock& block, bool silent)
-{
- LLFastTimer timer(FTM_PARSE_XUI);
-
- mParser = XML_ParserCreate(NULL);
- XML_SetUserData(mParser, this);
- XML_SetElementHandler( mParser, startElementHandler, endElementHandler);
- XML_SetCharacterDataHandler( mParser, characterDataHandler);
-
- mOutputStack.push_back(std::make_pair(&block, 0));
- mNameStack.clear();
- mCurFileName = filename;
- mCurReadDepth = 0;
- setParseSilently(silent);
-
- ScopedFile file(filename, "rb");
- if( !file.isOpen() )
- {
- LL_WARNS("ReadXUI") << "Unable to open file " << filename << LL_ENDL;
- XML_ParserFree( mParser );
- return false;
- }
-
- S32 bytes_read = 0;
-
- S32 buffer_size = file.getRemainingBytes();
- void* buffer = XML_GetBuffer(mParser, buffer_size);
- if( !buffer )
- {
- LL_WARNS("ReadXUI") << "Unable to allocate XML buffer while reading file " << filename << LL_ENDL;
- XML_ParserFree( mParser );
- return false;
- }
-
- bytes_read = (S32)fread(buffer, 1, buffer_size, file.mFile);
- if( bytes_read <= 0 )
- {
- LL_WARNS("ReadXUI") << "Error while reading file " << filename << LL_ENDL;
- XML_ParserFree( mParser );
- return false;
- }
-
- mEmptyLeafNode.push_back(false);
-
- if( !XML_ParseBuffer(mParser, bytes_read, TRUE ) )
- {
- LL_WARNS("ReadXUI") << "Error while parsing file " << filename << LL_ENDL;
- XML_ParserFree( mParser );
- return false;
- }
-
- mEmptyLeafNode.pop_back();
-
- XML_ParserFree( mParser );
- return true;
-}
-
-void LLSimpleXUIParser::startElementHandler(void *userData, const char *name, const char **atts)
-{
- LLSimpleXUIParser* self = reinterpret_cast<LLSimpleXUIParser*>(userData);
- self->startElement(name, atts);
-}
-
-void LLSimpleXUIParser::endElementHandler(void *userData, const char *name)
-{
- LLSimpleXUIParser* self = reinterpret_cast<LLSimpleXUIParser*>(userData);
- self->endElement(name);
-}
-
-void LLSimpleXUIParser::characterDataHandler(void *userData, const char *s, int len)
-{
- LLSimpleXUIParser* self = reinterpret_cast<LLSimpleXUIParser*>(userData);
- self->characterData(s, len);
-}
-
-void LLSimpleXUIParser::characterData(const char *s, int len)
-{
- mTextContents += std::string(s, len);
-}
-
-void LLSimpleXUIParser::startElement(const char *name, const char **atts)
-{
- processText();
-
- typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
- boost::char_separator<char> sep(".");
-
- if (mElementCB)
- {
- LLInitParam::BaseBlock* blockp = mElementCB(*this, name);
- if (blockp)
- {
- mOutputStack.push_back(std::make_pair(blockp, 0));
- }
- }
-
- mOutputStack.back().second++;
- S32 num_tokens_pushed = 0;
- std::string child_name(name);
-
- if (mOutputStack.back().second == 1)
- { // root node for this block
- mScope.push_back(child_name);
- }
- else
- { // compound attribute
- if (child_name.find(".") == std::string::npos)
- {
- mNameStack.push_back(std::make_pair(child_name, true));
- num_tokens_pushed++;
- mScope.push_back(child_name);
- }
- else
- {
- // parse out "dotted" name into individual tokens
- tokenizer name_tokens(child_name, sep);
-
- tokenizer::iterator name_token_it = name_tokens.begin();
- if(name_token_it == name_tokens.end())
- {
- return;
- }
-
- // check for proper nesting
- if(!mScope.empty() && *name_token_it != mScope.back())
- {
- return;
- }
-
- // now ignore first token
- ++name_token_it;
-
- // copy remaining tokens on to our running token list
- for(tokenizer::iterator token_to_push = name_token_it; token_to_push != name_tokens.end(); ++token_to_push)
- {
- mNameStack.push_back(std::make_pair(*token_to_push, true));
- num_tokens_pushed++;
- }
- mScope.push_back(mNameStack.back().first);
- }
- }
-
- // parent node is not empty
- mEmptyLeafNode.back() = false;
- // we are empty if we have no attributes
- mEmptyLeafNode.push_back(atts[0] == NULL);
-
- mTokenSizeStack.push_back(num_tokens_pushed);
- readAttributes(atts);
-
-}
-
-void LLSimpleXUIParser::endElement(const char *name)
-{
- bool has_text = processText();
-
- // no text, attributes, or children
- if (!has_text && mEmptyLeafNode.back())
- {
- // submit this as a valueless name (even though there might be text contents we haven't seen yet)
- mCurAttributeValueBegin = NO_VALUE_MARKER;
- mOutputStack.back().first->submitValue(mNameStack, *this, mParseSilently);
- }
-
- if (--mOutputStack.back().second == 0)
- {
- if (mOutputStack.empty())
- {
- LL_ERRS("ReadXUI") << "Parameter block output stack popped while empty." << LL_ENDL;
- }
- mOutputStack.pop_back();
- }
-
- S32 num_tokens_to_pop = mTokenSizeStack.back();
- mTokenSizeStack.pop_back();
- while(num_tokens_to_pop-- > 0)
- {
- mNameStack.pop_back();
- }
- mScope.pop_back();
- mEmptyLeafNode.pop_back();
-}
-
-bool LLSimpleXUIParser::readAttributes(const char **atts)
-{
- typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
- boost::char_separator<char> sep(".");
-
- bool any_parsed = false;
- for(S32 i = 0; atts[i] && atts[i+1]; i += 2 )
- {
- std::string attribute_name(atts[i]);
- mCurAttributeValueBegin = atts[i+1];
-
- S32 num_tokens_pushed = 0;
- tokenizer name_tokens(attribute_name, sep);
- // copy remaining tokens on to our running token list
- for(tokenizer::iterator token_to_push = name_tokens.begin(); token_to_push != name_tokens.end(); ++token_to_push)
- {
- mNameStack.push_back(std::make_pair(*token_to_push, true));
- num_tokens_pushed++;
- }
-
- // child nodes are not necessarily valid attributes, so don't complain once we've recursed
- any_parsed |= mOutputStack.back().first->submitValue(mNameStack, *this, mParseSilently);
-
- while(num_tokens_pushed-- > 0)
- {
- mNameStack.pop_back();
- }
- }
- return any_parsed;
-}
-
-bool LLSimpleXUIParser::processText()
-{
- if (!mTextContents.empty())
- {
- LLStringUtil::trim(mTextContents);
- if (!mTextContents.empty())
- {
- mNameStack.push_back(std::make_pair(std::string("value"), true));
- mCurAttributeValueBegin = mTextContents.c_str();
- mOutputStack.back().first->submitValue(mNameStack, *this, mParseSilently);
- mNameStack.pop_back();
- }
- mTextContents.clear();
- return true;
- }
- return false;
-}
-
-/*virtual*/ std::string LLSimpleXUIParser::getCurrentElementName()
-{
- std::string full_name;
- for (name_stack_t::iterator it = mNameStack.begin();
- it != mNameStack.end();
- ++it)
- {
- full_name += it->first + "."; // build up dotted names: "button.param.nestedparam."
- }
-
- return full_name;
-}
-
-void LLSimpleXUIParser::parserWarning(const std::string& message)
-{
-#ifdef LL_WINDOWS
- // use Visual Studo friendly formatting of output message for easy access to originating xml
- llutf16string utf16str = utf8str_to_utf16str(llformat("%s(%d):\t%s", mCurFileName.c_str(), LINE_NUMBER_HERE, message.c_str()).c_str());
- utf16str += '\n';
- OutputDebugString(utf16str.c_str());
-#else
- Parser::parserWarning(message);
-#endif
-}
-
-void LLSimpleXUIParser::parserError(const std::string& message)
-{
-#ifdef LL_WINDOWS
- llutf16string utf16str = utf8str_to_utf16str(llformat("%s(%d):\t%s", mCurFileName.c_str(), LINE_NUMBER_HERE, message.c_str()).c_str());
- utf16str += '\n';
- OutputDebugString(utf16str.c_str());
-#else
- Parser::parserError(message);
-#endif
-}
-
-bool LLSimpleXUIParser::readFlag(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- return self.mCurAttributeValueBegin == NO_VALUE_MARKER;
-}
-
-bool LLSimpleXUIParser::readBoolValue(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- if (!strcmp(self.mCurAttributeValueBegin, "true"))
- {
- *((bool*)val_ptr) = true;
- return true;
- }
- else if (!strcmp(self.mCurAttributeValueBegin, "false"))
- {
- *((bool*)val_ptr) = false;
- return true;
- }
-
- return false;
-}
-
-bool LLSimpleXUIParser::readStringValue(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- *((std::string*)val_ptr) = self.mCurAttributeValueBegin;
- return true;
-}
-
-bool LLSimpleXUIParser::readU8Value(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- return parse(self.mCurAttributeValueBegin, uint_p[assign_a(*(U8*)val_ptr)]).full;
-}
-
-bool LLSimpleXUIParser::readS8Value(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- return parse(self.mCurAttributeValueBegin, int_p[assign_a(*(S8*)val_ptr)]).full;
-}
-
-bool LLSimpleXUIParser::readU16Value(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- return parse(self.mCurAttributeValueBegin, uint_p[assign_a(*(U16*)val_ptr)]).full;
-}
-
-bool LLSimpleXUIParser::readS16Value(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- return parse(self.mCurAttributeValueBegin, int_p[assign_a(*(S16*)val_ptr)]).full;
-}
-
-bool LLSimpleXUIParser::readU32Value(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- return parse(self.mCurAttributeValueBegin, uint_p[assign_a(*(U32*)val_ptr)]).full;
-}
-
-bool LLSimpleXUIParser::readS32Value(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- return parse(self.mCurAttributeValueBegin, int_p[assign_a(*(S32*)val_ptr)]).full;
-}
-
-bool LLSimpleXUIParser::readF32Value(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- return parse(self.mCurAttributeValueBegin, real_p[assign_a(*(F32*)val_ptr)]).full;
-}
-
-bool LLSimpleXUIParser::readF64Value(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- return parse(self.mCurAttributeValueBegin, real_p[assign_a(*(F64*)val_ptr)]).full;
-}
-
-bool LLSimpleXUIParser::readColor4Value(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- LLColor4 value;
-
- if (parse(self.mCurAttributeValueBegin, real_p[assign_a(value.mV[0])] >> real_p[assign_a(value.mV[1])] >> real_p[assign_a(value.mV[2])] >> real_p[assign_a(value.mV[3])], space_p).full)
- {
- *(LLColor4*)(val_ptr) = value;
- return true;
- }
- return false;
-}
-
-bool LLSimpleXUIParser::readUIColorValue(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- LLColor4 value;
- LLUIColor* colorp = (LLUIColor*)val_ptr;
-
- if (parse(self.mCurAttributeValueBegin, real_p[assign_a(value.mV[0])] >> real_p[assign_a(value.mV[1])] >> real_p[assign_a(value.mV[2])] >> real_p[assign_a(value.mV[3])], space_p).full)
- {
- colorp->set(value);
- return true;
- }
- return false;
-}
-
-bool LLSimpleXUIParser::readUUIDValue(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- LLUUID temp_id;
- // LLUUID::set is destructive, so use temporary value
- if (temp_id.set(std::string(self.mCurAttributeValueBegin)))
- {
- *(LLUUID*)(val_ptr) = temp_id;
- return true;
- }
- return false;
-}
-
-bool LLSimpleXUIParser::readSDValue(Parser& parser, void* val_ptr)
-{
- LLSimpleXUIParser& self = static_cast<LLSimpleXUIParser&>(parser);
- *((LLSD*)val_ptr) = LLSD(self.mCurAttributeValueBegin);
- return true;
-}
diff --git a/indra/llxuixml/llxuiparser.h b/indra/llxuixml/llxuiparser.h
deleted file mode 100644
index d7cd256967..0000000000
--- a/indra/llxuixml/llxuiparser.h
+++ /dev/null
@@ -1,242 +0,0 @@
-/**
- * @file llxuiparser.h
- * @brief Utility functions for handling XUI structures in XML
- *
- * $LicenseInfo:firstyear=2003&license=viewerlgpl$
- * Second Life Viewer Source Code
- * Copyright (C) 2010, Linden Research, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation;
- * version 2.1 of the License only.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
- * $/LicenseInfo$
- */
-
-#ifndef LLXUIPARSER_H
-#define LLXUIPARSER_H
-
-#include "llinitparam.h"
-#include "llregistry.h"
-#include "llpointer.h"
-
-#include <boost/function.hpp>
-#include <iosfwd>
-#include <stack>
-#include <set>
-
-
-
-class LLView;
-
-
-typedef LLPointer<class LLXMLNode> LLXMLNodePtr;
-
-
-// lookup widget type by name
-class LLWidgetTypeRegistry
-: public LLRegistrySingleton<std::string, const std::type_info*, LLWidgetTypeRegistry>
-{};
-
-
-// global static instance for registering all widget types
-typedef boost::function<LLView* (LLXMLNodePtr node, LLView *parent, LLXMLNodePtr output_node)> LLWidgetCreatorFunc;
-
-typedef LLRegistry<std::string, LLWidgetCreatorFunc> widget_registry_t;
-
-class LLChildRegistryRegistry
-: public LLRegistrySingleton<const std::type_info*, widget_registry_t, LLChildRegistryRegistry>
-{};
-
-
-
-class LLXSDWriter : public LLInitParam::Parser
-{
- LOG_CLASS(LLXSDWriter);
-public:
- void writeXSD(const std::string& name, LLXMLNodePtr node, const LLInitParam::BaseBlock& block, const std::string& xml_namespace);
-
- /*virtual*/ std::string getCurrentElementName() { return LLStringUtil::null; }
-
- LLXSDWriter();
-
-protected:
- void writeAttribute(const std::string& type, const Parser::name_stack_t&, S32 min_count, S32 max_count, const std::vector<std::string>* possible_values);
- void addAttributeToSchema(LLXMLNodePtr nodep, const std::string& attribute_name, const std::string& type, bool mandatory, const std::vector<std::string>* possible_values);
- LLXMLNodePtr mAttributeNode;
- LLXMLNodePtr mElementNode;
- LLXMLNodePtr mSchemaNode;
-
- typedef std::set<std::string> string_set_t;
- typedef std::map<LLXMLNodePtr, string_set_t> attributes_map_t;
- attributes_map_t mAttributesWritten;
-};
-
-
-
-// NOTE: DOES NOT WORK YET
-// should support child widgets for XUI
-class LLXUIXSDWriter : public LLXSDWriter
-{
-public:
- void writeXSD(const std::string& name, const std::string& path, const LLInitParam::BaseBlock& block);
-};
-
-
-class LLXUIParserImpl;
-
-class LLXUIParser : public LLInitParam::Parser
-{
-LOG_CLASS(LLXUIParser);
-
-public:
- LLXUIParser();
- typedef LLInitParam::Parser::name_stack_t name_stack_t;
-
- /*virtual*/ std::string getCurrentElementName();
- /*virtual*/ void parserWarning(const std::string& message);
- /*virtual*/ void parserError(const std::string& message);
-
- void readXUI(LLXMLNodePtr node, LLInitParam::BaseBlock& block, const std::string& filename = LLStringUtil::null, bool silent=false);
- void writeXUI(LLXMLNodePtr node, const LLInitParam::BaseBlock& block, const LLInitParam::BaseBlock* diff_block = NULL);
-
-private:
- bool readXUIImpl(LLXMLNodePtr node, LLInitParam::BaseBlock& block);
- bool readAttributes(LLXMLNodePtr nodep, LLInitParam::BaseBlock& block);
-
- //reader helper functions
- static bool readFlag(Parser& parser, void* val_ptr);
- static bool readBoolValue(Parser& parser, void* val_ptr);
- static bool readStringValue(Parser& parser, void* val_ptr);
- static bool readU8Value(Parser& parser, void* val_ptr);
- static bool readS8Value(Parser& parser, void* val_ptr);
- static bool readU16Value(Parser& parser, void* val_ptr);
- static bool readS16Value(Parser& parser, void* val_ptr);
- static bool readU32Value(Parser& parser, void* val_ptr);
- 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 readColor4Value(Parser& parser, void* val_ptr);
- static bool readUIColorValue(Parser& parser, void* val_ptr);
- static bool readUUIDValue(Parser& parser, void* val_ptr);
- static bool readSDValue(Parser& parser, void* val_ptr);
-
- //writer helper functions
- static bool writeFlag(Parser& parser, const void* val_ptr, name_stack_t&);
- static bool writeBoolValue(Parser& parser, const void* val_ptr, name_stack_t&);
- static bool writeStringValue(Parser& parser, const void* val_ptr, name_stack_t&);
- static bool writeU8Value(Parser& parser, const void* val_ptr, name_stack_t&);
- static bool writeS8Value(Parser& parser, const void* val_ptr, name_stack_t&);
- static bool writeU16Value(Parser& parser, const void* val_ptr, name_stack_t&);
- static bool writeS16Value(Parser& parser, const void* val_ptr, name_stack_t&);
- static bool writeU32Value(Parser& parser, const void* val_ptr, name_stack_t&);
- 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 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&);
- static bool writeSDValue(Parser& parser, const void* val_ptr, name_stack_t&);
-
- LLXMLNodePtr getNode(name_stack_t& stack);
-
-private:
- Parser::name_stack_t mNameStack;
- LLXMLNodePtr mCurReadNode;
- // Root of the widget XML sub-tree, for example, "line_editor"
- LLXMLNodePtr mWriteRootNode;
-
- typedef std::map<std::string, LLXMLNodePtr> out_nodes_t;
- out_nodes_t mOutNodes;
- LLXMLNodePtr mLastWrittenChild;
- S32 mCurReadDepth;
- std::string mCurFileName;
- std::string mRootNodeName;
-};
-
-// LLSimpleXUIParser is a streamlined SAX-based XUI parser that does not support localization
-// or parsing of a tree of independent param blocks, such as child widgets.
-// Use this for reading non-localized files that only need a single param block as a result.
-//
-// NOTE: In order to support nested block parsing, we need callbacks for start element that
-// push new blocks contexts on the mScope stack.
-// NOTE: To support localization without building a DOM, we need to enforce consistent
-// ordering of child elements from base file to localized diff file. Then we can use a pair
-// of coroutines to perform matching of xml nodes during parsing. Not sure if the overhead
-// of coroutines would offset the gain from SAX parsing
-class LLSimpleXUIParserImpl;
-
-class LLSimpleXUIParser : public LLInitParam::Parser
-{
-LOG_CLASS(LLSimpleXUIParser);
-public:
- typedef LLInitParam::Parser::name_stack_t name_stack_t;
- typedef LLInitParam::BaseBlock* (*element_start_callback_t)(LLSimpleXUIParser&, const char* block_name);
-
- LLSimpleXUIParser(element_start_callback_t element_cb = NULL);
- virtual ~LLSimpleXUIParser();
-
- /*virtual*/ std::string getCurrentElementName();
- /*virtual*/ void parserWarning(const std::string& message);
- /*virtual*/ void parserError(const std::string& message);
-
- bool readXUI(const std::string& filename, LLInitParam::BaseBlock& block, bool silent=false);
-
-
-private:
- //reader helper functions
- static bool readFlag(Parser&, void* val_ptr);
- static bool readBoolValue(Parser&, void* val_ptr);
- static bool readStringValue(Parser&, void* val_ptr);
- static bool readU8Value(Parser&, void* val_ptr);
- static bool readS8Value(Parser&, void* val_ptr);
- static bool readU16Value(Parser&, void* val_ptr);
- static bool readS16Value(Parser&, void* val_ptr);
- static bool readU32Value(Parser&, void* val_ptr);
- static bool readS32Value(Parser&, void* val_ptr);
- static bool readF32Value(Parser&, void* val_ptr);
- static bool readF64Value(Parser&, void* val_ptr);
- static bool readColor4Value(Parser&, void* val_ptr);
- static bool readUIColorValue(Parser&, void* val_ptr);
- static bool readUUIDValue(Parser&, void* val_ptr);
- static bool readSDValue(Parser&, void* val_ptr);
-
-private:
- static void startElementHandler(void *userData, const char *name, const char **atts);
- static void endElementHandler(void *userData, const char *name);
- static void characterDataHandler(void *userData, const char *s, int len);
-
- void startElement(const char *name, const char **atts);
- void endElement(const char *name);
- void characterData(const char *s, int len);
- bool readAttributes(const char **atts);
- bool processText();
-
- Parser::name_stack_t mNameStack;
- struct XML_ParserStruct* mParser;
- LLXMLNodePtr mLastWrittenChild;
- S32 mCurReadDepth;
- std::string mCurFileName;
- std::string mTextContents;
- const char* mCurAttributeValueBegin;
- std::vector<S32> mTokenSizeStack;
- std::vector<std::string> mScope;
- std::vector<bool> mEmptyLeafNode;
- element_start_callback_t mElementCB;
-
- std::vector<std::pair<LLInitParam::BaseBlock*, S32> > mOutputStack;
-};
-
-
-#endif //LLXUIPARSER_H