1 /* 2 * Copyright (C) 2011 Tommi Maekitalo 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Lesser General Public 6 * License as published by the Free Software Foundation; either 7 * version 2.1 of the License, or (at your option) any later version. 8 * 9 * As a special exception, you may use this file as part of a free 10 * software library without restriction. Specifically, if other files 11 * instantiate templates or use macros or inline functions from this 12 * file, or you compile this file and link it with other files to 13 * produce an executable, this file does not by itself cause the 14 * resulting executable to be covered by the GNU General Public 15 * License. This exception does not however invalidate any other 16 * reasons why the executable file might be covered by the GNU Library 17 * General Public License. 18 * 19 * This library is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 * Lesser General Public License for more details. 23 * 24 * You should have received a copy of the GNU Lesser General Public 25 * License along with this library; if not, write to the Free Software 26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 27 */ 28 29 #ifndef CXXTOOLS_DESERIALIZERBASE_H 30 #define CXXTOOLS_DESERIALIZERBASE_H 31 32 #include <cxxtools/serializationinfo.h> 33 #include <cxxtools/api.h> 34 35 namespace cxxtools 36 { 37 /** 38 * convert format to SerializationInfo 39 */ 40 class CXXTOOLS_API DeserializerBase 41 { 42 public: 43 #ifdef HAVE_LONG_LONG 44 typedef long long int_type; 45 #else 46 typedef long int_type; 47 #endif 48 #ifdef HAVE_UNSIGNED_LONG_LONG 49 typedef unsigned long long unsigned_type; 50 #else 51 typedef unsigned long unsigned_type; 52 #endif 53 DeserializerBase()54 DeserializerBase() 55 : _current(0) 56 { } 57 ~DeserializerBase()58 virtual ~DeserializerBase() 59 { } 60 begin()61 void begin() 62 { 63 _current = &_si; 64 _si.clear(); 65 } 66 clear()67 void clear() 68 { 69 _current = 0; 70 _si.clear(); 71 } 72 si()73 SerializationInfo* si() 74 { return &_si; } 75 si()76 const SerializationInfo* si() const 77 { return &_si; } 78 current()79 SerializationInfo* current() 80 { return _current; } 81 82 void setCategory(SerializationInfo::Category category); 83 84 void setName(const std::string& name); 85 86 void setValue(const String& value); 87 88 void setValue(const std::string& value); 89 90 void setValue(const char* value); 91 92 void setValue(bool value); 93 94 void setValue(int_type value); 95 96 void setValue(unsigned_type value); 97 98 void setValue(long double value); 99 100 void setNull(); 101 102 void setTypeName(const std::string& type); 103 104 void beginMember(const std::string& name, const std::string& type, SerializationInfo::Category category); 105 106 void leaveMember(); 107 108 private: 109 SerializationInfo _si; 110 SerializationInfo* _current; 111 }; 112 113 } 114 115 #endif // CXXTOOLS_DESERIALIZERBASE_H 116