Commit 536c9eae authored by Tomáš Jakubec's avatar Tomáš Jakubec
Browse files

Merge branch 'refs/heads/master' into Heat_cond_test

parents f935db27 54bc1ed4
#ifndef MACROFOREACH_H
#define MACROFOREACH_H
/*
* Macros FOR_EACH are supposed to repeat
* any other mocro for each argument passed as
* variadic parameters.
*/
#define FOR_EACH_NARG(...) FOR_EACH_NARG_(__VA_ARGS__, FOR_EACH_RSEQ_N())
#define FOR_EACH_NARG_(...) FOR_EACH_ARG_N(__VA_ARGS__)
#define FOR_EACH_ARG_N(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, N, ...) N
#define FOR_EACH_RSEQ_N() 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 09, 08, 07, 06, 05, 04, 03, 02, 01, 00
#define CONCATENATE(arg1, arg2) CONCATENATE1(arg1, arg2)
#define CONCATENATE1(arg1, arg2) CONCATENATE2(arg1, arg2)
#define CONCATENATE2(arg1, arg2) arg1##arg2
#define FOR_EACH_00(what, ...)
#define FOR_EACH_01(what, x, ...) what(x)
#define FOR_EACH_02(what, x, ...) what(x), FOR_EACH_01(what, __VA_ARGS__)
#define FOR_EACH_03(what, x, ...) what(x), FOR_EACH_02(what, __VA_ARGS__)
#define FOR_EACH_04(what, x, ...) what(x), FOR_EACH_03(what, __VA_ARGS__)
#define FOR_EACH_05(what, x, ...) what(x), FOR_EACH_04(what, __VA_ARGS__)
#define FOR_EACH_06(what, x, ...) what(x), FOR_EACH_05(what, __VA_ARGS__)
#define FOR_EACH_07(what, x, ...) what(x), FOR_EACH_06(what, __VA_ARGS__)
#define FOR_EACH_08(what, x, ...) what(x), FOR_EACH_07(what, __VA_ARGS__)
#define FOR_EACH_09(what, x, ...) what(x), FOR_EACH_08(what, __VA_ARGS__)
#define FOR_EACH_10(what, x, ...) what(x), FOR_EACH_09(what, __VA_ARGS__)
#define FOR_EACH_11(what, x, ...) what(x), FOR_EACH_10(what, __VA_ARGS__)
#define FOR_EACH_12(what, x, ...) what(x), FOR_EACH_11(what, __VA_ARGS__)
#define FOR_EACH_13(what, x, ...) what(x), FOR_EACH_12(what, __VA_ARGS__)
#define FOR_EACH_14(what, x, ...) what(x), FOR_EACH_13(what, __VA_ARGS__)
#define FOR_EACH_15(what, x, ...) what(x), FOR_EACH_14(what, __VA_ARGS__)
#define FOR_EACH_16(what, x, ...) what(x), FOR_EACH_15(what, __VA_ARGS__)
#define FOR_EACH_17(what, x, ...) what(x), FOR_EACH_16(what, __VA_ARGS__)
#define FOR_EACH_18(what, x, ...) what(x), FOR_EACH_17(what, __VA_ARGS__)
#define FOR_EACH_19(what, x, ...) what(x), FOR_EACH_18(what, __VA_ARGS__)
#define FOR_EACH_20(what, x, ...) what(x), FOR_EACH_19(what, __VA_ARGS__)
#define FOR_EACH_21(what, x, ...) what(x), FOR_EACH_20(what, __VA_ARGS__)
#define FOR_EACH_22(what, x, ...) what(x), FOR_EACH_21(what, __VA_ARGS__)
#define FOR_EACH_23(what, x, ...) what(x), FOR_EACH_22(what, __VA_ARGS__)
#define FOR_EACH_24(what, x, ...) what(x), FOR_EACH_23(what, __VA_ARGS__)
#define FOR_EACH_25(what, x, ...) what(x), FOR_EACH_24(what, __VA_ARGS__)
#define FOR_EACH_26(what, x, ...) what(x), FOR_EACH_25(what, __VA_ARGS__)
#define FOR_EACH_27(what, x, ...) what(x), FOR_EACH_26(what, __VA_ARGS__)
#define FOR_EACH_28(what, x, ...) what(x), FOR_EACH_27(what, __VA_ARGS__)
#define FOR_EACH_29(what, x, ...) what(x), FOR_EACH_28(what, __VA_ARGS__)
#define FOR_EACH_30(what, x, ...) what(x), FOR_EACH_29(what, __VA_ARGS__)
#define FOR_EACH_31(what, x, ...) what(x), FOR_EACH_30(what, __VA_ARGS__)
#define FOR_EACH_32(what, x, ...) what(x), FOR_EACH_31(what, __VA_ARGS__)
#define FOR_EACH_33(what, x, ...) what(x), FOR_EACH_32(what, __VA_ARGS__)
#define FOR_EACH_34(what, x, ...) what(x), FOR_EACH_33(what, __VA_ARGS__)
#define FOR_EACH_35(what, x, ...) what(x), FOR_EACH_34(what, __VA_ARGS__)
#define FOR_EACH_36(what, x, ...) what(x), FOR_EACH_35(what, __VA_ARGS__)
#define FOR_EACH_37(what, x, ...) what(x), FOR_EACH_36(what, __VA_ARGS__)
#define FOR_EACH_38(what, x, ...) what(x), FOR_EACH_37(what, __VA_ARGS__)
#define FOR_EACH_39(what, x, ...) what(x), FOR_EACH_38(what, __VA_ARGS__)
#define FOR_EACH_40(what, x, ...) what(x), FOR_EACH_39(what, __VA_ARGS__)
#define FOR_EACH_(N, what, ...) CONCATENATE(FOR_EACH_, N)(what, __VA_ARGS__)
#define FOR_EACH(what, ...) FOR_EACH_(FOR_EACH_NARG(__VA_ARGS__), what, __VA_ARGS__)
#define FOR_EACH_EVEN_00(what, ...)
#define FOR_EACH_EVEN_02(what, x_odd, x_even, ...) what(x_even)
#define FOR_EACH_EVEN_04(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_02(what, __VA_ARGS__)
#define FOR_EACH_EVEN_06(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_04(what, __VA_ARGS__)
#define FOR_EACH_EVEN_08(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_06(what, __VA_ARGS__)
#define FOR_EACH_EVEN_10(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_08(what, __VA_ARGS__)
#define FOR_EACH_EVEN_12(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_10(what, __VA_ARGS__)
#define FOR_EACH_EVEN_14(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_12(what, __VA_ARGS__)
#define FOR_EACH_EVEN_16(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_14(what, __VA_ARGS__)
#define FOR_EACH_EVEN_18(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_16(what, __VA_ARGS__)
#define FOR_EACH_EVEN_20(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_18(what, __VA_ARGS__)
#define FOR_EACH_EVEN_22(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_20(what, __VA_ARGS__)
#define FOR_EACH_EVEN_24(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_22(what, __VA_ARGS__)
#define FOR_EACH_EVEN_26(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_24(what, __VA_ARGS__)
#define FOR_EACH_EVEN_28(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_26(what, __VA_ARGS__)
#define FOR_EACH_EVEN_30(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_28(what, __VA_ARGS__)
#define FOR_EACH_EVEN_32(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_30(what, __VA_ARGS__)
#define FOR_EACH_EVEN_34(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_32(what, __VA_ARGS__)
#define FOR_EACH_EVEN_36(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_34(what, __VA_ARGS__)
#define FOR_EACH_EVEN_38(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_36(what, __VA_ARGS__)
#define FOR_EACH_EVEN_40(what, x_odd, x_even, ...) what(x_even), FOR_EACH_EVEN_38(what, __VA_ARGS__)
#define FOR_EACH_EVEN_(N, what, ...) CONCATENATE(FOR_EACH_EVEN_, N)(what, __VA_ARGS__)
#define FOR_EACH_EVEN(what, ...) FOR_EACH_EVEN_(FOR_EACH_NARG(__VA_ARGS__), what, __VA_ARGS__)
#define DUMMY
#define FOR_EACH_ODD(what, ...) FOR_EACH_EVEN_(FOR_EACH_NARG( , __VA_ARGS__), what, , __VA_ARGS__)
#define FOR_EACH_2ARGS_00(what, ...)
#define FOR_EACH_2ARGS_02(what, x1, x2, ...) what(x1, x2)
#define FOR_EACH_2ARGS_04(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_02(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_06(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_04(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_08(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_06(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_10(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_08(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_12(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_10(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_14(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_12(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_16(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_14(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_18(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_16(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_20(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_18(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_22(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_20(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_24(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_22(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_26(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_24(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_28(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_26(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_30(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_28(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_32(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_30(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_34(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_32(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_36(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_34(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_38(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_36(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_40(what, x1, x2, ...) what(x1, x2), FOR_EACH_2ARGS_38(what, __VA_ARGS__)
#define FOR_EACH_2ARGS_(N, what, ...) CONCATENATE(FOR_EACH_2ARGS_, N)(what, __VA_ARGS__)
#define FOR_EACH_2ARGS(what, ...) FOR_EACH_2ARGS_(FOR_EACH_NARG(__VA_ARGS__), what, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_00(what, ...)
#define FOR_EACH_3ARGS_1STAT_02(what,x_stat, x1, x2, ...) what(x_stat, x1, x2)
#define FOR_EACH_3ARGS_1STAT_04(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_02(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_06(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_04(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_08(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_06(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_10(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_08(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_12(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_10(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_14(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_12(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_16(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_14(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_18(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_16(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_20(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_18(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_22(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_20(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_24(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_22(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_26(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_24(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_28(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_26(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_30(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_28(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_32(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_30(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_34(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_32(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_36(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_34(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_38(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_36(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_40(what,x_stat, x1, x2, ...) what(x_stat, x1, x2), FOR_EACH_3ARGS_1STAT_38(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT_(N, what, x_stat, ...) CONCATENATE(FOR_EACH_3ARGS_1STAT_, N)(what, x_stat, __VA_ARGS__)
#define FOR_EACH_3ARGS_1STAT(what, x_stat, ...) FOR_EACH_3ARGS_1STAT_(FOR_EACH_NARG(__VA_ARGS__), what, x_stat, __VA_ARGS__)
#endif // MACROFOREACH_H
#include "../debug/Debug.h"
#include "../Unstructured_mesh/UnstructuredMesh/UnstructuredMesh.h"
#include "../Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MemberApproach.h"
#include "../Unstructured_mesh/UnstructuredMesh/MeshDataContainer/Traits.h"
#include <functional>
#include <type_traits>
#include <iostream>
#include <list>
......@@ -45,7 +47,7 @@ struct member_ptr {
struct Temp {
double data;
double fun(double d){return data;}
double fun(double d [[maybe_unused]]){return data;}
};
void testDebug() {
......@@ -77,7 +79,7 @@ void testDebug() {
DBGVAR(Detail::is_indexable<decltype(vert)>::value);
Subelement<size_t> s({1,true});
Subelement<size_t> s({1});
DBGVAR(s);
HTMLDBGVAR(r, i, c, list, vec, b, m);
......@@ -250,7 +252,7 @@ struct tempData {
return density;
}
Vector<3,double> getMomentum(){
Vector<3,double> getMomentum()const{
return velocity*density;
}
......@@ -260,30 +262,153 @@ struct tempData {
};
/*
template<>
class Traits<tempData>{
public:
using ttype = Traits<tempData, double, Vector<3,double>>;
const static ttype tr;
};
const Traits<tempData>::ttype Traits<tempData>::tr("density", &tempData::density, "momentum"s, std::make_pair(&tempData::getMomentum, &tempData::setMomentum));
*/
void testMemberRef(){
MemberApproach<tempData, double>* app;
//MAKE_NAMED_ATTRIBUTE_TRAIT(tempData, "density", density, "velocity", velocity);
//MAKE_ATTRIBUTE_TRAIT(tempData, density, velocity);
//MemberReference<tempData, double, bool> invalid;
MAKE_CUSTOM_ATTRIBUTE_TRAIT(tempData, "density", &tempData::density, "momentum", std::make_pair(&tempData::getMomentum, &tempData::setMomentum))
MemberReference<tempData, double>::SuperRef<double tempData::*> ref(&tempData::density);
MemberReference<tempData, double>::SuperRef<double& (tempData::*)()> ref1(&tempData::getData);
struct ExportTest {
int attrInt = 1;
double attrDouble = 42.15;
char attrChar = 42;
std::string attrStr = "Ahojky";
std::vector<std::string> attrVec = {"tohle", "je", "nejlepsi", "debugovaci", "system"};
tempData attrTempData{42.15, {1,2,1}};
};
MAKE_ATTRIBUTE_TRAIT(ExportTest, attrInt, attrDouble, attrChar, attrStr, attrVec, attrTempData);
void testMemberRef(){
MemberReference<tempData, Vector<3,double>>::SuperRef ref2(std::make_pair(&tempData::getMomentum, &tempData::setMomentum));
app = &ref;
app = &ref1;
tempData d;
app->setValue(&d, 42.15);
DBGVAR(app->getValue(&d));
MemberApproach<tempData, Vector<3,double>>* app2 = &ref2;
app2->setValue(&d, {42.15,84.30,42.15});
DBGVAR(app2->getValue(&d), d.velocity);
//DBGVAR(Traits<tempData>::ttype::getName<0>());
Traits<tempData>::ttype::getReference<0>()->setValue(&d, 0.0);
DBGVAR(Traits<tempData>::ttype::getReference<0>()->getValue(&d));
Traits<tempData>::ttype::getReference<0>()->setValue(d, 42.15);
Traits<tempData>::ttype::getReference<1>()->setValue(&d, {42.15,84.30,42.15});
DBGVAR(Traits<tempData>::ttype::getName<0>(),(Traits<tempData>::ttype::getReference<0>()->getValue(&d)), Traits<tempData>::ttype::getName<1>(),(Traits<tempData, double, Vector<3,double>>::getReference<1>()->getValue(&d)), d.velocity);
DBGVAR(Traits<tempData>::is_specialized,Detail::has_default_traits<tempData>::value, d);
ExportTest e;
DBGVAR(e, ClassC<>());
}
#include "../Unstructured_mesh/UnstructuredMesh/MeshDataContainer/Singleton.h"
/*
Test of order of constructors
*/
/*
struct mem{
std::string s;
mem(){DBGVAR(s);}
};
template<typename statMem>
class C1 {
template<unsigned int Index>
struct mem{
std::string s;
mem(){DBGVAR(s);}
};
public:
C1(){
Singleton<mem<1>>::getInstance().s = "ahoj";
DBGVAR("C1", Singleton<mem<1>>::getInstance().s);
}
static std::string& getS() {return Singleton<mem<1>>::getInstance().s;}
};
template <typename dummy>
class C2 {
public:
static C1<mem> c;
C2() {DBGVAR(c.getS());}
};
template <typename dummy> C1<mem> C2<dummy>::c;
template<typename statMem>
class C1_wrong {
public:
static statMem s;
C1_wrong(){
s.s = "ahoj";
DBGVAR("C1_wrong", s.s);
}
static std::string& getS() {return s.s;}
};
template <typename statMem> statMem C1_wrong<statMem>::s;
template <typename dummy>
class C2_wrong {
public:
static C1_wrong<mem> c;
C2_wrong() {DBGVAR(c.getS());}
};
template <typename dummy> C1_wrong<mem> C2_wrong<dummy>::c;
class C1_ {
public:
static mem s1;
C1_(){
s1.s = "ahoj";
DBGVAR("C1_", s1.s);
}
};
mem C1_::s1;
class C2_ {
public:
static C1_ c;
C2_(){DBGVAR(c.s1.s);}
};
C1_ C2_::c;
using C = C1<mem>;
void testConstrucorOrder() {
C2_ c;
C2<void> c1;
DBGVAR(C2_::c.s1.s, C2<void>::c.getS(), C::getS(), C2_wrong<void>::c.getS());
}
*/
void testOrig() {
Vertex<5, double> vert;
vector<double> vec;
......@@ -348,16 +473,114 @@ public:
}
};
class Number {
public:
double num = 0;
Number(double num) {
this->num = num;
DBGMSG("constructing number");
}
Number operator+(const Number& rhs){
DBGMSG("operator+ const&");
return Number(this->num + rhs.num);
}
Number operator+(Number&& rhs){
DBGMSG("operator+ &&");
rhs.num += this->num;
return rhs;
}
Number operator*(const Number& rhs){
return Number(this->num * rhs.num);
}
Number operator*(Number&& rhs){
rhs.num *= this->num;
return rhs;
}
};
MAKE_ATTRIBUTE_TRAIT(Number,num);
void testOperator() {
Number n(42.15), m(42);
DBGMSG("start sum");
Number nn = n + (n *(m + (m + n)));
DBGVAR(nn);
}
int main()
{
Base b1(0.0);
/*Base b1(0.0);
Base b2(std::pair<char,int>{'1',3});
DBGVAR(b2.first,b2.second);
testMemberRef();
*/
testOperator();
//testMemberRef();
//testConstrucorOrder();
/*
std::function<int(int)> fce = [&b1](int i){return b1.data + 42 + i;};
std::cout << fce(2);
*/
return 0;
}
/** GCC error
#include <iostream>
#include <string>
struct mem{
std::string s;
mem(){std::cout <<"mem constructor: " << s << std::endl;}
};
template<typename statMem>
class C1_wrong {
public:
static statMem s;
C1_wrong(){
s.s = "hello";
std::cout << "C1_wrong s.s: " << s.s << std::endl;
}
static std::string& getS() {return s.s;}
};
template <typename statMem> statMem C1_wrong<statMem>::s;
template <typename dummy>
class C2_wrong {
public:
static C1_wrong<mem> c;
C2_wrong() {std::cout << "C2_wrong constructor c.getS(): " << c.getS() << std::endl;}
};
template <typename dummy> C1_wrong<mem> C2_wrong<dummy>::c;
void testConstrucorOrder() {
std::cout << "global value of C2: " << C2_wrong<void>::c.getS() << std::endl;
}
int main()
{
testConstrucorOrder();
}
*/
......@@ -3,131 +3,282 @@
#include <type_traits>
#include <utility>
/**
* @brief The MemberApproach class
* Generic abstract class providing the
*/
template <typename Class, typename ValueType>
class MemberApproach{
public:
virtual ValueType getValue(Class*) = 0;
virtual ValueType getValue(const Class*) = 0;
virtual void setValue(Class*, const ValueType&) = 0;
virtual ValueType getValue(const Class&) = 0;
virtual void setValue(Class&, const ValueType&) = 0;
};
template<typename Class, typename ValueType, typename Ref>
class MemberReference{
static_assert (std::is_same<Ref, ValueType Class::*>::value,
"The type MemberRef must be reference to member ValueType Class::* or pointer to getter and setter");
MemberReference(Ref);
};
template <typename Class, typename ValueType>
class MemberReference<Class, ValueType, ValueType Class::*> : public MemberApproach<Class, ValueType>{
template<typename Class, typename ValueType>
class MemberReference{
using refType = ValueType Class::*;
refType ref;
public:
template<typename Ref, typename VOID = void>
class Reference{
static_assert (std::is_same<Ref, ValueType Class::*>::value, "The type MemberRef must be reference to member ValueType Class::* or pointer to getter and setter");
public:
Reference(Ref){}
};
MemberReference(refType referenceToMember){
ref = referenceToMember;
}
virtual ValueType getValue(const Class* c) override {
return c->*ref;
}
template<typename Ref>
class SuperRef: public Reference<Ref, void>{
public:
SuperRef(Ref ref): Reference<Ref, void> (ref){}
};
virtual void setValue(Class* c, const ValueType& val) override {
c->*ref = val;
}
virtual ValueType getValue(const Class& c) override {
return c.*ref;
}
template<typename Ref>
class Reference<
Ref,
// enable if MemberRef is pointer to member
typename std::enable_if<
std::is_same<Ref, ValueType Class::*>::value
>::type
>
: public MemberApproach<Class, ValueType>{
virtual void setValue(Class& c, const ValueType& val) override {
c.*ref = val;
}
};
Ref ref;
public:
template <typename Class, typename ValueType>
class MemberReference<Class, ValueType, ValueType& (Class::*)()> : public MemberApproach<Class, ValueType>{
Reference(Ref referenceToMember){
ref = referenceToMember;
DBGVAR((std::is_same<Ref, ValueType Class::*>::value));
}
using refType = ValueType& (Class::*)();
virtual ValueType getValue(Class* c) override {
return c->*ref;
}
refType ref;
virtual void setValue(Class* c, const ValueType& val) override {
c->*ref = val;
}
};
public:
MemberReference(refType referenceToMember){
ref = referenceToMember;
}
virtual ValueType getValue(const Class* c) override {
return (c->*ref)();
}
virtual void setValue(Class* c, const ValueType& val) override {
(c->*ref)() = val;
}
virtual ValueType getValue(const Class& c) override {
return (c.*ref)();
}
virtual void setValue(Class& c, const ValueType& val) override {
(c.*ref)() = val;
}
};
template<typename Ref>
class Reference<
Ref,
// enable if MemberRef is pointer to member
typename std::enable_if<
std::is_same<Ref, ValueType& (Class::*)()>::value
>::type
>
: public MemberApproach<Class, ValueType>{
Ref ref;
public:
template <typename Class, typename ValueType>
class MemberReference<