|
16 | 16 | #include <iterator> |
17 | 17 | #include <iostream> |
18 | 18 | #include <iomanip> |
| 19 | +#if __cplusplus >= 201103L |
| 20 | +#include <type_traits> |
| 21 | +#endif |
19 | 22 |
|
20 | 23 | #include <epicsAssert.h> |
21 | 24 |
|
@@ -124,6 +127,36 @@ typedef std::tr1::shared_ptr<PVUnionArrayPtrArray> PVUnionArrayPtrArrayPtr; |
124 | 127 | class PVDataCreate; |
125 | 128 | typedef std::tr1::shared_ptr<PVDataCreate> PVDataCreatePtr; |
126 | 129 |
|
| 130 | +#if __cplusplus >= 201103L |
| 131 | +template <typename T> |
| 132 | +constexpr ScalarType typeToCode() { |
| 133 | + if (std::is_same<T, boolean>::value) |
| 134 | + return pvBoolean; |
| 135 | + else if (std::is_same<T, int8>::value) |
| 136 | + return pvByte; |
| 137 | + else if (std::is_same<T, uint8>::value) |
| 138 | + return pvUByte; |
| 139 | + else if (std::is_same<T, int16>::value) |
| 140 | + return pvShort; |
| 141 | + else if (std::is_same<T, uint16>::value) |
| 142 | + return pvUShort; |
| 143 | + else if (std::is_same<T, int32>::value) |
| 144 | + return pvInt; |
| 145 | + else if (std::is_same<T, uint32>::value) |
| 146 | + return pvUInt; |
| 147 | + else if (std::is_same<T, int64>::value) |
| 148 | + return pvLong; |
| 149 | + else if (std::is_same<T, uint64>::value) |
| 150 | + return pvULong; |
| 151 | + else if (std::is_same<T, float>::value) |
| 152 | + return pvFloat; |
| 153 | + else if (std::is_same<T, double>::value) |
| 154 | + return pvDouble; |
| 155 | + else if (std::is_same<T, std::string>::value) |
| 156 | + return pvString; |
| 157 | +} |
| 158 | +#endif |
| 159 | + |
127 | 160 | /** |
128 | 161 | * @brief This class is implemented by code that calls setPostHander |
129 | 162 | * |
@@ -383,7 +416,11 @@ class epicsShareClass PVScalarValue : public PVScalar { |
383 | 416 | typedef T* pointer; |
384 | 417 | typedef const T* const_pointer; |
385 | 418 |
|
| 419 | + #if __cplusplus < 201103L |
386 | 420 | static const ScalarType typeCode; |
| 421 | + #else |
| 422 | + constexpr static const ScalarType typeCode = typeToCode<T>(); |
| 423 | + #endif |
387 | 424 |
|
388 | 425 | /** |
389 | 426 | * Destructor |
@@ -1184,8 +1221,11 @@ class epicsShareClass PVValueArray : public detail::PVVectorStorage<T,PVScalarAr |
1184 | 1221 | typedef ::epics::pvData::shared_vector<T> svector; |
1185 | 1222 | typedef ::epics::pvData::shared_vector<const T> const_svector; |
1186 | 1223 |
|
1187 | | - |
| 1224 | + #if __cplusplus < 201103L |
1188 | 1225 | static const ScalarType typeCode; |
| 1226 | + #else |
| 1227 | + constexpr static const ScalarType typeCode = typeToCode<T>(); |
| 1228 | + #endif |
1189 | 1229 |
|
1190 | 1230 | /** |
1191 | 1231 | * Destructor |
|
0 commit comments