Making C++ classes final
[iot2.git] / iotjava / iotrmi / C++ / IoTRMITypes.hpp
1 /** Class IoTRMITypes is a class that provides type translations.
2  *  <p>
3  *  It stores C++ and Java types.
4  *
5  * @author      Rahmadi Trimananda <rtrimana @ uci.edu>
6  * @version     1.0
7  * @since       2016-10-18
8  */
9 #ifndef _IOTRMITYPES_HPP__
10 #define _IOTRMITYPES_HPP__
11
12 #include <iostream>
13 #include <string>
14 #include <map>
15 #include <vector>
16
17 using namespace std;
18
19 class IoTRMITypes final {
20
21         public:
22                 /* Public constants */
23                 const static int NUM_PRIMITIVES = 19;
24                 const static int NUM_NONPRIMITIVES = 6;
25
26                 /**
27                  * Primitive data types in Java
28                  */
29                 const static string primitivesJava[NUM_PRIMITIVES];
30
31
32                 /**
33                  * Primitive data types in C++ to map the primitives list
34                  */
35                 const static string primitivesCplus[NUM_PRIMITIVES];
36
37
38                 /**
39                  * Primitive sizes in Java/C++
40                  */
41                 const static int primitivesSizes[NUM_PRIMITIVES];
42
43
44                 /**
45                  * Non-primitive Java data types
46                  */
47                 const static string nonPrimitivesJava[NUM_NONPRIMITIVES];
48
49
50                 /**
51                  * Non-primitive C++ data types
52                  */
53                 const static string nonPrimitivesCplus[NUM_NONPRIMITIVES];
54
55
56                 /* Methods */
57                 static void             arraysToMap(map<string,string> &srcMap, const vector<string> arrKey, 
58                         const vector<string> arrVal);
59                 static void             arraysToMap(map<string,int> &srcMap, const vector<string> arrKey, 
60                         const vector<int> arrVal);
61                 static void     arraysToMap(map<void*,void*> &srcMap, const vector<void*> arrKey, 
62                         const vector<void*> arrVal);
63 };
64
65
66 const string IoTRMITypes::primitivesJava[IoTRMITypes::NUM_PRIMITIVES] = {
67
68         "byte",                 // 1 byte
69         "Byte",                 // 1 byte
70         "short",                // 2 bytes
71         "Short",                // 2 bytes
72         "int",                  // 4 bytes
73         "Integer",              // 4 bytes
74         "long",                 // 8 bytes
75         "Long",                 // 8 bytes
76         "float",                // 4 bytes
77         "Float",                // 4 bytes
78         "double",               // 8 bytes
79         "Double",               // 8 bytes
80         "boolean",              // 1 bytes
81         "Boolean",              // 1 bytes
82         "char",                 // 2 bytes
83         "Character",    // 2 bytes
84         "string",               // indefinite
85         "String",               // indefinite
86         "void"                  // 0 byte
87 };
88
89
90 const string IoTRMITypes::primitivesCplus[IoTRMITypes::NUM_PRIMITIVES] = {
91
92         "char",                 // 1 byte
93         "char",                 // 1 byte
94         "short",                // 2 bytes
95         "short",                // 2 bytes
96         "int",                  // 4 bytes
97         "int",                  // 4 bytes
98         "int64_t",              // 8 bytes
99         "int64_t",              // 8 bytes
100         "float",                // 4 bytes
101         "float",                // 4 bytes
102         "double",               // 8 bytes
103         "double",               // 8 bytes
104         "bool",                 // 1 byte
105         "bool",                 // 1 byte
106         "char",                 // 2 byte
107         "char",                 // 2 byte
108         "string",               // indefinite
109         "string",               // indefinite
110         "void"                  // 0 byte
111 };
112
113
114 const int IoTRMITypes::primitivesSizes[IoTRMITypes::NUM_PRIMITIVES] = {
115
116         1, 1, 2, 2, 4, 4, 8, 8, 4, 4, 8, 8, 1, 1, 2, 2, -1, -1, 0
117 };
118
119
120 const string IoTRMITypes::nonPrimitivesJava[IoTRMITypes::NUM_NONPRIMITIVES] = {
121
122         "Set",
123         "HashSet",
124         "Map",
125         "HashMap",
126         "List",
127         "ArrayList"
128 };
129
130
131 const string IoTRMITypes::nonPrimitivesCplus[IoTRMITypes::NUM_NONPRIMITIVES] = {
132
133         "set",
134         "unordered_set",
135         "map",
136         "unordered_map",
137         "list",
138         "list"
139 };
140
141
142 /**================
143  * Helper functions
144  **================
145  */
146 // Inserting array members into a Map object
147 // that maps arrKey to arrVal objects
148 void IoTRMITypes::arraysToMap(map<string,string> &srcMap, const vector<string> arrKey, 
149         const vector<string> arrVal) {
150
151         for(int i = 0; i < arrKey.size(); i++) {
152
153                 srcMap[arrKey[i]] = arrVal[i];
154         }
155 }
156
157
158 // Inserting array members into a Map object
159 // that maps arrKey to arrVal objects
160 void IoTRMITypes::arraysToMap(map<string,int> &srcMap, const vector<string> arrKey, 
161         const vector<int> arrVal) {
162
163         for(int i = 0; i < arrKey.size(); i++) {
164
165                 srcMap[arrKey[i]] = arrVal[i];
166         }
167 }
168
169
170 // Inserting array members into a Map object
171 // that maps arrKey to arrVal objects
172 void IoTRMITypes::arraysToMap(map<void*,void*> &srcMap, const vector<void*> arrKey, 
173         const vector<void*> arrVal) {
174
175         for(int i = 0; i < arrKey.size(); i++) {
176
177                 srcMap[arrKey[i]] = arrVal[i];
178         }
179 }
180
181 #endif