Loading...
Searching...
No Matches
VTKTypes.tpp
1/*---------------------------------------------------------------------------*\
2 *
3 * bitpit
4 *
5 * Copyright (C) 2015-2021 OPTIMAD engineering Srl
6 *
7 * -------------------------------------------------------------------------
8 * License
9 * This file is part of bitpit.
10 *
11 * bitpit is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License v3 (LGPL)
13 * as published by the Free Software Foundation.
14 *
15 * bitpit is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
18 * License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with bitpit. If not, see <http://www.gnu.org/licenses/>.
22 *
23\*---------------------------------------------------------------------------*/
24
25#include <cassert>
26#include <typeinfo>
27#include <type_traits>
28
29namespace bitpit{
30
35template<typename T>
37{
38 // If the type is already registered return the type
39 // currently associated with it
40 const std::type_info &typeInfo = typeid(T);
41 VTKDataType VTKType = whichType(typeInfo);
42 if (VTKType != VTKDataType::UNDEFINED) {
43 return VTKType;
44 }
45
46 // Find out the type
47 int size = 8 * sizeof(T);
48 if (typeInfo == typeid(VTKElementType)) {
49 if (size == 8) {
50 VTKType = VTKDataType::Int8;
51 } else if (size == 16) {
52 VTKType = VTKDataType::Int16;
53 } else if (size == 32) {
54 VTKType = VTKDataType::Int32;
55 } else if (size == 64) {
56 VTKType = VTKDataType::Int64;
57 }
58 } else if (std::is_floating_point<T>::value) {
59 if (size == 32) {
60 VTKType = VTKDataType::Float32;
61 } else if (size == 64) {
62 VTKType = VTKDataType::Float64;
63 }
64 } else if (std::is_integral<T>::value) {
65 if (!std::is_signed<T>::value) {
66 if (size == 8) {
67 VTKType = VTKDataType::UInt8;
68 } else if (size == 16) {
69 VTKType = VTKDataType::UInt16;
70 } else if (size == 32) {
71 VTKType = VTKDataType::UInt32;
72 } else if (size == 64) {
73 VTKType = VTKDataType::UInt64;
74 }
75 } else {
76 if (size == 8) {
77 VTKType = VTKDataType::Int8;
78 } else if (size == 16) {
79 VTKType = VTKDataType::Int16;
80 } else if (size == 32) {
81 VTKType = VTKDataType::Int32;
82 } else if (size == 64) {
83 VTKType = VTKDataType::Int64;
84 }
85 }
86 }
87 assert(VTKType != VTKDataType::UNDEFINED);
88
89 return registerType<T>(VTKType);
90}
91
97template<typename T>
99{
100 // Index associated to the type
101 const std::type_info &typeInfo = typeid(T);
102 std::type_index index = std::type_index(typeInfo);
103
104 // Add the type to the registered data types
105 m_types.insert({{index, VTKType}});
106
107 return VTKType;
108}
109
116template<typename T, int nesting, typename std::enable_if<std::is_pod<T>::value&&!utils::is_iterable<T>::value>::type*>
118 return whichType(typeid(T)) ;
119}
120
127template<typename T, int nesting, typename std::enable_if<utils::is_iterable<T>::value>::type*>
129 static_assert(nesting < 1,"Nested containers are not valid VTK data");
130 return whichType<typename T::value_type,nesting+1>();
131}
132
133}
static VTKDataType whichType()
Definition VTKTypes.tpp:117
static VTKDataType registerType()
Definition VTKTypes.tpp:36
VTKElementType
Definition VTK.hpp:112
VTKDataType
Definition VTK.hpp:74
--- layout: doxygen_footer ---