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

This commit is contained in:
2025-01-15 18:30:30 +01:00
parent e2cfedda6c
commit aaaf38cd79
2 changed files with 69 additions and 25 deletions

View File

@@ -2113,6 +2113,13 @@ bool Model::convert_to_bool(const pt::Space & space)
}
void Model::put_bool_to_stream(bool val, pt::Stream & str)
{
if( val )
str << L"true";
else
str << L"false";
}
} // namespace

View File

@@ -964,8 +964,9 @@ protected:
void field_member_ezc(const wchar_t * db_field_name, const wchar_t * flat_field_name, void (Model::*method)(Ezc::Env &), const FT & field_type)
{
if( model_connector && model_env && model_env->ezc_env && model_env->model )
if( model_connector && model_env && model_env->model )
{
if( field_type.is_primary_key() )
{
pt::Log * plog = model_connector->get_logger();
@@ -976,25 +977,40 @@ protected:
}
}
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM )
if( (is_empty_field(model_env->db_field_name) || is_the_same_field(db_field_name, model_env->db_field_name)) &&
(is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) )
{
field_member_ezc_put_field_value_to_stream(db_field_name, flat_field_name, method, field_type);
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM )
{
model_env->was_field_found = true;
if( model_env->ezc_env )
{
(model_env->model->*method)(*model_env->ezc_env);
// may if the method evaluates to a POD type then we should put such value to the stream?
}
else
{
pt::Log * plog = model_connector->get_logger();
if( plog )
{
(*plog) << pt::Log::log1 << "Morm: this method requires an Ezc::Env object"; // put a field name?
}
}
}
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_EZC_VAL )
{
model_env->was_field_found = true;
model_env->ezc_val.set_pointer_to(model_env->model, method);
}
}
}
}
void field_member_ezc_put_field_value_to_stream(const wchar_t * db_field_name, const wchar_t * flat_field_name, void (Model::*method)(Ezc::Env &), const FT & field_type)
{
if( (is_empty_field(model_env->db_field_name) || is_the_same_field(db_field_name, model_env->db_field_name)) &&
(is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) )
{
model_env->was_field_found = true;
(model_env->model->*method)(*model_env->ezc_env);
}
}
void field_member_ezc(const wchar_t * db_field_name, const wchar_t * flat_field_name, bool (Model::*method)(), const FT & field_type)
{
if( model_connector && model_env && model_env->model )
@@ -1009,14 +1025,20 @@ protected:
}
}
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM )
if( (is_empty_field(model_env->db_field_name) || is_the_same_field(db_field_name, model_env->db_field_name)) &&
(is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) )
{
if( (is_empty_field(model_env->db_field_name) || is_the_same_field(db_field_name, model_env->db_field_name)) &&
(is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) )
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM )
{
model_env->was_field_found = true;
bool result = (model_env->model->*method)();
model_env->ezc_val.set(result);
put_bool_to_stream(result, *model_env->stream);
}
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_EZC_VAL )
{
model_env->was_field_found = true;
model_env->ezc_val.set_pointer_to(model_env->model, method);
}
}
}
@@ -1037,14 +1059,20 @@ protected:
}
}
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM )
if( (is_empty_field(model_env->db_field_name) || is_the_same_field(db_field_name, model_env->db_field_name)) &&
(is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) )
{
if( (is_empty_field(model_env->db_field_name) || is_the_same_field(db_field_name, model_env->db_field_name)) &&
(is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) )
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM )
{
model_env->was_field_found = true;
bool result = (model_env->model->*method)();
model_env->ezc_val.set(result);
put_bool_to_stream(result, *model_env->stream);
}
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_EZC_VAL )
{
model_env->was_field_found = true;
model_env->ezc_val.set_pointer_to(model_env->model, method);
}
}
}
@@ -1065,10 +1093,18 @@ protected:
}
}
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_EZC_VAL )
if( (is_empty_field(model_env->db_field_name) || is_the_same_field(db_field_name, model_env->db_field_name)) &&
(is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) )
{
if( (is_empty_field(model_env->db_field_name) || is_the_same_field(db_field_name, model_env->db_field_name)) &&
(is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) )
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PUT_FIELD_RAW_VALUE_TO_STREAM )
{
model_env->was_field_found = true;
(model_env->model->*method)(model_env->ezc_val);
// may if the method evaluates to a POD type then we should put such value to the stream?
}
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_EZC_VAL )
{
model_env->ezc_val.set_pointer_to(model_env->model, method);
}
@@ -1685,6 +1721,7 @@ protected:
virtual bool convert_to_bool(const pt::Stream & val);
virtual bool convert_to_bool(const pt::Space & space);
virtual void put_bool_to_stream(bool val, pt::Stream & str);
template<typename ModelClass> friend class Finder;
template<typename ModelClass> friend class Cursor;