Loading TemplateTest/main.cpp +95 −6 Original line number Original line Diff line number Diff line #include "../debug/Debug.h" #include "../debug/Debug.h" #include "../Unstructured_mesh/UnstructuredMesh.h" #include "../Unstructured_mesh/UnstructuredMesh/UnstructuredMesh.h" #include "../Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MemberApproach.h" #include <type_traits> #include <iostream> #include <iostream> #include <list> #include <list> #include <map> #include <map> Loading Loading @@ -239,9 +241,50 @@ void callSpec() { } } int main() struct tempData { { double density; Vector<3,double> velocity; double& getData(){ return density; } Vector<3,double> getMomentum(){ return velocity*density; } void setMomentum(const Vector<3,double>& val){ velocity = val / density; } }; void testMemberRef(){ MemberApproach<tempData, double>* app; //MemberReference<tempData, double, bool> invalid; MemberReference<tempData, double>::SuperRef<double tempData::*> ref(&tempData::density); MemberReference<tempData, double>::SuperRef<double& (tempData::*)()> ref1(&tempData::getData); 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); } void testOrig() { Vertex<5, double> vert; Vertex<5, double> vert; vector<double> vec; vector<double> vec; DBGVAR(has_public_member<double>::value); DBGVAR(has_public_member<double>::value); Loading @@ -254,11 +297,11 @@ int main() member_ptr<Temp, double>::type pom = &Temp::data; member_ptr<Temp, double>::type pom = &Temp::data; DBGVAR(((&t)->*pom1)(0.0),pom); DBGVAR(((&t)->*pom1)(0.0),pom); //auto op = &vector<double>::operator[]; //auto op = &vector<double>::operator[]; member_const_function_ptr<vector<double>,const double&, size_t>::type c_at = &vector<double>::at; //member_const_function_ptr<vector<double>,const double&, size_t>::type c_at = &vector<double>::at; member_function_ptr<vector<double>,double&, size_t>::type at = &vector<double>::at; //member_function_ptr<vector<double>,double&, size_t>::type at = &vector<double>::at; member_const_function_ptr<vector<double>,const double&, size_t>::type op = &vector<double>::operator[]; //member_const_function_ptr<vector<double>,const double&, size_t>::type op = &vector<double>::operator[]; //DBGVAR(is_same<decltype(&vector<double>::operator[]), typename member_const_function_ptr<vector<double>,const double&, size_t>::type>::value); //DBGVAR(is_same<decltype(&vector<double>::operator[]), typename member_const_function_ptr<vector<double>,const double&, size_t>::type>::value); Loading @@ -270,5 +313,51 @@ int main() callSpec<int>(); callSpec<int>(); } template <typename T> class Base{ public: T data; Base(T dat){ data = dat; } }; template <> class Base<double>{ public: double data; Base(double dat){ DBGMSG("double"); data = dat; } }; template <typename T1, typename T2> class Base<std::pair<T1,T2>>{ public: T1 first; T2 second; Base(std::pair<T1,T2> pair){ first = pair.first; second = pair.second; } }; int main() { Base b1(0.0); Base b2(std::pair<char,int>{'1',3}); DBGVAR(b2.first,b2.second); testMemberRef(); return 0; return 0; } } Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MemberApproach.h 0 → 100644 +133 −0 Original line number Original line Diff line number Diff line #ifndef MEMBERAPPROACH_H #define MEMBERAPPROACH_H #include <type_traits> #include <utility> template <typename Class, typename ValueType> class MemberApproach{ public: virtual ValueType getValue(Class*) = 0; virtual void setValue(Class*, const ValueType&) = 0; }; template<typename Class, typename ValueType> class MemberReference{ 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){} }; template<typename Ref> class SuperRef: public Reference<Ref, void>{ public: SuperRef(Ref ref): Reference<Ref, void> (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>{ Ref ref; public: Reference(Ref referenceToMember){ ref = referenceToMember; DBGVAR((std::is_same<Ref, ValueType Class::*>::value)); } virtual ValueType getValue(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: Reference(Ref referenceToMember){ ref = referenceToMember; DBGVAR((std::is_same<Ref, ValueType Class::*>::value)); } virtual ValueType getValue(Class* c) override { return (c->*ref)(); } virtual void setValue(Class* c, const ValueType& val) override { (c->*ref)() = val; } }; template<typename MemberRefGet, typename MemberRefSet> class Reference< std::pair<MemberRefGet, MemberRefSet>, // enable if MemberRef is pointer to member typename std::enable_if< std::is_same<MemberRefGet, ValueType (Class::*)()>::value && std::is_same<MemberRefSet, void (Class::*)(const ValueType&)>::value >::type > : public MemberApproach<Class, ValueType>{ MemberRefGet refGet; MemberRefSet refSet; public: Reference(std::pair<MemberRefGet, MemberRefSet> getSet){ refGet = getSet.first; refSet = getSet.second; } virtual ValueType getValue(Class* c) override { return (c->*refGet)(); } virtual void setValue(Class* c, const ValueType& val) override { (c->*refSet)(val); } }; }; #endif // MEMBERAPPROACH_H Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MeshDataContainer.h +1 −1 Original line number Original line Diff line number Diff line #ifndef MESHDATACONTAINER_H #ifndef MESHDATACONTAINER_H #define MESHDATACONTAINER_H #define MESHDATACONTAINER_H #include "UnstructuredMesh/MeshElements/MeshElement.h" #include "../MeshElements/MeshElement.h" #include "../debug/Debug.h" #include "../debug/Debug.h" Loading Unstructured_mesh/Unstructured_mesh.pro +1 −0 Original line number Original line Diff line number Diff line Loading @@ -13,6 +13,7 @@ HEADERS += \ ../debug/HTMLLogger.h \ ../debug/HTMLLogger.h \ ../debug/VariableExport.h \ ../debug/VariableExport.h \ InlineArrayOperations.h \ InlineArrayOperations.h \ UnstructuredMesh/MeshDataContainer/MemberApproach.h \ UnstructuredMesh/MeshDataContainer/MeshDataContainer.h \ UnstructuredMesh/MeshDataContainer/MeshDataContainer.h \ UnstructuredMesh/MeshElements/CellBoundaryConnection.h \ UnstructuredMesh/MeshElements/CellBoundaryConnection.h \ UnstructuredMesh/MeshElements/CellConnection.h \ UnstructuredMesh/MeshElements/CellConnection.h \ Loading Unstructured_mesh/Unstructured_mesh.pro.user +1 −1 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject> <!-- Written by QtCreator 4.10.0, 2019-10-17T10:45:33. --> <!-- Written by QtCreator 4.10.0, 2019-10-22T14:43:15. --> <qtcreator> <qtcreator> <data> <data> <variable>EnvironmentId</variable> <variable>EnvironmentId</variable> Loading Loading
TemplateTest/main.cpp +95 −6 Original line number Original line Diff line number Diff line #include "../debug/Debug.h" #include "../debug/Debug.h" #include "../Unstructured_mesh/UnstructuredMesh.h" #include "../Unstructured_mesh/UnstructuredMesh/UnstructuredMesh.h" #include "../Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MemberApproach.h" #include <type_traits> #include <iostream> #include <iostream> #include <list> #include <list> #include <map> #include <map> Loading Loading @@ -239,9 +241,50 @@ void callSpec() { } } int main() struct tempData { { double density; Vector<3,double> velocity; double& getData(){ return density; } Vector<3,double> getMomentum(){ return velocity*density; } void setMomentum(const Vector<3,double>& val){ velocity = val / density; } }; void testMemberRef(){ MemberApproach<tempData, double>* app; //MemberReference<tempData, double, bool> invalid; MemberReference<tempData, double>::SuperRef<double tempData::*> ref(&tempData::density); MemberReference<tempData, double>::SuperRef<double& (tempData::*)()> ref1(&tempData::getData); 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); } void testOrig() { Vertex<5, double> vert; Vertex<5, double> vert; vector<double> vec; vector<double> vec; DBGVAR(has_public_member<double>::value); DBGVAR(has_public_member<double>::value); Loading @@ -254,11 +297,11 @@ int main() member_ptr<Temp, double>::type pom = &Temp::data; member_ptr<Temp, double>::type pom = &Temp::data; DBGVAR(((&t)->*pom1)(0.0),pom); DBGVAR(((&t)->*pom1)(0.0),pom); //auto op = &vector<double>::operator[]; //auto op = &vector<double>::operator[]; member_const_function_ptr<vector<double>,const double&, size_t>::type c_at = &vector<double>::at; //member_const_function_ptr<vector<double>,const double&, size_t>::type c_at = &vector<double>::at; member_function_ptr<vector<double>,double&, size_t>::type at = &vector<double>::at; //member_function_ptr<vector<double>,double&, size_t>::type at = &vector<double>::at; member_const_function_ptr<vector<double>,const double&, size_t>::type op = &vector<double>::operator[]; //member_const_function_ptr<vector<double>,const double&, size_t>::type op = &vector<double>::operator[]; //DBGVAR(is_same<decltype(&vector<double>::operator[]), typename member_const_function_ptr<vector<double>,const double&, size_t>::type>::value); //DBGVAR(is_same<decltype(&vector<double>::operator[]), typename member_const_function_ptr<vector<double>,const double&, size_t>::type>::value); Loading @@ -270,5 +313,51 @@ int main() callSpec<int>(); callSpec<int>(); } template <typename T> class Base{ public: T data; Base(T dat){ data = dat; } }; template <> class Base<double>{ public: double data; Base(double dat){ DBGMSG("double"); data = dat; } }; template <typename T1, typename T2> class Base<std::pair<T1,T2>>{ public: T1 first; T2 second; Base(std::pair<T1,T2> pair){ first = pair.first; second = pair.second; } }; int main() { Base b1(0.0); Base b2(std::pair<char,int>{'1',3}); DBGVAR(b2.first,b2.second); testMemberRef(); return 0; return 0; } }
Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MemberApproach.h 0 → 100644 +133 −0 Original line number Original line Diff line number Diff line #ifndef MEMBERAPPROACH_H #define MEMBERAPPROACH_H #include <type_traits> #include <utility> template <typename Class, typename ValueType> class MemberApproach{ public: virtual ValueType getValue(Class*) = 0; virtual void setValue(Class*, const ValueType&) = 0; }; template<typename Class, typename ValueType> class MemberReference{ 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){} }; template<typename Ref> class SuperRef: public Reference<Ref, void>{ public: SuperRef(Ref ref): Reference<Ref, void> (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>{ Ref ref; public: Reference(Ref referenceToMember){ ref = referenceToMember; DBGVAR((std::is_same<Ref, ValueType Class::*>::value)); } virtual ValueType getValue(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: Reference(Ref referenceToMember){ ref = referenceToMember; DBGVAR((std::is_same<Ref, ValueType Class::*>::value)); } virtual ValueType getValue(Class* c) override { return (c->*ref)(); } virtual void setValue(Class* c, const ValueType& val) override { (c->*ref)() = val; } }; template<typename MemberRefGet, typename MemberRefSet> class Reference< std::pair<MemberRefGet, MemberRefSet>, // enable if MemberRef is pointer to member typename std::enable_if< std::is_same<MemberRefGet, ValueType (Class::*)()>::value && std::is_same<MemberRefSet, void (Class::*)(const ValueType&)>::value >::type > : public MemberApproach<Class, ValueType>{ MemberRefGet refGet; MemberRefSet refSet; public: Reference(std::pair<MemberRefGet, MemberRefSet> getSet){ refGet = getSet.first; refSet = getSet.second; } virtual ValueType getValue(Class* c) override { return (c->*refGet)(); } virtual void setValue(Class* c, const ValueType& val) override { (c->*refSet)(val); } }; }; #endif // MEMBERAPPROACH_H
Unstructured_mesh/UnstructuredMesh/MeshDataContainer/MeshDataContainer.h +1 −1 Original line number Original line Diff line number Diff line #ifndef MESHDATACONTAINER_H #ifndef MESHDATACONTAINER_H #define MESHDATACONTAINER_H #define MESHDATACONTAINER_H #include "UnstructuredMesh/MeshElements/MeshElement.h" #include "../MeshElements/MeshElement.h" #include "../debug/Debug.h" #include "../debug/Debug.h" Loading
Unstructured_mesh/Unstructured_mesh.pro +1 −0 Original line number Original line Diff line number Diff line Loading @@ -13,6 +13,7 @@ HEADERS += \ ../debug/HTMLLogger.h \ ../debug/HTMLLogger.h \ ../debug/VariableExport.h \ ../debug/VariableExport.h \ InlineArrayOperations.h \ InlineArrayOperations.h \ UnstructuredMesh/MeshDataContainer/MemberApproach.h \ UnstructuredMesh/MeshDataContainer/MeshDataContainer.h \ UnstructuredMesh/MeshDataContainer/MeshDataContainer.h \ UnstructuredMesh/MeshElements/CellBoundaryConnection.h \ UnstructuredMesh/MeshElements/CellBoundaryConnection.h \ UnstructuredMesh/MeshElements/CellConnection.h \ UnstructuredMesh/MeshElements/CellConnection.h \ Loading
Unstructured_mesh/Unstructured_mesh.pro.user +1 −1 Original line number Original line Diff line number Diff line <?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject> <!-- Written by QtCreator 4.10.0, 2019-10-17T10:45:33. --> <!-- Written by QtCreator 4.10.0, 2019-10-22T14:43:15. --> <qtcreator> <qtcreator> <data> <data> <variable>EnvironmentId</variable> <variable>EnvironmentId</variable> Loading