|
|
|
@ -44,6 +44,7 @@
|
|
|
|
|
#include "space.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace PT
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@ -52,8 +53,10 @@ class SpaceToJSON
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
void ChangeSpacesToTable(const wchar_t * space_name);
|
|
|
|
|
void ChangeSpacesToTable(const std::wstring & space_name);
|
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
|
|
void TreatAsTable(const wchar_t * space_name);
|
|
|
|
|
void TreatAsTable(const std::wstring & space_name);
|
|
|
|
|
|
|
|
|
|
void TreatAsNumeric(const wchar_t * name);
|
|
|
|
|
void TreatAsNumeric(const std::wstring & name);
|
|
|
|
@ -61,10 +64,18 @@ public:
|
|
|
|
|
void TreatAsBool(const wchar_t * name);
|
|
|
|
|
void TreatAsBool(const std::wstring & name);
|
|
|
|
|
|
|
|
|
|
template<class Stream>
|
|
|
|
|
void Serialize(Space & space, Stream & out, bool use_indents = false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
std::set<std::wstring> numeric, boolean, table;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Stream>
|
|
|
|
|
void Serialize(Space & space, Stream & out, bool use_indents = false, int level = 0, bool use_comma = false, bool skip_name = false);
|
|
|
|
|
void Serialize(Space & space, Stream & out, bool use_indents, int level,
|
|
|
|
|
bool use_comma, bool treat_as_table, bool skip_name);
|
|
|
|
|
|
|
|
|
|
template<class Stream>
|
|
|
|
|
void SerializeTableSingle(Space & space, Stream & out, bool use_indents, int level, bool use_comma);
|
|
|
|
@ -79,17 +90,10 @@ public:
|
|
|
|
|
void PrintLevel(Stream & out, bool use_indents, int level);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
|
|
bool HasUnnamedSpace(Space & space);
|
|
|
|
|
bool HasSpace(Space & space, const std::wstring & name);
|
|
|
|
|
|
|
|
|
|
bool IsNumeric(const std::wstring & name);
|
|
|
|
|
bool IsBool(const std::wstring & name);
|
|
|
|
|
bool IsTable(const std::wstring & name);
|
|
|
|
|
|
|
|
|
|
std::vector<std::wstring> spaces_to_table;
|
|
|
|
|
std::vector<bool> space_used;
|
|
|
|
|
std::set<std::wstring> numeric, boolean;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -221,7 +225,8 @@ bool is_special;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Stream>
|
|
|
|
|
void SpaceToJSON::Serialize(Space & space, Stream & out, bool use_indents, int level, bool use_comma, bool skip_name)
|
|
|
|
|
void SpaceToJSON::Serialize(Space & space, Stream & out, bool use_indents, int level,
|
|
|
|
|
bool use_comma, bool treat_as_table, bool skip_name)
|
|
|
|
|
{
|
|
|
|
|
if( use_comma )
|
|
|
|
|
{
|
|
|
|
@ -233,74 +238,63 @@ void SpaceToJSON::Serialize(Space & space, Stream & out, bool use_indents, int l
|
|
|
|
|
|
|
|
|
|
if( !skip_name )
|
|
|
|
|
{
|
|
|
|
|
if( !space.name.empty() )
|
|
|
|
|
if( space.name.empty() )
|
|
|
|
|
{
|
|
|
|
|
out << L"\"empty\": ";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PrintToken(out, space.name);
|
|
|
|
|
out << L": ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out << L"{\n";
|
|
|
|
|
if( treat_as_table )
|
|
|
|
|
out << L"[\n";
|
|
|
|
|
else
|
|
|
|
|
out << L"{\n";
|
|
|
|
|
|
|
|
|
|
bool printed_something = false;
|
|
|
|
|
|
|
|
|
|
SerializeTableSingle(space, out, use_indents, level, false);
|
|
|
|
|
SerializeTableMulti(space, out, use_indents, level, !space.table_single.empty());
|
|
|
|
|
|
|
|
|
|
if( !space.table_single.empty() || !space.table.empty() )
|
|
|
|
|
printed_something = true;
|
|
|
|
|
|
|
|
|
|
space_used.resize(space.spaces.size());
|
|
|
|
|
|
|
|
|
|
for(size_t i=0 ; i<space_used.size() ; ++i)
|
|
|
|
|
space_used[i] = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(size_t z=0 ; z<spaces_to_table.size() ; ++z)
|
|
|
|
|
if( !treat_as_table )
|
|
|
|
|
{
|
|
|
|
|
if( HasSpace(space, spaces_to_table[z]) )
|
|
|
|
|
{
|
|
|
|
|
if( printed_something )
|
|
|
|
|
{
|
|
|
|
|
out << L",\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PrintToken(out, spaces_to_table[z]);
|
|
|
|
|
out << L": [\n";
|
|
|
|
|
|
|
|
|
|
for(size_t i=0 ; i<space.spaces.size() ; ++i)
|
|
|
|
|
{
|
|
|
|
|
if( space.spaces[i]->name == spaces_to_table[z] )
|
|
|
|
|
{
|
|
|
|
|
space_used[i] = true;
|
|
|
|
|
Serialize(*space.spaces[i], out, use_indents, level+1, i>0, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
SerializeTableSingle(space, out, use_indents, level, false);
|
|
|
|
|
SerializeTableMulti(space, out, use_indents, level, !space.table_single.empty());
|
|
|
|
|
|
|
|
|
|
out << L"]\n";
|
|
|
|
|
if( !space.table_single.empty() || !space.table.empty() )
|
|
|
|
|
printed_something = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* !! IMPROVE ME when serializing a table
|
|
|
|
|
* we can make a test whether a space is empty and has a name
|
|
|
|
|
* in such a case put it as a string
|
|
|
|
|
* this is the same way as the json parser works
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
for(size_t i=0 ; i<space.spaces.size() ; ++i)
|
|
|
|
|
{
|
|
|
|
|
if( !space_used[i] )
|
|
|
|
|
{
|
|
|
|
|
Serialize(*space.spaces[i], out, use_indents, level+1, printed_something || i>0);
|
|
|
|
|
|
|
|
|
|
if( i + 1 < space.spaces.size() )
|
|
|
|
|
{
|
|
|
|
|
PrintLevel(out, use_indents, level);
|
|
|
|
|
out << L",\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printed_something = true;
|
|
|
|
|
}
|
|
|
|
|
bool next_skip_name = treat_as_table;
|
|
|
|
|
bool next_is_table = IsTable(space.spaces[i]->name);
|
|
|
|
|
Serialize(*space.spaces[i], out, use_indents, level+1, printed_something, next_is_table, next_skip_name);
|
|
|
|
|
printed_something = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PrintLevel(out, use_indents, level);
|
|
|
|
|
out << L"}\n";
|
|
|
|
|
|
|
|
|
|
if( treat_as_table )
|
|
|
|
|
out << L"]\n";
|
|
|
|
|
else
|
|
|
|
|
out << L"}\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class Stream>
|
|
|
|
|
void SpaceToJSON::Serialize(Space & space, Stream & out, bool use_indents)
|
|
|
|
|
{
|
|
|
|
|
bool treat_as_table = IsTable(space.name);
|
|
|
|
|
Serialize(space, out, use_indents, 0, false, treat_as_table, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|