summaryrefslogtreecommitdiff
path: root/indra/llui/llsdparam.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llui/llsdparam.cpp')
-rw-r--r--indra/llui/llsdparam.cpp272
1 files changed, 150 insertions, 122 deletions
diff --git a/indra/llui/llsdparam.cpp b/indra/llui/llsdparam.cpp
index 9ad13054cb..0e29873bb0 100644
--- a/indra/llui/llsdparam.cpp
+++ b/indra/llui/llsdparam.cpp
@@ -34,6 +34,9 @@
static LLInitParam::Parser::parser_read_func_map_t sReadFuncs;
static LLInitParam::Parser::parser_write_func_map_t sWriteFuncs;
static LLInitParam::Parser::parser_inspect_func_map_t sInspectFuncs;
+static const LLSD NO_VALUE_MARKER;
+
+LLFastTimer::DeclareTimer FTM_SD_PARAM_ADAPTOR("LLSD to LLInitParam conversion");
//
// LLParamSDParser
@@ -45,7 +48,7 @@ LLParamSDParser::LLParamSDParser()
if (sReadFuncs.empty())
{
- registerParserFuncs<LLInitParam::NoParamValue>(readNoValue, &LLParamSDParser::writeNoValue);
+ registerParserFuncs<LLInitParam::Flag>(readFlag, &LLParamSDParser::writeFlag);
registerParserFuncs<S32>(readS32, &LLParamSDParser::writeTypedValue<S32>);
registerParserFuncs<U32>(readU32, &LLParamSDParser::writeU32Param);
registerParserFuncs<F32>(readF32, &LLParamSDParser::writeTypedValue<F32>);
@@ -60,29 +63,34 @@ LLParamSDParser::LLParamSDParser()
}
// special case handling of U32 due to ambiguous LLSD::assign overload
-bool LLParamSDParser::writeU32Param(LLParamSDParser::parser_t& parser, const void* val_ptr, const parser_t::name_stack_t& name_stack)
+bool LLParamSDParser::writeU32Param(LLParamSDParser::parser_t& parser, const void* val_ptr, parser_t::name_stack_t& name_stack)
{
LLParamSDParser& sdparser = static_cast<LLParamSDParser&>(parser);
if (!sdparser.mWriteRootSD) return false;
- LLSD* sd_to_write = sdparser.getSDWriteNode(name_stack);
- if (!sd_to_write) return false;
+ parser_t::name_stack_range_t range(name_stack.begin(), name_stack.end());
+ LLSD& sd_to_write = LLParamSDParserUtilities::getSDWriteNode(*sdparser.mWriteRootSD, range);
+ sd_to_write.assign((S32)*((const U32*)val_ptr));
- sd_to_write->assign((S32)*((const U32*)val_ptr));
return true;
}
-bool LLParamSDParser::writeNoValue(LLParamSDParser::parser_t& parser, const void* val_ptr, const parser_t::name_stack_t& name_stack)
+bool LLParamSDParser::writeFlag(LLParamSDParser::parser_t& parser, const void* val_ptr, parser_t::name_stack_t& name_stack)
{
LLParamSDParser& sdparser = static_cast<LLParamSDParser&>(parser);
if (!sdparser.mWriteRootSD) return false;
- LLSD* sd_to_write = sdparser.getSDWriteNode(name_stack);
- if (!sd_to_write) return false;
+ parser_t::name_stack_range_t range(name_stack.begin(), name_stack.end());
+ LLParamSDParserUtilities::getSDWriteNode(*sdparser.mWriteRootSD, range);
return true;
}
+void LLParamSDParser::submit(LLInitParam::BaseBlock& block, const LLSD& sd, LLInitParam::Parser::name_stack_t& name_stack)
+{
+ mCurReadSD = &sd;
+ block.submitValue(name_stack, *this);
+}
void LLParamSDParser::readSD(const LLSD& sd, LLInitParam::BaseBlock& block, bool silent)
{
@@ -90,51 +98,17 @@ void LLParamSDParser::readSD(const LLSD& sd, LLInitParam::BaseBlock& block, bool
mNameStack.clear();
setParseSilently(silent);
- readSDValues(sd, block);
+ LLParamSDParserUtilities::readSDValues(boost::bind(&LLParamSDParser::submit, this, boost::ref(block), _1, _2), sd, mNameStack);
+ //readSDValues(sd, block);
}
void LLParamSDParser::writeSD(LLSD& sd, const LLInitParam::BaseBlock& block)
{
mNameStack.clear();
mWriteRootSD = &sd;
- block.serializeBlock(*this);
-}
-
-const LLSD NO_VALUE_MARKER;
-void LLParamSDParser::readSDValues(const LLSD& sd, LLInitParam::BaseBlock& block)
-{
- if (sd.isMap())
- {
- for (LLSD::map_const_iterator it = sd.beginMap();
- it != sd.endMap();
- ++it)
- {
- mNameStack.push_back(make_pair(it->first, newParseGeneration()));
- readSDValues(it->second, block);
- mNameStack.pop_back();
- }
- }
- else if (sd.isArray())
- {
- for (LLSD::array_const_iterator it = sd.beginArray();
- it != sd.endArray();
- ++it)
- {
- mNameStack.back().second = newParseGeneration();
- readSDValues(*it, block);
- }
- }
- else if (sd.isUndefined())
- {
- mCurReadSD = &NO_VALUE_MARKER;
- block.submitValue(mNameStack, *this);
- }
- else
- {
- mCurReadSD = &sd;
- block.submitValue(mNameStack, *this);
- }
+ name_stack_t name_stack;
+ block.serializeBlock(*this, name_stack);
}
/*virtual*/ std::string LLParamSDParser::getCurrentElementName()
@@ -150,83 +124,8 @@ void LLParamSDParser::readSDValues(const LLSD& sd, LLInitParam::BaseBlock& block
return full_name;
}
-LLSD* LLParamSDParser::getSDWriteNode(const parser_t::name_stack_t& name_stack)
-{
- //TODO: implement nested LLSD writing
- LLSD* sd_to_write = mWriteRootSD;
- bool new_traversal = false;
- for (name_stack_t::const_iterator it = name_stack.begin(), prev_it = mNameStack.begin();
- it != name_stack.end();
- ++it)
- {
- bool new_array_entry = false;
- if (prev_it == mNameStack.end())
- {
- new_traversal = true;
- }
- else
- {
- if (!new_traversal // have not diverged yet from previous trace
- && prev_it->first == it->first // names match
- && prev_it->second != it->second) // versions differ
- {
- // name stacks match, but version numbers differ in last place.
- // create a different entry at this point using an LLSD array
- new_array_entry = true;
- }
- if (prev_it->first != it->first // names differ
- || prev_it->second != it->second) // versions differ
- {
- // at this point we have diverged from our last trace
- // so any elements referenced here are new
- new_traversal = true;
- }
- }
-
- LLSD* child_sd = &(*sd_to_write)[it->first];
- if (child_sd->isArray())
- {
- if (new_traversal)
- {
- // write to new element at end
- sd_to_write = &(*child_sd)[child_sd->size()];
- }
- else
- {
- // write to last of existing elements, or first element if empty
- sd_to_write = &(*child_sd)[llmax(0, child_sd->size() - 1)];
- }
- }
- else
- {
- if (new_array_entry && !child_sd->isArray())
- {
- // copy child contents into first element of an array
- LLSD new_array = LLSD::emptyArray();
- new_array.append(*child_sd);
- // assign array to slot that previously held the single value
- *child_sd = new_array;
- // return next element in that array
- sd_to_write = &((*child_sd)[1]);
- }
- else
- {
- sd_to_write = child_sd;
- }
- }
- if (prev_it != mNameStack.end())
- {
- ++prev_it;
- }
- }
- mNameStack = name_stack;
-
- //llinfos << ll_pretty_print_sd(*mWriteRootSD) << llendl;
- return sd_to_write;
-}
-
-bool LLParamSDParser::readNoValue(Parser& parser, void* val_ptr)
+bool LLParamSDParser::readFlag(Parser& parser, void* val_ptr)
{
LLParamSDParser& self = static_cast<LLParamSDParser&>(parser);
return self.mCurReadSD == &NO_VALUE_MARKER;
@@ -312,3 +211,132 @@ bool LLParamSDParser::readSD(Parser& parser, void* val_ptr)
*((LLSD*)val_ptr) = *self.mCurReadSD;
return true;
}
+
+// static
+LLSD& LLParamSDParserUtilities::getSDWriteNode(LLSD& input, LLInitParam::Parser::name_stack_range_t& name_stack_range)
+{
+ LLSD* sd_to_write = &input;
+
+ for (LLInitParam::Parser::name_stack_t::iterator it = name_stack_range.first;
+ it != name_stack_range.second;
+ ++it)
+ {
+ bool new_traversal = it->second;
+
+ LLSD* child_sd = it->first.empty() ? sd_to_write : &(*sd_to_write)[it->first];
+
+ if (child_sd->isArray())
+ {
+ if (new_traversal)
+ {
+ // write to new element at end
+ sd_to_write = &(*child_sd)[child_sd->size()];
+ }
+ else
+ {
+ // write to last of existing elements, or first element if empty
+ sd_to_write = &(*child_sd)[llmax(0, child_sd->size() - 1)];
+ }
+ }
+ else
+ {
+ if (new_traversal
+ && child_sd->isDefined()
+ && !child_sd->isArray())
+ {
+ // copy child contents into first element of an array
+ LLSD new_array = LLSD::emptyArray();
+ new_array.append(*child_sd);
+ // assign array to slot that previously held the single value
+ *child_sd = new_array;
+ // return next element in that array
+ sd_to_write = &((*child_sd)[1]);
+ }
+ else
+ {
+ sd_to_write = child_sd;
+ }
+ }
+ it->second = false;
+ }
+
+ return *sd_to_write;
+}
+
+//static
+void LLParamSDParserUtilities::readSDValues(read_sd_cb_t cb, const LLSD& sd, LLInitParam::Parser::name_stack_t& stack)
+{
+ if (sd.isMap())
+ {
+ for (LLSD::map_const_iterator it = sd.beginMap();
+ it != sd.endMap();
+ ++it)
+ {
+ stack.push_back(make_pair(it->first, true));
+ readSDValues(cb, it->second, stack);
+ stack.pop_back();
+ }
+ }
+ else if (sd.isArray())
+ {
+ for (LLSD::array_const_iterator it = sd.beginArray();
+ it != sd.endArray();
+ ++it)
+ {
+ stack.back().second = true;
+ readSDValues(cb, *it, stack);
+ }
+ }
+ else if (sd.isUndefined())
+ {
+ if (!cb.empty())
+ {
+ cb(NO_VALUE_MARKER, stack);
+ }
+ }
+ else
+ {
+ if (!cb.empty())
+ {
+ cb(sd, stack);
+ }
+ }
+}
+
+//static
+void LLParamSDParserUtilities::readSDValues(read_sd_cb_t cb, const LLSD& sd)
+{
+ LLInitParam::Parser::name_stack_t stack = LLInitParam::Parser::name_stack_t();
+ readSDValues(cb, sd, stack);
+}
+namespace LLInitParam
+{
+ // LLSD specialization
+ // block param interface
+ bool ParamValue<LLSD, TypeValues<LLSD>, false>::deserializeBlock(Parser& p, Parser::name_stack_range_t name_stack, bool new_name)
+ {
+ LLSD& sd = LLParamSDParserUtilities::getSDWriteNode(mValue, name_stack);
+
+ LLSD::String string;
+
+ if (p.readValue<LLSD::String>(string))
+ {
+ sd = string;
+ return true;
+ }
+ return false;
+ }
+
+ //static
+ void ParamValue<LLSD, TypeValues<LLSD>, false>::serializeElement(Parser& p, const LLSD& sd, Parser::name_stack_t& name_stack)
+ {
+ p.writeValue<LLSD::String>(sd.asString(), name_stack);
+ }
+
+ void ParamValue<LLSD, TypeValues<LLSD>, false>::serializeBlock(Parser& p, Parser::name_stack_t& name_stack, const BaseBlock* diff_block) const
+ {
+ // read from LLSD value and serialize out to parser (which could be LLSD, XUI, etc)
+ Parser::name_stack_t stack;
+ LLParamSDParserUtilities::readSDValues(boost::bind(&serializeElement, boost::ref(p), _1, _2), mValue, stack);
+ }
+}