Adding premature C++ side; supporting only primitive types (including string) for now
[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 {
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 - Long is 8 bytes and char is 2 bytes
40                  */
41                 const static int primitivesJavaSizes[NUM_PRIMITIVES];
42
43
44                 /**
45                  * Primitive sizes in Cplus - Long is 4 bytes and char is 1 byte
46                  */
47                 const static int primitivesCplusSizes[NUM_PRIMITIVES];
48
49
50                 /**
51                  * Non-primitive Java data types
52                  */
53                 const static string nonPrimitivesJava[NUM_NONPRIMITIVES];
54
55
56                 /**
57                  * Non-primitive C++ data types
58                  */
59                 const static string nonPrimitivesCplus[NUM_NONPRIMITIVES];
60
61
62                 /* Methods */
63                 static void             arraysToMap(map<string,string> &srcMap, const vector<string> arrKey, 
64                         const vector<string> arrVal);
65                 static void             arraysToMap(map<string,int> &srcMap, const vector<string> arrKey, 
66                         const vector<int> arrVal);
67                 static void     arraysToMap(map<void*,void*> &srcMap, const vector<void*> arrKey, 
68                         const vector<void*> arrVal);
69 };
70
71
72 const string IoTRMITypes::primitivesJava[IoTRMITypes::NUM_PRIMITIVES] = {
73
74         "byte",                 // 1 byte
75         "Byte",                 // 1 byte
76         "short",                // 2 bytes
77         "Short",                // 2 bytes
78         "int",                  // 4 bytes
79         "Integer",              // 4 bytes
80         "long",                 // 8 bytes
81         "Long",                 // 8 bytes
82         "float",                // 4 bytes
83         "Float",                // 4 bytes
84         "double",               // 8 bytes
85         "Double",               // 8 bytes
86         "boolean",              // 1 bytes
87         "Boolean",              // 1 bytes
88         "char",                 // 2 bytes
89         "Character",    // 2 bytes
90         "string",               // indefinite
91         "String",               // indefinite
92         "void"                  // 0 byte
93 };
94
95
96 const string IoTRMITypes::primitivesCplus[IoTRMITypes::NUM_PRIMITIVES] = {
97
98         "char",                 // 1 byte
99         "char",                 // 1 byte
100         "short",                // 2 bytes
101         "short",                // 2 bytes
102         "int",                  // 4 bytes
103         "int",                  // 4 bytes
104         "int64_t",              // 8 bytes
105         "int64_t",              // 8 bytes
106         "float",                // 4 bytes
107         "float",                // 4 bytes
108         "double",               // 8 bytes
109         "double",               // 8 bytes
110         "bool",                 // 1 byte
111         "bool",                 // 1 byte
112         "char",                 // 2 byte
113         "char",                 // 2 byte
114         "string",               // indefinite
115         "string",               // indefinite
116         "void"                  // 0 byte
117 };
118
119
120 const int IoTRMITypes::primitivesJavaSizes[IoTRMITypes::NUM_PRIMITIVES] = {
121
122         1, 1, 2, 2, 4, 4, 8, 8, 4, 4, 8, 8, 1, 1, 2, 2, -1, -1, 0
123 };
124
125
126 const int IoTRMITypes::primitivesCplusSizes[IoTRMITypes::NUM_PRIMITIVES] = {
127
128         1, 1, 2, 2, 4, 4, 8, 8, 4, 4, 8, 8, 1, 1, 2, 2, -1, -1, 0
129 };
130
131
132 const string IoTRMITypes::nonPrimitivesJava[IoTRMITypes::NUM_NONPRIMITIVES] = {
133
134         "Set",
135         "HashSet",
136         "Map",
137         "HashMap",
138         "List",
139         "ArrayList"
140 };
141
142
143 const string IoTRMITypes::nonPrimitivesCplus[IoTRMITypes::NUM_NONPRIMITIVES] = {
144
145         "set",
146         "unordered_set",
147         "map",
148         "unordered_map",
149         "list",
150         "list"
151 };
152
153
154 /**================
155  * Helper functions
156  **================
157  */
158 // Inserting array members into a Map object
159 // that maps arrKey to arrVal objects
160 void IoTRMITypes::arraysToMap(map<string,string> &srcMap, const vector<string> arrKey, 
161         const vector<string> 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<string,int> &srcMap, const vector<string> arrKey, 
173         const vector<int> arrVal) {
174
175         for(int i = 0; i < arrKey.size(); i++) {
176
177                 srcMap[arrKey[i]] = arrVal[i];
178         }
179 }
180
181
182 // Inserting array members into a Map object
183 // that maps arrKey to arrVal objects
184 void IoTRMITypes::arraysToMap(map<void*,void*> &srcMap, const vector<void*> arrKey, 
185         const vector<void*> arrVal) {
186
187         for(int i = 0; i < arrKey.size(); i++) {
188
189                 srcMap[arrKey[i]] = arrVal[i];
190         }
191 }
192
193 #endif