1 /******************************************************************
3 * Copyright 2014 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
24 #include "GeneralData.h"
26 //#define __INTER_DEBUG__
27 // Hidden Class define.
28 template <typename TYPE>
29 class AllFormat_data : public Virtual_data
31 typedef Virtual_data base;
36 AllFormat_data(int typenum) : base(typenum)
38 #ifdef __INTER_DEBUG__
39 printf("[DEBUG] Test_data Constructor().\n");
43 virtual void put_data( void *value)
45 data = *(TYPE *)value;
48 virtual void *get_data( void )
56 /*******************************************
57 * Virtual_data class member function define.
59 void Virtual_data::s2data( const char *value)
65 char data = atoi(value);
66 put_data( (void *)&data );
71 int data = atoi(value);
72 put_data( (void *)&data );
77 float data = atof(value);
78 put_data( (void *)&data );
83 double data = atof(value);
84 put_data( (void *)&data );
88 printf("Error: dataType must have defined.\n");
91 printf("Error: Not yet supported type.\n");
96 Virtual_data::Virtual_data( void )
98 dataType = TYPE_NODEFINE;
101 Virtual_data::Virtual_data(int type)
103 #ifdef __INTER_DEBUG__
104 printf("[DEBUG] Virtual_data Constructor().\n");
109 void Virtual_data::put(std::string value)
111 if (dataType == TYPE_STRING )
112 put_data( (void *)&value );
114 s2data( value.c_str() );
117 void Virtual_data::put(char *value)
119 if (dataType == TYPE_STRING )
121 std::string temp = std::string(value);
122 put_data( (void *)&temp );
128 int Virtual_data::get( std::string *value)
130 if (dataType != TYPE_STRING)
132 printf("Error : dataType is Not string.\n");
136 void *data = get_data();
137 *value = *(std::string *)data;
141 void Virtual_data::put_data( void *value )
143 printf("Error: virtual function(put_data) called.\n");
146 void *Virtual_data::get_data( void )
148 printf("Error: virtual function(get) called.\n");
157 /*******************************************
158 * GeneralData class member function define.
160 void GeneralData::set_dataType(const char *type)
162 if ( strstr(type, "string") != NULL )
164 dataType = TYPE_STRING;
165 #ifdef __INTER_DEBUG__
166 printf("DataType is std::string.\n");
170 if ( strstr(type, "char") != NULL )
172 dataType = TYPE_CHAR;
173 #ifdef __INTER_DEBUG__
174 printf("DataType is Character.\n");
178 if ( strstr(type, "int") != NULL )
181 #ifdef __INTER_DEBUG__
182 printf("DataType is Integer.\n");
186 if ( strstr(type, "short") != NULL )
188 dataType = TYPE_SHORT;
189 #ifdef __INTER_DEBUG__
190 printf("DataType is Short.\n");
194 if ( strstr(type, "float") != NULL )
196 dataType = TYPE_FLOAT;
197 #ifdef __INTER_DEBUG__
198 printf("DataType is Floating.\n");
202 if ( strstr(type, "double") != NULL )
204 dataType = TYPE_DOUBLE;
205 #ifdef __INTER_DEBUG__
206 printf("DataType is Double.\n");
211 dataType = TYPE_NODEFINE;
214 GeneralData::GeneralData( void )
216 #ifdef __INTER_DEBUG__
217 printf("[DEBUG] Virtual_Test Constructor().\n");
221 dataType = TYPE_NODEFINE;
225 GeneralData::GeneralData( std::string name, std::string type )
227 #ifdef __INTER_DEBUG__
228 printf("[DEBUG] Data_Normal Constructor().\n");
232 dataType = TYPE_NODEFINE;
235 flag = initial( name, type );
238 GeneralData::GeneralData( std::string name, std::string type, std::string value )
240 #ifdef __INTER_DEBUG__
241 printf("[DEBUG] Data_Normal Constructor().\n");
245 dataType = TYPE_NODEFINE;
248 flag = initial( name, type );
252 bool GeneralData::initial( std::string name, std::string type )
255 set_dataType( type.c_str() );
260 pValue = new AllFormat_data<std::string>(dataType);
263 pValue = new AllFormat_data<char>(dataType);
266 pValue = new AllFormat_data<int>(dataType);
269 pValue = new AllFormat_data<short>(dataType);
272 pValue = new AllFormat_data<float>(dataType);
275 pValue = new AllFormat_data<double>(dataType);
279 printf("Error : set_dataType()function is returned TYPE_NODEFINE.\n");
286 bool GeneralData::get_Name( std::string &name )
294 void GeneralData::put( std::string value )
300 void GeneralData::put( const char *value )
306 int GeneralData::get_DataType( void )
313 bool GeneralData::get( std::string *data )
317 if ( pValue->get(data) == NULL )
319 printf("Error : No data.\n");
329 void Conversion_DataFormat( std::vector < std::map< std::string, std::string > > lVector ,
330 std::vector< GeneralData > &gVector )
332 #ifdef __INTERNAL_DEBUG__
333 std::cout << "[DEBUG] ITS::" << __func__ << " is called." << std::endl;
340 for (unsigned int j = 0; j < lVector.size(); j++)
342 name = lVector[j]["name"];
343 type = lVector[j]["type"];
344 value = lVector[j]["value"];
346 GeneralData pValue(name, type, value);
347 gVector.push_back(pValue);
350 /*************************************************
351 * Debugging print ( GeneralData format confirm. )
353 #ifdef __INTERNAL_DEBUG__
354 for (unsigned int j = 0; j < gVector.size(); j++)
356 if ( gVector[j].get_Name(name) == false )
358 printf("Error : Not initialed.\n");
362 int dataType = gVector[j].get_DataType();
368 if ( gVector[j].get(&data) == false )
370 printf("Error : Not initialed.\n");
373 printf("name=%s , type=%d, value=%s\n", name.c_str(), dataType, data.c_str() );
381 if ( gVector[j].get(&data) == false )
383 printf("Error : Not initialed.\n");
386 printf("name=%s , type=%d, value=%d\n", name.c_str(), dataType, data );
393 if ( gVector[j].get(&data) == false )
395 printf("Error : Not initialed.\n");
398 printf("name=%s , type=%d, value=%f\n", name.c_str(), dataType, data );
405 printf("Conversion_DataFormat() is Successful.\n");