/[svn]/libgig/trunk/src/Serialization.cpp
ViewVC logotype

Diff of /libgig/trunk/src/Serialization.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3185 by schoenebeck, Wed May 17 15:42:58 2017 UTC revision 3464 by schoenebeck, Sun Feb 10 20:25:05 2019 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2   *                                                                         *   *                                                                         *
3   *   Copyright (C) 2017 Christian Schoenebeck                              *   *   Copyright (C) 2017-2019 Christian Schoenebeck                         *
4   *                      <cuse@users.sourceforge.net>                       *   *                           <cuse@users.sourceforge.net>                  *
5   *                                                                         *   *                                                                         *
6   *   This library is part of libgig.                                       *   *   This library is part of libgig.                                       *
7   *                                                                         *   *                                                                         *
# Line 21  Line 21 
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>
# Line 250  namespace Serialization { Line 254  namespace Serialization {
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    
# Line 281  namespace Serialization { Line 290  namespace Serialization {
290      bool DataType::operator<(const DataType& other) const {      bool DataType::operator<(const DataType& other) const {
291          return m_baseTypeName  < other.m_baseTypeName ||          return m_baseTypeName  < other.m_baseTypeName ||
292                (m_baseTypeName == other.m_baseTypeName &&                (m_baseTypeName == other.m_baseTypeName &&
293                 m_customTypeName  < other.m_customTypeName ||                (m_customTypeName  < other.m_customTypeName ||
294                (m_customTypeName == other.m_customTypeName &&                (m_customTypeName == other.m_customTypeName &&
295                 m_size  < other.m_size ||                (m_size  < other.m_size ||
296                (m_size == other.m_size &&                (m_size == other.m_size &&
297                 m_isPointer < other.m_isPointer)));                 m_isPointer < other.m_isPointer)))));
298      }      }
299    
300      /** @brief Greater than comparison.      /** @brief Greater than comparison.
# Line 395  namespace Serialization { Line 404  namespace Serialization {
404      String DataType::customTypeName(bool demangle) const {      String DataType::customTypeName(bool demangle) const {
405          if (!demangle) return m_customTypeName;          if (!demangle) return m_customTypeName;
406          int status;          int status;
407          const char* result =          char* result =
408              abi::__cxa_demangle(m_customTypeName.c_str(), 0, 0, &status);              abi::__cxa_demangle(m_customTypeName.c_str(), 0, 0, &status);
409          return (status == 0) ? result : m_customTypeName;          String sResult = result;
410            free(result);
411            return (status == 0) ? sResult : m_customTypeName;
412      }      }
413    
414      // *************** Member ***************      // *************** Member ***************
# Line 568  namespace Serialization { Line 579  namespace Serialization {
579      bool Member::operator<(const Member& other) const {      bool Member::operator<(const Member& other) const {
580          return m_uid  < other.m_uid ||          return m_uid  < other.m_uid ||
581                (m_uid == other.m_uid &&                (m_uid == other.m_uid &&
582                 m_offset  < other.m_offset ||                (m_offset  < other.m_offset ||
583                (m_offset == other.m_offset &&                (m_offset == other.m_offset &&
584                 m_name  < other.m_name ||                (m_name  < other.m_name ||
585                (m_name == other.m_name &&                (m_name == other.m_name &&
586                 m_type < other.m_type)));                 m_type < other.m_type)))));
587      }      }
588    
589      /** @brief Greater than comparison.      /** @brief Greater than comparison.
# Line 1409  namespace Serialization { Line 1420  namespace Serialization {
1420          return (time_t) i;          return (time_t) i;
1421      }      }
1422    
1423      DataType _popDataTypeBlob(const char*& p, const char* end) {      static DataType _popDataTypeBlob(const char*& p, const char* end) {
1424          _Blob blob = _decodeBlob(p, end);          _Blob blob = _decodeBlob(p, end);
1425          p   = blob.p;          p   = blob.p;
1426          end = blob.end;          end = blob.end;
# Line 2090  namespace Serialization { Line 2101  namespace Serialization {
2101                  setBoolValue(object, false);                  setBoolValue(object, false);
2102              else              else
2103                  setBoolValue(object, atof(value.c_str()));                  setBoolValue(object, atof(value.c_str()));
2104          } else if (type.isEnum())          } else if (type.isEnum())
2105              setEnumValue(object, atoll(value.c_str()));              setEnumValue(object, atoll(value.c_str()));
2106          else          else
2107              throw Exception("Not a primitive data type");              throw Exception("Not a primitive data type");
# Line 2286  namespace Serialization { Line 2297  namespace Serialization {
2297      // *************** Exception ***************      // *************** Exception ***************
2298      // *      // *
2299    
2300        Exception::Exception() {
2301        }
2302    
2303        Exception::Exception(String format, ...) {
2304            va_list arg;
2305            va_start(arg, format);
2306            Message = assemble(format, arg);
2307            va_end(arg);
2308        }
2309    
2310        Exception::Exception(String format, va_list arg) {
2311            Message = assemble(format, arg);
2312        }
2313    
2314      /** @brief Print exception message to stdout.      /** @brief Print exception message to stdout.
2315       *       *
2316       * Prints the message of this Exception to the currently defined standard       * Prints the message of this Exception to the currently defined standard
# Line 2295  namespace Serialization { Line 2320  namespace Serialization {
2320          std::cout << "Serialization::Exception: " << Message << std::endl;          std::cout << "Serialization::Exception: " << Message << std::endl;
2321      }      }
2322    
2323        String Exception::assemble(String format, va_list arg) {
2324            char* buf = NULL;
2325            vasprintf(&buf, format.c_str(), arg);
2326            String s = buf;
2327            free(buf);
2328            return s;
2329        }
2330    
2331  } // namespace Serialization  } // namespace Serialization

Legend:
Removed from v.3185  
changed lines
  Added in v.3464

  ViewVC Help
Powered by ViewVC