Daniel Espen | e9fd695 | 2019-10-11 11:01:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * anyTypeChecker.h |
| 3 | * |
| 4 | * Author: wendel |
| 5 | */ |
| 6 | |
| 7 | #ifndef UTIL_ANYTYPECHECKER_H_ |
| 8 | #define UTIL_ANYTYPECHECKER_H_ |
| 9 | |
Tobias Klausmann | f13b5e2 | 2019-12-13 11:56:37 +0100 | [diff] [blame] | 10 | #include <BaSyx/shared/types.h> |
| 11 | #include <BaSyx/shared/object.h> |
Daniel Espen | e9fd695 | 2019-10-11 11:01:16 +0200 | [diff] [blame] | 12 | |
| 13 | #include <string> |
| 14 | |
| 15 | namespace basyx { |
| 16 | |
| 17 | namespace PropertyTypeInfo |
| 18 | { |
Thomas Psota | 79a97d6 | 2019-11-25 15:33:10 +0100 | [diff] [blame] | 19 | static constexpr char STRING[] = "string"; |
| 20 | static constexpr char INT[] = "int"; |
| 21 | static constexpr char COLLECTION[] = "collection"; |
| 22 | static constexpr char MAP[] = "map"; |
| 23 | static constexpr char BOOL[] = "boolean"; |
| 24 | static constexpr char DOUBLE[] = "double"; |
| 25 | static constexpr char FLOAT[] = "long"; |
| 26 | static constexpr char PROPNULL[] = "null"; |
| 27 | static constexpr char NONETYPE[] = "Type not specified"; |
Daniel Espen | e9fd695 | 2019-10-11 11:01:16 +0200 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | |
Johannes Wendel | ed007a1 | 2019-11-25 17:09:45 +0100 | [diff] [blame] | 31 | static std::string getPropertyTypeInfo(const basyx::object & object) |
Daniel Espen | e9fd695 | 2019-10-11 11:01:16 +0200 | [diff] [blame] | 32 | { |
| 33 | if ( object.InstanceOf<std::string>() ) |
| 34 | return PropertyTypeInfo::STRING; |
| 35 | if ( object.InstanceOf<int>() ) |
| 36 | return PropertyTypeInfo::INT; |
Johannes Wendel | ed007a1 | 2019-11-25 17:09:45 +0100 | [diff] [blame] | 37 | if ( object.InstanceOf<basyx::object::object_list_t>() ) |
Daniel Espen | e9fd695 | 2019-10-11 11:01:16 +0200 | [diff] [blame] | 38 | return PropertyTypeInfo::COLLECTION; |
Johannes Wendel | ed007a1 | 2019-11-25 17:09:45 +0100 | [diff] [blame] | 39 | if ( object.InstanceOf<basyx::object::object_map_t>() ) |
Daniel Espen | e9fd695 | 2019-10-11 11:01:16 +0200 | [diff] [blame] | 40 | return PropertyTypeInfo::MAP; |
| 41 | if ( object.InstanceOf<bool>() ) |
| 42 | return PropertyTypeInfo::BOOL; |
| 43 | if ( object.InstanceOf<double>() ) |
| 44 | return PropertyTypeInfo::DOUBLE; |
| 45 | if ( object.InstanceOf<float>() ) |
| 46 | return PropertyTypeInfo::FLOAT; |
| 47 | if ( object.InstanceOf<std::nullptr_t>() ) |
| 48 | return PropertyTypeInfo::PROPNULL; |
| 49 | return PropertyTypeInfo::NONETYPE; |
| 50 | } |
| 51 | |
| 52 | } |
| 53 | |
| 54 | |
| 55 | #endif // !UTIL_ANYTYPECHECKER_H_ |