add and use concept adc_is_callable rewrite value holder and device attribute classes with new constructor's arguments resolution scheme
47 lines
999 B
C++
47 lines
999 B
C++
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
|
#include <doctest/doctest.h>
|
|
#include <iostream>
|
|
|
|
|
|
#include "../device/adc_device_attribute.h"
|
|
|
|
using namespace adc;
|
|
|
|
template <typename T>
|
|
struct V {
|
|
static T getter() { return _v; }
|
|
static void setter(const T& v) { _v = v; }
|
|
|
|
static bool validator(const T& v)
|
|
{
|
|
if (v < 1)
|
|
return false;
|
|
else
|
|
return true;
|
|
}
|
|
|
|
private:
|
|
inline static T _v = 1;
|
|
};
|
|
|
|
|
|
TEST_CASE("[ADC DEVICE ATTRIBUTE]")
|
|
{
|
|
double av = -10;
|
|
using vv = V<unsigned>;
|
|
|
|
using attr_t = AdcDeviceAttribute<std::string_view>;
|
|
|
|
attr_t attr("ATTR_A", AdcValueHolder::_defaultTrivialConvTypes, vv::getter, vv::setter, vv::validator);
|
|
|
|
attr = 10.7;
|
|
av = attr;
|
|
|
|
std::cout << "ATTR = " << av << "\n";
|
|
// std::cout << "ATTR = " << (unsigned)attr << "\n";
|
|
|
|
attr_t aw("ATTR_WO", AdcValueHolder::_defaultTrivialConvTypes, vv::setter, vv::validator);
|
|
|
|
std::cout << "ACC_TYPE: " << aw.accessType() << "\n";
|
|
}
|