use new FindHelper struct in places where fields, field_index, parameters variables were used

This commit is contained in:
Tomasz Sowa 2021-11-05 09:34:05 +01:00
parent 6d79cdb2fc
commit b8a9217429
3 changed files with 326 additions and 410 deletions

View File

@ -124,9 +124,6 @@ struct Stack
}; };
// !! IMPROVE ME
// the name is bad
// may it should be called Env (environment) or FunEnv
template<class StreamType> template<class StreamType>
struct Env struct Env
{ {

View File

@ -135,7 +135,7 @@ public:
private: private:
struct FindHelper struct FindHelperOld
{ {
//const std::wstring * fun_name; //const std::wstring * fun_name;
@ -151,7 +151,7 @@ private:
size_t field_index; size_t field_index;
#endif #endif
FindHelper() FindHelperOld()
{ {
//fun_name = nullptr; //fun_name = nullptr;
@ -169,6 +169,45 @@ private:
}; };
// RENAMEME
struct FindHelper
{
const std::wstring & name;
std::vector<std::wstring> & fields;
size_t field_index;
std::vector<Var<StreamType>> & parameters;
Var<StreamType> & result;
bool found;
bool evaluate_last;
const std::wstring * previous_name;
Var<StreamType> * previous_result;
FindHelper(const std::wstring & name, std::vector<std::wstring> & fields, std::vector<Var<StreamType>> & parameters, Var<StreamType> & result):
name(name), fields(fields), parameters(parameters), result(result)
{
field_index = 0;
found = false;
evaluate_last = true;
previous_name = nullptr;
previous_result = nullptr;
}
const std::wstring & current_name()
{
return (field_index == 0)? name : fields[field_index - 1];
}
bool is_last_field()
{
if( field_index == 0 )
return true;
return field_index == fields.size();
}
};
struct BlockStack struct BlockStack
{ {
std::vector<Var<StreamType>> args; std::vector<Var<StreamType>> args;
@ -282,70 +321,67 @@ private:
bool IsTestingFunctionExistence(); bool IsTestingFunctionExistence();
bool CheckBlockArgument(int arg_index, FindHelper & find_helper); bool CheckBlockArgument(int arg_index, FindHelperOld & find_helper);
#ifdef EZC_HAS_MORM_LIBRARY #ifdef EZC_HAS_MORM_LIBRARY
bool FindInModels(FindHelper & find_helper); //bool FindInModels(FindHelperOld & find_helper);
#endif #endif
void PrepareEnvStruct(Env<StreamType> & info); void PrepareEnvStruct(Env<StreamType> & info);
void CallFunction(typename Functions<StreamType>::UserFunction & function, Env<StreamType> & info); void CallFunction(typename Functions<StreamType>::UserFunction & function, Env<StreamType> & info);
void CallFunction(typename Functions<StreamType>::UserFunction & function, void CallFunction(typename Functions<StreamType>::UserFunction & function, FindHelper & find_helper);
Var<StreamType> & result,
std::vector<Var<StreamType>> & parameters,
const StreamType & in_stream);
bool CallBlock(Item & item_block, bool CallBlock(Item & item_block,
Var<StreamType> & result, Var<StreamType> & result,
std::vector<Var<StreamType>> & parameters); std::vector<Var<StreamType>> & parameters);
void PrintDate(pt::Date & date, std::vector<Var<StreamType>> & parameters, Var<StreamType> & result); void PrintDate(pt::Date & date, FindHelper & find_helper);
//bool PrintDatePart(pt::Date & date, const std::wstring & field, std::vector<Var<StreamType>> & parameters, Var<StreamType> & result); //bool PrintDatePart(pt::Date & date, const std::wstring & field, std::vector<Var<StreamType>> & parameters, Var<StreamType> & result);
//bool CallDate(pt::Date & date, const std::wstring & name, std::vector<std::wstring> & fields, size_t & field_index, std::vector<Var<StreamType>> & parameters, Var<StreamType> & result); //bool CallDate(pt::Date & date, const std::wstring & name, std::vector<std::wstring> & fields, size_t & field_index, std::vector<Var<StreamType>> & parameters, Var<StreamType> & result);
void PrintLastSpaceField(pt::Space * space, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters); void PrintLastSpaceField(pt::Space & space, FindHelper & find_helper);
void CallSpaceObjectForLastField(Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, pt::Space * space); void CallSpaceObjectForLastField(pt::Space & space, FindHelper & find_helper);
//pt::Space * CallSpaceObjectForMiddleField(const std::wstring & root_space_name, std::vector<std::wstring> & fields, size_t field_index, pt::Space * space); //pt::Space * CallSpaceObjectForMiddleField(const std::wstring & root_space_name, std::vector<std::wstring> & fields, size_t field_index, pt::Space * space);
void CallSpaceTableForLastField(morm::SpaceWrapper & space_wrapper, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, void CallSpaceTableForLastField(morm::SpaceWrapper & space_wrapper, pt::Space & space, FindHelper & find_helper, size_t model_wrapper_space_table_index);
pt::Space * space, size_t model_wrapper_space_table_index);
pt::Space * CallSpaceTableForMiddleField(morm::SpaceWrapper & space_wrapper, const std::wstring & root_space_name, std::vector<std::wstring> & fields, pt::Space * CallSpaceTableForMiddleField(morm::SpaceWrapper & space_wrapper, pt::Space & space, FindHelper & find_helper, size_t model_wrapper_space_table_index);
size_t field_index, pt::Space * space, size_t model_wrapper_space_table_index);
bool CallSpace(morm::SpaceWrapper * space_wrapper, const std::wstring & name, size_t & field_index, std::vector<std::wstring> & fields, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters); bool CallSpace(morm::SpaceWrapper & space_wrapper, FindHelper & find_helper);
#ifdef EZC_HAS_MORM_LIBRARY #ifdef EZC_HAS_MORM_LIBRARY
bool CallModelField(morm::Model & model, const std::wstring & field, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters); bool CallModelField(morm::Model & model, FindHelper & find_helper);
// bool CallModel(morm::Model & model, const std::wstring & name, std::vector<std::wstring> & fields, size_t field_index, // bool CallModel(morm::Model & model, const std::wstring & name, std::vector<std::wstring> & fields, size_t field_index,
// std::vector<Var<StreamType>> & parameters, Var<StreamType> & result); // std::vector<Var<StreamType>> & parameters, Var<StreamType> & result);
// void FindLastModelWrapper(FindHelper & find_helper, std::vector<std::wstring> & fields); // void FindLastModelWrapper(FindHelperOld & find_helper, std::vector<std::wstring> & fields);
// bool CallWrapper(FindHelper & find_helper, std::vector<std::wstring> & fields, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, const StreamType & in_stream); // bool CallWrapper(FindHelperOld & find_helper, std::vector<std::wstring> & fields, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, const StreamType & in_stream);
bool XXXRenameMe(Var<StreamType> & variable, std::vector<std::wstring> & fields, size_t & field_index, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, const StreamType & in_stream);
#endif #endif
Var<StreamType> * FindInScope(const std::wstring & name); Var<StreamType> * FindInScope(const std::wstring & name);
Var<StreamType> * FindVariable(const std::wstring & name, std::vector<std::wstring> & fields, size_t & field_index, std::vector<Var<StreamType>> & parameters); void FindVariable(FindHelper & find_helper
//const std::wstring & name, std::vector<std::wstring> & fields, size_t & field_index, std::vector<Var<StreamType>> & parameters
);
bool EvaluateVariable(const std::wstring & name, Var<StreamType> & var, std::vector<std::wstring> & fields, size_t & field_index, std::vector<Var<StreamType>> & parameters, Var<StreamType> & result); void EvaluateVariable(FindHelper & find_helper
//const std::wstring & name, Var<StreamType> & var, std::vector<std::wstring> & fields, size_t & field_index, std::vector<Var<StreamType>> & parameters, Var<StreamType> & result
);
bool CallVariable(std::wstring & name, // bool CallVariable(FindHelper & findxxx
std::vector<std::wstring> & fields, // const std::wstring & name,
size_t & field_index, // std::vector<std::wstring> & fields,
Var<StreamType> & result, // size_t & field_index,
std::vector<Var<StreamType>> & parameters, // Var<StreamType> & result,
const StreamType & in_stream); // std::vector<Var<StreamType>> & parameters
// );
void NormalizeResult(Var<StreamType> & result);
bool Call(Item::Function & item_fun, bool Call(Item::Function & item_fun,
const std::wstring * fun_name, const std::wstring * fun_name,
@ -368,7 +404,7 @@ private:
bool ShouldMakeJsonDump(std::vector<Var<StreamType>> & parameters); bool ShouldMakeJsonDump(std::vector<Var<StreamType>> & parameters);
bool IsPrettyPrint(std::vector<Var<StreamType>> & parameters); bool IsPrettyPrint(std::vector<Var<StreamType>> & parameters);
void DumpSpaceIfNeeded(Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, pt::Space * space); void DumpSpaceIfNeeded(pt::Space & space, FindHelper & find_helper);
void DumpModelIfNeeded(morm::Model & model, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters); void DumpModelIfNeeded(morm::Model & model, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters);
@ -928,7 +964,7 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::IsTesting
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CheckBlockArgument(int arg_index, FindHelper & find_helper) bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CheckBlockArgument(int arg_index, FindHelperOld & find_helper)
{ {
if( arg_index < 0 ) if( arg_index < 0 )
return false; return false;
@ -953,22 +989,22 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CheckBloc
#ifdef EZC_HAS_MORM_LIBRARY #ifdef EZC_HAS_MORM_LIBRARY
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> //template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::FindInModels(FindHelper & find_helper) //bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::FindInModels(FindHelperOld & find_helper)
{ //{
if( pmodels ) // if( pmodels )
{ // {
morm::Wrapper * m = pmodels->Find(*find_helper.fun_name); // morm::Wrapper * m = pmodels->Find(*find_helper.fun_name);
//
if( m ) // if( m )
{ // {
find_helper.wrapper = m; // find_helper.wrapper = m;
return true; // return true;
} // }
} // }
//
return false; // return false;
} //}
#endif #endif
@ -1002,23 +1038,22 @@ void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallFunct
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallFunction(typename Functions<StreamType>::UserFunction & function, void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallFunction(
Var<StreamType> & result, typename Functions<StreamType>::UserFunction & function, FindHelper & find_helper)
std::vector<Var<StreamType>> & parameters,
const StreamType & in_stream)
{ {
if( !IsTestingFunctionExistence() ) if( !IsTestingFunctionExistence() )
{ {
if( parameters.empty() ) // if( find_helper.parameters.empty() )
{ {
Env<StreamType> info(result, parameters, in_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item); StreamType fake_stream;
CallFunction(function, info); Env<StreamType> info(find_helper.result, find_helper.parameters, fake_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
}
else
{
Env<StreamType> info(result, parameters, in_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
CallFunction(function, info); CallFunction(function, info);
} }
// else
// {
// Env<StreamType> info(result, parameters, in_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
// CallFunction(function, info);
// }
} }
} }
@ -1063,25 +1098,25 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::IsPrettyP
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::DumpSpaceIfNeeded(Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, pt::Space * space) void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::DumpSpaceIfNeeded(pt::Space & space, FindHelper & find_helper)
{ {
bool dump_space = ShouldMakeSpaceDump(parameters); bool dump_space = ShouldMakeSpaceDump(find_helper.parameters);
bool dump_json = ShouldMakeJsonDump(parameters); bool dump_json = ShouldMakeJsonDump(find_helper.parameters);
if( dump_space || dump_json ) if( dump_space || dump_json )
{ {
bool pretty = IsPrettyPrint(parameters); bool pretty = IsPrettyPrint(find_helper.parameters);
if( dump_space ) if( dump_space )
{ {
space->serialize_to_space_stream(result.stream, pretty); space.serialize_to_space_stream(find_helper.result.stream, pretty);
result.type = Var<StreamType>::TYPE_STREAM; find_helper.result.type = Var<StreamType>::TYPE_STREAM;
} }
else else
if( dump_json ) if( dump_json )
{ {
space->serialize_to_json_stream(result.stream, pretty); space.serialize_to_json_stream(find_helper.result.stream, pretty);
result.type = Var<StreamType>::TYPE_STREAM; find_helper.result.type = Var<StreamType>::TYPE_STREAM;
} }
} }
} }
@ -1121,32 +1156,32 @@ void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::DumpModel
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::PrintDate( void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::PrintDate(
pt::Date & date, std::vector<Var<StreamType>> & parameters, Var<StreamType> & result) pt::Date & date, FindHelper & find_helper)
{ {
bool is_roman = HasParam(parameters, L"roman"); bool is_roman = HasParam(find_helper.parameters, L"roman");
bool is_no_sec = HasParam(parameters, L"no_sec"); bool is_no_sec = HasParam(find_helper.parameters, L"no_sec");
bool only_date = HasParam(parameters, L"only_date"); bool only_date = HasParam(find_helper.parameters, L"only_date");
bool only_time = HasParam(parameters, L"only_time"); bool only_time = HasParam(find_helper.parameters, L"only_time");
if( only_date ) if( only_date )
{ {
result.type = Var<StreamType>::TYPE_STREAM; find_helper.result.type = Var<StreamType>::TYPE_STREAM;
date.SerializeYearMonthDay(result.stream, is_roman); date.SerializeYearMonthDay(find_helper.result.stream, is_roman);
} }
else else
if( only_time ) if( only_time )
{ {
result.type = Var<StreamType>::TYPE_STREAM; find_helper.result.type = Var<StreamType>::TYPE_STREAM;
if( is_no_sec ) if( is_no_sec )
date.SerializeHourMin(result.stream); date.SerializeHourMin(find_helper.result.stream);
else else
date.SerializeHourMinSec(result.stream); date.SerializeHourMinSec(find_helper.result.stream);
} }
else else
{ {
result.type = Var<StreamType>::TYPE_STREAM; find_helper.result.type = Var<StreamType>::TYPE_STREAM;
date.Serialize(result.stream, is_roman, !is_no_sec); date.Serialize(find_helper.result.stream, is_roman, !is_no_sec);
} }
} }
@ -1267,12 +1302,12 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallDate(
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpaceObjectForLastField(Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, pt::Space * space) void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpaceObjectForLastField(pt::Space & space, FindHelper & find_helper)
{ {
if( !IsTestingFunctionExistence() ) if( !IsTestingFunctionExistence() )
{ {
// CHECKME should we convert the last value to last_res? // CHECKME should we convert the last value to last_res?
DumpSpaceIfNeeded(result, parameters, space); DumpSpaceIfNeeded(space, find_helper);
} }
} }
@ -1295,10 +1330,9 @@ void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpace
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpaceTableForLastField( void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpaceTableForLastField(
morm::SpaceWrapper & space_wrapper, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, morm::SpaceWrapper & space_wrapper, pt::Space & space, FindHelper & find_helper, size_t model_wrapper_space_table_index)
pt::Space * space, size_t model_wrapper_space_table_index)
{ {
pt::Space::TableType * table = space->get_table(); pt::Space::TableType * table = space.get_table();
if( is_generating_for ) if( is_generating_for )
{ {
@ -1318,16 +1352,18 @@ void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpace
if( !IsTestingFunctionExistence() ) if( !IsTestingFunctionExistence() )
{ {
DumpSpaceIfNeeded(result, parameters, space); DumpSpaceIfNeeded(space, find_helper);
if( HasParam(parameters, L"index") ) if( HasParam(find_helper.parameters, L"index") )
{ {
result.stream << space_wrapper.get_space_iterator_value(model_wrapper_space_table_index); find_helper.result.stream << space_wrapper.get_space_iterator_value(model_wrapper_space_table_index);
find_helper.result.type = Var<StreamType>::TYPE_STREAM;
} }
if( HasParam(parameters, L"index-one") ) if( HasParam(find_helper.parameters, L"index-one") )
{ {
result.stream << (space_wrapper.get_space_iterator_value(model_wrapper_space_table_index) + 1); find_helper.result.stream << (space_wrapper.get_space_iterator_value(model_wrapper_space_table_index) + 1);
find_helper.result.type = Var<StreamType>::TYPE_STREAM;
} }
} }
} }
@ -1335,10 +1371,10 @@ void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpace
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
pt::Space * Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpaceTableForMiddleField( pt::Space * Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpaceTableForMiddleField(
morm::SpaceWrapper & space_wrapper, const std::wstring & root_space_name, std::vector<std::wstring> & fields, morm::SpaceWrapper & space_wrapper, pt::Space & space_table, FindHelper & find_helper, size_t model_wrapper_space_table_index)
size_t field_index, pt::Space * space, size_t model_wrapper_space_table_index)
{ {
pt::Space::TableType * table = space->get_table(); pt::Space::TableType * table = space_table.get_table();
pt::Space * space = nullptr;
// check the current iterator, if it is correct then select the item from the table // check the current iterator, if it is correct then select the item from the table
size_t iterator_value = space_wrapper.get_space_iterator_value(model_wrapper_space_table_index); size_t iterator_value = space_wrapper.get_space_iterator_value(model_wrapper_space_table_index);
@ -1350,7 +1386,7 @@ pt::Space * Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::Ca
else else
{ {
// this message can be print even for [if-def...] // this message can be print even for [if-def...]
CreateMsg(L"space table: ", root_space_name, fields, field_index, L" is not initialized, have you forgotten to use [for...] statement?"); //CreateMsg(L"space table: ", root_space_name, fields, field_index, L" is not initialized, have you forgotten to use [for...] statement?");
space = nullptr; space = nullptr;
} }
@ -1360,24 +1396,24 @@ pt::Space * Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::Ca
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::PrintLastSpaceField( void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::PrintLastSpaceField(
pt::Space * space, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters) pt::Space & space, FindHelper & find_helper)
{ {
bool no_escape = HasParam(parameters, L"raw", L"noescape"); bool no_escape = HasParam(find_helper.parameters, L"raw", L"noescape");
// FIXME what about escaping here? // FIXME what about escaping here?
if( no_escape ) if( no_escape )
{ {
//pt::WTextStream str; //pt::WTextStream str;
space->serialize_to_string(result.stream); space.serialize_to_string(find_helper.result.stream);
result.type = Var<StreamType>::TYPE_STREAM; find_helper.result.type = Var<StreamType>::TYPE_STREAM;
//CopyStream(str, out_stream, false); //CopyStream(str, out_stream, false);
} }
else else
{ {
// space->serialize_to_string(out_stream); // space->serialize_to_string(out_stream);
space->serialize_to_string(result.stream); space.serialize_to_string(find_helper.result.stream);
result.type = Var<StreamType>::TYPE_STREAM; find_helper.result.type = Var<StreamType>::TYPE_STREAM;
} }
} }
@ -1385,9 +1421,9 @@ void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::PrintLast
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpace( bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpace(
morm::SpaceWrapper * space_wrapper, const std::wstring & name, size_t & field_index, std::vector<std::wstring> & fields, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters) morm::SpaceWrapper & space_wrapper, FindHelper & find_helper)
{ {
pt::Space * space = space_wrapper->get_space(); pt::Space * space = space_wrapper.get_space();
size_t model_wrapper_space_table_index = 0; size_t model_wrapper_space_table_index = 0;
bool status = false; bool status = false;
@ -1398,62 +1434,60 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpace
* the first item is the root_space with a find_helper.fun_name name * the first item is the root_space with a find_helper.fun_name name
* *
*/ */
while( (field_index < fields.size() + 1) && space ) while( (find_helper.field_index < find_helper.fields.size() + 1) && space )
{ {
if( space->is_object() ) if( space->is_object() )
{ {
std::wstring & next_field = fields[field_index]; std::wstring & next_field = find_helper.fields[find_helper.field_index];
pt::Space * next_space = space->get_space(next_field); pt::Space * next_space = space->get_space(next_field);
if( !next_space ) if( !next_space )
{ {
CallSpaceObjectForLastField(result, parameters, space); CallSpaceObjectForLastField(*space, find_helper);
status = true; status = true;
} }
space = next_space; space = next_space;
if( space ) if( space )
field_index += 1; find_helper.field_index += 1;
} }
else else
if( space->is_table() ) if( space->is_table() )
{ {
bool is_last_field = (field_index == fields.size()); if( model_wrapper_space_table_index < space_wrapper.space_indices_table_size() )
if( model_wrapper_space_table_index < space_wrapper->space_indices_table_size() )
{ {
if( is_last_field ) if( find_helper.is_last_field() )
{ {
CallSpaceTableForLastField(*space_wrapper, result, parameters, space, model_wrapper_space_table_index); CallSpaceTableForLastField(space_wrapper, *space, find_helper, model_wrapper_space_table_index);
field_index += 1; find_helper.field_index += 1;
status = true; status = true;
} }
else else
{ {
space = CallSpaceTableForMiddleField(*space_wrapper, name, fields, field_index, space, model_wrapper_space_table_index); space = CallSpaceTableForMiddleField(space_wrapper, *space, find_helper, model_wrapper_space_table_index);
// increment field_index only if next_field is 'this' and space is not an object // increment field_index only if next_field is 'this' and space is not an object
if( space && !space->is_object() ) if( space && !space->is_object() )
{ {
std::wstring & next_field = fields[field_index]; std::wstring & next_field = find_helper.fields[find_helper.field_index];
if( next_field == L"this" ) if( next_field == L"this" )
{ {
field_index += 1; find_helper.field_index += 1;
} }
} }
} }
} }
else else
{ {
CreateMsg(L"", name, fields, field_index, L" exceeded the maximum number of fields for a space object"); CreateMsg(L"", find_helper.name, find_helper.fields, find_helper.field_index, L" exceeded the maximum number of fields for a space object");
space = nullptr; space = nullptr;
} }
} }
else else
{ {
PrintLastSpaceField(space, result, parameters); PrintLastSpaceField(*space, find_helper);
status = true; status = true;
// increment field_index here? // increment field_index here?
break; break;
@ -1490,7 +1524,7 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpace
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallModelField( bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallModelField(
morm::Model & model, const std::wstring & field, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters) morm::Model & model, FindHelper & find_helper)
{ {
/* /*
* if 'field' is a POD type then 'str' will be used in get_raw_value() * if 'field' is a POD type then 'str' will be used in get_raw_value()
@ -1502,8 +1536,8 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallModel
bool found = false; bool found = false;
StreamType fake_stream; StreamType fake_stream;
Env<StreamType> info(result, parameters, fake_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item); Env<StreamType> info(find_helper.result, find_helper.parameters, fake_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
found = model.get_raw_value(nullptr, field.c_str(), nullptr, info); found = model.get_raw_value(nullptr, find_helper.current_name().c_str(), nullptr, info);
// if( found && !str.empty()) // if( found && !str.empty())
// { // {
@ -1624,7 +1658,7 @@ void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::FindLastM
/* /*
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallWrapper( bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallWrapper(
FindHelper & find_helper, std::vector<std::wstring> & fields, FindHelperOld & find_helper, std::vector<std::wstring> & fields,
Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, const StreamType & in_stream) Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, const StreamType & in_stream)
{ {
bool found = true; bool found = true;
@ -1737,129 +1771,22 @@ return true;
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::XXXRenameMe(
Var<StreamType> & variable, std::vector<std::wstring> & fields, size_t & field_index, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, const StreamType & in_stream)
{
Var<StreamType> * last_var = &variable;
Var<StreamType> res;
//find_helper.wrapper->has_model_object() //template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
while( field_index < fields.size() ) //bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallVariable(FindHelper & find_helper)
{ // //const std::wstring & name, std::vector<std::wstring> & fields, size_t & field_index, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters)
std::wstring & field = fields[field_index]; //{
size_t old_field_index = field_index; // Var<StreamType> * variable = FindVariable(find_helper);
// bool status = false;
if( last_var->type == Var<StreamType>::TYPE_FUNCTION ) //
{ // if( variable )
std::vector<Var<StreamType>> params; // {
params.push_back(*last_var); // // here we cannot pass 'name' but the last field instead?
field_index += 1; // status = EvaluateVariable(name, *variable, fields, field_index, parameters, result);
// }
if( !CallVariable(field, fields, field_index, res, params, in_stream) ) //
return false; // return status;
} //}
if( last_var->type == Var<StreamType>::TYPE_MODEL )
{
/*
* if 'field' is a POD type then 'str' will be used in get_raw_value()
* if 'field' is a getter method with pt::Stream then 'str' will be used too
* if 'field' is a getter method which takes Env<> then out_stream will be used and 'str' will be empty
*
*/
bool found = false;
Env<StreamType> info(res, parameters, in_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
found = last_var->model->get_raw_value(nullptr, field.c_str(), nullptr, info);
if( found && res.type == Var<StreamType>::TYPE_VOID && !res.stream.empty() )
{
res.type = Var<StreamType>::TYPE_STREAM;
}
if( !found )
{
CreateMsg(L"not found: ", field.c_str());
return false;
}
}
if( last_var->type == Var<StreamType>::TYPE_SPACE_WRAPPER )
{
//CallSpace();
}
last_var = &res;
if( old_field_index == field_index )
field_index += 1;
}
result = res;
return true;
}
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallVariable(
std::wstring & name, std::vector<std::wstring> & fields, size_t & field_index, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, const StreamType & in_stream)
{
Var<StreamType> * variable = pvars->find(name);
Var<StreamType> res;
if( !variable )
return false;
while( variable->type == Var<StreamType>::TYPE_FUNCTION || variable->type == Var<StreamType>::TYPE_MODEL )
{
if( variable->type == Var<StreamType>::TYPE_FUNCTION )
{
if( variable->user_function )
{
CallFunction(variable->user_function, res, parameters, in_stream);
}
else
{
// put some log that variable.user_function is null?
return false;
}
}
else
if( variable->type == Var<StreamType>::TYPE_MODEL )
{
if( variable->model )
{
if( !XXXRenameMe(variable, fields, field_index, res, parameters, in_stream) )
return false;
}
else
{
// put some log that model is null?
return false;
}
}
variable = &res;
}
{
if( !IsTestingFunctionExistence() )
{
result = variable;
//variable.serialize_to(out_stream);
//out_stream << variable.str;
//last_res = variable.res;
}
return true;
}
result = res;
}
@ -1878,140 +1805,121 @@ Var<StreamType> * Generator<StreamType, is_pikotools_stream, is_autoescape_strea
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
Var<StreamType> * Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::FindVariable( void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::FindVariable(FindHelper & find_helper)
const std::wstring & name, std::vector<std::wstring> & fields, size_t & field_index, std::vector<Var<StreamType>> & parameters)
{ {
Var<StreamType> * var = nullptr; find_helper.field_index = 0;
std::vector<Var<StreamType>> res; find_helper.previous_name = nullptr;
res.resize(1); find_helper.previous_result = nullptr;
bool was_evaluated = false;
do do
{ {
const std::wstring * pname = (field_index == 0)? &name : &fields[field_index - 1]; find_helper.found = false;
Var<StreamType> * old_var = var; EvaluateVariable(find_helper);
var = nullptr;
if( field_index > 1 && old_var ) if( find_helper.found )
{ {
var = old_var->find_child(*pname); find_helper.previous_name = &find_helper.current_name();
} find_helper.field_index += 1;
if( !var )
{
var = FindInScope(*pname);
}
if( var )
{
/*
* fix me
* this is incorrect, as the parameters would be passed to the first function
* if the first function is a model we do not pass parameters to it, but to a field of the model (our next field)
*
*/
if( was_evaluated )
{
Var<StreamType> improve_me;
EvaluateVariable(name, *var, fields, field_index, res, improve_me);
res[0] = improve_me;
}
else
{
if( EvaluateVariable(name, *var, fields, field_index, parameters, res[0]) )
was_evaluated = true;
}
} }
else else
{ {
// log something find_helper.result.clear();
} }
field_index += 1;
} }
while( field_index < fields.size() + 1 && var ) while( find_helper.found && find_helper.field_index < find_helper.fields.size() + 1 );
return var;
} }
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream> template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::EvaluateVariable( void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::EvaluateVariable(FindHelper & find_helper)
const std::wstring & name, Var<StreamType> & var, std::vector<std::wstring> & fields, size_t & field_index, std::vector<Var<StreamType>> & parameters, Var<StreamType> & result)
{ {
StreamType fake_stream; Var<StreamType> * var = nullptr;
bool status = false; const std::wstring & name = find_helper.current_name();
bool all_fields_known = (field_index == fields.size());
if( var.type == Var<StreamType>::TYPE_FUNCTION ) if( find_helper.previous_name && find_helper.previous_result )
{ {
if( var.user_function ) //var = find_helper.previous_result->find_child(name);
{
CallFunction(var.user_function, result, parameters, fake_stream);
status = true;
}
else
{
// put some log that variable.user_function is null?
}
}
if( var.type == Var<StreamType>::TYPE_MODEL ) //if( !var )
{
if( var.model )
{ {
status = CallModelField(*var.model, name, result, parameters); if( find_helper.previous_result->type == Var<StreamType>::TYPE_MODEL )
}
else
{
// put some log that variable.user_function is null?
}
}
if( var.type == Var<StreamType>::TYPE_MODEL_CONTAINER_WRAPPER && var->model_container_wrapper )
{
morm::Model * model = var.model_container_wrapper->get_model();
if( model )
{
status = CallModelField(*model, name, result, parameters);
}
else
{
// can be printed even for [if-def...]
CreateMsg(L"model ", name, fields, L" is not initialized, have you forgotten to use [for ...] statement?");
status = false;
}
if( all_fields_known )
{
if( is_generating_for )
{ {
var.model_container_wrapper->increment_iterator(); find_helper.found = CallModelField(*find_helper.previous_result->model, find_helper);
var.clear_childs(); find_helper.previous_result = find_helper.found ? &find_helper.result : nullptr;
}
if( find_helper.previous_result->type == Var<StreamType>::TYPE_MODEL_CONTAINER_WRAPPER )
{
morm::Model * model = find_helper.previous_result->model_container_wrapper->get_model();
if( model )
{
find_helper.found = CallModelField(*model, find_helper); // parameters here?
find_helper.previous_result = find_helper.found ? &find_helper.result : nullptr;
}
else
{
// put some log (no [for] statement)
// CreateMsg(L"model ", name, fields, L" is not initialized, have you forgotten to use [for ...] statement?");
return;
}
} }
} }
// else
// {
// // child found
//
// }
} }
if( var.type == Var<StreamType>::TYPE_SPACE_WRAPPER ) if( !find_helper.found )
{ {
if( var.space_wrapper ) var = FindInScope(name);
if( var )
{ {
status = CallSpace(*var.space_wrapper, name, field_index, fields, result, parameters); // if a function returns another function we should make CallFunction() again?
} if( var->type == Var<StreamType>::TYPE_FUNCTION && var->user_function )
else {
{ CallFunction(var->user_function, find_helper);
// put some log that variable.user_function is null? find_helper.found = true;
}
if( var->type == Var<StreamType>::TYPE_MODEL_CONTAINER_WRAPPER && var->model_container_wrapper )
{
if( find_helper.is_last_field() && is_generating_for )
{
var->model_container_wrapper->increment_iterator();
var->clear_childs();
}
}
if( var->type == Var<StreamType>::TYPE_SPACE_WRAPPER && var->space_wrapper )
{
find_helper.found = CallSpace(*var->space_wrapper, find_helper);
}
if( var->type == Var<StreamType>::TYPE_DATE && var->date )
{
if( find_helper.is_last_field() )
PrintDate(*var->date, find_helper);
}
} }
find_helper.previous_result = var ? &find_helper.result : nullptr;
} }
if( var.type == Var<StreamType>::TYPE_DATE && var.date ) if( find_helper.found )
{ {
if( all_fields_known ) if( find_helper.result.type == Var<StreamType>::Type::TYPE_VOID && !find_helper.result.stream.empty() )
PrintDate(*var.date, parameters, result); find_helper.result.type = Var<StreamType>::Type::TYPE_STREAM;
}
return status; // if( !find_helper.is_last_field() || find_helper.evaluate_last )
// {
//
//
// }
}
} }
@ -2064,15 +1972,6 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallVaria
// give me a better name
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::NormalizeResult(Var<StreamType> & result)
{
if( result.type == Var<StreamType>::TYPE_VOID && !result.stream.empty() )
result.type = Var<StreamType>::TYPE_STREAM;
}
/* /*
* fun_name can be null, it is used only with [let ...] statements * fun_name can be null, it is used only with [let ...] statements
@ -2087,7 +1986,7 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::Call(
Var<StreamType> & result, Var<StreamType> & result,
const StreamType & in_stream) const StreamType & in_stream)
{ {
FindHelper find_helper; //FindHelperOld find_helper;
std::vector<Var<StreamType>> parameters; std::vector<Var<StreamType>> parameters;
// if( clear_out_stream ) // if( clear_out_stream )
@ -2135,10 +2034,9 @@ std::vector<Var<StreamType>> parameters;
} }
} }
size_t field_index = 0; FindHelper find_helper(*name, item_fun.fields, parameters, result);
bool result_status = CallVariable(item_fun.fields, field_index, *var, result, parameters, in_stream); FindVariable(find_helper);
NormalizeResult(result); return find_helper.found;
return result_status;
} }
@ -2531,11 +2429,13 @@ void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::MakeTextF
else else
{ {
Var<StreamType> result; Var<StreamType> result;
Call(item.function, nullptr, result, empty_stream);
if( output_stream ) if( Call(item.function, nullptr, result, empty_stream) )
{ {
result.serialize_to(*output_stream); if( output_stream )
{
result.serialize_to(*output_stream);
}
} }
/* /*

111
src/var.h
View File

@ -42,7 +42,14 @@
#include "date/date.h" #include "date/date.h"
#include "modelcontainerwrapper.h" #include "modelcontainerwrapper.h"
#include "textstream/textstream.h" #include "textstream/textstream.h"
#include "morm.h"
namespace morm
{
class Model;
class ModelContainerWrapper;
class SpaceWrapper;
}
@ -68,11 +75,11 @@ public:
// string or wstring from space_local // string or wstring from space_local
TYPE_VOID, TYPE_VOID,
// or change maybe to something like TYPE_LOCAL_SPACE? TYPE_SPACE_LOCAL,
TYPE_BOOL, // TYPE_BOOL,
TYPE_LONG, // TYPE_LONG,
TYPE_DOUBLE, // TYPE_DOUBLE,
TYPE_STRING, // TYPE_STRING,
TYPE_STREAM, TYPE_STREAM,
@ -375,10 +382,11 @@ bool Var<StreamType>::to_bool() const
case TYPE_VOID: case TYPE_VOID:
return false; return false;
case TYPE_BOOL: // case TYPE_BOOL:
case TYPE_LONG: // case TYPE_LONG:
case TYPE_DOUBLE: // case TYPE_DOUBLE:
case TYPE_STRING: // case TYPE_STRING:
case TYPE_SPACE_LOCAL:
return space_local.to_bool(); return space_local.to_bool();
case TYPE_STREAM: case TYPE_STREAM:
@ -399,7 +407,7 @@ bool Var<StreamType>::to_bool() const
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(const char * str) void Var<StreamType>::set(const char * str)
{ {
type = TYPE_STRING; type = TYPE_SPACE_LOCAL;
space_local.set(str); space_local.set(str);
} }
@ -407,7 +415,7 @@ void Var<StreamType>::set(const char * str)
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(const wchar_t * str) void Var<StreamType>::set(const wchar_t * str)
{ {
type = TYPE_STRING; type = TYPE_SPACE_LOCAL;
space_local.set(str); space_local.set(str);
} }
@ -415,7 +423,7 @@ void Var<StreamType>::set(const wchar_t * str)
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(const std::string & str) void Var<StreamType>::set(const std::string & str)
{ {
type = TYPE_STRING; type = TYPE_SPACE_LOCAL;
space_local.set(str); space_local.set(str);
} }
@ -423,7 +431,7 @@ void Var<StreamType>::set(const std::string & str)
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(const std::wstring & str) void Var<StreamType>::set(const std::wstring & str)
{ {
type = TYPE_STRING; type = TYPE_SPACE_LOCAL;
space_local.set(str); space_local.set(str);
} }
@ -431,21 +439,21 @@ void Var<StreamType>::set(const std::wstring & str)
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(char val) void Var<StreamType>::set(char val)
{ {
type = TYPE_STRING; type = TYPE_SPACE_LOCAL;
space_local.set(str); space_local.set(str);
} }
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(unsigned char val) void Var<StreamType>::set(unsigned char val)
{ {
type = TYPE_STRING; type = TYPE_SPACE_LOCAL;
space_local.set(str); space_local.set(str);
} }
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(wchar_t val) void Var<StreamType>::set(wchar_t val)
{ {
type = TYPE_STRING; type = TYPE_SPACE_LOCAL;
space_local.set(str); space_local.set(str);
} }
*/ */
@ -454,7 +462,7 @@ void Var<StreamType>::set(wchar_t val)
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(bool val) void Var<StreamType>::set(bool val)
{ {
type = TYPE_BOOL; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
@ -463,56 +471,56 @@ void Var<StreamType>::set(bool val)
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(short val) void Var<StreamType>::set(short val)
{ {
type = TYPE_LONG; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(int val) void Var<StreamType>::set(int val)
{ {
type = TYPE_LONG; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(long val) void Var<StreamType>::set(long val)
{ {
type = TYPE_LONG; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(long long val) void Var<StreamType>::set(long long val)
{ {
type = TYPE_LONG; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(unsigned short val) void Var<StreamType>::set(unsigned short val)
{ {
type = TYPE_LONG; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(unsigned int val) void Var<StreamType>::set(unsigned int val)
{ {
type = TYPE_LONG; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(unsigned long val) void Var<StreamType>::set(unsigned long val)
{ {
type = TYPE_LONG; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(unsigned long long val) void Var<StreamType>::set(unsigned long long val)
{ {
type = TYPE_LONG; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
@ -520,7 +528,7 @@ void Var<StreamType>::set(unsigned long long val)
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(float val) void Var<StreamType>::set(float val)
{ {
type = TYPE_DOUBLE; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
@ -528,7 +536,7 @@ void Var<StreamType>::set(float val)
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(double val) void Var<StreamType>::set(double val)
{ {
type = TYPE_DOUBLE; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
@ -536,7 +544,7 @@ void Var<StreamType>::set(double val)
template<typename StreamType> template<typename StreamType>
void Var<StreamType>::set(long double val) void Var<StreamType>::set(long double val)
{ {
type = TYPE_DOUBLE; type = TYPE_SPACE_LOCAL;
space_local.set(val); space_local.set(val);
} }
@ -589,21 +597,26 @@ bool Var<StreamType>::is_equal(const char * str) const
{ {
switch(type) switch(type)
{ {
case TYPE_BOOL: case TYPE_SPACE_LOCAL:
return is_equal_bool(str); if( space_local.is_str() || space_local.is_wstr() )
return is_equal_string(str);
case TYPE_STRING: if( space_local.is_bool() )
return is_equal_string(str); return is_equal_bool(str);
// IMPLEMENTME
// implement the rest of conversion methods
return false;
case TYPE_VOID: case TYPE_VOID:
case TYPE_LONG:
case TYPE_DOUBLE:
case TYPE_STREAM: case TYPE_STREAM:
case TYPE_FUNCTION: case TYPE_FUNCTION:
case TYPE_DATE: case TYPE_DATE:
case TYPE_MODEL: case TYPE_MODEL:
case TYPE_MODEL_CONTAINER_WRAPPER: case TYPE_MODEL_CONTAINER_WRAPPER:
case TYPE_SPACE_WRAPPER: case TYPE_SPACE_WRAPPER:
// IMPLEMENTME
break; break;
} }
@ -617,21 +630,26 @@ bool Var<StreamType>::is_equal(const wchar_t * str) const
{ {
switch(type) switch(type)
{ {
case TYPE_BOOL: case TYPE_SPACE_LOCAL:
return is_equal_bool(str); if( space_local.is_str() || space_local.is_wstr() )
return is_equal_string(str);
case TYPE_STRING: if( space_local.is_bool() )
return is_equal_string(str); return is_equal_bool(str);
// IMPLEMENTME
// implement the rest of conversion methods
return false;
case TYPE_VOID: case TYPE_VOID:
case TYPE_LONG:
case TYPE_DOUBLE:
case TYPE_STREAM: case TYPE_STREAM:
case TYPE_FUNCTION: case TYPE_FUNCTION:
case TYPE_DATE: case TYPE_DATE:
case TYPE_MODEL: case TYPE_MODEL:
case TYPE_MODEL_CONTAINER_WRAPPER: case TYPE_MODEL_CONTAINER_WRAPPER:
case TYPE_SPACE_WRAPPER: case TYPE_SPACE_WRAPPER:
// IMPLEMENTME
break; break;
} }
@ -726,15 +744,16 @@ void Var<StreamType>::serialize_to(pt::WTextStream & str)
{ {
switch(type) switch(type)
{ {
case TYPE_BOOL: case TYPE_SPACE_LOCAL:
case TYPE_LONG: // case TYPE_BOOL:
case TYPE_DOUBLE: // case TYPE_LONG:
case TYPE_STRING: // case TYPE_DOUBLE:
// case TYPE_STRING:
space_local.serialize_to_string(str); space_local.serialize_to_string(str);
break; break;
case TYPE_STREAM: case TYPE_STREAM:
str = stream; str << stream;
break; break;
case TYPE_DATE: case TYPE_DATE: