morm/src/ft.h

168 lines
3.1 KiB
C++

/*
* This file is a part of morm
* and is distributed under the 2-Clause BSD licence.
* Author: Tomasz Sowa <t.sowa@ttmath.org>
*/
/*
* Copyright (c) 2021, Tomasz Sowa
* 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.
*
*/
#ifndef headerfile_morm_ft
#define headerfile_morm_ft
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 */
no_removable = 64,
raw_field_name = 128,
dont_use_utf8 = 256,
hexadecimal = 512,
binary = 1024,
};
/*
* 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;
}
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);
}
bool is_removable() const
{
return !is_flag_set(no_removable);
}
bool is_raw_field_name() const
{
return is_flag_set(raw_field_name);
}
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);
}
};
}
#endif