diff --git a/src/phasicFlow/typeSelection/typeInfo.H b/src/phasicFlow/typeSelection/typeInfo.H new file mode 100644 index 00000000..6f5596cf --- /dev/null +++ b/src/phasicFlow/typeSelection/typeInfo.H @@ -0,0 +1,172 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +-----------------------------------------------------------------------------*/ + + +#ifndef __typeInfo_H__ +#define __typeInfo_H__ + +#include +#include + +#include "bTypes.H" + + +#define has_static_member(name) \ + template \ + struct has_static_member_##name; \ + \ + template \ + struct has_static_member_##name { \ + template struct Check; \ + \ + template \ + static std::true_type Test(Check*); \ + template \ + static std::false_type Test(...); \ + static const bool value = decltype(Test(0))::value; \ +}; + + + +#define TypeName(tName) \ + inline static word TYPENAME() {return tName; } \ + virtual word typeName() const {return TYPENAME();} + +#define TypeNameNV(tName) \ + inline static word TYPENAME() {return tName; } \ + word typeName() const {return TYPENAME();} + + +#define TypeNameTemplate(tName, Type) \ + has_static_member(TYPENAME); \ + inline static word TYPENAME() \ + { \ + if constexpr( has_static_member_TYPENAME::value) \ + { return word(tName)+"<"+Type::TYPENAME()+">";} \ + else \ + return word(tName)+"<"+basicTypeName()+">"; \ + } \ + virtual word typeName() const { return TYPENAME();} + +#define TypeNameTemplate2(tName, Type1, Type2) \ + has_static_member(TYPENAME); \ + inline static word TYPENAME() \ + { \ + if constexpr( has_static_member_TYPENAME::value) \ + { return word(tName)+"<"+Type1::TYPENAME()+","+Type2::TYPENAME()+">";} \ + else \ + return word(tName)+"<"+basicTypeName()+","+Type2::TYPENAME()+">";\ + } \ + virtual word typeName() const { return TYPENAME();} + +#define TypeNameTemplate3(tName, Type1, Type2, Type3) \ + inline static word TYPENAME() \ + { \ + return word(tName)+"<"+Type1::TYPENAME()+","+Type2::TYPENAME()+","+Type3::TYPENAME()+">";\ + } \ + virtual word typeName() const { return TYPENAME();} + +// this is the non-virtual version +#define TypeNameTemplateNV(tName, Type) \ + has_static_member(TYPENAME); \ + inline static word TYPENAME() \ + { \ + if constexpr( has_static_member_TYPENAME::value) \ + { return word(tName)+"<"+Type::TYPENAME()+">";} \ + else \ + return word(tName)+"<"+basicTypeName()+">"; \ + return "noTYPE"; \ + } \ + inline word typeName() const { return TYPENAME();} + + +#define TypeNameTemplateNV2(tName, Type, tName2) \ + has_static_member(TYPENAME); \ + inline static word TYPENAME() \ + { \ + if constexpr( has_static_member_TYPENAME::value) \ + { return word(tName)+"<"+Type::TYPENAME()+","+word(tName2)+">";} \ + else \ + return word(tName)+"<"+basicTypeName()+","+word(tName2)+">"; \ + return "noTYPE"; \ + } \ + inline word typeName() const { return TYPENAME();} + + + + +namespace pFlow +{ + + template + inline word basicTypeName() + { + int status; + auto& ti = typeid(T); + char* realname = abi::__cxa_demangle(ti.name(), 0, 0, &status); + word name(realname); + free(realname); + return name; + } + + template<> + inline word basicTypeName(){ return "word"; } + + template<> + inline word basicTypeName(){ return "int64"; } + + template<> + inline word basicTypeName(){ return "int32"; } + + template<> + inline word basicTypeName(){ return "int16"; } + + template<> + inline word basicTypeName(){ return "int8"; } + + template<> + inline word basicTypeName