added index attribute to field class
This commit is contained in:
parent
6bbc870362
commit
9a02abacea
|
|
@ -64,8 +64,9 @@ class field
|
|||
public:
|
||||
explicit field(std::string name);
|
||||
template<typename Type>
|
||||
field(std::string name, Type value)
|
||||
field(std::string name, Type value, int index = -1)
|
||||
: name_(std::move(name))
|
||||
, index_(index)
|
||||
, value_(value)
|
||||
, type_(field_traits<Type>::type()) {}
|
||||
field(const field &x) = default;
|
||||
|
|
@ -81,6 +82,7 @@ public:
|
|||
}
|
||||
|
||||
[[nodiscard]] const std::string& name() const;
|
||||
[[nodiscard]] int index() const;
|
||||
|
||||
template<class Type>
|
||||
std::optional<Type> as() const
|
||||
|
|
@ -103,6 +105,7 @@ public:
|
|||
|
||||
private:
|
||||
std::string name_;
|
||||
int index_{-1};
|
||||
any_type value_;
|
||||
field_type type_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,21 +3,29 @@
|
|||
namespace matador::sql {
|
||||
|
||||
field::field(std::string name)
|
||||
: name_(std::move(name)), value_(nullptr), type_(field_traits<nullptr_t>::type())
|
||||
: name_(std::move(name))
|
||||
, value_(nullptr)
|
||||
, type_(field_traits<nullptr_t>::type())
|
||||
{}
|
||||
|
||||
field::field(field &&x) noexcept
|
||||
: name_(std::move(x.name_)), value_(std::move(x.value_)), type_(x.type_)
|
||||
: name_(std::move(x.name_))
|
||||
, index_(x.index_)
|
||||
, value_(std::move(x.value_))
|
||||
, type_(x.type_)
|
||||
{
|
||||
x.value_ = nullptr;
|
||||
x.index_ = -1;
|
||||
x.type_ = field_type::Null;
|
||||
}
|
||||
|
||||
field &field::operator=(field &&x) noexcept
|
||||
{
|
||||
name_ = std::move(x.name_);
|
||||
index_ = x.index_;
|
||||
value_ = std::move(x.value_);
|
||||
type_ = x.type_;
|
||||
x.index_ = -1;
|
||||
x.value_ = nullptr;
|
||||
x.type_ = field_type::Null;
|
||||
|
||||
|
|
@ -29,6 +37,11 @@ const std::string &field::name() const
|
|||
return name_;
|
||||
}
|
||||
|
||||
int field::index() const
|
||||
{
|
||||
return index_;
|
||||
}
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const field &col)
|
||||
{
|
||||
out << col.str();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ TEST_CASE("Field test", "[field]") {
|
|||
sql::field f("name");
|
||||
|
||||
REQUIRE(f.name() == "name");
|
||||
REQUIRE(f.index() == -1);
|
||||
REQUIRE(f.is_null());
|
||||
REQUIRE(!f.is_integer());
|
||||
REQUIRE(!f.is_floating_point());
|
||||
|
|
@ -36,7 +37,8 @@ TEST_CASE("Field test", "[field]") {
|
|||
REQUIRE(bool_val.has_value());
|
||||
REQUIRE(bool_val.value());
|
||||
|
||||
f = utils::blob{ 7,8,6,5,4,3 };
|
||||
f = sql::field("name", utils::blob{ 7,8,6,5,4,3 }, 1);
|
||||
REQUIRE(f.index() == 1);
|
||||
REQUIRE(!f.is_null());
|
||||
REQUIRE(!f.is_integer());
|
||||
REQUIRE(!f.is_floating_point());
|
||||
|
|
|
|||
Loading…
Reference in New Issue