WIP: add a Val struct as an input/output when calling a function

This commit is contained in:
2025-01-30 18:05:37 +01:00
parent 44ea6a162e
commit b646287c9b
3 changed files with 43 additions and 9 deletions

View File

@@ -2059,10 +2059,13 @@ bool Generator::EvaluateFunctions(pt::Stream & out_stream, ValWrapper & valwrapp
{ {
valwrapper.has_evaluated_val = true; valwrapper.has_evaluated_val = true;
if( out_stream.size() != current_size ) if( valwrapper.evaluated_val.is_allowed_to_cache() )
{ {
valwrapper.evaluated_str = out_stream.new_empty(); if( out_stream.size() != current_size )
copy_stream(out_stream, current_size, out_stream.size(), *valwrapper.evaluated_str); {
valwrapper.evaluated_str = out_stream.new_empty();
copy_stream(out_stream, current_size, out_stream.size(), *valwrapper.evaluated_str);
}
} }
} }
else else
@@ -2124,13 +2127,16 @@ bool Generator::FindLastModelWrapper(FindHelper & find_helper, bool is_for_alias
ValWrapper valwrapper; ValWrapper valwrapper;
valwrapper.val = model->get_ezc_val(nullptr, field.c_str()); // may it would be better to provide a pointer to get_ezc_val() method? valwrapper.val = model->get_ezc_val(nullptr, field.c_str()); // may it would be better to provide a pointer to get_ezc_val() method?
if( (find_helper.field_index + 1 < find_helper.fields.size()) || !is_for_alias ) if( valwrapper.val.has_function() || valwrapper.val.has_method() )
{ {
bool use_parameters = (find_helper.field_index + 1 == find_helper.fields.size()); if( (find_helper.field_index + 1 < find_helper.fields.size()) || !is_for_alias )
if( EvaluateFunctions(find_helper, use_parameters, valwrapper) )
{ {
child_valwrapper = find_helper.valwrapper->add_child(field, valwrapper); bool use_parameters = (find_helper.field_index + 1 == find_helper.fields.size());
if( !EvaluateFunctions(find_helper, use_parameters, valwrapper) )
{
return false;
}
} }
} }

View File

@@ -105,6 +105,7 @@ void Val::copy(const Val & val)
// space = val.space; // space = val.space;
output_stream = val.output_stream; output_stream = val.output_stream;
allow_to_cache_value = val.allow_to_cache_value;
increment_model_container_wrapper_ref(); increment_model_container_wrapper_ref();
increment_space_wrapper_ref(); increment_space_wrapper_ref();
@@ -160,6 +161,7 @@ void Val::initialize_empty()
model_method4 = nullptr; model_method4 = nullptr;
space_wrapper = nullptr; space_wrapper = nullptr;
space_table_index = 0; space_table_index = 0;
allow_to_cache_value = false;
} }
@@ -496,6 +498,7 @@ void Val::set_pointer_to(morm::ModelContainerWrapper * model_container_wrapper)
clear(); clear();
type = TYPE_MODEL_CONTAINER_WRAPPER; type = TYPE_MODEL_CONTAINER_WRAPPER;
this->pointer = model_container_wrapper; this->pointer = model_container_wrapper;
this->allow_to_cache_value = true;
model_container_wrapper->increment_reference_counter(); model_container_wrapper->increment_reference_counter();
} }
@@ -507,6 +510,7 @@ void Val::set_pointer_to(morm::SpaceWrapper * space_wrapper)
this->pointer = space_wrapper->get_space(); this->pointer = space_wrapper->get_space();
this->space_wrapper = space_wrapper; this->space_wrapper = space_wrapper;
this->space_wrapper->increment_reference_counter(); this->space_wrapper->increment_reference_counter();
this->allow_to_cache_value = true;
} }
@@ -518,7 +522,8 @@ void Val::set_pointer_to(pt::Space * space, bool create_wrapper)
if( create_wrapper ) if( create_wrapper )
{ {
space_wrapper = new morm::SpaceWrapper(space); this->space_wrapper = new morm::SpaceWrapper(space);
this->allow_to_cache_value = true;
} }
} }
@@ -1344,6 +1349,17 @@ void Val::put_pod_type_to_stream()
} }
void Val::allow_to_cache(bool allow_to_cache)
{
this->allow_to_cache_value = allow_to_cache;
}
bool Val::is_allowed_to_cache()
{
return this->allow_to_cache_value;
}
} // namespace Ezc } // namespace Ezc

View File

@@ -237,8 +237,14 @@ public:
Val & operator=(bool res); Val & operator=(bool res);
void put_pod_type_to_stream(); void put_pod_type_to_stream();
void allow_to_cache(bool allow_to_cache);
bool is_allowed_to_cache();
Type type; Type type;
pt::Space space_local; pt::Space space_local;
void * pointer; void * pointer;
@@ -255,6 +261,8 @@ public:
morm::SpaceWrapper * space_wrapper; morm::SpaceWrapper * space_wrapper;
size_t space_table_index; size_t space_table_index;
bool allow_to_cache_value;
// UserFunction user_function; // UserFunction user_function;
// // Wrapper // // Wrapper
@@ -340,6 +348,7 @@ void Val::set_pointer_to(std::vector<ModelType> * model_container)
clear(); clear();
type = TYPE_MODEL_CONTAINER_WRAPPER; type = TYPE_MODEL_CONTAINER_WRAPPER;
this->pointer = new morm::ModelWrapperVector<ModelType>(model_container); this->pointer = new morm::ModelWrapperVector<ModelType>(model_container);
this->allow_to_cache_value = true;
} }
@@ -349,6 +358,7 @@ void Val::set_pointer_to(std::list<ModelType> * model_container)
clear(); clear();
type = TYPE_MODEL_CONTAINER_WRAPPER; type = TYPE_MODEL_CONTAINER_WRAPPER;
this->pointer = new morm::ModelWrapperList<ModelType>(model_container); this->pointer = new morm::ModelWrapperList<ModelType>(model_container);
this->allow_to_cache_value = true;
} }
@@ -358,6 +368,7 @@ void Val::set_pointer_to(std::vector<ModelType*> * model_container)
clear(); clear();
type = TYPE_MODEL_CONTAINER_WRAPPER; type = TYPE_MODEL_CONTAINER_WRAPPER;
this->pointer = new morm::ModelWrapperVectorPointer<ModelType>(model_container); this->pointer = new morm::ModelWrapperVectorPointer<ModelType>(model_container);
this->allow_to_cache_value = true;
} }
@@ -367,6 +378,7 @@ void Val::set_pointer_to(std::list<ModelType*> * model_container)
clear(); clear();
type = TYPE_MODEL_CONTAINER_WRAPPER; type = TYPE_MODEL_CONTAINER_WRAPPER;
this->pointer = new morm::ModelWrapperListPointer<ModelType>(model_container); this->pointer = new morm::ModelWrapperListPointer<ModelType>(model_container);
this->allow_to_cache_value = true;
} }