removed the value field from attribute_definition because it's a definition and should not hold a value.
This commit is contained in:
@@ -27,14 +27,14 @@ public:
|
||||
|
||||
attribute_definition() = default;
|
||||
template<typename Type>
|
||||
explicit attribute_definition(std::string name, std::string table_name, const utils::field_attributes& attr)
|
||||
attribute_definition(std::string name, std::string table_name, const utils::field_attributes& attr)
|
||||
: attribute_definition(std::move(name), std::move(table_name), utils::data_type_traits<Type>::type(attr.size()), attr)
|
||||
{}
|
||||
|
||||
attribute_definition(std::string name, std::string table_name, utils::basic_type type, const utils::field_attributes& attr);
|
||||
|
||||
template<typename Type>
|
||||
explicit attribute_definition(std::string name, const utils::field_attributes& attr)
|
||||
attribute_definition(std::string name, const utils::field_attributes& attr)
|
||||
: attribute_definition(std::move(name), utils::data_type_traits<Type>::type(attr.size()), attr)
|
||||
{}
|
||||
|
||||
@@ -48,15 +48,15 @@ public:
|
||||
: attribute_definition(std::move(name), utils::data_type_traits<const char*>::type(attr.size()), attr, null_opt)
|
||||
{}
|
||||
|
||||
attribute_definition(std::string name, utils::basic_type type, const utils::field_attributes&, null_option null_opt, size_t index = 0);
|
||||
attribute_definition(std::string name, std::string table_name, utils::basic_type type, const utils::field_attributes&, null_option null_opt, size_t index = 0);
|
||||
attribute_definition(std::string name, utils::basic_type type, const utils::field_attributes&, null_option null_opt, int index = 0);
|
||||
attribute_definition(std::string name, std::string table_name, utils::basic_type type, const utils::field_attributes&, null_option null_opt, int index = 0);
|
||||
|
||||
template<typename Type>
|
||||
attribute_definition(std::string name, const std::shared_ptr<attribute_definition> &ref_column, const utils::field_attributes& attr, null_option null_opt)
|
||||
: attribute_definition(std::move(name), utils::data_type_traits<Type>::type(attr.size()), ref_column, attr, null_opt)
|
||||
{}
|
||||
|
||||
attribute_definition(std::string name, utils::basic_type type, size_t index, const std::shared_ptr<attribute_definition> &ref_column, const utils::field_attributes& attr, null_option null_opt);
|
||||
attribute_definition(std::string name, utils::basic_type type, int index, const std::shared_ptr<attribute_definition> &ref_column, const utils::field_attributes& attr, null_option null_opt);
|
||||
|
||||
[[nodiscard]] const std::string& name() const;
|
||||
void name(const std::string& n);
|
||||
@@ -68,6 +68,11 @@ public:
|
||||
[[nodiscard]] utils::field_attributes& attributes();
|
||||
[[nodiscard]] bool is_nullable() const;
|
||||
[[nodiscard]] utils::basic_type type() const;
|
||||
void change_type(utils::basic_type type, const utils::field_attributes &attr = utils::null_attributes);
|
||||
template < typename Type >
|
||||
void change_type(const utils::field_attributes &attr = utils::null_attributes) {
|
||||
type_ = utils::data_type_traits<Type>::type(attr.size());
|
||||
}
|
||||
[[nodiscard]] std::shared_ptr<attribute_definition> reference_column() const;
|
||||
[[nodiscard]] bool is_foreign_reference() const;
|
||||
|
||||
@@ -81,49 +86,12 @@ public:
|
||||
[[nodiscard]] bool is_blob() const;
|
||||
[[nodiscard]] bool is_null() const;
|
||||
|
||||
void type(utils::basic_type type);
|
||||
|
||||
template< typename Type >
|
||||
[[nodiscard]] bool is_type_of() const {
|
||||
return std::holds_alternative<Type>(value_);
|
||||
return type() == utils::data_type_traits<Type>::type(attributes().size());
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string str() const;
|
||||
|
||||
template<typename Type>
|
||||
void set(const Type &value, const utils::field_attributes &attr = utils::null_attributes)
|
||||
{
|
||||
attributes_ = attr;
|
||||
value_ = value;
|
||||
}
|
||||
|
||||
void set(const std::string &value, const utils::field_attributes &attr)
|
||||
{
|
||||
value_ = value;
|
||||
attributes_ = attr;
|
||||
}
|
||||
|
||||
void set(const char *value, const utils::field_attributes &attr)
|
||||
{
|
||||
value_ = std::string(value);
|
||||
attributes_ = attr;
|
||||
}
|
||||
|
||||
template<class Type>
|
||||
std::optional<Type> as() const
|
||||
{
|
||||
return value_.as<Type>();
|
||||
}
|
||||
|
||||
friend std::ostream& operator<<(std::ostream &out, const attribute_definition &col);
|
||||
|
||||
private:
|
||||
template<class Operator>
|
||||
void process(Operator &op)
|
||||
{
|
||||
op.on_attribute(name_.c_str(), value_, attributes_);
|
||||
}
|
||||
|
||||
using data_type_index = std::vector<utils::basic_type>;
|
||||
|
||||
private:
|
||||
@@ -134,7 +102,9 @@ private:
|
||||
int index_{-1};
|
||||
utils::field_attributes attributes_;
|
||||
null_option null_option_{null_option::NOT_NULL};
|
||||
utils::value value_;
|
||||
utils::basic_type type_{utils::basic_type::type_null};
|
||||
size_t size_{0};
|
||||
|
||||
std::shared_ptr<attribute_definition> reference_column_;
|
||||
};
|
||||
|
||||
|
||||
@@ -11,10 +11,7 @@ namespace matador::utils {
|
||||
|
||||
namespace detail {
|
||||
template<typename Type>
|
||||
size_t determine_size(const Type &/*val*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
size_t determine_size(const Type &/*val*/) { return 0; }
|
||||
size_t determine_size(const std::string &val);
|
||||
size_t determine_size(const char *val);
|
||||
size_t determine_size(const blob &val);
|
||||
|
||||
Reference in New Issue
Block a user