add value and parameter classes
This commit is contained in:
parent
b9f10c8db2
commit
9862749cca
@ -9,12 +9,11 @@ class PgConnection;
|
||||
}
|
||||
|
||||
namespace eedb {
|
||||
class PgCategory;
|
||||
|
||||
class PgCategories : public Categories {
|
||||
// Categories interface
|
||||
public:
|
||||
PgCategories(std::vector<std::unique_ptr<eedb::PgCategory> > &&data);
|
||||
PgCategories(std::vector<std::unique_ptr<eedb::Category> > &&data);
|
||||
|
||||
long size() const override;
|
||||
|
||||
|
||||
@ -4,18 +4,19 @@
|
||||
#ifndef CATEGORYMOCK_HPP
|
||||
#define CATEGORYMOCK_HPP
|
||||
|
||||
#include <eedb/db/Category.hpp>
|
||||
#include <gmock/gmock.h>
|
||||
#include "././eedb/db/Category.hpp"
|
||||
|
||||
namespace eedb {
|
||||
|
||||
class CategoryMock : public Category
|
||||
{
|
||||
public:
|
||||
MOCK_CONST_METHOD0(parent, Category*());
|
||||
class CategoryMock : public Category {
|
||||
public:
|
||||
MOCK_CONST_METHOD0(display_name, std::string_view());
|
||||
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
|
||||
|
||||
#endif // CATEGORYMOCK_HPP
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ namespace eedb {
|
||||
struct PgCategories::PgCategoriesPriv {
|
||||
private:
|
||||
static auto getTransform() {
|
||||
return [](auto & cat) { return static_cast< Category * >(cat.get()); };
|
||||
return [](auto & cat) { return cat.get(); };
|
||||
}
|
||||
|
||||
auto tBegin() {
|
||||
@ -24,7 +24,7 @@ struct PgCategories::PgCategoriesPriv {
|
||||
}
|
||||
|
||||
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() {
|
||||
return Categories::Iterable{tBegin()};
|
||||
@ -35,10 +35,10 @@ struct PgCategories::PgCategoriesPriv {
|
||||
}
|
||||
|
||||
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))} {}
|
||||
|
||||
long PgCategories::size() const {
|
||||
|
||||
@ -69,7 +69,7 @@ struct PgCategory::PgCategoryPrivate {
|
||||
}
|
||||
|
||||
auto categories() const {
|
||||
std::vector< std::unique_ptr< PgCategory > > children;
|
||||
std::vector< std::unique_ptr< Category > > children;
|
||||
children.reserve(100);
|
||||
for(auto & category_row : _db(select(columns()).from(table_list()).where(parent_match()))) {
|
||||
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 <eedb/mock/db/pg/CategoryMock.hpp>
|
||||
#include <utils/UniquePtrMockWrapper.hpp>
|
||||
|
||||
class PgCategoriesTest : public DbTestBase< PgCategoriesTest > {
|
||||
public:
|
||||
PgCategoriesTest() {
|
||||
db().native()->start_transaction();
|
||||
|
||||
// sut = std::make_unique< eedb::PgCategories >();
|
||||
|
||||
//sut = std::make_unique< eedb::PgCategories >(_categories);
|
||||
}
|
||||
|
||||
~PgCategoriesTest() {
|
||||
db().native()->rollback_transaction(false);
|
||||
}
|
||||
|
||||
private:
|
||||
protected:
|
||||
std::vector< UniquePtrMockWrapper< eedb::CategoryMock > > _categories;
|
||||
|
||||
std::unique_ptr< eedb::PgCategories > sut;
|
||||
};
|
||||
|
||||
template <>
|
||||
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"));
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
class Units {
|
||||
public:
|
||||
virtual ~Units() = default;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The Unit class
|
||||
*/
|
||||
class Unit {
|
||||
public:
|
||||
|
||||
std::string_view name() const;
|
||||
Unit toBase() const;
|
||||
};
|
||||
|
||||
} // 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 Items;
|
||||
class Values;
|
||||
class Units;
|
||||
class Parameters;
|
||||
|
||||
/**
|
||||
* @brief The ItemQueryFilters class
|
||||
*/
|
||||
@ -58,6 +59,12 @@ class Items {
|
||||
*/
|
||||
virtual long size() const = 0;
|
||||
|
||||
/**
|
||||
* @brief commonParameters
|
||||
* @return
|
||||
*/
|
||||
virtual Parameters commonParameters() const = 0;
|
||||
|
||||
/**
|
||||
* @brief begin
|
||||
* @return
|
||||
@ -78,8 +85,22 @@ class Item {
|
||||
public:
|
||||
virtual ~Item() = default;
|
||||
|
||||
/**
|
||||
* @brief displayName
|
||||
* @return
|
||||
*/
|
||||
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
|
||||
|
||||
@ -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