attributes.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 #ifndef LIBMESH_ATTRIBUTES_H
20 #define LIBMESH_ATTRIBUTES_H
21 
22 // C++ includes
23 #include <limits>
24 #include <set>
25 #include <vector>
26 
27 
28 namespace libMesh
29 {
30 
31 namespace Parallel
32 {
33 //-------------------------------------------------------------------
34 
35 /*
36  * The unspecialized class gives default, lowest-common-denominator
37  * attributes, for values which can't be used with Parallel min/max.
38  * Specialized classes can set this to true, and should define
39  * the lowest and highest values possible for the type.
40  */
41 template<typename T>
42 struct Attributes
43 {
44  static const bool has_min_max = false;
45  static void set_lowest(T &) {}
46  static void set_highest(T &) {}
47 };
48 
49 // ------------------------------------------------------------
50 // Declare Attributes specializations for C++ built-in types
51 
52 #define LIBMESH_INT_TYPE(cxxtype) \
53  template<> \
54  struct Attributes<cxxtype> \
55  { \
56  static const bool has_min_max = true; \
57  static void set_lowest(cxxtype & x) { x = std::numeric_limits<cxxtype>::min(); } \
58  static void set_highest(cxxtype & x) { x = std::numeric_limits<cxxtype>::max(); } \
59  }
60 
61 #define LIBMESH_FLOAT_TYPE(cxxtype) \
62  template<> \
63  struct Attributes<cxxtype> \
64  { \
65  static const bool has_min_max = true; \
66  static void set_lowest(cxxtype & x) { x = -std::numeric_limits<cxxtype>::infinity(); } \
67  static void set_highest(cxxtype & x) { x = std::numeric_limits<cxxtype>::infinity(); } \
68  }
69 
70 #define LIBMESH_CONTAINER_TYPE(cxxtype) \
71  struct Attributes<cxxtype> \
72  { \
73  static const bool has_min_max = Attributes<T>::has_min_max; \
74  static void set_lowest(cxxtype & x) { \
75  for (auto & val : x) \
76  Attributes<T>::set_lowest(val); } \
77  static void set_highest(cxxtype & x) { \
78  for (auto & val : x) \
79  Attributes<T>::set_highest(val); } \
80  }
81 
82 
83 LIBMESH_INT_TYPE(char);
84 LIBMESH_INT_TYPE(signed char);
85 LIBMESH_INT_TYPE(unsigned char);
86 LIBMESH_INT_TYPE(short int);
87 LIBMESH_INT_TYPE(unsigned short int);
88 LIBMESH_INT_TYPE(int);
89 LIBMESH_INT_TYPE(unsigned int);
90 LIBMESH_INT_TYPE(long);
91 LIBMESH_INT_TYPE(long long);
92 LIBMESH_INT_TYPE(unsigned long);
93 LIBMESH_INT_TYPE(unsigned long long);
94 
95 LIBMESH_FLOAT_TYPE(float);
96 LIBMESH_FLOAT_TYPE(double);
97 LIBMESH_FLOAT_TYPE(long double);
98 
99 #define LIBMESH_ATTRIBUTES_COMMA ,
100 
101 template <typename T, typename C, typename A>
102 LIBMESH_CONTAINER_TYPE(std::set<T LIBMESH_ATTRIBUTES_COMMA C LIBMESH_ATTRIBUTES_COMMA A>);
103 
104 template <typename T, typename A>
105 LIBMESH_CONTAINER_TYPE(std::vector<T LIBMESH_ATTRIBUTES_COMMA A>);
106 
107 } // namespace Parallel
108 
109 } // namespace libMesh
110 
111 #endif // LIBMESH_ATTRIBUTES_H
static void set_lowest(T &)
Definition: attributes.h:45
LIBMESH_CONTAINER_TYPE(std::set< T LIBMESH_ATTRIBUTES_COMMA C LIBMESH_ATTRIBUTES_COMMA A >)
LIBMESH_FLOAT_TYPE(float)
static void set_highest(T &)
Definition: attributes.h:46
static const bool has_min_max
Definition: attributes.h:44