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_BIN_VALUEPARSER_H 30 #define CXXTOOLS_BIN_VALUEPARSER_H 31 32 #include <cxxtools/serializationinfo.h> 33 34 namespace cxxtools 35 { 36 37 class DeserializerBase; 38 39 namespace bin 40 { 41 42 class ValueParser 43 { ValueParser(const ValueParser &)44 ValueParser(const ValueParser&) { } 45 ValueParser& operator= (const ValueParser&) { return *this; } 46 47 public: ValueParser()48 ValueParser() 49 : _next(0) 50 { } 51 ~ValueParser()52 ~ValueParser() 53 { 54 delete _next; 55 } 56 57 void begin(DeserializerBase& handler); 58 59 void beginSkip(); 60 61 bool advance(char ch); // returns true, if number is read completely 62 current()63 DeserializerBase* current() 64 { return _deserializer; } 65 66 private: 67 68 bool processFloatBase(char ch, unsigned shift, unsigned expOffset); 69 enum State 70 { 71 state_type, 72 state_name, 73 state_value_type_other, 74 state_value_intsign, 75 state_value_int, 76 state_value_uint, 77 state_value_bool, 78 state_value_bcd0, 79 state_value_bcd, 80 state_value_binary_length, 81 state_value_binary, 82 state_value_value, 83 state_sfloat_exp, 84 state_sfloat_base, 85 state_mfloat_exp, 86 state_mfloat_base, 87 state_lfloat_exp, 88 state_lfloat_base, 89 state_object_type, 90 state_object_type_other, 91 state_object_member, 92 state_object_member_value, 93 state_array_type, 94 state_array_type_other, 95 state_array_member, 96 state_array_member_value, 97 state_array_member_value_next, 98 state_end 99 } _state, _nextstate; 100 101 std::string _token; 102 unsigned _count; 103 uint64_t _int; 104 int _exp; 105 bool _isNeg; 106 DeserializerBase* _deserializer; 107 ValueParser* _next; 108 }; 109 } 110 } 111 112 #endif // CXXTOOLS_BIN_VALUEPARSER_H 113 114