2021-03-10 16:20:11 +01:00
/*
* This file is a part of morm
* and is distributed under the 2 - Clause BSD licence .
* Author : Tomasz Sowa < t . sowa @ ttmath . org >
*/
/*
2023-02-26 18:28:16 +01:00
* Copyright ( c ) 2021 - 2023 , Tomasz Sowa
2021-03-10 16:20:11 +01:00
* All rights reserved .
*
* Redistribution and use in source and binary forms , with or without
* modification , are permitted provided that the following conditions are met :
*
* 1. Redistributions of source code must retain the above copyright notice ,
* this list of conditions and the following disclaimer .
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice , this list of conditions and the following disclaimer in the
* documentation and / or other materials provided with the distribution .
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS " AS IS "
* AND ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR
* CONSEQUENTIAL DAMAGES ( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES ; LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS
* INTERRUPTION ) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY , WHETHER IN
* CONTRACT , STRICT LIABILITY , OR TORT ( INCLUDING NEGLIGENCE OR OTHERWISE )
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE , EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE .
*
*/
2022-06-30 13:28:38 +02:00
# ifndef headerfile_morm_src_ft
# define headerfile_morm_src_ft
2021-03-10 16:20:11 +01:00
namespace morm
{
/*
* field types
*/
class FT
{
public :
enum FieldType
{
default_type = 0 ,
primary_key = 1 ,
foreign_key = 2 ,
foreign_key_in_child = 4 ,
no_insertable = 8 ,
no_updatable = 16 ,
no_fetchable = 32 , /* not supported yet */
2021-05-21 22:12:10 +02:00
no_removable = 64 ,
raw_field_name = 128 ,
2022-10-22 16:29:40 +02:00
dont_use_utf8 = 256 , /* used only with wchar_t and std::wstring, ignored if a binary or a hexadecimal flags are used */
2021-05-21 22:12:10 +02:00
hexadecimal = 512 ,
binary = 1024 ,
2021-08-12 21:56:32 +02:00
json = 2048 ,
space = 4096 ,
pretty_print = 8192 ,
2022-05-16 13:42:51 +02:00
numeric = 16384 ,
2022-10-22 16:29:40 +02:00
date_only = 32768 , /* use only year, month and day from pt::Date, no_time_zone flag is not used here */
time_only = 65536 , /* use only hour, min, sec from pt::Date, no_time_zone flag is not used here */
no_time_zone = 131072 , /* no time zone, used only with pt::Date */
2023-02-26 18:28:16 +01:00
/*
* if this flag is set and a model does not have a primary key set
* then we print only ' null '
* ( this is used only with flat strings )
*
*/
serialize_to_null_if_null = 262144 ,
do_not_serialize_if_null = 524288 , /* null objects are completely skipped when serializing to a flat string (test only for Model objects, not lists/vectors with childs models */
2021-03-10 16:20:11 +01:00
} ;
/*
* type can be a superposition from FieldType values
*/
int type ;
FT ( )
{
type = 0 ;
}
FT ( const FT & field_type )
{
type = field_type . type ;
}
FT ( FieldType type )
{
this - > type = static_cast < int > ( type ) ;
}
FT ( int type )
{
this - > type = type ;
}
FT & operator = ( const FT & field_type )
{
type = field_type . type ;
return * this ;
}
2022-07-11 17:48:13 +02:00
FT & operator = ( FieldType type )
{
this - > type = static_cast < int > ( type ) ;
return * this ;
}
FT & operator = ( int type )
{
this - > type = type ;
return * this ;
}
2021-03-10 16:20:11 +01:00
bool is_flag_set ( int flag_mask ) const
{
return ( type & flag_mask ) ! = 0 ;
}
bool is_primary_key ( ) const
{
return is_flag_set ( primary_key ) ;
}
bool is_foreign_key ( ) const
{
return is_flag_set ( foreign_key ) ;
}
bool is_foreign_key_in_child ( ) const
{
return is_flag_set ( foreign_key_in_child ) ;
}
bool is_insertable ( ) const
{
return ! is_flag_set ( no_insertable ) ;
}
bool is_updatable ( ) const
{
return ! is_flag_set ( no_updatable ) ;
}
bool is_fetchable ( ) const
{
return ! is_flag_set ( no_fetchable ) ;
}
2021-05-21 22:12:10 +02:00
bool is_removable ( ) const
{
return ! is_flag_set ( no_removable ) ;
}
2021-04-12 18:53:55 +02:00
bool is_raw_field_name ( ) const
{
return is_flag_set ( raw_field_name ) ;
}
2021-05-11 22:11:31 +02:00
bool use_utf8 ( ) const
{
return ! is_flag_set ( dont_use_utf8 ) ;
}
bool is_hexadecimal ( ) const
{
return is_flag_set ( hexadecimal ) ;
}
bool is_binary ( ) const
{
return is_flag_set ( binary ) ;
}
2021-08-12 21:56:32 +02:00
bool is_json ( ) const
{
return is_flag_set ( json ) ;
}
bool is_space ( ) const
{
return is_flag_set ( space ) ;
}
bool is_pretty_print ( ) const
{
return is_flag_set ( pretty_print ) ;
}
2021-05-11 22:11:31 +02:00
2022-05-16 13:42:51 +02:00
bool is_numeric ( ) const
{
return is_flag_set ( numeric ) ;
}
2022-10-22 16:29:40 +02:00
bool is_date_only ( ) const
{
return is_flag_set ( date_only ) ;
}
bool is_time_only ( ) const
{
return is_flag_set ( time_only ) ;
}
bool is_no_time_zone ( ) const
{
return is_flag_set ( no_time_zone ) ;
}
2023-02-26 18:28:16 +01:00
bool is_serialize_to_null_if_null ( ) const
{
return is_flag_set ( serialize_to_null_if_null ) ;
}
bool is_do_not_serialize_if_null ( ) const
{
return is_flag_set ( do_not_serialize_if_null ) ;
}
2021-03-10 16:20:11 +01:00
} ;
}
# endif