use new FindHelper struct in places where fields, field_index, parameters variables were used
This commit is contained in:
parent
6d79cdb2fc
commit
b8a9217429
|
@ -124,9 +124,6 @@ struct Stack
|
|||
};
|
||||
|
||||
|
||||
// !! IMPROVE ME
|
||||
// the name is bad
|
||||
// may it should be called Env (environment) or FunEnv
|
||||
template<class StreamType>
|
||||
struct Env
|
||||
{
|
||||
|
|
622
src/generator.h
622
src/generator.h
|
@ -135,7 +135,7 @@ public:
|
|||
private:
|
||||
|
||||
|
||||
struct FindHelper
|
||||
struct FindHelperOld
|
||||
{
|
||||
//const std::wstring * fun_name;
|
||||
|
||||
|
@ -151,7 +151,7 @@ private:
|
|||
size_t field_index;
|
||||
#endif
|
||||
|
||||
FindHelper()
|
||||
FindHelperOld()
|
||||
{
|
||||
//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
|
||||
{
|
||||
std::vector<Var<StreamType>> args;
|
||||
|
@ -282,70 +321,67 @@ private:
|
|||
|
||||
bool IsTestingFunctionExistence();
|
||||
|
||||
bool CheckBlockArgument(int arg_index, FindHelper & find_helper);
|
||||
bool CheckBlockArgument(int arg_index, FindHelperOld & find_helper);
|
||||
|
||||
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
bool FindInModels(FindHelper & find_helper);
|
||||
//bool FindInModels(FindHelperOld & find_helper);
|
||||
#endif
|
||||
|
||||
void PrepareEnvStruct(Env<StreamType> & info);
|
||||
|
||||
void CallFunction(typename Functions<StreamType>::UserFunction & function, Env<StreamType> & info);
|
||||
|
||||
void CallFunction(typename Functions<StreamType>::UserFunction & function,
|
||||
Var<StreamType> & result,
|
||||
std::vector<Var<StreamType>> & parameters,
|
||||
const StreamType & in_stream);
|
||||
void CallFunction(typename Functions<StreamType>::UserFunction & function, FindHelper & find_helper);
|
||||
|
||||
bool CallBlock(Item & item_block,
|
||||
Var<StreamType> & result,
|
||||
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 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 CallSpaceObjectForLastField(Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, pt::Space * space);
|
||||
void PrintLastSpaceField(pt::Space & space, FindHelper & find_helper);
|
||||
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);
|
||||
|
||||
void CallSpaceTableForLastField(morm::SpaceWrapper & space_wrapper, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters,
|
||||
pt::Space * space, size_t model_wrapper_space_table_index);
|
||||
void CallSpaceTableForLastField(morm::SpaceWrapper & space_wrapper, pt::Space & space, FindHelper & find_helper, 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,
|
||||
size_t field_index, pt::Space * space, size_t model_wrapper_space_table_index);
|
||||
pt::Space * CallSpaceTableForMiddleField(morm::SpaceWrapper & space_wrapper, pt::Space & space, FindHelper & find_helper, 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
|
||||
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,
|
||||
// std::vector<Var<StreamType>> & parameters, Var<StreamType> & result);
|
||||
// void FindLastModelWrapper(FindHelper & 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 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);
|
||||
// void FindLastModelWrapper(FindHelperOld & find_helper, std::vector<std::wstring> & fields);
|
||||
// bool CallWrapper(FindHelperOld & find_helper, std::vector<std::wstring> & fields, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters, const StreamType & in_stream);
|
||||
|
||||
#endif
|
||||
|
||||
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,
|
||||
std::vector<std::wstring> & fields,
|
||||
size_t & field_index,
|
||||
Var<StreamType> & result,
|
||||
std::vector<Var<StreamType>> & parameters,
|
||||
const StreamType & in_stream);
|
||||
// bool CallVariable(FindHelper & findxxx
|
||||
// const std::wstring & name,
|
||||
// std::vector<std::wstring> & fields,
|
||||
// size_t & field_index,
|
||||
// Var<StreamType> & result,
|
||||
// std::vector<Var<StreamType>> & parameters
|
||||
// );
|
||||
|
||||
void NormalizeResult(Var<StreamType> & result);
|
||||
|
||||
bool Call(Item::Function & item_fun,
|
||||
const std::wstring * fun_name,
|
||||
|
@ -368,7 +404,7 @@ private:
|
|||
bool ShouldMakeJsonDump(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);
|
||||
|
||||
|
||||
|
@ -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>
|
||||
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 )
|
||||
return false;
|
||||
|
@ -953,22 +989,22 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CheckBloc
|
|||
|
||||
#ifdef EZC_HAS_MORM_LIBRARY
|
||||
|
||||
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
|
||||
bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::FindInModels(FindHelper & find_helper)
|
||||
{
|
||||
if( pmodels )
|
||||
{
|
||||
morm::Wrapper * m = pmodels->Find(*find_helper.fun_name);
|
||||
|
||||
if( m )
|
||||
{
|
||||
find_helper.wrapper = m;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
//template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
|
||||
//bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::FindInModels(FindHelperOld & find_helper)
|
||||
//{
|
||||
// if( pmodels )
|
||||
// {
|
||||
// morm::Wrapper * m = pmodels->Find(*find_helper.fun_name);
|
||||
//
|
||||
// if( m )
|
||||
// {
|
||||
// find_helper.wrapper = m;
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return false;
|
||||
//}
|
||||
|
||||
#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>
|
||||
void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallFunction(typename Functions<StreamType>::UserFunction & function,
|
||||
Var<StreamType> & result,
|
||||
std::vector<Var<StreamType>> & parameters,
|
||||
const StreamType & in_stream)
|
||||
void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallFunction(
|
||||
typename Functions<StreamType>::UserFunction & function, FindHelper & find_helper)
|
||||
{
|
||||
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);
|
||||
CallFunction(function, info);
|
||||
}
|
||||
else
|
||||
{
|
||||
Env<StreamType> info(result, parameters, in_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
|
||||
StreamType fake_stream;
|
||||
Env<StreamType> info(find_helper.result, find_helper.parameters, fake_stream, stack_tab[stack_index-1], *stack_tab[stack_index-1].item);
|
||||
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>
|
||||
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_json = ShouldMakeJsonDump(parameters);
|
||||
bool dump_space = ShouldMakeSpaceDump(find_helper.parameters);
|
||||
bool dump_json = ShouldMakeJsonDump(find_helper.parameters);
|
||||
|
||||
if( dump_space || dump_json )
|
||||
{
|
||||
bool pretty = IsPrettyPrint(parameters);
|
||||
bool pretty = IsPrettyPrint(find_helper.parameters);
|
||||
|
||||
if( dump_space )
|
||||
{
|
||||
space->serialize_to_space_stream(result.stream, pretty);
|
||||
result.type = Var<StreamType>::TYPE_STREAM;
|
||||
space.serialize_to_space_stream(find_helper.result.stream, pretty);
|
||||
find_helper.result.type = Var<StreamType>::TYPE_STREAM;
|
||||
}
|
||||
else
|
||||
if( dump_json )
|
||||
{
|
||||
space->serialize_to_json_stream(result.stream, pretty);
|
||||
result.type = Var<StreamType>::TYPE_STREAM;
|
||||
space.serialize_to_json_stream(find_helper.result.stream, pretty);
|
||||
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>
|
||||
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_no_sec = HasParam(parameters, L"no_sec");
|
||||
bool only_date = HasParam(parameters, L"only_date");
|
||||
bool only_time = HasParam(parameters, L"only_time");
|
||||
bool is_roman = HasParam(find_helper.parameters, L"roman");
|
||||
bool is_no_sec = HasParam(find_helper.parameters, L"no_sec");
|
||||
bool only_date = HasParam(find_helper.parameters, L"only_date");
|
||||
bool only_time = HasParam(find_helper.parameters, L"only_time");
|
||||
|
||||
if( only_date )
|
||||
{
|
||||
result.type = Var<StreamType>::TYPE_STREAM;
|
||||
date.SerializeYearMonthDay(result.stream, is_roman);
|
||||
find_helper.result.type = Var<StreamType>::TYPE_STREAM;
|
||||
date.SerializeYearMonthDay(find_helper.result.stream, is_roman);
|
||||
}
|
||||
else
|
||||
if( only_time )
|
||||
{
|
||||
result.type = Var<StreamType>::TYPE_STREAM;
|
||||
find_helper.result.type = Var<StreamType>::TYPE_STREAM;
|
||||
|
||||
if( is_no_sec )
|
||||
date.SerializeHourMin(result.stream);
|
||||
date.SerializeHourMin(find_helper.result.stream);
|
||||
else
|
||||
date.SerializeHourMinSec(result.stream);
|
||||
date.SerializeHourMinSec(find_helper.result.stream);
|
||||
}
|
||||
else
|
||||
{
|
||||
result.type = Var<StreamType>::TYPE_STREAM;
|
||||
date.Serialize(result.stream, is_roman, !is_no_sec);
|
||||
find_helper.result.type = Var<StreamType>::TYPE_STREAM;
|
||||
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>
|
||||
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() )
|
||||
{
|
||||
// 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>
|
||||
void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpaceTableForLastField(
|
||||
morm::SpaceWrapper & space_wrapper, Var<StreamType> & result, std::vector<Var<StreamType>> & parameters,
|
||||
pt::Space * space, size_t model_wrapper_space_table_index)
|
||||
morm::SpaceWrapper & space_wrapper, pt::Space & space, FindHelper & find_helper, 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 )
|
||||
{
|
||||
|
@ -1318,16 +1352,18 @@ void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallSpace
|
|||
|
||||
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>
|
||||
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,
|
||||
size_t field_index, pt::Space * space, size_t model_wrapper_space_table_index)
|
||||
morm::SpaceWrapper & space_wrapper, pt::Space & space_table, FindHelper & find_helper, 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
|
||||
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
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
@ -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>
|
||||
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?
|
||||
|
||||
if( no_escape )
|
||||
{
|
||||
//pt::WTextStream str;
|
||||
space->serialize_to_string(result.stream);
|
||||
result.type = Var<StreamType>::TYPE_STREAM;
|
||||
space.serialize_to_string(find_helper.result.stream);
|
||||
find_helper.result.type = Var<StreamType>::TYPE_STREAM;
|
||||
//CopyStream(str, out_stream, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// space->serialize_to_string(out_stream);
|
||||
space->serialize_to_string(result.stream);
|
||||
result.type = Var<StreamType>::TYPE_STREAM;
|
||||
space.serialize_to_string(find_helper.result.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>
|
||||
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;
|
||||
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
|
||||
*
|
||||
*/
|
||||
while( (field_index < fields.size() + 1) && space )
|
||||
while( (find_helper.field_index < find_helper.fields.size() + 1) && space )
|
||||
{
|
||||
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);
|
||||
|
||||
if( !next_space )
|
||||
{
|
||||
CallSpaceObjectForLastField(result, parameters, space);
|
||||
CallSpaceObjectForLastField(*space, find_helper);
|
||||
status = true;
|
||||
}
|
||||
|
||||
space = next_space;
|
||||
|
||||
if( space )
|
||||
field_index += 1;
|
||||
find_helper.field_index += 1;
|
||||
}
|
||||
else
|
||||
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);
|
||||
field_index += 1;
|
||||
CallSpaceTableForLastField(space_wrapper, *space, find_helper, model_wrapper_space_table_index);
|
||||
find_helper.field_index += 1;
|
||||
status = true;
|
||||
}
|
||||
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
|
||||
|
||||
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" )
|
||||
{
|
||||
field_index += 1;
|
||||
find_helper.field_index += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintLastSpaceField(space, result, parameters);
|
||||
PrintLastSpaceField(*space, find_helper);
|
||||
status = true;
|
||||
// increment field_index here?
|
||||
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>
|
||||
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()
|
||||
|
@ -1502,8 +1536,8 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::CallModel
|
|||
bool found = false;
|
||||
StreamType fake_stream;
|
||||
|
||||
Env<StreamType> info(result, 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);
|
||||
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, find_helper.current_name().c_str(), nullptr, info);
|
||||
|
||||
// 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>
|
||||
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)
|
||||
{
|
||||
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()
|
||||
while( field_index < fields.size() )
|
||||
{
|
||||
std::wstring & field = fields[field_index];
|
||||
size_t old_field_index = field_index;
|
||||
|
||||
if( last_var->type == Var<StreamType>::TYPE_FUNCTION )
|
||||
{
|
||||
std::vector<Var<StreamType>> params;
|
||||
params.push_back(*last_var);
|
||||
field_index += 1;
|
||||
|
||||
if( !CallVariable(field, fields, field_index, res, params, in_stream) )
|
||||
return false;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
//template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
|
||||
//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)
|
||||
//{
|
||||
// Var<StreamType> * variable = FindVariable(find_helper);
|
||||
// bool status = false;
|
||||
//
|
||||
// if( variable )
|
||||
// {
|
||||
// // here we cannot pass 'name' but the last field instead?
|
||||
// status = EvaluateVariable(name, *variable, fields, field_index, parameters, result);
|
||||
// }
|
||||
//
|
||||
// return status;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
@ -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>
|
||||
Var<StreamType> * Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::FindVariable(
|
||||
const std::wstring & name, std::vector<std::wstring> & fields, size_t & field_index, std::vector<Var<StreamType>> & parameters)
|
||||
void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::FindVariable(FindHelper & find_helper)
|
||||
{
|
||||
Var<StreamType> * var = nullptr;
|
||||
std::vector<Var<StreamType>> res;
|
||||
res.resize(1);
|
||||
bool was_evaluated = false;
|
||||
find_helper.field_index = 0;
|
||||
find_helper.previous_name = nullptr;
|
||||
find_helper.previous_result = nullptr;
|
||||
|
||||
do
|
||||
{
|
||||
const std::wstring * pname = (field_index == 0)? &name : &fields[field_index - 1];
|
||||
Var<StreamType> * old_var = var;
|
||||
var = nullptr;
|
||||
find_helper.found = false;
|
||||
EvaluateVariable(find_helper);
|
||||
|
||||
if( field_index > 1 && old_var )
|
||||
if( find_helper.found )
|
||||
{
|
||||
var = old_var->find_child(*pname);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
find_helper.previous_name = &find_helper.current_name();
|
||||
find_helper.field_index += 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
// log something
|
||||
find_helper.result.clear();
|
||||
}
|
||||
|
||||
field_index += 1;
|
||||
}
|
||||
while( field_index < fields.size() + 1 && var )
|
||||
|
||||
return var;
|
||||
while( find_helper.found && find_helper.field_index < find_helper.fields.size() + 1 );
|
||||
}
|
||||
|
||||
|
||||
template<class StreamType, bool is_pikotools_stream, bool is_autoescape_stream>
|
||||
bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::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 Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::EvaluateVariable(FindHelper & find_helper)
|
||||
{
|
||||
StreamType fake_stream;
|
||||
bool status = false;
|
||||
bool all_fields_known = (field_index == fields.size());
|
||||
Var<StreamType> * var = nullptr;
|
||||
const std::wstring & name = find_helper.current_name();
|
||||
|
||||
if( var.type == Var<StreamType>::TYPE_FUNCTION )
|
||||
if( find_helper.previous_name && find_helper.previous_result )
|
||||
{
|
||||
if( var.user_function )
|
||||
{
|
||||
CallFunction(var.user_function, result, parameters, fake_stream);
|
||||
status = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// put some log that variable.user_function is null?
|
||||
}
|
||||
}
|
||||
//var = find_helper.previous_result->find_child(name);
|
||||
|
||||
if( var.type == Var<StreamType>::TYPE_MODEL )
|
||||
{
|
||||
if( var.model )
|
||||
//if( !var )
|
||||
{
|
||||
status = CallModelField(*var.model, name, result, parameters);
|
||||
}
|
||||
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 )
|
||||
if( find_helper.previous_result->type == Var<StreamType>::TYPE_MODEL )
|
||||
{
|
||||
var.model_container_wrapper->increment_iterator();
|
||||
var.clear_childs();
|
||||
find_helper.found = CallModelField(*find_helper.previous_result->model, find_helper);
|
||||
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);
|
||||
}
|
||||
else
|
||||
{
|
||||
// put some log that variable.user_function is null?
|
||||
// if a function returns another function we should make CallFunction() again?
|
||||
if( var->type == Var<StreamType>::TYPE_FUNCTION && var->user_function )
|
||||
{
|
||||
CallFunction(var->user_function, find_helper);
|
||||
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 )
|
||||
PrintDate(*var.date, parameters, result);
|
||||
}
|
||||
if( find_helper.result.type == Var<StreamType>::Type::TYPE_VOID && !find_helper.result.stream.empty() )
|
||||
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
|
||||
|
@ -2087,7 +1986,7 @@ bool Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::Call(
|
|||
Var<StreamType> & result,
|
||||
const StreamType & in_stream)
|
||||
{
|
||||
FindHelper find_helper;
|
||||
//FindHelperOld find_helper;
|
||||
std::vector<Var<StreamType>> parameters;
|
||||
|
||||
// if( clear_out_stream )
|
||||
|
@ -2135,10 +2034,9 @@ std::vector<Var<StreamType>> parameters;
|
|||
}
|
||||
}
|
||||
|
||||
size_t field_index = 0;
|
||||
bool result_status = CallVariable(item_fun.fields, field_index, *var, result, parameters, in_stream);
|
||||
NormalizeResult(result);
|
||||
return result_status;
|
||||
FindHelper find_helper(*name, item_fun.fields, parameters, result);
|
||||
FindVariable(find_helper);
|
||||
return find_helper.found;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2531,11 +2429,13 @@ void Generator<StreamType, is_pikotools_stream, is_autoescape_stream>::MakeTextF
|
|||
else
|
||||
{
|
||||
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
111
src/var.h
|
@ -42,7 +42,14 @@
|
|||
#include "date/date.h"
|
||||
#include "modelcontainerwrapper.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
|
||||
TYPE_VOID,
|
||||
|
||||
// or change maybe to something like TYPE_LOCAL_SPACE?
|
||||
TYPE_BOOL,
|
||||
TYPE_LONG,
|
||||
TYPE_DOUBLE,
|
||||
TYPE_STRING,
|
||||
TYPE_SPACE_LOCAL,
|
||||
// TYPE_BOOL,
|
||||
// TYPE_LONG,
|
||||
// TYPE_DOUBLE,
|
||||
// TYPE_STRING,
|
||||
|
||||
TYPE_STREAM,
|
||||
|
||||
|
@ -375,10 +382,11 @@ bool Var<StreamType>::to_bool() const
|
|||
case TYPE_VOID:
|
||||
return false;
|
||||
|
||||
case TYPE_BOOL:
|
||||
case TYPE_LONG:
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_STRING:
|
||||
// case TYPE_BOOL:
|
||||
// case TYPE_LONG:
|
||||
// case TYPE_DOUBLE:
|
||||
// case TYPE_STRING:
|
||||
case TYPE_SPACE_LOCAL:
|
||||
return space_local.to_bool();
|
||||
|
||||
case TYPE_STREAM:
|
||||
|
@ -399,7 +407,7 @@ bool Var<StreamType>::to_bool() const
|
|||
template<typename StreamType>
|
||||
void Var<StreamType>::set(const char * str)
|
||||
{
|
||||
type = TYPE_STRING;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(str);
|
||||
}
|
||||
|
||||
|
@ -407,7 +415,7 @@ void Var<StreamType>::set(const char * str)
|
|||
template<typename StreamType>
|
||||
void Var<StreamType>::set(const wchar_t * str)
|
||||
{
|
||||
type = TYPE_STRING;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(str);
|
||||
}
|
||||
|
||||
|
@ -415,7 +423,7 @@ void Var<StreamType>::set(const wchar_t * str)
|
|||
template<typename StreamType>
|
||||
void Var<StreamType>::set(const std::string & str)
|
||||
{
|
||||
type = TYPE_STRING;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(str);
|
||||
}
|
||||
|
||||
|
@ -423,7 +431,7 @@ void Var<StreamType>::set(const std::string & str)
|
|||
template<typename StreamType>
|
||||
void Var<StreamType>::set(const std::wstring & str)
|
||||
{
|
||||
type = TYPE_STRING;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(str);
|
||||
}
|
||||
|
||||
|
@ -431,21 +439,21 @@ void Var<StreamType>::set(const std::wstring & str)
|
|||
template<typename StreamType>
|
||||
void Var<StreamType>::set(char val)
|
||||
{
|
||||
type = TYPE_STRING;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(str);
|
||||
}
|
||||
|
||||
template<typename StreamType>
|
||||
void Var<StreamType>::set(unsigned char val)
|
||||
{
|
||||
type = TYPE_STRING;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(str);
|
||||
}
|
||||
|
||||
template<typename StreamType>
|
||||
void Var<StreamType>::set(wchar_t val)
|
||||
{
|
||||
type = TYPE_STRING;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(str);
|
||||
}
|
||||
*/
|
||||
|
@ -454,7 +462,7 @@ void Var<StreamType>::set(wchar_t val)
|
|||
template<typename StreamType>
|
||||
void Var<StreamType>::set(bool val)
|
||||
{
|
||||
type = TYPE_BOOL;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
|
@ -463,56 +471,56 @@ void Var<StreamType>::set(bool val)
|
|||
template<typename StreamType>
|
||||
void Var<StreamType>::set(short val)
|
||||
{
|
||||
type = TYPE_LONG;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
template<typename StreamType>
|
||||
void Var<StreamType>::set(int val)
|
||||
{
|
||||
type = TYPE_LONG;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
template<typename StreamType>
|
||||
void Var<StreamType>::set(long val)
|
||||
{
|
||||
type = TYPE_LONG;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
template<typename StreamType>
|
||||
void Var<StreamType>::set(long long val)
|
||||
{
|
||||
type = TYPE_LONG;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
template<typename StreamType>
|
||||
void Var<StreamType>::set(unsigned short val)
|
||||
{
|
||||
type = TYPE_LONG;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
template<typename StreamType>
|
||||
void Var<StreamType>::set(unsigned int val)
|
||||
{
|
||||
type = TYPE_LONG;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
template<typename StreamType>
|
||||
void Var<StreamType>::set(unsigned long val)
|
||||
{
|
||||
type = TYPE_LONG;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
template<typename StreamType>
|
||||
void Var<StreamType>::set(unsigned long long val)
|
||||
{
|
||||
type = TYPE_LONG;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
|
@ -520,7 +528,7 @@ void Var<StreamType>::set(unsigned long long val)
|
|||
template<typename StreamType>
|
||||
void Var<StreamType>::set(float val)
|
||||
{
|
||||
type = TYPE_DOUBLE;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
|
@ -528,7 +536,7 @@ void Var<StreamType>::set(float val)
|
|||
template<typename StreamType>
|
||||
void Var<StreamType>::set(double val)
|
||||
{
|
||||
type = TYPE_DOUBLE;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
|
@ -536,7 +544,7 @@ void Var<StreamType>::set(double val)
|
|||
template<typename StreamType>
|
||||
void Var<StreamType>::set(long double val)
|
||||
{
|
||||
type = TYPE_DOUBLE;
|
||||
type = TYPE_SPACE_LOCAL;
|
||||
space_local.set(val);
|
||||
}
|
||||
|
||||
|
@ -589,21 +597,26 @@ bool Var<StreamType>::is_equal(const char * str) const
|
|||
{
|
||||
switch(type)
|
||||
{
|
||||
case TYPE_BOOL:
|
||||
return is_equal_bool(str);
|
||||
case TYPE_SPACE_LOCAL:
|
||||
if( space_local.is_str() || space_local.is_wstr() )
|
||||
return is_equal_string(str);
|
||||
|
||||
case TYPE_STRING:
|
||||
return is_equal_string(str);
|
||||
if( space_local.is_bool() )
|
||||
return is_equal_bool(str);
|
||||
|
||||
// IMPLEMENTME
|
||||
// implement the rest of conversion methods
|
||||
|
||||
return false;
|
||||
|
||||
case TYPE_VOID:
|
||||
case TYPE_LONG:
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_STREAM:
|
||||
case TYPE_FUNCTION:
|
||||
case TYPE_DATE:
|
||||
case TYPE_MODEL:
|
||||
case TYPE_MODEL_CONTAINER_WRAPPER:
|
||||
case TYPE_SPACE_WRAPPER:
|
||||
// IMPLEMENTME
|
||||
break;
|
||||
|
||||
}
|
||||
|
@ -617,21 +630,26 @@ bool Var<StreamType>::is_equal(const wchar_t * str) const
|
|||
{
|
||||
switch(type)
|
||||
{
|
||||
case TYPE_BOOL:
|
||||
return is_equal_bool(str);
|
||||
case TYPE_SPACE_LOCAL:
|
||||
if( space_local.is_str() || space_local.is_wstr() )
|
||||
return is_equal_string(str);
|
||||
|
||||
case TYPE_STRING:
|
||||
return is_equal_string(str);
|
||||
if( space_local.is_bool() )
|
||||
return is_equal_bool(str);
|
||||
|
||||
// IMPLEMENTME
|
||||
// implement the rest of conversion methods
|
||||
|
||||
return false;
|
||||
|
||||
case TYPE_VOID:
|
||||
case TYPE_LONG:
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_STREAM:
|
||||
case TYPE_FUNCTION:
|
||||
case TYPE_DATE:
|
||||
case TYPE_MODEL:
|
||||
case TYPE_MODEL_CONTAINER_WRAPPER:
|
||||
case TYPE_SPACE_WRAPPER:
|
||||
// IMPLEMENTME
|
||||
break;
|
||||
|
||||
}
|
||||
|
@ -726,15 +744,16 @@ void Var<StreamType>::serialize_to(pt::WTextStream & str)
|
|||
{
|
||||
switch(type)
|
||||
{
|
||||
case TYPE_BOOL:
|
||||
case TYPE_LONG:
|
||||
case TYPE_DOUBLE:
|
||||
case TYPE_STRING:
|
||||
case TYPE_SPACE_LOCAL:
|
||||
// case TYPE_BOOL:
|
||||
// case TYPE_LONG:
|
||||
// case TYPE_DOUBLE:
|
||||
// case TYPE_STRING:
|
||||
space_local.serialize_to_string(str);
|
||||
break;
|
||||
|
||||
case TYPE_STREAM:
|
||||
str = stream;
|
||||
str << stream;
|
||||
break;
|
||||
|
||||
case TYPE_DATE:
|
||||
|
|
Loading…
Reference in New Issue