summaryrefslogtreecommitdiff
path: root/indra/llcommon/llsd.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llcommon/llsd.cpp')
-rw-r--r--indra/llcommon/llsd.cpp103
1 files changed, 65 insertions, 38 deletions
diff --git a/indra/llcommon/llsd.cpp b/indra/llcommon/llsd.cpp
index ecca4c9b71..6ca0737445 100644
--- a/indra/llcommon/llsd.cpp
+++ b/indra/llcommon/llsd.cpp
@@ -2,30 +2,25 @@
* @file llsd.cpp
* @brief LLSD flexible data system
*
- * $LicenseInfo:firstyear=2005&license=viewergpl$
- *
- * Copyright (c) 2005-2007, Linden Research, Inc.
- *
+ * $LicenseInfo:firstyear=2005&license=viewerlgpl$
* Second Life Viewer Source Code
- * The source code in this file ("Source Code") is provided by Linden Lab
- * to you under the terms of the GNU General Public License, version 2.0
- * ("GPL"), unless you have obtained a separate licensing agreement
- * ("Other License"), formally executed by you and Linden Lab. Terms of
- * the GPL can be found in doc/GPL-license.txt in this distribution, or
- * online at http://secondlife.com/developers/opensource/gplv2
+ * Copyright (C) 2010, Linden Research, Inc.
*
- * There are special exceptions to the terms and conditions of the GPL as
- * it is applied to this Source Code. View the full text of the exception
- * in the file doc/FLOSS-exception.txt in this software distribution, or
- * online at http://secondlife.com/developers/opensource/flossexception
+ * 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.
*
- * By copying, modifying or distributing this software, you acknowledge
- * that you have read and understood your obligations described above,
- * and agree to abide by those obligations.
+ * 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.
*
- * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
- * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
- * COMPLETENESS OR PERFORMANCE.
+ * 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$
*/
@@ -42,10 +37,11 @@
#endif
#ifdef NAME_UNNAMED_NAMESPACE
-namespace LLSDUnnamedNamespace {
+namespace LLSDUnnamedNamespace
#else
-namespace {
+namespace
#endif
+{
class ImplMap;
class ImplArray;
}
@@ -127,10 +123,10 @@ public:
virtual void erase(Integer) { }
virtual const LLSD& ref(Integer) const { return undef(); }
- virtual LLSD::map_const_iterator beginMap() const { return LLSD::map_const_iterator(); }
- virtual LLSD::map_const_iterator endMap() const { return LLSD::map_const_iterator(); }
- virtual LLSD::array_const_iterator beginArray() const { return LLSD::array_const_iterator(); }
- virtual LLSD::array_const_iterator endArray() const { return LLSD::array_const_iterator(); }
+ virtual LLSD::map_const_iterator beginMap() const { return endMap(); }
+ virtual LLSD::map_const_iterator endMap() const { static const std::map<String, LLSD> empty; return empty.end(); }
+ virtual LLSD::array_const_iterator beginArray() const { return endArray(); }
+ virtual LLSD::array_const_iterator endArray() const { static const std::vector<LLSD> empty; return empty.end(); }
static const LLSD& undef();
@@ -139,10 +135,11 @@ public:
};
#ifdef NAME_UNNAMED_NAMESPACE
-namespace LLSDUnnamedNamespace {
+namespace LLSDUnnamedNamespace
#else
-namespace {
+namespace
#endif
+{
template<LLSD::Type T, class Data, class DataRef = Data>
class ImplBase : public LLSD::Impl
///< This class handles most of the work for a subclass of Impl
@@ -159,6 +156,7 @@ namespace {
virtual LLSD::Type type() const { return T; }
+ using LLSD::Impl::assign; // Unhiding base class virtuals...
virtual void assign(LLSD::Impl*& var, DataRef value) {
if (shared())
{
@@ -185,6 +183,11 @@ namespace {
};
LLSD::String ImplBoolean::asString() const
+ // *NOTE: The reason that false is not converted to "false" is
+ // because that would break roundtripping,
+ // e.g. LLSD(false).asString().asBoolean(). There are many
+ // reasons for wanting LLSD("false").asBoolean() == true, such
+ // as "everything else seems to work that way".
{ return mValue ? "true" : ""; }
@@ -341,8 +344,12 @@ namespace {
virtual LLSD::Boolean asBoolean() const { return !mData.empty(); }
virtual bool has(const LLSD::String&) const;
+
+ using LLSD::Impl::get; // Unhiding get(LLSD::Integer)
+ using LLSD::Impl::erase; // Unhiding erase(LLSD::Integer)
+ using LLSD::Impl::ref; // Unhiding ref(LLSD::Integer)
virtual LLSD get(const LLSD::String&) const;
- void insert(const LLSD::String& k, const LLSD& v);
+ void insert(const LLSD::String& k, const LLSD& v);
virtual void erase(const LLSD::String&);
LLSD& ref(const LLSD::String&);
virtual const LLSD& ref(const LLSD::String&) const;
@@ -426,6 +433,9 @@ namespace {
virtual LLSD::Boolean asBoolean() const { return !mData.empty(); }
+ using LLSD::Impl::get; // Unhiding get(LLSD::String)
+ using LLSD::Impl::erase; // Unhiding erase(LLSD::String)
+ using LLSD::Impl::ref; // Unhiding ref(LLSD::String)
virtual int size() const;
virtual LLSD get(LLSD::Integer) const;
void set(LLSD::Integer, const LLSD&);
@@ -480,7 +490,9 @@ namespace {
void ImplArray::insert(LLSD::Integer i, const LLSD& v)
{
- if (i < 0) { return; }
+ if (i < 0) {
+ return;
+ }
DataVector::size_type index = i;
if (index >= mData.size())
@@ -650,10 +662,11 @@ U32 LLSD::Impl::sOutstandingCount = 0;
#ifdef NAME_UNNAMED_NAMESPACE
-namespace LLSDUnnamedNamespace {
+namespace LLSDUnnamedNamespace
#else
-namespace {
+namespace
#endif
+{
inline LLSD::Impl& safe(LLSD::Impl* impl)
{ return LLSD::Impl::safe(impl); }
@@ -730,9 +743,13 @@ LLSD LLSD::emptyMap()
bool LLSD::has(const String& k) const { return safe(impl).has(k); }
LLSD LLSD::get(const String& k) const { return safe(impl).get(k); }
+void LLSD::insert(const String& k, const LLSD& v) { makeMap(impl).insert(k, v); }
-void LLSD::insert(const String& k, const LLSD& v)
- { makeMap(impl).insert(k, v); }
+LLSD& LLSD::with(const String& k, const LLSD& v)
+ {
+ makeMap(impl).insert(k, v);
+ return *this;
+ }
void LLSD::erase(const String& k) { makeMap(impl).erase(k); }
LLSD& LLSD::operator[](const String& k)
@@ -752,9 +769,13 @@ int LLSD::size() const { return safe(impl).size(); }
LLSD LLSD::get(Integer i) const { return safe(impl).get(i); }
void LLSD::set(Integer i, const LLSD& v){ makeArray(impl).set(i, v); }
+void LLSD::insert(Integer i, const LLSD& v) { makeArray(impl).insert(i, v); }
-void LLSD::insert(Integer i, const LLSD& v)
- { makeArray(impl).insert(i, v); }
+LLSD& LLSD::with(Integer i, const LLSD& v)
+ {
+ makeArray(impl).insert(i, v);
+ return *this;
+ }
void LLSD::append(const LLSD& v) { makeArray(impl).append(v); }
void LLSD::erase(Integer i) { makeArray(impl).erase(i); }
@@ -780,9 +801,15 @@ static const char *llsd_dump(const LLSD &llsd, bool useXMLFormat)
{
std::ostringstream out;
if (useXMLFormat)
- out << LLSDXMLStreamer(llsd);
+ {
+ LLSDXMLStreamer xml_streamer(llsd);
+ out << xml_streamer;
+ }
else
- out << LLSDNotationStreamer(llsd);
+ {
+ LLSDNotationStreamer notation_streamer(llsd);
+ out << notation_streamer;
+ }
out_string = out.str();
}
int len = out_string.length();