fixed in Model::field_generic_put_raw_value_to_stream() - a boolean status for ezc was not set
added to Model: - method field() which can take a pointer to a member which returns bool: void field(const wchar_t * field_name, bool (ClassName::*method)(), const morm::FT & field_type = morm::FT::default_type) - method field() which can take a pointer to a member which can set morm::ModelWrapper object void field(const wchar_t * field_name, void (ClassName::*method)(morm::ModelWrapper **), const morm::FT & field_type = morm::FT::default_type) - methods: bool Model::convert_to_bool(...) - they are used for creating a result for ezc from local fields
This commit is contained in:
parent
5cf55ecce3
commit
9a142548d0
|
@ -81,12 +81,12 @@ public:
|
|||
{
|
||||
if constexpr (!std::is_base_of<Model, IsContainerByValueRenameMe>())
|
||||
{
|
||||
for(auto * item : container)
|
||||
{
|
||||
// for(auto * item : container)
|
||||
// {
|
||||
// IMPROVEME we need to rethink how to handle pointers
|
||||
// delete item;
|
||||
// item = nullptr;
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
124
src/model.cpp
124
src/model.cpp
|
@ -1909,5 +1909,129 @@ void Model::field_member(
|
|||
|
||||
|
||||
|
||||
bool Model::convert_to_bool(char v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(unsigned char v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(wchar_t v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
|
||||
bool Model::convert_to_bool(const std::wstring & str)
|
||||
{
|
||||
return !str.empty();
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(const wchar_t * str)
|
||||
{
|
||||
return str != nullptr && *str != 0;
|
||||
}
|
||||
|
||||
|
||||
bool Model::convert_to_bool(const std::string & str)
|
||||
{
|
||||
return !str.empty();
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(const char * str)
|
||||
{
|
||||
return str != nullptr && *str != 0;
|
||||
}
|
||||
|
||||
|
||||
bool Model::convert_to_bool(bool v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
bool Model::convert_to_bool(short v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(unsigned short v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(int v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(unsigned int v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(long v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(unsigned long v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(long long v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(unsigned long long v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
|
||||
bool Model::convert_to_bool(float v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(double v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(long double v)
|
||||
{
|
||||
return v != 0;
|
||||
}
|
||||
|
||||
|
||||
bool Model::convert_to_bool(const pt::Date & date)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(const pt::TextStream & val)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(const pt::WTextStream & val)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Model::convert_to_bool(const pt::Space & space)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace
|
||||
|
||||
|
|
142
src/model.h
142
src/model.h
|
@ -92,6 +92,36 @@
|
|||
typedef void (Model::*ModelMember)(Ezc::FunInfo<FunInfoStreamType> &); \
|
||||
ModelMember model_member = static_cast<ModelMember>(method); \
|
||||
field_member_ezc(db_field_name, flat_field_name, model_member, field_type); \
|
||||
} \
|
||||
void field(const wchar_t * field_name, bool (ClassName::*method)(), const morm::FT & field_type = morm::FT::default_type) \
|
||||
{ \
|
||||
field(field_name, field_name, method, field_type); \
|
||||
} \
|
||||
void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, bool (ClassName::*method)(), const morm::FT & field_type = morm::FT::default_type) \
|
||||
{ \
|
||||
typedef bool (Model::*ModelMember)(); \
|
||||
ModelMember model_member = static_cast<ModelMember>(method); \
|
||||
field_member_ezc(db_field_name, flat_field_name, model_member, field_type); \
|
||||
} \
|
||||
void field(const wchar_t * field_name, bool (ClassName::*method)() const, const morm::FT & field_type = morm::FT::default_type) \
|
||||
{ \
|
||||
field(field_name, field_name, method, field_type); \
|
||||
} \
|
||||
void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, bool (ClassName::*method)() const, const morm::FT & field_type = morm::FT::default_type) \
|
||||
{ \
|
||||
typedef bool (Model::*ModelMember)() const; \
|
||||
ModelMember model_member = static_cast<ModelMember>(method); \
|
||||
field_member_ezc(db_field_name, flat_field_name, model_member, field_type); \
|
||||
} \
|
||||
void field(const wchar_t * field_name, void (ClassName::*method)(morm::ModelWrapper **), const morm::FT & field_type = morm::FT::default_type) \
|
||||
{ \
|
||||
field(field_name, field_name, method, field_type); \
|
||||
} \
|
||||
void field(const wchar_t * db_field_name, const wchar_t * flat_field_name, void (ClassName::*method)(morm::ModelWrapper **), const morm::FT & field_type = morm::FT::default_type) \
|
||||
{ \
|
||||
typedef void (Model::*ModelMember)(morm::ModelWrapper **); \
|
||||
ModelMember model_member = static_cast<ModelMember>(method); \
|
||||
field_member_ezc(db_field_name, flat_field_name, model_member, field_type); \
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -256,6 +286,7 @@ public:
|
|||
try
|
||||
{
|
||||
fields();
|
||||
fun_info.res = model_env->ezc_fun_result;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
|
@ -733,6 +764,10 @@ protected:
|
|||
{
|
||||
(*model_env->stream) << field_value;
|
||||
}
|
||||
|
||||
#ifdef MORM_HAS_EZC_LIBRARY
|
||||
model_env->ezc_fun_result = convert_to_bool(field_value);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -837,7 +872,7 @@ protected:
|
|||
|
||||
if( plog )
|
||||
{
|
||||
(*plog) << pt::Log::log1 << "Morm:: ezc methods 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -848,6 +883,7 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
template<typename FunInfoStreamType>
|
||||
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::FunInfo<FunInfoStreamType> &), const FT & field_type)
|
||||
{
|
||||
|
@ -858,6 +894,7 @@ protected:
|
|||
{
|
||||
Ezc::FunInfo<FunInfoStreamType> * ezc_fun_info = reinterpret_cast<Ezc::FunInfo<FunInfoStreamType>*>(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
|
||||
{
|
||||
|
@ -870,6 +907,85 @@ protected:
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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 )
|
||||
{
|
||||
if( field_type.is_primary_key() )
|
||||
{
|
||||
pt::Log * plog = model_connector->get_logger();
|
||||
|
||||
if( plog )
|
||||
{
|
||||
(*plog) << pt::Log::log1 << "Morm:: an ezc method cannot be used as a primary key" << pt::Log::logend;
|
||||
}
|
||||
}
|
||||
|
||||
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)) )
|
||||
{
|
||||
model_env->ezc_fun_result = (model_env->model->*method)();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void field_member_ezc(const wchar_t * db_field_name, const wchar_t * flat_field_name, bool (Model::*method)() const, const FT & field_type)
|
||||
{
|
||||
if( model_connector && model_env && model_env->model )
|
||||
{
|
||||
if( field_type.is_primary_key() )
|
||||
{
|
||||
pt::Log * plog = model_connector->get_logger();
|
||||
|
||||
if( plog )
|
||||
{
|
||||
(*plog) << pt::Log::log1 << "Morm:: an ezc method cannot be used as a primary key" << pt::Log::logend;
|
||||
}
|
||||
}
|
||||
|
||||
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)) )
|
||||
{
|
||||
model_env->ezc_fun_result = (model_env->model->*method)();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void field_member_ezc(const wchar_t * db_field_name, const wchar_t * flat_field_name, void (Model::*method)(ModelWrapper ** model_wrapper), const FT & field_type)
|
||||
{
|
||||
if( model_connector && model_env && model_env->model )
|
||||
{
|
||||
if( field_type.is_primary_key() )
|
||||
{
|
||||
pt::Log * plog = model_connector->get_logger();
|
||||
|
||||
if( plog )
|
||||
{
|
||||
(*plog) << pt::Log::log1 << "Morm:: an ezc method cannot be used as a primary key" << pt::Log::logend;
|
||||
}
|
||||
}
|
||||
|
||||
if( model_env->model_work_mode == MORM_MODEL_WORK_MODE_GET_MODEL_WRAPPER )
|
||||
{
|
||||
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->model_wrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -1384,6 +1500,30 @@ protected:
|
|||
return status;
|
||||
}
|
||||
|
||||
// those methods are used when converting fields to bool for Ezc library
|
||||
virtual bool convert_to_bool(char v);
|
||||
virtual bool convert_to_bool(unsigned char v);
|
||||
virtual bool convert_to_bool(wchar_t v);
|
||||
virtual bool convert_to_bool(const std::wstring & str);
|
||||
virtual bool convert_to_bool(const wchar_t * str);
|
||||
virtual bool convert_to_bool(const std::string & str);
|
||||
virtual bool convert_to_bool(const char * str);
|
||||
virtual bool convert_to_bool(bool v);
|
||||
virtual bool convert_to_bool(short v);
|
||||
virtual bool convert_to_bool(unsigned short v);
|
||||
virtual bool convert_to_bool(int v);
|
||||
virtual bool convert_to_bool(unsigned int v);
|
||||
virtual bool convert_to_bool(long v);
|
||||
virtual bool convert_to_bool(unsigned long v);
|
||||
virtual bool convert_to_bool(long long v);
|
||||
virtual bool convert_to_bool(unsigned long long v);
|
||||
virtual bool convert_to_bool(float v);
|
||||
virtual bool convert_to_bool(double v);
|
||||
virtual bool convert_to_bool(long double v);
|
||||
virtual bool convert_to_bool(const pt::Date & date);
|
||||
virtual bool convert_to_bool(const pt::TextStream & val);
|
||||
virtual bool convert_to_bool(const pt::WTextStream & val);
|
||||
virtual bool convert_to_bool(const pt::Space & space);
|
||||
|
||||
|
||||
template<typename ModelClass> friend class Finder;
|
||||
|
|
|
@ -98,6 +98,7 @@ public:
|
|||
|
||||
#ifdef MORM_HAS_EZC_LIBRARY
|
||||
void * ezc_fun_info;
|
||||
bool ezc_fun_result;
|
||||
const std::type_info * ezc_fun_info_typeinfo;
|
||||
#endif
|
||||
|
||||
|
@ -125,14 +126,17 @@ public:
|
|||
db_field_name = e.db_field_name;
|
||||
flat_field_name = e.flat_field_name;
|
||||
model = e.model;
|
||||
ezc_fun_info = e.ezc_fun_info;
|
||||
ezc_fun_info_typeinfo = e.ezc_fun_info_typeinfo;
|
||||
child_model = e.child_model;
|
||||
model_wrapper = e.model_wrapper;
|
||||
stream = e.stream;
|
||||
|
||||
#ifdef MORM_HAS_EZC_LIBRARY
|
||||
ezc_fun_info = e.ezc_fun_info;
|
||||
ezc_fun_result = e.ezc_fun_result;
|
||||
ezc_fun_info_typeinfo = e.ezc_fun_info_typeinfo;
|
||||
#endif
|
||||
|
||||
// schema_name and table_name don't have to be copied
|
||||
// schema_name and table_name don't have to be copied
|
||||
table2_name = nullptr;
|
||||
}
|
||||
|
||||
|
@ -174,10 +178,11 @@ public:
|
|||
model_wrapper = nullptr;
|
||||
stream = nullptr;
|
||||
|
||||
#ifdef MORM_HAS_EZC_LIBRARY
|
||||
#ifdef MORM_HAS_EZC_LIBRARY
|
||||
ezc_fun_info = nullptr;
|
||||
ezc_fun_result = false;
|
||||
ezc_fun_info_typeinfo = nullptr;
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue