add value and parameter classes
This commit is contained in:
parent
b9f10c8db2
commit
9862749cca
@ -9,12 +9,11 @@ class PgConnection;
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace eedb {
|
namespace eedb {
|
||||||
class PgCategory;
|
|
||||||
|
|
||||||
class PgCategories : public Categories {
|
class PgCategories : public Categories {
|
||||||
// Categories interface
|
// Categories interface
|
||||||
public:
|
public:
|
||||||
PgCategories(std::vector<std::unique_ptr<eedb::PgCategory> > &&data);
|
PgCategories(std::vector<std::unique_ptr<eedb::Category> > &&data);
|
||||||
|
|
||||||
long size() const override;
|
long size() const override;
|
||||||
|
|
||||||
|
|||||||
@ -4,18 +4,19 @@
|
|||||||
#ifndef CATEGORYMOCK_HPP
|
#ifndef CATEGORYMOCK_HPP
|
||||||
#define CATEGORYMOCK_HPP
|
#define CATEGORYMOCK_HPP
|
||||||
|
|
||||||
|
#include <eedb/db/Category.hpp>
|
||||||
#include <gmock/gmock.h>
|
#include <gmock/gmock.h>
|
||||||
#include "././eedb/db/Category.hpp"
|
|
||||||
|
|
||||||
namespace eedb {
|
namespace eedb {
|
||||||
|
|
||||||
class CategoryMock : public Category
|
class CategoryMock : public Category {
|
||||||
{
|
public:
|
||||||
public:
|
MOCK_CONST_METHOD0(display_name, std::string_view());
|
||||||
MOCK_CONST_METHOD0(parent, Category*());
|
MOCK_CONST_METHOD0(parent, Category *());
|
||||||
|
MOCK_CONST_METHOD2(create, std::unique_ptr< Category >(std::string, std::string));
|
||||||
|
MOCK_CONST_METHOD0(children, std::unique_ptr< Categories >());
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace eedb
|
} // namespace eedb
|
||||||
|
|
||||||
#endif // CATEGORYMOCK_HPP
|
#endif // CATEGORYMOCK_HPP
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ namespace eedb {
|
|||||||
struct PgCategories::PgCategoriesPriv {
|
struct PgCategories::PgCategoriesPriv {
|
||||||
private:
|
private:
|
||||||
static auto getTransform() {
|
static auto getTransform() {
|
||||||
return [](auto & cat) { return static_cast< Category * >(cat.get()); };
|
return [](auto & cat) { return cat.get(); };
|
||||||
}
|
}
|
||||||
|
|
||||||
auto tBegin() {
|
auto tBegin() {
|
||||||
@ -24,7 +24,7 @@ struct PgCategories::PgCategoriesPriv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PgCategoriesPriv(std::vector< std::unique_ptr< PgCategory > > && data) : _cache{std::move(data)} {}
|
PgCategoriesPriv(std::vector< std::unique_ptr< Category > > && data) : _cache{std::move(data)} {}
|
||||||
|
|
||||||
auto begin() {
|
auto begin() {
|
||||||
return Categories::Iterable{tBegin()};
|
return Categories::Iterable{tBegin()};
|
||||||
@ -35,10 +35,10 @@ struct PgCategories::PgCategoriesPriv {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector< std::unique_ptr< PgCategory > > _cache;
|
std::vector< std::unique_ptr< Category > > _cache;
|
||||||
};
|
};
|
||||||
|
|
||||||
PgCategories::PgCategories(std::vector< std::unique_ptr< PgCategory > > && data)
|
PgCategories::PgCategories(std::vector< std::unique_ptr< Category > > && data)
|
||||||
: _priv{spimpl::make_unique_impl< PgCategoriesPriv >(std::move(data))} {}
|
: _priv{spimpl::make_unique_impl< PgCategoriesPriv >(std::move(data))} {}
|
||||||
|
|
||||||
long PgCategories::size() const {
|
long PgCategories::size() const {
|
||||||
|
|||||||
@ -69,7 +69,7 @@ struct PgCategory::PgCategoryPrivate {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto categories() const {
|
auto categories() const {
|
||||||
std::vector< std::unique_ptr< PgCategory > > children;
|
std::vector< std::unique_ptr< Category > > children;
|
||||||
children.reserve(100);
|
children.reserve(100);
|
||||||
for(auto & category_row : _db(select(columns()).from(table_list()).where(parent_match()))) {
|
for(auto & category_row : _db(select(columns()).from(table_list()).where(parent_match()))) {
|
||||||
auto priv = spimpl::make_impl< PgCategoryPrivate >(_db, _owner, _self);
|
auto priv = spimpl::make_impl< PgCategoryPrivate >(_db, _owner, _self);
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
#include <eedb/Value.hpp>
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <eedb/db/Item.hpp>
|
||||||
@ -2,21 +2,33 @@
|
|||||||
|
|
||||||
#include "DbTestBase.hpp"
|
#include "DbTestBase.hpp"
|
||||||
|
|
||||||
|
#include <eedb/mock/db/pg/CategoryMock.hpp>
|
||||||
|
#include <utils/UniquePtrMockWrapper.hpp>
|
||||||
|
|
||||||
class PgCategoriesTest : public DbTestBase< PgCategoriesTest > {
|
class PgCategoriesTest : public DbTestBase< PgCategoriesTest > {
|
||||||
public:
|
public:
|
||||||
PgCategoriesTest() {
|
PgCategoriesTest() {
|
||||||
db().native()->start_transaction();
|
db().native()->start_transaction();
|
||||||
|
|
||||||
// sut = std::make_unique< eedb::PgCategories >();
|
|
||||||
|
//sut = std::make_unique< eedb::PgCategories >(_categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
~PgCategoriesTest() {
|
~PgCategoriesTest() {
|
||||||
db().native()->rollback_transaction(false);
|
db().native()->rollback_transaction(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
|
std::vector< UniquePtrMockWrapper< eedb::CategoryMock > > _categories;
|
||||||
|
|
||||||
std::unique_ptr< eedb::PgCategories > sut;
|
std::unique_ptr< eedb::PgCategories > sut;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgCategoriesTest >::_test_db = {};
|
std::unique_ptr< PgTestDatabasePrepare > DbTestBase< PgCategoriesTest >::_test_db = {};
|
||||||
|
|
||||||
|
//TEST_F(PgCategoriesTest, size) {
|
||||||
|
// EXPECT_EQ(sut->size(), 4);
|
||||||
|
//}
|
||||||
|
|
||||||
|
//TEST_F(PgCategoriesTest, )
|
||||||
|
|||||||
@ -67,4 +67,4 @@ TEST_F(PgUserTest, getIdentities) {
|
|||||||
EXPECT_TRUE(sut->authIdentities().byProvider("loginname"));
|
EXPECT_TRUE(sut->authIdentities().byProvider("loginname"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PgUserTest, getTokens) {}
|
TEST_F(PgUserTest, getConfig) {}
|
||||||
|
|||||||
13
src/libs/eedb/include/eedb/Parameter.hpp
Normal file
13
src/libs/eedb/include/eedb/Parameter.hpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
|
#include <eedb/Unit.hpp>
|
||||||
|
|
||||||
|
namespace eedb {
|
||||||
|
|
||||||
|
class Parameter {
|
||||||
|
public:
|
||||||
|
std::optional< Unit > unit() const {}
|
||||||
|
};
|
||||||
|
} // namespace eedb
|
||||||
@ -4,15 +4,13 @@
|
|||||||
|
|
||||||
namespace eedb {
|
namespace eedb {
|
||||||
|
|
||||||
class Units {
|
/**
|
||||||
public:
|
* @brief The Unit class
|
||||||
virtual ~Units() = default;
|
*/
|
||||||
};
|
|
||||||
|
|
||||||
class Unit {
|
class Unit {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
std::string_view name() const;
|
std::string_view name() const;
|
||||||
Unit toBase() const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace eedb
|
} // namespace eedb
|
||||||
76
src/libs/eedb/include/eedb/Value.hpp
Normal file
76
src/libs/eedb/include/eedb/Value.hpp
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
|
#include <eedb/Parameter.hpp>
|
||||||
|
|
||||||
|
namespace eedb {
|
||||||
|
|
||||||
|
class Value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The Values class
|
||||||
|
*/
|
||||||
|
class Values {
|
||||||
|
public:
|
||||||
|
virtual ~Values() = default;
|
||||||
|
};
|
||||||
|
|
||||||
|
class NumericValue {
|
||||||
|
public:
|
||||||
|
explicit NumericValue(double t) : _value{t} {}
|
||||||
|
|
||||||
|
std::string to_string() const {
|
||||||
|
return std::to_string(_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
double value() const {
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
double _value;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TextValue {
|
||||||
|
public:
|
||||||
|
explicit TextValue(std::string_view value) : _value{value} {}
|
||||||
|
|
||||||
|
std::string to_string() const {
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string_view value() const {
|
||||||
|
return _value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string _value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief The Value class
|
||||||
|
*/
|
||||||
|
class Value {
|
||||||
|
public:
|
||||||
|
enum class Type { Numeric, Text };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief to_string
|
||||||
|
* @return returns value as string
|
||||||
|
*/
|
||||||
|
std::string to_string() const;
|
||||||
|
|
||||||
|
Type type() const {
|
||||||
|
return Type::Numeric;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional< Parameter > parameter() const {}
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::variant< TextValue, NumericValue > _value;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace eedb
|
||||||
@ -11,7 +11,8 @@ class Category;
|
|||||||
class Item;
|
class Item;
|
||||||
class Items;
|
class Items;
|
||||||
class Values;
|
class Values;
|
||||||
class Units;
|
class Parameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The ItemQueryFilters class
|
* @brief The ItemQueryFilters class
|
||||||
*/
|
*/
|
||||||
@ -58,6 +59,12 @@ class Items {
|
|||||||
*/
|
*/
|
||||||
virtual long size() const = 0;
|
virtual long size() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief commonParameters
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual Parameters commonParameters() const = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief begin
|
* @brief begin
|
||||||
* @return
|
* @return
|
||||||
@ -78,8 +85,22 @@ class Item {
|
|||||||
public:
|
public:
|
||||||
virtual ~Item() = default;
|
virtual ~Item() = default;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief displayName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
virtual std::string_view displayName() const = 0;
|
virtual std::string_view displayName() const = 0;
|
||||||
|
|
||||||
virtual Values & values() const = 0;
|
/**
|
||||||
|
* @brief assignedUnits
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual Values assignedUnits() const = 0;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief assignedParameters
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
virtual Parameters assignedParameters() const = 0;
|
||||||
};
|
};
|
||||||
} // namespace eedb
|
} // namespace eedb
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <variant>
|
|
||||||
|
|
||||||
namespace eedb {
|
|
||||||
class Value;
|
|
||||||
class Values {
|
|
||||||
public:
|
|
||||||
virtual ~Values() = default;
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
class Value {
|
|
||||||
public:
|
|
||||||
};
|
|
||||||
} // namespace eedb
|
|
||||||
Loading…
Reference in New Issue
Block a user