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:
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;
|
||||
|
Reference in New Issue
Block a user