21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
24 |
|
// enable implementation specific declarations in Serialization.h required to |
25 |
|
// build this C++ unit, which should be ignored in the public API though |
26 |
|
#define LIBGIG_SERIALIZATION_INTERNAL 1 |
27 |
|
|
28 |
#include "Serialization.h" |
#include "Serialization.h" |
29 |
|
|
30 |
#include <iostream> |
#include <iostream> |
254 |
* characteristic is compared as well. So a @c double type and @c double* |
* characteristic is compared as well. So a @c double type and @c double* |
255 |
* type are also considered to be not equal data types and hence this method |
* type are also considered to be not equal data types and hence this method |
256 |
* would return @c false. |
* would return @c false. |
257 |
|
* |
258 |
|
* As an exception here, classes and structs with the same class/struct name |
259 |
|
* but different sizes are also considered to be "equal". This relaxed |
260 |
|
* requirement is necessary to retain backward compatiblity to older |
261 |
|
* versions of the same native C++ classes/structs. |
262 |
*/ |
*/ |
263 |
bool DataType::operator==(const DataType& other) const { |
bool DataType::operator==(const DataType& other) const { |
264 |
return m_baseTypeName == other.m_baseTypeName && |
return m_baseTypeName == other.m_baseTypeName && |
265 |
m_customTypeName == other.m_customTypeName && |
m_customTypeName == other.m_customTypeName && |
266 |
m_size == other.m_size && |
(m_size == other.m_size || (isClass() && other.isClass())) && |
267 |
m_isPointer == other.m_isPointer; |
m_isPointer == other.m_isPointer; |
268 |
} |
} |
269 |
|
|
440 |
* |
* |
441 |
* Returns the unique identifier of the original C/C++ member instance of |
* Returns the unique identifier of the original C/C++ member instance of |
442 |
* your C++ class. It is important to know that this unique identifier is |
* your C++ class. It is important to know that this unique identifier is |
443 |
* not generated particularly for Member objects. That means no matter how |
* not meant to be unique for Member instances themselves, but it is rather |
444 |
* many individual Member objects are created, as long as they are |
* meant to be unique for the original native C/C++ data these Member |
445 |
* representing the same member variable of the same original native |
* instances are representing. So that means no matter how many individual |
446 |
|
* Member objects are created, as long as they are representing the same |
447 |
|
* original native member variable of the same original native |
448 |
* instance of your C++ class, then all those separately created Member |
* instance of your C++ class, then all those separately created Member |
449 |
* objects return the same unique identifier here. |
* objects return the same unique identifier here. |
450 |
* |
* |
1418 |
return (time_t) i; |
return (time_t) i; |
1419 |
} |
} |
1420 |
|
|
1421 |
DataType _popDataTypeBlob(const char*& p, const char* end) { |
static DataType _popDataTypeBlob(const char*& p, const char* end) { |
1422 |
_Blob blob = _decodeBlob(p, end); |
_Blob blob = _decodeBlob(p, end); |
1423 |
p = blob.p; |
p = blob.p; |
1424 |
end = blob.end; |
end = blob.end; |
2091 |
setIntValue(object, atoll(value.c_str())); |
setIntValue(object, atoll(value.c_str())); |
2092 |
else if (type.isReal()) |
else if (type.isReal()) |
2093 |
setRealValue(object, atof(value.c_str())); |
setRealValue(object, atof(value.c_str())); |
2094 |
else if (type.isBool()) |
else if (type.isBool()) { |
2095 |
setBoolValue(object, atof(value.c_str())); |
String val = toLowerCase(value); |
2096 |
else if (type.isEnum()) |
if (val == "true" || val == "yes" || val == "1") |
2097 |
|
setBoolValue(object, true); |
2098 |
|
else if (val == "false" || val == "no" || val == "0") |
2099 |
|
setBoolValue(object, false); |
2100 |
|
else |
2101 |
|
setBoolValue(object, atof(value.c_str())); |
2102 |
|
} else if (type.isEnum()) |
2103 |
setEnumValue(object, atoll(value.c_str())); |
setEnumValue(object, atoll(value.c_str())); |
2104 |
else |
else |
2105 |
throw Exception("Not a primitive data type"); |
throw Exception("Not a primitive data type"); |
2295 |
// *************** Exception *************** |
// *************** Exception *************** |
2296 |
// * |
// * |
2297 |
|
|
2298 |
|
Exception::Exception() { |
2299 |
|
} |
2300 |
|
|
2301 |
|
Exception::Exception(String format, ...) { |
2302 |
|
va_list arg; |
2303 |
|
va_start(arg, format); |
2304 |
|
Message = assemble(format, arg); |
2305 |
|
va_end(arg); |
2306 |
|
} |
2307 |
|
|
2308 |
|
Exception::Exception(String format, va_list arg) { |
2309 |
|
Message = assemble(format, arg); |
2310 |
|
} |
2311 |
|
|
2312 |
/** @brief Print exception message to stdout. |
/** @brief Print exception message to stdout. |
2313 |
* |
* |
2314 |
* Prints the message of this Exception to the currently defined standard |
* Prints the message of this Exception to the currently defined standard |
2318 |
std::cout << "Serialization::Exception: " << Message << std::endl; |
std::cout << "Serialization::Exception: " << Message << std::endl; |
2319 |
} |
} |
2320 |
|
|
2321 |
|
String Exception::assemble(String format, va_list arg) { |
2322 |
|
char* buf = NULL; |
2323 |
|
vasprintf(&buf, format.c_str(), arg); |
2324 |
|
String s = buf; |
2325 |
|
free(buf); |
2326 |
|
return s; |
2327 |
|
} |
2328 |
|
|
2329 |
} // namespace Serialization |
} // namespace Serialization |