added value class
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
#ifndef QUERY_FIELD_HPP
|
||||
#define QUERY_FIELD_HPP
|
||||
|
||||
#include "matador/sql/any_type.hpp"
|
||||
#include "matador/sql/any_type_to_visitor.hpp"
|
||||
#include "matador/sql/data_type_traits.hpp"
|
||||
|
||||
#include "matador/utils/types.hpp"
|
||||
#include "matador/sql/value.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -19,10 +15,8 @@ public:
|
||||
template<typename Type>
|
||||
field(std::string name, Type value, size_t size = 0, int index = -1)
|
||||
: name_(std::move(name))
|
||||
, size_(size)
|
||||
, index_(index)
|
||||
, value_(value)
|
||||
, type_(data_type_traits<Type>::builtin_type(size)) {}
|
||||
, value_(value, size) {}
|
||||
field(std::string name, data_type_t data_type, size_t size = 0, int index = -1);
|
||||
field(const field &x) = default;
|
||||
field& operator=(const field &x) = default;
|
||||
@@ -32,7 +26,7 @@ public:
|
||||
template<typename Type>
|
||||
field& operator=(Type value) {
|
||||
value_ = std::move(value);
|
||||
type_ = data_type_traits<Type>::builtin_type(-1);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -43,9 +37,7 @@ public:
|
||||
template<class Type>
|
||||
std::optional<Type> as() const
|
||||
{
|
||||
any_type_to_visitor<Type> visitor;
|
||||
std::visit(visitor, const_cast<any_type&>(value_));
|
||||
return visitor.result;
|
||||
return value_.as<Type>();
|
||||
}
|
||||
|
||||
[[nodiscard]] std::string str() const;
|
||||
@@ -65,7 +57,7 @@ private:
|
||||
template<class Operator>
|
||||
void process(Operator &op)
|
||||
{
|
||||
op.on_attribute(name_.c_str(), value_, type_, size_);
|
||||
op.on_attribute(name_.c_str(), value_, value_.size());
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -73,9 +65,8 @@ private:
|
||||
|
||||
std::string name_;
|
||||
int index_{-1};
|
||||
any_type value_;
|
||||
size_t size_{};
|
||||
data_type_t type_;
|
||||
|
||||
value value_;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user