aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llcommon/llsdutil.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:45:27 -0500
committerJacek Antonelli2008-08-15 23:45:27 -0500
commita8a62201ba762e98dff92cf49033e577fc34d8d4 (patch)
tree11f8513c5cdc222f2fac0c93eb724c089803c200 /linden/indra/llcommon/llsdutil.cpp
parentSecond Life viewer sources 1.18.6.4-RC (diff)
downloadmeta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.zip
meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.gz
meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.bz2
meta-impy-a8a62201ba762e98dff92cf49033e577fc34d8d4.tar.xz
Second Life viewer sources 1.19.0.0
Diffstat (limited to '')
-rw-r--r--linden/indra/llcommon/llsdutil.cpp124
1 files changed, 122 insertions, 2 deletions
diff --git a/linden/indra/llcommon/llsdutil.cpp b/linden/indra/llcommon/llsdutil.cpp
index c4be282..d1ccce0 100644
--- a/linden/indra/llcommon/llsdutil.cpp
+++ b/linden/indra/llcommon/llsdutil.cpp
@@ -14,12 +14,12 @@
14 * ("GPL"), unless you have obtained a separate licensing agreement 14 * ("GPL"), unless you have obtained a separate licensing agreement
15 * ("Other License"), formally executed by you and Linden Lab. Terms of 15 * ("Other License"), formally executed by you and Linden Lab. Terms of
16 * the GPL can be found in doc/GPL-license.txt in this distribution, or 16 * the GPL can be found in doc/GPL-license.txt in this distribution, or
17 * online at http://secondlife.com/developers/opensource/gplv2 17 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
18 * 18 *
19 * There are special exceptions to the terms and conditions of the GPL as 19 * There are special exceptions to the terms and conditions of the GPL as
20 * it is applied to this Source Code. View the full text of the exception 20 * it is applied to this Source Code. View the full text of the exception
21 * in the file doc/FLOSS-exception.txt in this software distribution, or 21 * in the file doc/FLOSS-exception.txt in this software distribution, or
22 * online at http://secondlife.com/developers/opensource/flossexception 22 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
23 * 23 *
24 * By copying, modifying or distributing this software, you acknowledge 24 * By copying, modifying or distributing this software, you acknowledge
25 * that you have read and understood your obligations described above, 25 * that you have read and understood your obligations described above,
@@ -301,3 +301,123 @@ char* ll_pretty_print_sd(const LLSD& sd)
301 buffer[bufferSize - 1] = '\0'; 301 buffer[bufferSize - 1] = '\0';
302 return buffer; 302 return buffer;
303} 303}
304
305//compares the structure of an LLSD to a template LLSD and stores the
306//"valid" values in a 3rd LLSD. Default values are stored in the template
307//
308//If the llsd to test has a specific key to a map and the values
309//are not of the same type, false is returned or if the LLSDs are not
310//of the same value. Ordering of arrays matters
311//Otherwise, returns true
312BOOL compare_llsd_with_template(
313 const LLSD& llsd_to_test,
314 const LLSD& template_llsd,
315 LLSD& resultant_llsd)
316{
317 if (
318 llsd_to_test.isUndefined() &&
319 template_llsd.isDefined() )
320 {
321 resultant_llsd = template_llsd;
322 return TRUE;
323 }
324 else if ( llsd_to_test.type() != template_llsd.type() )
325 {
326 resultant_llsd = LLSD();
327 return FALSE;
328 }
329
330 if ( llsd_to_test.isArray() )
331 {
332 //they are both arrays
333 //we loop over all the items in the template
334 //verifying that the to_test has a subset (in the same order)
335 //any shortcoming in the testing_llsd are just taken
336 //to be the rest of the template
337 LLSD data;
338 LLSD::array_const_iterator test_iter;
339 LLSD::array_const_iterator template_iter;
340
341 resultant_llsd = LLSD::emptyArray();
342 test_iter = llsd_to_test.beginArray();
343
344 for (
345 template_iter = template_llsd.beginArray();
346 (template_iter != template_llsd.endArray() &&
347 test_iter != llsd_to_test.endArray());
348 ++template_iter)
349 {
350 if ( !compare_llsd_with_template(
351 *test_iter,
352 *template_iter,
353 data) )
354 {
355 resultant_llsd = LLSD();
356 return FALSE;
357 }
358 else
359 {
360 resultant_llsd.append(data);
361 }
362
363 ++test_iter;
364 }
365
366 //so either the test or the template ended
367 //we do another loop now to the end of the template
368 //grabbing the default values
369 for (;
370 template_iter != template_llsd.endArray();
371 ++template_iter)
372 {
373 resultant_llsd.append(*template_iter);
374 }
375 }
376 else if ( llsd_to_test.isMap() )
377 {
378 //now we loop over the keys of the two maps
379 //any excess is taken from the template
380 //excess is ignored in the test
381 LLSD value;
382 LLSD::map_const_iterator template_iter;
383
384 resultant_llsd = LLSD::emptyMap();
385 for (
386 template_iter = template_llsd.beginMap();
387 template_iter != template_llsd.endMap();
388 ++template_iter)
389 {
390 if ( llsd_to_test.has(template_iter->first) )
391 {
392 //the test LLSD has the same key
393 if ( !compare_llsd_with_template(
394 llsd_to_test[template_iter->first],
395 template_iter->second,
396 value) )
397 {
398 resultant_llsd = LLSD();
399 return FALSE;
400 }
401 else
402 {
403 resultant_llsd[template_iter->first] = value;
404 }
405 }
406 else
407 {
408 //test llsd doesn't have it...take the
409 //template as default value
410 resultant_llsd[template_iter->first] =
411 template_iter->second;
412 }
413 }
414 }
415 else
416 {
417 //of same type...take the test llsd's value
418 resultant_llsd = llsd_to_test;
419 }
420
421
422 return TRUE;
423}