cafeDataType.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008 #ifndef CAFEDATATYPE_H
00009 #define CAFEDATATYPE_H
00010
00011 #include <cadef.h>
00012 #include <iostream>
00013 #include <string>
00014 #include <map>
00015
00016 enum CAFE_DATATYPE {
00017 CAFE_TYPENOTCONN = TYPENOTCONN,
00018 CAFE_STRING = DBF_STRING,
00019 CAFE_SHORT = DBF_SHORT,
00020 CAFE_INT = DBF_INT,
00021 CAFE_FLOAT = DBF_FLOAT,
00022 CAFE_ENUM = DBF_ENUM,
00023 CAFE_USHORT = DBF_ENUM,
00024 CAFE_CHAR = DBF_CHAR,
00025 CAFE_LONG = DBF_LONG,
00026 CAFE_DOUBLE = DBF_DOUBLE,
00027 CAFE_NO_ACCESS = DBF_NO_ACCESS,
00028 CAFE_INVALID_DATATYPE = 8,
00029 CAFE_NOT_REQUESTED = 100,
00030 CAFE_NOT_SHOWN = 101
00031 };
00032
00037 class CAFEDataTypeCode {
00038 typedef std::map<int, std::string> mapLongString;
00039 private:
00040 mapLongString mapDataType;
00041 mapLongString::iterator pos;
00042 public:
00043 CAFEDataTypeCode() {
00044 mapDataType.insert(std::make_pair((int) CAFE_TYPENOTCONN, "CAFE_TYPENOTCONN" ));
00045 mapDataType.insert(std::make_pair((int) CAFE_STRING, "DBF_STRING" ));
00046 mapDataType.insert(std::make_pair((int) CAFE_SHORT, "DBF_SHORT" ));
00047 mapDataType.insert(std::make_pair((int) CAFE_INT, "DBF_SHORT" ));
00048 mapDataType.insert(std::make_pair((int) CAFE_FLOAT, "DBF_FLOAT" ));
00049 mapDataType.insert(std::make_pair((int) CAFE_ENUM, "DBF_ENUM" ));
00050 mapDataType.insert(std::make_pair((int) CAFE_CHAR, "DBF_CHAR" ));
00051 mapDataType.insert(std::make_pair((int) CAFE_LONG, "DBF_LONG" ));
00052 mapDataType.insert(std::make_pair((int) CAFE_DOUBLE, "DBF_DOUBLE" ));
00053 mapDataType.insert(std::make_pair((int) CAFE_NO_ACCESS, "DBF_NO_ACCESS" ));
00054 mapDataType.insert(std::make_pair((int) CAFE_INVALID_DATATYPE, "CAFE_INVALID_DATATYPE"));
00055 mapDataType.insert(std::make_pair((int) CAFE_NOT_REQUESTED, "CAFE_NOT_REQUESTED"));
00056 mapDataType.insert(std::make_pair((int) CAFE_NOT_SHOWN, "CAFE_NOT_SHOWN (IN STOP MONITOR)"));
00057 };
00058
00059 ~CAFEDataTypeCode() {};
00060
00061 std::string message (int i) {
00062 pos = mapDataType.find(i);
00063 if (pos != mapDataType.end()) return pos->second;
00064 return "CAFE_DATATYPE_UNKNOWN";
00065 };
00066
00067
00068 std::string asString (int i) {
00069 pos = mapDataType.find(i);
00070 if (pos != mapDataType.end()) return pos->second;
00071 return "CAFE_DATATYPE_UNKNOWN";
00072 };
00073
00074 int enumIs (std::string message) {
00075 for (pos=mapDataType.begin(); pos != mapDataType.end(); ++pos)
00076 if (pos->second==message) return pos->first;
00077 return -1;
00078 };
00079
00080
00081 int asEnum (std::string message) {
00082 for (pos=mapDataType.begin(); pos != mapDataType.end(); ++pos)
00083 if (pos->second==message) return pos->first;
00084 return -1;
00085 };
00086
00087 void show() {print();}
00088
00089 void print ( ) {
00090 std::cout << "------------------" << std::endl;
00091 std::cout << "CAFE_DATATYPE LIST" << std::endl;
00092 std::cout << "-----------------" << std::endl;
00093 for (pos=mapDataType.begin(); pos != mapDataType.end(); ++pos) {
00094 std::cout << pos->first << " " << pos->second << std::endl;
00095 }
00096 std::cout << "-----------------" << std::endl;
00097 };
00098
00099 };
00100
00104 union CAFE_DATATYPE_UNION {
00105 dbr_string_t str;
00106 dbr_short_t s;
00107 dbr_float_t f;
00108 dbr_enum_t us;
00109 dbr_char_t ch;
00110 dbr_long_t l;
00111 dbr_double_t d;
00112 };
00113
00114 typedef CAFE_DATATYPE_UNION * CAFE_DATATYPE_UNION_SEQ;
00115
00116
00117
00118 #endif