OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
DiscType.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef DISC_TYPE_H
12 #define DISC_TYPE_H
13 
14 /***************************************************************************
15  * DiscType<T> is a simple class that returns a string via the static method
16  * "str()" based on the type T. It is specialized for our standard types,
17  * and has a default value of "u" for "user" or "unknown" types.
18  ***************************************************************************/
19 
20 // include files
21 #include "AppTypes/Vektor.h"
22 #include "AppTypes/Tenzor.h"
23 #include "AppTypes/SymTenzor.h"
24 #include "AppTypes/AntiSymTenzor.h"
25 
27 // a base class for all DiscType's, that provides common routines to
28 // parse a type string and determine the apptype, the dimension, and the
29 // scalar type
30 struct DiscTypeBase {
31  // enums for scalar types and apptypes
34 
35  // determine the scalar data type for a given type string
36  static int scalarType(const std::string &s) {
37  if (s.length() == 0 || s.length() == 2 || s.length() > 3)
38  return UNKNOWN;
39  char c = static_cast<char>(tolower(s[s.length() - 1]));
40  if (c == 'c')
41  return CHAR;
42  else if (c == 's')
43  return SHORT;
44  else if (c == 'i')
45  return INT;
46  else if (c == 'l')
47  return LONG;
48  else if (c == 'f')
49  return FLOAT;
50  else if (c == 'd')
51  return DOUBLE;
52  else if (c == 'y')
53  return FCOMPLEX;
54  else if (c == 'z')
55  return DCOMPLEX;
56  else
57  return UNKNOWN;
58  }
59 
60  // determine the dimension of the apptype. If it is a scalar, return 0.
61  // if there is an error, return -1.
62  static int dim(const std::string &s) {
63  if (s.length() == 0 || s.length() == 2 || s.length() > 3)
64  return (-1);
65  if (s.length() == 1)
66  return 0;
67  char c = s[1];
68  if (c < '1' || c > '9')
69  return (-1);
70  return (c - '1' + 1);
71  }
72 
73  // determine the apptype of the string
74  static int appType(const std::string &s) {
75  if (s.length() == 0 || s.length() == 2 || s.length() > 3)
76  return UNKNOWN;
77  if (s.length() == 1)
78  return SCALAR;
79  char c = static_cast<char>(tolower(s[0]));
80  if (c == 'v')
81  return VEKTOR;
82  else if (c == 't')
83  return TENZOR;
84  else if (c == 's')
85  return SYMTENZOR;
86  else if (c == 'a')
87  return ANTISYMTENZOR;
88  else
89  return UNKNOWN;
90  }
91 };
92 
93 
95 // the general class, that is the default if the user does not specify
96 // one of the specialized types below
97 template<class T>
98 struct DiscType : public DiscTypeBase {
99  static std::string str() { return std::string("u"); }
100 };
101 
102 
104 // specializations for char, short, int, float, double
105 // codes:
106 // c = char
107 // s = short
108 // i = int
109 // l = long
110 // f = float
111 // d = double
112 // z = complex<double>
113 // y = complex<float>
114 #define DEFINE_DISCTYPE_SCALAR(TYPE, STRING) \
115 template<> \
116 struct DiscType< TYPE > : public DiscTypeBase { \
117  static std::string str() { return std::string(STRING); } \
118 };
119 
126 
127 DEFINE_DISCTYPE_SCALAR(unsigned char, "c")
128 DEFINE_DISCTYPE_SCALAR(unsigned short, "s")
129 DEFINE_DISCTYPE_SCALAR(unsigned int, "i")
130 DEFINE_DISCTYPE_SCALAR(unsigned long, "l")
131 
134 
136 // specializations for Vektor, Tenzor, SymTenzor, AntiSymTenzor
137 // codes:
138 // vNs = Vektor of dimension N and scalar type s
139 // tNs = Tenzor of dimension N and scalar type s
140 // sNs = SymTenzor of dimension N and scalar type s
141 // aNs = AntiSymTenzor of dimension N and scalar type s
142 #define DEFINE_DISCTYPE_APPTYPE(TYPE, STRING) \
143 template<class T, unsigned D> \
144 struct DiscType< TYPE<T, D> > : public DiscTypeBase { \
145  static std::string str() { \
146  CTAssert(D < 10); \
147  std::string retval = STRING; \
148  retval += "0"; \
149  retval += DiscType<T>::str(); \
150  retval[1] += D; \
151  return retval; \
152  } \
153 };
154 
159 
160 #endif
161 
162 /***************************************************************************
163  * $RCSfile: DiscType.h,v $ $Author: adelmann $
164  * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
165  * IPPL_VERSION_ID: $Id: DiscType.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
166  ***************************************************************************/
std::complex< double > a
#define DEFINE_DISCTYPE_SCALAR(TYPE, STRING)
Definition: DiscType.h:114
#define DEFINE_DISCTYPE_APPTYPE(TYPE, STRING)
Definition: DiscType.h:142
MMatrix< m_complex > complex(MMatrix< double > real)
Definition: MMatrix.cpp:396
constexpr double c
The velocity of light in m/s.
Definition: Physics.h:51
Definition: Tenzor.h:35
Definition: Vektor.h:32
@ ANTISYMTENZOR
Definition: DiscType.h:33
static int scalarType(const std::string &s)
Definition: DiscType.h:36
static int appType(const std::string &s)
Definition: DiscType.h:74
static int dim(const std::string &s)
Definition: DiscType.h:62
static std::string str()
Definition: DiscType.h:99