fixed: in Space: pointers 'name' and 'child_spaces' were not correctly initialized in cctors

added in Space:
- some methods for adding values to an object, such as:
  Space & Space::add(const std::wstring & field, bool val) (bool, short, int, long, long long etc.)
- methods for creating lists:
  void Space::to_list(std::list<std::string> & output_list, bool clear_list) const
  bool Space::to_list(const wchar_t * field, std::list<std::string> & output_list, bool clear_list) const
- methods for converting a value from an object field:
  bool Space::to_bool(const wchar_t * field, bool default_value) const
- methods for testing strings:
  bool Space::is_equal(const char * val) const
  bool Space::is_equal(const std::string & val) const
  bool Space::is_equal(const wchar_t * val) const
  bool Space::is_equal(const std::wstring & val) const
- methods to get the raw pointer to a value from an object, such as:
  bool * Space::get_bool(const wchar_t * field)
  float * Space::get_float(const wchar_t * field)
- methods for finding a child space (used in Space format only)
  Space * Space::find_child_space(const wchar_t * name)
  Space & Space::find_add_child_space(const wchar_t * name)
pull/4/head
Tomasz Sowa 2 years ago
parent 0aeac12fa0
commit a2339eed34

@ -49,14 +49,13 @@ namespace PT
Space::Space()
{
type = type_null;
child_spaces = nullptr;
name = nullptr;
initialize();
}
Space::Space(const Space & space)
{
initialize();
copy_from(space);
}
@ -78,84 +77,100 @@ Space::~Space()
Space::Space(bool val)
{
initialize();
set(val);
}
Space::Space(short val)
{
initialize();
set(val);
}
Space::Space(int val)
{
initialize();
set(val);
}
Space::Space(long val)
{
initialize();
set(val);
}
Space::Space(long long val)
{
initialize();
set(val);
}
Space::Space(unsigned short val)
{
initialize();
set(val);
}
Space::Space(unsigned int val)
{
initialize();
set(val);
}
Space::Space(unsigned long val)
{
initialize();
set(val);
}
Space::Space(unsigned long long val)
{
initialize();
set(val);
}
Space::Space(float val)
{
initialize();
set(val);
}
Space::Space(double val)
{
initialize();
set(val);
}
Space::Space(const char * str)
{
initialize();
set(str);
}
Space::Space(const wchar_t * str)
{
initialize();
set(str);
}
Space::Space(const std::string & str)
{
initialize();
set(str);
}
Space::Space(const std::wstring & str)
{
initialize();
set(str);
}
Space::Space(const Space * space)
{
initialize();
set(space);
}
@ -387,6 +402,10 @@ Space & Space::add(const Space * space)
return add_generic(space);
}
Space & Space::add_empty_space()
{
return add_generic(static_cast<Space*>(nullptr));
}
@ -476,6 +495,99 @@ Space & Space::add_empty_space(const wchar_t * field)
return add_generic(field, static_cast<Space*>(nullptr));
}
Space & Space::add(const std::wstring & field, bool val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, short val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, int val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, long val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, long long val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, unsigned short val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, unsigned int val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, unsigned long val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, unsigned long long val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, float val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, double val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, const char * val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, const wchar_t * val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, const std::string & val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, const std::wstring & val)
{
return add_generic(field, val);
}
Space & Space::add(const std::wstring & field, const Space * space)
{
return add_generic(field, space);
}
Space & Space::add_empty_space(const std::wstring & field)
{
return add_generic(field, static_cast<Space*>(nullptr));
}
Space & Space::add_child_space(const wchar_t * space_name)
{
initialize_child_spaces_if_needed();
@ -554,6 +666,9 @@ bool Space::is_table() const
bool Space::to_bool() const
{
if( type == type_bool )
return value.value_bool;
long long val = to_long_long();
return (val != 0) ? true : false;
}
@ -737,9 +852,7 @@ std::wstring Space::to_wstr() const
if( type == type_string )
{
PT::WTextStream stream;
serialize_string_buffer(value.value_string.c_str(), stream, Escape::no_escape);
stream.to_string(str);
PT::UTF8ToWide(value.value_string, str);
return str;
}
@ -748,6 +861,314 @@ std::wstring Space::to_wstr() const
}
void Space::to_list(std::list<std::string> & output_list, bool clear_list) const
{
to_list_str_generic(output_list, clear_list);
}
void Space::to_list(std::list<std::wstring> & output_list, bool clear_list) const
{
to_list_wstr_generic(output_list, clear_list);
}
void Space::to_list(std::vector<std::string> & output_list, bool clear_list) const
{
to_list_str_generic(output_list, clear_list);
}
void Space::to_list(std::vector<std::wstring> & output_list, bool clear_list) const
{
to_list_wstr_generic(output_list, clear_list);
}
bool Space::to_bool(const wchar_t * field, bool default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_bool() : default_value;
}
short Space::to_short(const wchar_t * field, short default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_short() : default_value;
}
int Space::to_int(const wchar_t * field, int default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_int() : default_value;
}
long Space::to_long(const wchar_t * field, long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_long() : default_value;
}
long long Space::to_llong(const wchar_t * field, long long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_llong() : default_value;
}
long long Space::to_long_long(const wchar_t * field, long long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_long_long() : default_value;
}
unsigned short Space::to_ushort(const wchar_t * field, unsigned short default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_ushort() : default_value;
}
unsigned int Space::to_uint(const wchar_t * field, unsigned int default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_uint() : default_value;
}
unsigned long Space::to_ulong(const wchar_t * field, unsigned long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_ulong() : default_value;
}
unsigned long long Space::to_ullong(const wchar_t * field, unsigned long long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_ullong() : default_value;
}
unsigned long long Space::to_ulong_long(const wchar_t * field, unsigned long long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_ulong_long() : default_value;
}
std::string Space::to_str(const wchar_t * field, const char * default_value) const
{
const Space * space = get_object_field(field);
if( space )
{
return space->to_str();
}
if( default_value )
{
return std::string(default_value);
}
return std::string();
}
std::string Space::to_str(const wchar_t * field, const std::string & default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_str() : default_value;
}
std::wstring Space::to_wstr(const wchar_t * field, const wchar_t * default_value) const
{
const Space * space = get_object_field(field);
if( space )
{
return space->to_wstr();
}
if( default_value )
{
return std::wstring(default_value);
}
return std::wstring();
}
std::wstring Space::to_wstr(const wchar_t * field, const std::wstring & default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_wstr() : default_value;
}
bool Space::to_list(const wchar_t * field, std::list<std::string> & output_list, bool clear_list) const
{
return to_list_generic(field, output_list, clear_list);
}
bool Space::to_list(const wchar_t * field, std::list<std::wstring> & output_list, bool clear_list) const
{
return to_list_generic(field, output_list, clear_list);
}
bool Space::to_list(const std::wstring & field, std::list<std::string> & output_list, bool clear_list) const
{
return to_list_generic(field, output_list, clear_list);
}
bool Space::to_list(const std::wstring & field, std::list<std::wstring> & output_list, bool clear_list) const
{
return to_list_generic(field, output_list, clear_list);
}
bool Space::to_list(const wchar_t * field, std::vector<std::string> & output_list, bool clear_list) const
{
return to_list_generic(field, output_list, clear_list);
}
bool Space::to_list(const wchar_t * field, std::vector<std::wstring> & output_list, bool clear_list) const
{
return to_list_generic(field, output_list, clear_list);
}
bool Space::to_list(const std::wstring & field, std::vector<std::string> & output_list, bool clear_list) const
{
return to_list_generic(field, output_list, clear_list);
}
bool Space::to_list(const std::wstring & field, std::vector<std::wstring> & output_list, bool clear_list) const
{
return to_list_generic(field, output_list, clear_list);
}
bool Space::to_bool(const std::wstring & field, bool default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_bool() : default_value;
}
short Space::to_short(const std::wstring & field, short default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_short() : default_value;
}
int Space::to_int(const std::wstring & field, int default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_int() : default_value;
}
long Space::to_long(const std::wstring & field, long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_long() : default_value;
}
long long Space::to_llong(const std::wstring & field, long long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_llong() : default_value;
}
long long Space::to_long_long(const std::wstring & field, long long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_long_long() : default_value;
}
unsigned short Space::to_ushort(const std::wstring & field, unsigned short default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_ushort() : default_value;
}
unsigned int Space::to_uint(const std::wstring & field, unsigned int default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_uint() : default_value;
}
unsigned long Space::to_ulong(const std::wstring & field, unsigned long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_ulong() : default_value;
}
unsigned long long Space::to_ullong(const std::wstring & field, unsigned long long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_ullong() : default_value;
}
unsigned long long Space::to_ulong_long(const std::wstring & field, unsigned long long default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_ulong_long() : default_value;
}
std::string Space::to_str(const std::wstring & field, const char * default_value) const
{
const Space * space = get_object_field(field);
if( space )
{
return space->to_str();
}
if( default_value )
{
return std::string(default_value);
}
return std::string();
}
std::string Space::to_str(const std::wstring & field, const std::string & default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_str() : default_value;
}
std::wstring Space::to_wstr(const std::wstring & field, const wchar_t * default_value) const
{
const Space * space = get_object_field(field);
if( space )
{
return space->to_wstr();
}
if( default_value )
{
return std::wstring(default_value);
}
return std::wstring();
}
std::wstring Space::to_wstr(const std::wstring & field, const std::wstring & default_value) const
{
const Space * space = get_object_field(field);
return space ? space->to_wstr() : default_value;
}
std::string Space::serialize_to_space_str(bool pretty_print) const
{
std::string str;
@ -843,12 +1264,12 @@ double * Space::get_double()
return type == type_double ? &value.value_double : nullptr;
}
std::string * Space::get_string()
std::string * Space::get_str()
{
return type == type_string ? &value.value_string : nullptr;
}
std::wstring * Space::get_wstring()
std::wstring * Space::get_wstr()
{
return type == type_wstring ? &value.value_wstring : nullptr;
}
@ -863,6 +1284,121 @@ Space::TableType * Space::get_table()
return type == type_table ? &value.value_table : nullptr;
}
bool Space::is_equal(const char * val) const
{
if( type == type_string )
{
return value.value_string == val;
}
return false;
}
bool Space::is_equal(const std::string & val) const
{
if( type == type_string )
{
return value.value_string == val;
}
return false;
}
bool Space::is_equal(const wchar_t * val) const
{
if( type == type_wstring )
{
return value.value_wstring == val;
}
return false;
}
bool Space::is_equal(const std::wstring & val) const
{
if( type == type_wstring )
{
return value.value_wstring == val;
}
return false;
}
Space * Space::get_object_field(const wchar_t * field)
{
if( is_object() )
{
ObjectType::iterator i = value.value_object.find(field);
if( i != value.value_object.end() )
{
return i->second;
}
}
return nullptr;
}
bool * Space::get_bool(const wchar_t * field)
{
Space * space = get_object_field(field);
return space ? space->get_bool() : nullptr;
}
long long * Space::get_llong(const wchar_t * field)
{
Space * space = get_object_field(field);
return space ? space->get_llong() : nullptr;
}
long long * Space::get_long_long(const wchar_t * field)
{
Space * space = get_object_field(field);
return space ? space->get_long_long() : nullptr;
}
float * Space::get_float(const wchar_t * field)
{
Space * space = get_object_field(field);
return space ? space->get_float() : nullptr;
}
double * Space::get_double(const wchar_t * field)
{
Space * space = get_object_field(field);
return space ? space->get_double() : nullptr;
}
std::string * Space::get_str(const wchar_t * field)
{
Space * space = get_object_field(field);
return space ? space->get_str() : nullptr;
}
std::wstring * Space::get_wstr(const wchar_t * field)
{
Space * space = get_object_field(field);
return space ? space->get_wstr() : nullptr;
}
Space::ObjectType * Space::get_object(const wchar_t * field)
{
Space * space = get_object_field(field);
return space ? space->get_object() : nullptr;
}
Space::TableType * Space::get_table(const wchar_t * field)
{
Space * space = get_object_field(field);
return space ? space->get_table() : nullptr;
}
@ -892,12 +1428,12 @@ const double * Space::get_double() const
return type == type_double ? &value.value_double : nullptr;
}
const std::string * Space::get_string() const
const std::string * Space::get_str() const
{
return type == type_string ? &value.value_string : nullptr;
}
const std::wstring * Space::get_wstring() const
const std::wstring * Space::get_wstr() const
{
return type == type_wstring ? &value.value_wstring : nullptr;
}
@ -914,6 +1450,221 @@ const Space::TableType * Space::get_table() const
bool Space::has_key(const wchar_t * field) const
{
return get_object_field(field) != nullptr;
}
bool Space::has_key(const std::wstring & field) const
{
return get_object_field(field) != nullptr;
}
const Space * Space::get_object_field(const wchar_t * field) const
{
if( is_object() )
{
ObjectType::const_iterator i = value.value_object.find(field);
if( i != value.value_object.end() )
{
return i->second;
}
}
return nullptr;
}
const Space * Space::get_object_field(const std::wstring & field) const
{
return get_object_field(field.c_str());
}
const bool * Space::get_bool(const wchar_t * field) const
{
const Space * space = get_object_field(field);
return space ? space->get_bool() : nullptr;
}
const long long * Space::get_llong(const wchar_t * field) const
{
const Space * space = get_object_field(field);
return space ? space->get_llong() : nullptr;
}
const long long * Space::get_long_long(const wchar_t * field) const
{
const Space * space = get_object_field(field);
return space ? space->get_long_long() : nullptr;
}
const float * Space::get_float(const wchar_t * field) const
{
const Space * space = get_object_field(field);
return space ? space->get_float() : nullptr;
}
const double * Space::get_double(const wchar_t * field) const
{
const Space * space = get_object_field(field);
return space ? space->get_double() : nullptr;
}
const std::string * Space::get_str(const wchar_t * field) const
{
const Space * space = get_object_field(field);
return space ? space->get_str() : nullptr;
}
const std::wstring * Space::get_wstr(const wchar_t * field) const
{
const Space * space = get_object_field(field);
return space ? space->get_wstr() : nullptr;
}
const Space::ObjectType * Space::get_object(const wchar_t * field) const
{
const Space * space = get_object_field(field);
return space ? space->get_object() : nullptr;
}
const Space::TableType * Space::get_table(const wchar_t * field) const
{
const Space * space = get_object_field(field);
return space ? space->get_table() : nullptr;
}
void Space::remove(const wchar_t * field)
{
remove(std::wstring(field));
}
void Space::remove(const std::wstring & field)
{
if( type == type_object )
{
ObjectType::iterator i = value.value_object.find(field);
if( i != value.value_object.end() )
{
delete i->second;
i->second = nullptr;
value.value_object.erase(i);
}
}
}
bool Space::is_equal(const wchar_t * field, const char * val) const
{
const Space * space = get_object_field(field);
if( space )
{
return space->is_equal(val);
}
return false;
}
bool Space::is_equal(const wchar_t * field, const std::string & val) const
{
const Space * space = get_object_field(field);
if( space )
{
return space->is_equal(val);
}
return false;
}
bool Space::is_equal(const wchar_t * field, const wchar_t * val) const
{
const Space * space = get_object_field(field);
if( space )
{
return space->is_equal(val);
}
return false;
}
bool Space::is_equal(const wchar_t * field, const std::wstring & val) const
{
const Space * space = get_object_field(field);
if( space )
{
return space->is_equal(val);
}
return false;
}
Space * Space::find_child_space(const wchar_t * name)
{
return find_child_space_generic(name);
}
Space * Space::find_child_space(const std::wstring & name)
{
return find_child_space_generic(name);
}
const Space * Space::find_child_space(const wchar_t * name) const
{
return find_child_space_generic(name);
}
const Space * Space::find_child_space(const std::wstring & name) const
{
return find_child_space_generic(name);
}
Space & Space::find_add_child_space(const wchar_t * name)
{
Space * space = find_child_space(name);
if( !space )
{
return add_child_space(name);
}
return *space;
}
Space & Space::find_add_child_space(const std::wstring & name)
{
return find_add_child_space(name.c_str());
}
void Space::copy_value_from(const Space & space)
{
@ -1037,6 +1788,13 @@ void Space::copy_value_table(const Value & value_from)
}
void Space::initialize()
{
type = type_null;
child_spaces = nullptr;
name = nullptr;
}
void Space::initialize_value_null_if_needed()
{
if( type != type_null )
@ -1259,6 +2017,8 @@ void Space::remove_space_name()
} // namespace

@ -39,13 +39,14 @@
#define headerfile_picotools_space_space
#include <string>
#include <list>
#include <vector>
#include <map>
#include <cstdio>
#include <cwchar>
#include "textstream/types.h"
#include "convert/inttostr.h"
//#include "utf8/utf8.h"
@ -251,6 +252,9 @@ public:
Space & add(const std::string & val);
Space & add(const std::wstring & val);
Space & add(const Space * space);
Space & add_empty_space(); // IMPROVEME rename me to something better
// add a value to the object, change to object if needed, return the reference to the new inserted item
Space & add(const wchar_t * field, bool val);
@ -271,10 +275,51 @@ public:
Space & add(const wchar_t * field, const Space * space);
Space & add_empty_space(const wchar_t * field); // IMPROVEME rename me to something better
Space & add(const std::wstring & field, bool val);
Space & add(const std::wstring & field, short val);
Space & add(const std::wstring & field, int val);
Space & add(const std::wstring & field, long val);
Space & add(const std::wstring & field, long long val);
Space & add(const std::wstring & field, unsigned short val);
Space & add(const std::wstring & field, unsigned int val);
Space & add(const std::wstring & field, unsigned long val);
Space & add(const std::wstring & field, unsigned long long val);
Space & add(const std::wstring & field, float val);
Space & add(const std::wstring & field, double val);
Space & add(const std::wstring & field, const char * val);
Space & add(const std::wstring & field, const wchar_t * val);
Space & add(const std::wstring & field, const std::string & val);
Space & add(const std::wstring & field, const std::wstring & val);
Space & add(const std::wstring & field, const Space * space);
Space & add_empty_space(const std::wstring & field); // IMPROVEME rename me to something better
// for child spaces (used only in Space format)
// rename to something better
Space & add_child_space(const wchar_t * space_name);
// IMPROVEME add a similar 'set' method and cctor
template<typename StreamType>
Space & add_stream(const wchar_t * field, StreamType & str)
{
std::wstring temp;
str.to_string(temp);
return add(field, temp);
}
template<typename StreamType>
Space & add_stream(const std::wstring & field, StreamType & str)
{
std::wstring temp;
str.to_string(temp);
return add(field, temp);
}
bool is_null() const;
bool is_bool() const;
bool is_llong() const;
@ -304,6 +349,59 @@ public:
std::string to_str() const;
std::wstring to_wstr() const;
void to_list(std::list<std::string> & output_list, bool clear_list = true) const;
void to_list(std::list<std::wstring> & output_list, bool clear_list = true) const;
void to_list(std::vector<std::string> & output_list, bool clear_list = true) const;
void to_list(std::vector<std::wstring> & output_list, bool clear_list = true) const;
// returns value from object, field is a key
bool to_bool(const wchar_t * field, bool default_value = false) const;
short to_short(const wchar_t * field, short default_value = 0) const;
int to_int(const wchar_t * field, int default_value = 0) const;
long to_long(const wchar_t * field, long default_value = 0) const;
long long to_llong(const wchar_t * field, long long default_value = 0) const;
long long to_long_long(const wchar_t * field, long long default_value = 0) const;
unsigned short to_ushort(const wchar_t * field, unsigned short default_value = 0) const;
unsigned int to_uint(const wchar_t * field, unsigned int default_value = 0) const;
unsigned long to_ulong(const wchar_t * field, unsigned long default_value = 0) const;
unsigned long long to_ullong(const wchar_t * field, unsigned long long default_value = 0) const;
unsigned long long to_ulong_long(const wchar_t * field, unsigned long long default_value = 0) const;
std::string to_str(const wchar_t * field, const char * default_value = nullptr) const;
std::string to_str(const wchar_t * field, const std::string & default_value) const;
std::wstring to_wstr(const wchar_t * field, const wchar_t * default_value = nullptr) const;
std::wstring to_wstr(const wchar_t * field, const std::wstring & default_value) const;
bool to_list(const wchar_t * field, std::list<std::string> & output_list, bool clear_list = true) const;
bool to_list(const wchar_t * field, std::list<std::wstring> & output_list, bool clear_list = true) const;
bool to_list(const std::wstring & field, std::list<std::string> & output_list, bool clear_list = true) const;
bool to_list(const std::wstring & field, std::list<std::wstring> & output_list, bool clear_list = true) const;
bool to_list(const wchar_t * field, std::vector<std::string> & output_list, bool clear_list = true) const;
bool to_list(const wchar_t * field, std::vector<std::wstring> & output_list, bool clear_list = true) const;
bool to_list(const std::wstring & field, std::vector<std::string> & output_list, bool clear_list = true) const;
bool to_list(const std::wstring & field, std::vector<std::wstring> & output_list, bool clear_list = true) const;
// returns value from object, field is a key
bool to_bool(const std::wstring & field, bool default_value = false) const;
short to_short(const std::wstring & field, short default_value = 0) const;
int to_int(const std::wstring & field, int default_value = 0) const;
long to_long(const std::wstring & field, long default_value = 0) const;
long long to_llong(const std::wstring & field, long long default_value = 0) const;
long long to_long_long(const std::wstring & field, long long default_value = 0) const;
unsigned short to_ushort(const std::wstring & field, unsigned short default_value = 0) const;
unsigned int to_uint(const std::wstring & field, unsigned int default_value = 0) const;
unsigned long to_ulong(const std::wstring & field, unsigned long default_value = 0) const;
unsigned long long to_ullong(const std::wstring & field, unsigned long long default_value = 0) const;
unsigned long long to_ulong_long(const std::wstring & field, unsigned long long default_value = 0) const;
std::string to_str(const std::wstring & field, const char * default_value = nullptr) const;
std::string to_str(const std::wstring & field, const std::string & default_value) const;
std::wstring to_wstr(const std::wstring & field, const wchar_t * default_value = nullptr) const;
std::wstring to_wstr(const std::wstring & field, const std::wstring & default_value) const;
bool to_str_list(std::list<std::string> & output_list) const;
bool to_wstr_list(std::list<std::wstring> & output_list) const;
bool * get_bool();
@ -311,11 +409,36 @@ public:
long long * get_long_long();
float * get_float();
double * get_double();
std::string * get_string();
std::wstring * get_wstring();
std::string * get_str();
std::wstring * get_wstr();
ObjectType * get_object();
TableType * get_table();
bool is_equal(const char * val) const;
bool is_equal(const std::string & val) const;
bool is_equal(const wchar_t * val) const;
bool is_equal(const std::wstring & val) const;
// add these is_equal with std::wstring
// what about getters from tables?
// may something like: Space * get_table_item(size_t index)?
// and get_table_bool(size_t index)
// or just only get_bool(size_t index)?
// size_t argument will be only for tables, wchar_t* or std::wstring for objects?
// getters from object
Space * get_object_field(const wchar_t * field); // may a better name?
bool * get_bool(const wchar_t * field);
long long * get_llong(const wchar_t * field);
long long * get_long_long(const wchar_t * field);
float * get_float(const wchar_t * field);
double * get_double(const wchar_t * field);
std::string * get_str(const wchar_t * field);
std::wstring * get_wstr(const wchar_t * field);
ObjectType * get_object(const wchar_t * field);
TableType * get_table(const wchar_t * field);
// add these getters with std::wstring
const bool * get_bool() const;
@ -323,11 +446,32 @@ public:
const long long * get_long_long() const;
const float * get_float() const;
const double * get_double() const;
const std::string * get_string() const;
const std::wstring * get_wstring() const;
const std::string * get_str() const;
const std::wstring * get_wstr() const;
const ObjectType * get_object() const;
const TableType * get_table() const;
bool has_key(const wchar_t * field) const; // may has_key() would be a better name?
bool has_key(const std::wstring & field) const;
const Space * get_object_field(const wchar_t * field) const; // may a better name?
const Space * get_object_field(const std::wstring & field) const; // may a better name?
const bool * get_bool(const wchar_t * field) const;
const long long * get_llong(const wchar_t * field) const;
const long long * get_long_long(const wchar_t * field) const;
const float * get_float(const wchar_t * field) const;
const double * get_double(const wchar_t * field) const;
const std::string * get_str(const wchar_t * field) const;
const std::wstring * get_wstr(const wchar_t * field) const;
const ObjectType * get_object(const wchar_t * field) const;
const TableType * get_table(const wchar_t * field) const;
// add these getters with std::wstring
// remove a field from an object
void remove(const wchar_t * field);
void remove(const std::wstring & field);
std::string serialize_to_space_str(bool pretty_print = false) const;
@ -353,7 +497,7 @@ public:
template<typename StreamType>
void serialize_to_json_stream(StreamType & str) const
void serialize_to_json_stream(StreamType & str, bool pretty_print = false) const
{
switch(type)
{
@ -396,11 +540,26 @@ public:
}
bool is_equal(const wchar_t * field, const char * val) const;
bool is_equal(const wchar_t * field, const std::string & val) const;
bool is_equal(const wchar_t * field, const wchar_t * val) const;
bool is_equal(const wchar_t * field, const std::wstring & val) const;
// add these is_equal with std::wstring
Space * find_child_space(const wchar_t * name);
Space * find_child_space(const std::wstring & name);
const Space * find_child_space(const wchar_t * name) const;
const Space * find_child_space(const std::wstring & name) const;
Space & find_add_child_space(const wchar_t * name);
Space & find_add_child_space(const std::wstring & name);
protected:
template<typename ArgType>
Space & add_generic(ArgType val)
Space & add_generic(const ArgType & val)
{
initialize_value_table_if_needed();
@ -412,7 +571,7 @@ protected:
template<typename ArgType>
Space & add_generic(const wchar_t * field, ArgType val)
Space & add_generic(const wchar_t * field, const ArgType & val)
{
initialize_value_object_if_needed();
@ -423,6 +582,13 @@ protected:
}
template<typename ArgType>
Space & add_generic(const std::wstring & field, const ArgType & val)
{
return add_generic(field.c_str(), val);
}
template<typename ArgType>
ArgType to_generic_numeric_signed_value() const
{
@ -452,6 +618,129 @@ protected:
unsigned long long convert_wstring_to_ulong_long() const;
template<typename ListType>
void to_list_str_generic(ListType & output_list, bool clear_list) const
{
if( clear_list )
output_list.clear();
if( type == type_string )
{
output_list.push_back(value.value_string);
}
else
if( type == type_table )
{
for(size_t i = 0 ; i < value.value_table.size() ; ++i)
{
output_list.push_back(value.value_table[i]->to_str());
}
}
else
{
output_list.push_back(to_str());
}
}
template<typename ListType>
void to_list_wstr_generic(ListType & output_list, bool clear_list) const
{
if( clear_list )
output_list.clear();
if( type == type_wstring )
{
output_list.push_back(value.value_wstring);
}
else
if( type == type_table )
{
for(size_t i = 0 ; i < value.value_table.size() ; ++i)
{
output_list.push_back(value.value_table[i]->to_wstr());
}
}
else
{
output_list.push_back(to_wstr());
}
}
template<typename ListType>
bool to_list_generic(const wchar_t * field, ListType & output_list, bool clear_list) const
{
if( clear_list )
output_list.clear();
const Space * space = get_object_field(field);
if( space )
{
space->to_list(output_list, false);
return true;
}
return false;
}
template<typename ListType>
bool to_list_generic(const std::wstring & field, ListType & output_list, bool clear_list) const
{
if( clear_list )
output_list.clear();
const Space * space = get_object_field(field);
if( space )
{
space->to_list(output_list, false);
return true;
}
return false;
}
template<typename ArgType>
Space * find_child_space_generic(const ArgType & name)
{
if( child_spaces )
{
for(size_t i = 0 ; i < child_spaces->size() ; ++i)
{
Space * space = (*child_spaces)[i];
if( space->name && *space->name == name )
{
return space;
}
}
}
return nullptr;
}
template<typename ArgType>
Space * find_child_space_generic(const ArgType & name) const
{
if( child_spaces )
{
for(size_t i = 0 ; i < child_spaces->size() ; ++i)
{
Space * space = (*child_spaces)[i];
if( space->name && *space->name == name )
{
return space;
}
}
}
return nullptr;
}
template<typename StreamType>
@ -531,11 +820,14 @@ protected:
}
else
{
StreamType temp_stream;
// input is utf8 but output is wide
UTF8ToWide(input_str, temp_stream, false);
copy_input_stream_to_output(temp_stream, out_str, escape);
copy_input_string_to_output(input_str, out_str, escape); // temporarily
// !!!!!!!!!!!!!!!!!!! FIXME
// StreamType temp_stream;
// UTF8ToWide(input_str, temp_stream, false);
//
// copy_input_stream_to_output(temp_stream, out_str, escape);
}
}
@ -862,38 +1154,6 @@ protected:
}
public:
///////////////////////////// remove me
template<class Stream>
void Serialize(Stream & out, bool use_indents = false, bool use_comments = false, int level = 0) const
{
}
template<class Stream>
void SerializeTableMulti(Stream & out, bool use_indents, int level) const
{
}
template<class Stream, class StringType>
static void PrintValue(Stream & out, const StringType & str, bool use_quote = true)
{
}
template<class Stream>
static void PrintKey(Stream & out, const std::wstring & str)
{
}
template<class Stream>
static void PrintLevel(Stream & out, bool use_indents, int level)
{
}
/////////////////////////////
protected:
template<typename StreamType>
@ -998,6 +1258,7 @@ protected:
void copy_value_object(const Value & value_from);
void copy_value_table(const Value & value_from);
void initialize();
void initialize_value_null_if_needed();
void initialize_value_bool_if_needed();
void initialize_value_long_if_needed();

@ -431,7 +431,7 @@ void SpaceParser::ParseSpace(Space * space)
void SpaceParser::ParseTextValue(Space * space)
{
space->set_empty_wstring();
std::wstring * str = space->get_wstring();
std::wstring * str = space->get_wstr();
if( parsing_space )
ReadMultilineTokenQuoted(<