Loading Macros/MacroForEach.h 0 → 100644 +155 −0 Original line number Diff line number Diff line #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 TemplateTest/main.cpp +242 −19 Original line number Diff line number Diff line #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> Loading Loading @@ -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() { Loading Loading @@ -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); Loading Loading @@ -250,7 +252,7 @@ struct tempData { return density; } Vector<3,double> getMomentum(){ Vector<3,double> getMomentum()const{ return velocity*density; } Loading @@ -260,29 +262,152 @@ 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; Loading Loading @@ -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(); } */ Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MemberApproach.h +233 −82 File changed.Preview size limit exceeded, changes collapsed. Show changes Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MeshDataContainer.h +34 −3 Original line number Diff line number Diff line Loading @@ -10,11 +10,11 @@ template<typename DataType, unsigned int Position, unsigned int MappedDimenion> struct DataContainer : public std::vector<DataType> { using type = DataType; constexpr unsigned int getPosition() { static constexpr unsigned int getPosition() { return Position; } constexpr unsigned int getMappedDimension() { static constexpr unsigned int getMappedDimension() { return MappedDimenion; } }; Loading Loading @@ -56,9 +56,25 @@ public: }; template<typename _DataType> struct _DataContainer<_DataType, 0> : public std::vector<_DataType>{ struct _DataContainer<_DataType, 0>{ DataContainer<_DataType, 0, dimensionAt<0U>()> _data; }; /** * Data container type according to pos */ template <unsigned int Pos> using DataContainerType = DataContainer<DataType, 0, dimensionAt<Pos>()>; /** * @brief size<HR> * Returns the number of vectors contained in the MeshDataContainer. * @return */ static constexpr unsigned int size() { return sizeof... (Dimensions); } private: template<unsigned int pos, typename dummy = void> struct Alocator{ Loading Loading @@ -227,6 +243,21 @@ public: //std::vector<DataType<0>> _data; }; /** * Data container type according to pos */ template <unsigned int Pos> using DataContainerType = DataContainer<DataType<Pos>, 0, dimensionAt<Pos>()>; /** * @brief size<HR> * Returns the number of vectors contained in the MeshDataContainer. * @return */ static constexpr unsigned int size() { return sizeof... (Dimensions); } template<unsigned int pos, typename _DataType, typename... _DataTypes> struct Alocator{ template<unsigned int Dimension, typename IndexType, typename Real, unsigned int ...Reserve> Loading Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MeshDataIO/VTKMeshDataReader.h 0 → 100644 +129 −0 Original line number Diff line number Diff line #ifndef VTKMESHDATAREADER_H #define VTKMESHDATAREADER_H #include "../Traits.h" #include "../MeshDataContainer.h" #include <istream> #include <map> #include <sstream> template <unsigned int MeshDimension, typename IndexType> class VTKMeshDataReader { /** * @brief readColumn * reads a single column of traited data */ static void readColumn(std::istream& ist [[maybe_unused]],...){ DBGMSG("capture"); throw std::runtime_error("capture of read column must not be called."); } template<typename T, unsigned int Index, unsigned int Position> static auto readColumn(std::istream& ist, DataContainer<T, Position, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions) -> typename std::enable_if< Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value >::type { ist.seekg(dataPositions[Traits<T>::ttype::template getName<Index>()]); typename Traits<T>::ttype::template type<Index> value; for (IndexType i = 0; i < data.size(); i++) { for (unsigned int j = 0; j < Traits<T>::ttype::template getValue<Index>(data.at(i)).size(); j++){ ist >> value[j]; } Traits<T>::ttype::template setValue<Index>(data.at(i), value); } } template<typename T, unsigned int Index, unsigned int Position> static auto readColumn(std::istream& ist, DataContainer<T, Position, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions) -> typename std::enable_if< !Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value >::type { ist.seekg(dataPositions[Traits<T>::ttype::template getName<Index>()]); typename Traits<T>::ttype::template type<Index> value; for (IndexType i = 0; i < data.size(); i++){ ist >> value; Traits<T>::ttype::template setValue<Index>(data.at(i), value); } } private: template<typename T,unsigned int Index = 0, typename VOID = void> struct readCellData{}; template<typename T,unsigned int Index, typename... Types> struct readCellData <Traits<T, Types...>, Index, std::enable_if_t<Index < Traits<T, Types...>::size() - 1>>{ template<unsigned int Position> static void read(std::istream& ist, DataContainer<T, Position, MeshDimension> &data, std::map<std::string, std::istream::pos_type>& dataPositions){ DBGVAR(Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value); readColumn<T, Index, Position>(ist, data, dataPositions); readCellData<Traits<T, Types...>, Index + 1>::read(ist, data, dataPositions); } }; template<typename T,unsigned int Index, typename ... Types> struct readCellData <Traits<T, Types...>, Index, std::enable_if_t<Index == Traits<T, Types...>::size() - 1>>{ template<unsigned int Position> static void read(std::istream& ist, DataContainer<T, Position, MeshDimension> &data, std::map<std::string, std::istream::pos_type>& dataPositions){ readColumn<T, Index, Position>(ist, data, dataPositions); } }; public: static std::map<std::string, std::istream::pos_type> indexData(std::istream& ist) { std::map<std::string, std::istream::pos_type> dataPositions; std::string line; ist.seekg(ist.beg); while(getline(ist, line)) { int flag = (line.find("SCALARS")!= line.npos ? 1 : line.find("VECTORS") != line.npos ? 2 : 0 ); if (flag != 0){ std::string dataName; std::stringstream sstream(line); sstream.ignore(9, ' '); sstream >> dataName; if (flag == 1) { // scalar quantity found ist.ignore(500, '\n'); } dataPositions.insert(std::pair(dataName, ist.tellg())); } } ist.clear(); return dataPositions; } template<typename T, unsigned int Position> static void readData(std::istream& ist, DataContainer<T, Position, MeshDimension>& data) { std::map<std::string, std::istream::pos_type> dataPositions = indexData(ist); readCellData<typename Traits<T>::ttype>::read(ist, data, dataPositions); } }; #endif // VTKMESHDATAREADER_H Loading
Macros/MacroForEach.h 0 → 100644 +155 −0 Original line number Diff line number Diff line #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
TemplateTest/main.cpp +242 −19 Original line number Diff line number Diff line #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> Loading Loading @@ -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() { Loading Loading @@ -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); Loading Loading @@ -250,7 +252,7 @@ struct tempData { return density; } Vector<3,double> getMomentum(){ Vector<3,double> getMomentum()const{ return velocity*density; } Loading @@ -260,29 +262,152 @@ 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; Loading Loading @@ -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(); } */
Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MemberApproach.h +233 −82 File changed.Preview size limit exceeded, changes collapsed. Show changes
Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MeshDataContainer.h +34 −3 Original line number Diff line number Diff line Loading @@ -10,11 +10,11 @@ template<typename DataType, unsigned int Position, unsigned int MappedDimenion> struct DataContainer : public std::vector<DataType> { using type = DataType; constexpr unsigned int getPosition() { static constexpr unsigned int getPosition() { return Position; } constexpr unsigned int getMappedDimension() { static constexpr unsigned int getMappedDimension() { return MappedDimenion; } }; Loading Loading @@ -56,9 +56,25 @@ public: }; template<typename _DataType> struct _DataContainer<_DataType, 0> : public std::vector<_DataType>{ struct _DataContainer<_DataType, 0>{ DataContainer<_DataType, 0, dimensionAt<0U>()> _data; }; /** * Data container type according to pos */ template <unsigned int Pos> using DataContainerType = DataContainer<DataType, 0, dimensionAt<Pos>()>; /** * @brief size<HR> * Returns the number of vectors contained in the MeshDataContainer. * @return */ static constexpr unsigned int size() { return sizeof... (Dimensions); } private: template<unsigned int pos, typename dummy = void> struct Alocator{ Loading Loading @@ -227,6 +243,21 @@ public: //std::vector<DataType<0>> _data; }; /** * Data container type according to pos */ template <unsigned int Pos> using DataContainerType = DataContainer<DataType<Pos>, 0, dimensionAt<Pos>()>; /** * @brief size<HR> * Returns the number of vectors contained in the MeshDataContainer. * @return */ static constexpr unsigned int size() { return sizeof... (Dimensions); } template<unsigned int pos, typename _DataType, typename... _DataTypes> struct Alocator{ template<unsigned int Dimension, typename IndexType, typename Real, unsigned int ...Reserve> Loading
Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MeshDataIO/VTKMeshDataReader.h 0 → 100644 +129 −0 Original line number Diff line number Diff line #ifndef VTKMESHDATAREADER_H #define VTKMESHDATAREADER_H #include "../Traits.h" #include "../MeshDataContainer.h" #include <istream> #include <map> #include <sstream> template <unsigned int MeshDimension, typename IndexType> class VTKMeshDataReader { /** * @brief readColumn * reads a single column of traited data */ static void readColumn(std::istream& ist [[maybe_unused]],...){ DBGMSG("capture"); throw std::runtime_error("capture of read column must not be called."); } template<typename T, unsigned int Index, unsigned int Position> static auto readColumn(std::istream& ist, DataContainer<T, Position, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions) -> typename std::enable_if< Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value >::type { ist.seekg(dataPositions[Traits<T>::ttype::template getName<Index>()]); typename Traits<T>::ttype::template type<Index> value; for (IndexType i = 0; i < data.size(); i++) { for (unsigned int j = 0; j < Traits<T>::ttype::template getValue<Index>(data.at(i)).size(); j++){ ist >> value[j]; } Traits<T>::ttype::template setValue<Index>(data.at(i), value); } } template<typename T, unsigned int Index, unsigned int Position> static auto readColumn(std::istream& ist, DataContainer<T, Position, MeshDimension> &data,std::map<std::string, std::istream::pos_type>& dataPositions) -> typename std::enable_if< !Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value >::type { ist.seekg(dataPositions[Traits<T>::ttype::template getName<Index>()]); typename Traits<T>::ttype::template type<Index> value; for (IndexType i = 0; i < data.size(); i++){ ist >> value; Traits<T>::ttype::template setValue<Index>(data.at(i), value); } } private: template<typename T,unsigned int Index = 0, typename VOID = void> struct readCellData{}; template<typename T,unsigned int Index, typename... Types> struct readCellData <Traits<T, Types...>, Index, std::enable_if_t<Index < Traits<T, Types...>::size() - 1>>{ template<unsigned int Position> static void read(std::istream& ist, DataContainer<T, Position, MeshDimension> &data, std::map<std::string, std::istream::pos_type>& dataPositions){ DBGVAR(Detail::is_indexable<typename Traits<T>::ttype::template type<Index>>::value); readColumn<T, Index, Position>(ist, data, dataPositions); readCellData<Traits<T, Types...>, Index + 1>::read(ist, data, dataPositions); } }; template<typename T,unsigned int Index, typename ... Types> struct readCellData <Traits<T, Types...>, Index, std::enable_if_t<Index == Traits<T, Types...>::size() - 1>>{ template<unsigned int Position> static void read(std::istream& ist, DataContainer<T, Position, MeshDimension> &data, std::map<std::string, std::istream::pos_type>& dataPositions){ readColumn<T, Index, Position>(ist, data, dataPositions); } }; public: static std::map<std::string, std::istream::pos_type> indexData(std::istream& ist) { std::map<std::string, std::istream::pos_type> dataPositions; std::string line; ist.seekg(ist.beg); while(getline(ist, line)) { int flag = (line.find("SCALARS")!= line.npos ? 1 : line.find("VECTORS") != line.npos ? 2 : 0 ); if (flag != 0){ std::string dataName; std::stringstream sstream(line); sstream.ignore(9, ' '); sstream >> dataName; if (flag == 1) { // scalar quantity found ist.ignore(500, '\n'); } dataPositions.insert(std::pair(dataName, ist.tellg())); } } ist.clear(); return dataPositions; } template<typename T, unsigned int Position> static void readData(std::istream& ist, DataContainer<T, Position, MeshDimension>& data) { std::map<std::string, std::istream::pos_type> dataPositions = indexData(ist); readCellData<typename Traits<T>::ttype>::read(ist, data, dataPositions); } }; #endif // VTKMESHDATAREADER_H