From e2cfedda6c0e0ad2713890fda9b9c89977cd953e Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Sun, 12 Jan 2025 16:58:15 +0100 Subject: [PATCH] WIP: add a Val struct as an input/output when calling a function --- src/model.cpp | 7 +++-- src/model.h | 74 ++++++++++++++++++++++---------------------------- src/modelenv.h | 12 ++------ 3 files changed, 40 insertions(+), 53 deletions(-) diff --git a/src/model.cpp b/src/model.cpp index 2586a79..ec0d7c6 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -1663,15 +1663,16 @@ void Model::field_model(const wchar_t * db_field_name, const wchar_t * flat_fiel } } + #ifdef MORM_HAS_EZC_LIBRARY 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)) && - !model_env->ezc_val.pointer ) + (is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) ) { model_env->ezc_val.set_pointer_to(&field_model); } } + #endif if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_PROPAGATE_SAVE_STATUS ) { @@ -1956,7 +1957,7 @@ void Model::field_member( if( plog ) { - (*plog) << pt::Log::log1 << "Morm:: getters and setters cannot be used as a primary key" << pt::Log::logend; + (*plog) << pt::Log::log1 << "Morm: getters and setters cannot be used as a primary key" << pt::Log::logend; } } diff --git a/src/model.h b/src/model.h index 1cc0749..e31775e 100644 --- a/src/model.h +++ b/src/model.h @@ -264,13 +264,13 @@ public: bool get_raw_value(const wchar_t * db_field_name, const wchar_t * flat_field_name, ModelData * model_data, pt::Stream & stream, bool clear_stream = true); - #ifdef MORM_HAS_EZC_LIBRARY Ezc::Val get_ezc_val(const wchar_t * db_field_name, const wchar_t * flat_field_name); + /* bool get_raw_value(const wchar_t * db_field_name, const wchar_t * flat_field_name, ModelData * model_data, - Ezc::Env & fun_info, pt::Stream & stream, bool clear_stream = true) + Ezc::Env & ezc_env, pt::Stream & stream, bool clear_stream = true) { if( clear_stream ) { @@ -286,14 +286,12 @@ public: model_env->flat_field_name = flat_field_name; model_env->model_data = model_data; model_env->stream = &stream; - model_env->ezc_fun_info = &fun_info; - model_env->ezc_fun_info_typeinfo = &typeid(fun_info); // now we don't need to check types, Env is not a template now + model_env->ezc_env = &ezc_env; model_env->model = this; try { fields(); - //fun_info.res = model_env->ezc_fun_result; } catch(...) { @@ -304,6 +302,7 @@ public: model_env = nullptr; return model_env_local.was_field_found; } + */ #endif @@ -881,16 +880,17 @@ protected: { if( model_connector && model_env ) { + #ifdef MORM_HAS_EZC_LIBRARY 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)) && - !model_env->ezc_val.pointer ) + (is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) ) { model_env->ezc_val.set_pointer_to(&field_value); } } else + #endif { field_generic(db_field_name, flat_field_name, field_value, field_type); } @@ -902,16 +902,17 @@ protected: { if( model_connector && model_env ) { + #ifdef MORM_HAS_EZC_LIBRARY 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)) && - !model_env->ezc_val.pointer ) + (is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) ) { model_env->ezc_val.set_pointer_to(new SpaceWrapper(&field_value)); } } else + #endif { field_generic(db_field_name, flat_field_name, field_value, field_type); } @@ -963,7 +964,7 @@ 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_fun_info && model_env->ezc_fun_info_typeinfo && model_env->model ) + if( model_connector && model_env && model_env->ezc_env && model_env->model ) { if( field_type.is_primary_key() ) { @@ -971,7 +972,7 @@ protected: if( plog ) { - (*plog) << pt::Log::log1 << "Morm:: an ezc method cannot be used as a primary key" << pt::Log::logend; + (*plog) << pt::Log::log1 << "Morm: an ezc method cannot be used as a primary key" << pt::Log::logend; } } @@ -989,22 +990,7 @@ protected: (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; - - if( typeid(Ezc::Env) == *model_env->ezc_fun_info_typeinfo ) - { - Ezc::Env * ezc_fun_info = reinterpret_cast(model_env->ezc_fun_info); - (model_env->model->*method)(*ezc_fun_info); - //model_env->ezc_fun_result = ezc_fun_info->res; // ezc_fun_info->res is overwritten in get_raw_value() after fields() method call so we have to remember it in model_env - } - else - { - pt::Log * plog = model_connector->get_logger(); - - if( plog ) - { - (*plog) << pt::Log::log2 << "Morm: incorrect method type for field: " << flat_field_name << pt::Log::logend; - } - } + (model_env->model->*method)(*model_env->ezc_env); } } @@ -1019,7 +1005,7 @@ protected: if( plog ) { - (*plog) << pt::Log::log1 << "Morm:: an ezc method cannot be used as a primary key" << pt::Log::logend; + (*plog) << pt::Log::log1 << "Morm: an ezc method cannot be used as a primary key" << pt::Log::logend; } } @@ -1029,7 +1015,8 @@ protected: (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->ezc_fun_result = (model_env->model->*method)(); + bool result = (model_env->model->*method)(); + model_env->ezc_val.set(result); } } } @@ -1046,7 +1033,7 @@ protected: if( plog ) { - (*plog) << pt::Log::log1 << "Morm:: an ezc method cannot be used as a primary key" << pt::Log::logend; + (*plog) << pt::Log::log1 << "Morm: an ezc method cannot be used as a primary key" << pt::Log::logend; } } @@ -1056,7 +1043,8 @@ protected: (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->ezc_fun_result = (model_env->model->*method)(); + bool result = (model_env->model->*method)(); + model_env->ezc_val.set(result); } } } @@ -1073,7 +1061,7 @@ protected: if( plog ) { - (*plog) << pt::Log::log1 << "Morm:: an ezc method cannot be used as a primary key" << pt::Log::logend; + (*plog) << pt::Log::log1 << "Morm: an ezc method cannot be used as a primary key" << pt::Log::logend; } } @@ -1082,7 +1070,7 @@ protected: 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->model->*method)(model_env->ezc_val); + model_env->ezc_val.set_pointer_to(model_env->model, method); } } } @@ -1291,19 +1279,20 @@ protected: { ContainerItemType * item_type_null_pointer = nullptr; + #ifdef MORM_HAS_EZC_LIBRARY if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_EZC_VAL ) { if constexpr (std::is_base_of()) { 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->ezc_val.pointer ) + (is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) ) { model_env->ezc_val.set_pointer_to(new ModelWrapperVector(&field_value)); } } } else + #endif { ContainerItemType * pointer = nullptr; field_list_generic(db_field_name, flat_field_name, field_value, item_type_null_pointer, field_type, pointer); @@ -1316,19 +1305,20 @@ protected: { ContainerItemType * item_type_null_pointer = nullptr; + #ifdef MORM_HAS_EZC_LIBRARY if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_EZC_VAL ) { if constexpr (std::is_base_of()) { 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->ezc_val.pointer ) + (is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) ) { model_env->ezc_val.set_pointer_to(new ModelWrapperList(&field_value)); } } } else + #endif { ContainerItemType * pointer = nullptr; field_list_generic(db_field_name, flat_field_name, field_value, item_type_null_pointer, field_type, pointer); @@ -1341,19 +1331,20 @@ protected: { ContainerItemType * item_type_null_pointer = nullptr; + #ifdef MORM_HAS_EZC_LIBRARY if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_EZC_VAL ) { if constexpr (std::is_base_of()) { 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->ezc_val.pointer ) + (is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) ) { model_env->ezc_val.set_pointer_to(new ModelWrapperVectorPointer(&field_value)); } } } else + #endif { void * pointer = nullptr; field_list_generic(db_field_name, flat_field_name, field_value, item_type_null_pointer, field_type, pointer); @@ -1366,19 +1357,20 @@ protected: { ContainerItemType * item_type_null_pointer = nullptr; + #ifdef MORM_HAS_EZC_LIBRARY if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_EZC_VAL ) { if constexpr (std::is_base_of()) { 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->ezc_val.pointer ) + (is_empty_field(model_env->flat_field_name) || is_the_same_field(flat_field_name, model_env->flat_field_name)) ) { model_env->ezc_val.set_pointer_to(new ModelWrapperListPointer(&field_value)); } } } else + #endif { void * pointer = nullptr; field_list_generic(db_field_name, flat_field_name, field_value, item_type_null_pointer, field_type, pointer); diff --git a/src/modelenv.h b/src/modelenv.h index ddb223a..7259a68 100644 --- a/src/modelenv.h +++ b/src/modelenv.h @@ -97,9 +97,7 @@ public: #ifdef MORM_HAS_EZC_LIBRARY Ezc::Val ezc_val; - void * ezc_fun_info; // is still needed? - //bool ezc_fun_result; - const std::type_info * ezc_fun_info_typeinfo; + Ezc::Env * ezc_env; #endif bool status; @@ -156,9 +154,7 @@ public: #ifdef MORM_HAS_EZC_LIBRARY ezc_val = e.ezc_val; - ezc_fun_info = e.ezc_fun_info; - //ezc_fun_result = e.ezc_fun_result; - ezc_fun_info_typeinfo = e.ezc_fun_info_typeinfo; + ezc_env = e.ezc_env; #endif // schema_name and table_name don't have to be copied @@ -215,9 +211,7 @@ public: #ifdef MORM_HAS_EZC_LIBRARY ezc_val.clear(); - ezc_fun_info = nullptr; - //ezc_fun_result = false; - ezc_fun_info_typeinfo = nullptr; + ezc_env = nullptr; #endif }