├── .gitignore ├── LICENSE ├── Makefile.am ├── Makefile.in ├── NOTICE ├── README.md ├── aclocal.m4 ├── configure ├── configure.ac ├── include ├── Makefile.am ├── Makefile.in └── jsmincpp │ ├── ConstString.h │ ├── FloatPoint_3x1.h │ ├── IntegerOverflowControl.h │ ├── StaticString.h │ ├── TypesUtilities.h │ ├── deserialize │ ├── CRC32Hash.h │ ├── Deserializer.h │ ├── GetNameHash.h │ ├── GetNameHash.rlh │ ├── MallocCreator.h │ ├── Params.h │ ├── ParseBool.h │ ├── ParseBool.rlh │ ├── ParseFloat.h │ ├── ParseFloat.rlh │ ├── ParseInt.h │ ├── ParseInt.rlh │ ├── ParseStaticString.h │ ├── ParseStaticString.rlh │ ├── ParseUInt.h │ ├── ParseUInt.rlh │ ├── STLSupport │ │ ├── Deque.h │ │ ├── ForwardList.h │ │ ├── List.h │ │ ├── Map.h │ │ ├── ParseStdString.h │ │ ├── ParseStdString.rlh │ │ ├── STLContiners.h │ │ ├── Set.h │ │ ├── SharedPrtCreator.h │ │ ├── String.h │ │ └── Vector.h │ ├── SkipEndJSONString.h │ ├── SkipEndJSONString.rlh │ └── Tuple.h │ └── serialize │ ├── JSONSerializer.h │ ├── STLSupport │ ├── Deque.h │ ├── ForwardList.h │ ├── List.h │ ├── Map.h │ ├── Set.h │ ├── String.h │ └── Vector.h │ └── Serializer.h ├── install-sh ├── missing ├── test-driver └── tests ├── Makefile.am ├── Makefile.in ├── MockSerializeHandler.h ├── SymbolStream.h ├── test_GetNameHash.cpp ├── test_JSONParser.cpp ├── test_JSONSerialiser.cpp ├── test_ParseBool.cpp ├── test_ParseFloat.cpp ├── test_ParseInteger.cpp ├── test_STLContainersDeserialise.cpp ├── test_STLContainersSerialise.cpp ├── test_SaticString.cpp └── test_SkipEndJSONString.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | autom4te.cache 31 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = \ 2 | tests \ 3 | include 4 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | ====================================================================================== 2 | == NOTICE file corresponding to the section 4d of the Apache License, Version 2.0, == 3 | == in this case for jsmincpp library. == 4 | ====================================================================================== 5 | 6 | This product includes software developed by Voevodin Dmitry (http://www.damonblog.com/). 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # jsmincpp 2 | 3 | Версия 1.0RC 4 | 5 | Быстрая и компактная С++ библиотека сериализации/десериализации JSON. 6 | 7 | Основные особенности: 8 | 9 | * в базовом функционале (без использования контейнеров STL) не использует динамическую память, вообще; 10 | * состоит только из заголовочных файлов (headers-only); 11 | * есть поддержка контейнеров STL; 12 | * позволяет создавать расширения для обработки произвольных типов. 13 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ([2.69]) 2 | AC_INIT([jsmincpp], [1.0RC], [damon at damonblog.com]) 3 | AC_LANG(C++) 4 | AM_INIT_AUTOMAKE([foreign subdir-objects]) 5 | 6 | AC_CHECK_PROG(RAGEL_CHECK, ragel, yes) 7 | if test x"$RAGEL_CHECK" != x"yes" ; then 8 | AC_MSG_WARN([ragel is not installed. Please install ragel.]) 9 | fi 10 | 11 | LIBS=" -lpthread -lgmock -lgtest" 12 | AC_CHECK_LIB([gtest_main], [main], 13 | [HAVE_GTEST=1] [TEST_LIBS="$TEST_LIBS -lgtest_main -lgtest"], 14 | AC_MSG_WARN([libgtest is not installed. Please install libgtest.])) 15 | 16 | AC_CHECK_LIB([gmock_main], [main], 17 | [HAVE_GMOCK=1] [TEST_LIBS="$TEST_LIBS -lgmock_main -lgmock"], 18 | AC_MSG_WARN([libgmock is not installed. Please install libgmock.])) 19 | LIBS="" 20 | 21 | AC_CONFIG_FILES([Makefile include/Makefile tests/Makefile]) 22 | AC_OUTPUT 23 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | nobase_include_HEADERS = \ 2 | jsmincpp/ConstString.h \ 3 | jsmincpp/deserialize/CRC32Hash.h \ 4 | jsmincpp/deserialize/Deserializer.h \ 5 | jsmincpp/deserialize/GetNameHash.h \ 6 | jsmincpp/deserialize/GetNameHash.rlh \ 7 | jsmincpp/deserialize/MallocCreator.h \ 8 | jsmincpp/deserialize/Params.h \ 9 | jsmincpp/deserialize/ParseBool.h \ 10 | jsmincpp/deserialize/ParseBool.rlh \ 11 | jsmincpp/deserialize/ParseFloat.h \ 12 | jsmincpp/deserialize/ParseFloat.rlh \ 13 | jsmincpp/deserialize/ParseInt.h \ 14 | jsmincpp/deserialize/ParseInt.rlh \ 15 | jsmincpp/deserialize/ParseStaticString.h \ 16 | jsmincpp/deserialize/ParseStaticString.rlh \ 17 | jsmincpp/deserialize/ParseUInt.h \ 18 | jsmincpp/deserialize/ParseUInt.rlh \ 19 | jsmincpp/deserialize/SkipEndJSONString.h \ 20 | jsmincpp/deserialize/SkipEndJSONString.rlh \ 21 | jsmincpp/deserialize/STLSupport/Deque.h \ 22 | jsmincpp/deserialize/STLSupport/ForwardList.h \ 23 | jsmincpp/deserialize/STLSupport/List.h \ 24 | jsmincpp/deserialize/STLSupport/Map.h \ 25 | jsmincpp/deserialize/STLSupport/ParseStdString.h \ 26 | jsmincpp/deserialize/STLSupport/ParseStdString.rlh \ 27 | jsmincpp/deserialize/STLSupport/Set.h \ 28 | jsmincpp/deserialize/STLSupport/SharedPrtCreator.h \ 29 | jsmincpp/deserialize/STLSupport/STLContiners.h \ 30 | jsmincpp/deserialize/STLSupport/String.h \ 31 | jsmincpp/deserialize/STLSupport/Vector.h \ 32 | jsmincpp/deserialize/Tuple.h \ 33 | jsmincpp/FloatPoint_3x1.h \ 34 | jsmincpp/IntegerOverflowControl.h \ 35 | jsmincpp/serialize/JSONSerializer.h \ 36 | jsmincpp/serialize/Serializer.h \ 37 | jsmincpp/serialize/STLSupport/Deque.h \ 38 | jsmincpp/serialize/STLSupport/ForwardList.h \ 39 | jsmincpp/serialize/STLSupport/List.h \ 40 | jsmincpp/serialize/STLSupport/Map.h \ 41 | jsmincpp/serialize/STLSupport/Set.h \ 42 | jsmincpp/serialize/STLSupport/String.h \ 43 | jsmincpp/serialize/STLSupport/Vector.h \ 44 | jsmincpp/StaticString.h \ 45 | jsmincpp/TypesUtilities.h 46 | 47 | 48 | 49 | RM := rm 50 | ECHO := echo 51 | 52 | RL := ragel 53 | RLFLAGS := -G2 54 | 55 | source_dirs := $(top_srcdir)/include/jsmincpp/deserialize $(top_srcdir)/include/jsmincpp/deserialize/STLSupport 56 | generated_files := $(patsubst %.rlh, %.h, $(wildcard $(addsuffix /*.rlh, $(source_dirs)))) 57 | 58 | BUILT_SOURCES := $(generated_files) 59 | 60 | %.rlh: 61 | 62 | %.h: %.rlh 63 | @$(ECHO) Compile $< 64 | $(RL) $(RLFLAGS) $< -p -o $(patsubst %.rlh, %.h, $<) 65 | 66 | clean: 67 | $(RM) -f $(generated_files) 68 | -------------------------------------------------------------------------------- /include/Makefile.in: -------------------------------------------------------------------------------- 1 | # Makefile.in generated by automake 1.14.1 from Makefile.am. 2 | # @configure_input@ 3 | 4 | # Copyright (C) 1994-2013 Free Software Foundation, Inc. 5 | 6 | # This Makefile.in is free software; the Free Software Foundation 7 | # gives unlimited permission to copy and/or distribute it, 8 | # with or without modifications, as long as this notice is preserved. 9 | 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY, to the extent permitted by law; without 12 | # even the implied warranty of MERCHANTABILITY or FITNESS FOR A 13 | # PARTICULAR PURPOSE. 14 | 15 | @SET_MAKE@ 16 | 17 | VPATH = @srcdir@ 18 | am__is_gnu_make = test -n '$(MAKEFILE_LIST)' && test -n '$(MAKELEVEL)' 19 | am__make_running_with_option = \ 20 | case $${target_option-} in \ 21 | ?) ;; \ 22 | *) echo "am__make_running_with_option: internal error: invalid" \ 23 | "target option '$${target_option-}' specified" >&2; \ 24 | exit 1;; \ 25 | esac; \ 26 | has_opt=no; \ 27 | sane_makeflags=$$MAKEFLAGS; \ 28 | if $(am__is_gnu_make); then \ 29 | sane_makeflags=$$MFLAGS; \ 30 | else \ 31 | case $$MAKEFLAGS in \ 32 | *\\[\ \ ]*) \ 33 | bs=\\; \ 34 | sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ 35 | | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ 36 | esac; \ 37 | fi; \ 38 | skip_next=no; \ 39 | strip_trailopt () \ 40 | { \ 41 | flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ 42 | }; \ 43 | for flg in $$sane_makeflags; do \ 44 | test $$skip_next = yes && { skip_next=no; continue; }; \ 45 | case $$flg in \ 46 | *=*|--*) continue;; \ 47 | -*I) strip_trailopt 'I'; skip_next=yes;; \ 48 | -*I?*) strip_trailopt 'I';; \ 49 | -*O) strip_trailopt 'O'; skip_next=yes;; \ 50 | -*O?*) strip_trailopt 'O';; \ 51 | -*l) strip_trailopt 'l'; skip_next=yes;; \ 52 | -*l?*) strip_trailopt 'l';; \ 53 | -[dEDm]) skip_next=yes;; \ 54 | -[JT]) skip_next=yes;; \ 55 | esac; \ 56 | case $$flg in \ 57 | *$$target_option*) has_opt=yes; break;; \ 58 | esac; \ 59 | done; \ 60 | test $$has_opt = yes 61 | am__make_dryrun = (target_option=n; $(am__make_running_with_option)) 62 | am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) 63 | pkgdatadir = $(datadir)/@PACKAGE@ 64 | pkgincludedir = $(includedir)/@PACKAGE@ 65 | pkglibdir = $(libdir)/@PACKAGE@ 66 | pkglibexecdir = $(libexecdir)/@PACKAGE@ 67 | am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd 68 | install_sh_DATA = $(install_sh) -c -m 644 69 | install_sh_PROGRAM = $(install_sh) -c 70 | install_sh_SCRIPT = $(install_sh) -c 71 | INSTALL_HEADER = $(INSTALL_DATA) 72 | transform = $(program_transform_name) 73 | NORMAL_INSTALL = : 74 | PRE_INSTALL = : 75 | POST_INSTALL = : 76 | NORMAL_UNINSTALL = : 77 | PRE_UNINSTALL = : 78 | POST_UNINSTALL = : 79 | subdir = include 80 | DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/Makefile.am \ 81 | $(nobase_include_HEADERS) 82 | ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 83 | am__aclocal_m4_deps = $(top_srcdir)/configure.ac 84 | am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ 85 | $(ACLOCAL_M4) 86 | mkinstalldirs = $(install_sh) -d 87 | CONFIG_CLEAN_FILES = 88 | CONFIG_CLEAN_VPATH_FILES = 89 | AM_V_P = $(am__v_P_@AM_V@) 90 | am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) 91 | am__v_P_0 = false 92 | am__v_P_1 = : 93 | AM_V_GEN = $(am__v_GEN_@AM_V@) 94 | am__v_GEN_ = $(am__v_GEN_@AM_DEFAULT_V@) 95 | am__v_GEN_0 = @echo " GEN " $@; 96 | am__v_GEN_1 = 97 | AM_V_at = $(am__v_at_@AM_V@) 98 | am__v_at_ = $(am__v_at_@AM_DEFAULT_V@) 99 | am__v_at_0 = @ 100 | am__v_at_1 = 101 | depcomp = 102 | am__depfiles_maybe = 103 | SOURCES = 104 | DIST_SOURCES = 105 | am__can_run_installinfo = \ 106 | case $$AM_UPDATE_INFO_DIR in \ 107 | n|no|NO) false;; \ 108 | *) (install-info --version) >/dev/null 2>&1;; \ 109 | esac 110 | am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; 111 | am__vpath_adj = case $$p in \ 112 | $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ 113 | *) f=$$p;; \ 114 | esac; 115 | am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; 116 | am__install_max = 40 117 | am__nobase_strip_setup = \ 118 | srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` 119 | am__nobase_strip = \ 120 | for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" 121 | am__nobase_list = $(am__nobase_strip_setup); \ 122 | for p in $$list; do echo "$$p $$p"; done | \ 123 | sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ 124 | $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ 125 | if (++n[$$2] == $(am__install_max)) \ 126 | { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ 127 | END { for (dir in files) print dir, files[dir] }' 128 | am__base_list = \ 129 | sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ 130 | sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' 131 | am__uninstall_files_from_dir = { \ 132 | test -z "$$files" \ 133 | || { test ! -d "$$dir" && test ! -f "$$dir" && test ! -r "$$dir"; } \ 134 | || { echo " ( cd '$$dir' && rm -f" $$files ")"; \ 135 | $(am__cd) "$$dir" && rm -f $$files; }; \ 136 | } 137 | am__installdirs = "$(DESTDIR)$(includedir)" 138 | HEADERS = $(nobase_include_HEADERS) 139 | am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) 140 | # Read a list of newline-separated strings from the standard input, 141 | # and print each of them once, without duplicates. Input order is 142 | # *not* preserved. 143 | am__uniquify_input = $(AWK) '\ 144 | BEGIN { nonempty = 0; } \ 145 | { items[$$0] = 1; nonempty = 1; } \ 146 | END { if (nonempty) { for (i in items) print i; }; } \ 147 | ' 148 | # Make sure the list of sources is unique. This is necessary because, 149 | # e.g., the same source file might be shared among _SOURCES variables 150 | # for different programs/libraries. 151 | am__define_uniq_tagged_files = \ 152 | list='$(am__tagged_files)'; \ 153 | unique=`for i in $$list; do \ 154 | if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ 155 | done | $(am__uniquify_input)` 156 | ETAGS = etags 157 | CTAGS = ctags 158 | DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) 159 | ACLOCAL = @ACLOCAL@ 160 | AMTAR = @AMTAR@ 161 | AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ 162 | AUTOCONF = @AUTOCONF@ 163 | AUTOHEADER = @AUTOHEADER@ 164 | AUTOMAKE = @AUTOMAKE@ 165 | AWK = @AWK@ 166 | CPPFLAGS = @CPPFLAGS@ 167 | CXX = @CXX@ 168 | CXXDEPMODE = @CXXDEPMODE@ 169 | CXXFLAGS = @CXXFLAGS@ 170 | CYGPATH_W = @CYGPATH_W@ 171 | DEFS = @DEFS@ 172 | DEPDIR = @DEPDIR@ 173 | ECHO_C = @ECHO_C@ 174 | ECHO_N = @ECHO_N@ 175 | ECHO_T = @ECHO_T@ 176 | EXEEXT = @EXEEXT@ 177 | INSTALL = @INSTALL@ 178 | INSTALL_DATA = @INSTALL_DATA@ 179 | INSTALL_PROGRAM = @INSTALL_PROGRAM@ 180 | INSTALL_SCRIPT = @INSTALL_SCRIPT@ 181 | INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ 182 | LDFLAGS = @LDFLAGS@ 183 | LIBOBJS = @LIBOBJS@ 184 | LIBS = @LIBS@ 185 | LTLIBOBJS = @LTLIBOBJS@ 186 | MAKEINFO = @MAKEINFO@ 187 | MKDIR_P = @MKDIR_P@ 188 | OBJEXT = @OBJEXT@ 189 | PACKAGE = @PACKAGE@ 190 | PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ 191 | PACKAGE_NAME = @PACKAGE_NAME@ 192 | PACKAGE_STRING = @PACKAGE_STRING@ 193 | PACKAGE_TARNAME = @PACKAGE_TARNAME@ 194 | PACKAGE_URL = @PACKAGE_URL@ 195 | PACKAGE_VERSION = @PACKAGE_VERSION@ 196 | PATH_SEPARATOR = @PATH_SEPARATOR@ 197 | RAGEL_CHECK = @RAGEL_CHECK@ 198 | SET_MAKE = @SET_MAKE@ 199 | SHELL = @SHELL@ 200 | STRIP = @STRIP@ 201 | VERSION = @VERSION@ 202 | abs_builddir = @abs_builddir@ 203 | abs_srcdir = @abs_srcdir@ 204 | abs_top_builddir = @abs_top_builddir@ 205 | abs_top_srcdir = @abs_top_srcdir@ 206 | ac_ct_CXX = @ac_ct_CXX@ 207 | am__include = @am__include@ 208 | am__leading_dot = @am__leading_dot@ 209 | am__quote = @am__quote@ 210 | am__tar = @am__tar@ 211 | am__untar = @am__untar@ 212 | bindir = @bindir@ 213 | build_alias = @build_alias@ 214 | builddir = @builddir@ 215 | datadir = @datadir@ 216 | datarootdir = @datarootdir@ 217 | docdir = @docdir@ 218 | dvidir = @dvidir@ 219 | exec_prefix = @exec_prefix@ 220 | host_alias = @host_alias@ 221 | htmldir = @htmldir@ 222 | includedir = @includedir@ 223 | infodir = @infodir@ 224 | install_sh = @install_sh@ 225 | libdir = @libdir@ 226 | libexecdir = @libexecdir@ 227 | localedir = @localedir@ 228 | localstatedir = @localstatedir@ 229 | mandir = @mandir@ 230 | mkdir_p = @mkdir_p@ 231 | oldincludedir = @oldincludedir@ 232 | pdfdir = @pdfdir@ 233 | prefix = @prefix@ 234 | program_transform_name = @program_transform_name@ 235 | psdir = @psdir@ 236 | sbindir = @sbindir@ 237 | sharedstatedir = @sharedstatedir@ 238 | srcdir = @srcdir@ 239 | sysconfdir = @sysconfdir@ 240 | target_alias = @target_alias@ 241 | top_build_prefix = @top_build_prefix@ 242 | top_builddir = @top_builddir@ 243 | top_srcdir = @top_srcdir@ 244 | nobase_include_HEADERS = \ 245 | jsmincpp/ConstString.h \ 246 | jsmincpp/deserialize/CRC32Hash.h \ 247 | jsmincpp/deserialize/Deserializer.h \ 248 | jsmincpp/deserialize/GetNameHash.h \ 249 | jsmincpp/deserialize/GetNameHash.rlh \ 250 | jsmincpp/deserialize/MallocCreator.h \ 251 | jsmincpp/deserialize/Params.h \ 252 | jsmincpp/deserialize/ParseBool.h \ 253 | jsmincpp/deserialize/ParseBool.rlh \ 254 | jsmincpp/deserialize/ParseFloat.h \ 255 | jsmincpp/deserialize/ParseFloat.rlh \ 256 | jsmincpp/deserialize/ParseInt.h \ 257 | jsmincpp/deserialize/ParseInt.rlh \ 258 | jsmincpp/deserialize/ParseStaticString.h \ 259 | jsmincpp/deserialize/ParseStaticString.rlh \ 260 | jsmincpp/deserialize/ParseUInt.h \ 261 | jsmincpp/deserialize/ParseUInt.rlh \ 262 | jsmincpp/deserialize/SkipEndJSONString.h \ 263 | jsmincpp/deserialize/SkipEndJSONString.rlh \ 264 | jsmincpp/deserialize/STLSupport/Deque.h \ 265 | jsmincpp/deserialize/STLSupport/ForwardList.h \ 266 | jsmincpp/deserialize/STLSupport/List.h \ 267 | jsmincpp/deserialize/STLSupport/Map.h \ 268 | jsmincpp/deserialize/STLSupport/ParseStdString.h \ 269 | jsmincpp/deserialize/STLSupport/ParseStdString.rlh \ 270 | jsmincpp/deserialize/STLSupport/Set.h \ 271 | jsmincpp/deserialize/STLSupport/SharedPrtCreator.h \ 272 | jsmincpp/deserialize/STLSupport/STLContiners.h \ 273 | jsmincpp/deserialize/STLSupport/String.h \ 274 | jsmincpp/deserialize/STLSupport/Vector.h \ 275 | jsmincpp/deserialize/Tuple.h \ 276 | jsmincpp/FloatPoint_3x1.h \ 277 | jsmincpp/IntegerOverflowControl.h \ 278 | jsmincpp/serialize/JSONSerializer.h \ 279 | jsmincpp/serialize/Serializer.h \ 280 | jsmincpp/serialize/STLSupport/Deque.h \ 281 | jsmincpp/serialize/STLSupport/ForwardList.h \ 282 | jsmincpp/serialize/STLSupport/List.h \ 283 | jsmincpp/serialize/STLSupport/Map.h \ 284 | jsmincpp/serialize/STLSupport/Set.h \ 285 | jsmincpp/serialize/STLSupport/String.h \ 286 | jsmincpp/serialize/STLSupport/Vector.h \ 287 | jsmincpp/StaticString.h \ 288 | jsmincpp/TypesUtilities.h 289 | 290 | RM := rm 291 | ECHO := echo 292 | RL := ragel 293 | RLFLAGS := -G2 294 | source_dirs := $(top_srcdir)/include/jsmincpp/deserialize $(top_srcdir)/include/jsmincpp/deserialize/STLSupport 295 | generated_files := $(patsubst %.rlh, %.h, $(wildcard $(addsuffix /*.rlh, $(source_dirs)))) 296 | BUILT_SOURCES := $(generated_files) 297 | all: $(BUILT_SOURCES) 298 | $(MAKE) $(AM_MAKEFLAGS) all-am 299 | 300 | .SUFFIXES: 301 | $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) 302 | @for dep in $?; do \ 303 | case '$(am__configure_deps)' in \ 304 | *$$dep*) \ 305 | ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ 306 | && { if test -f $@; then exit 0; else break; fi; }; \ 307 | exit 1;; \ 308 | esac; \ 309 | done; \ 310 | echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign --ignore-deps include/Makefile'; \ 311 | $(am__cd) $(top_srcdir) && \ 312 | $(AUTOMAKE) --foreign --ignore-deps include/Makefile 313 | .PRECIOUS: Makefile 314 | Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status 315 | @case '$?' in \ 316 | *config.status*) \ 317 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ 318 | *) \ 319 | echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ 320 | cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ 321 | esac; 322 | 323 | $(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) 324 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 325 | 326 | $(top_srcdir)/configure: $(am__configure_deps) 327 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 328 | $(ACLOCAL_M4): $(am__aclocal_m4_deps) 329 | cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh 330 | $(am__aclocal_m4_deps): 331 | install-nobase_includeHEADERS: $(nobase_include_HEADERS) 332 | @$(NORMAL_INSTALL) 333 | @list='$(nobase_include_HEADERS)'; test -n "$(includedir)" || list=; \ 334 | if test -n "$$list"; then \ 335 | echo " $(MKDIR_P) '$(DESTDIR)$(includedir)'"; \ 336 | $(MKDIR_P) "$(DESTDIR)$(includedir)" || exit 1; \ 337 | fi; \ 338 | $(am__nobase_list) | while read dir files; do \ 339 | xfiles=; for file in $$files; do \ 340 | if test -f "$$file"; then xfiles="$$xfiles $$file"; \ 341 | else xfiles="$$xfiles $(srcdir)/$$file"; fi; done; \ 342 | test -z "$$xfiles" || { \ 343 | test "x$$dir" = x. || { \ 344 | echo " $(MKDIR_P) '$(DESTDIR)$(includedir)/$$dir'"; \ 345 | $(MKDIR_P) "$(DESTDIR)$(includedir)/$$dir"; }; \ 346 | echo " $(INSTALL_HEADER) $$xfiles '$(DESTDIR)$(includedir)/$$dir'"; \ 347 | $(INSTALL_HEADER) $$xfiles "$(DESTDIR)$(includedir)/$$dir" || exit $$?; }; \ 348 | done 349 | 350 | uninstall-nobase_includeHEADERS: 351 | @$(NORMAL_UNINSTALL) 352 | @list='$(nobase_include_HEADERS)'; test -n "$(includedir)" || list=; \ 353 | $(am__nobase_strip_setup); files=`$(am__nobase_strip)`; \ 354 | dir='$(DESTDIR)$(includedir)'; $(am__uninstall_files_from_dir) 355 | 356 | ID: $(am__tagged_files) 357 | $(am__define_uniq_tagged_files); mkid -fID $$unique 358 | tags: tags-am 359 | TAGS: tags 360 | 361 | tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) 362 | set x; \ 363 | here=`pwd`; \ 364 | $(am__define_uniq_tagged_files); \ 365 | shift; \ 366 | if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ 367 | test -n "$$unique" || unique=$$empty_fix; \ 368 | if test $$# -gt 0; then \ 369 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 370 | "$$@" $$unique; \ 371 | else \ 372 | $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ 373 | $$unique; \ 374 | fi; \ 375 | fi 376 | ctags: ctags-am 377 | 378 | CTAGS: ctags 379 | ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) 380 | $(am__define_uniq_tagged_files); \ 381 | test -z "$(CTAGS_ARGS)$$unique" \ 382 | || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ 383 | $$unique 384 | 385 | GTAGS: 386 | here=`$(am__cd) $(top_builddir) && pwd` \ 387 | && $(am__cd) $(top_srcdir) \ 388 | && gtags -i $(GTAGS_ARGS) "$$here" 389 | cscopelist: cscopelist-am 390 | 391 | cscopelist-am: $(am__tagged_files) 392 | list='$(am__tagged_files)'; \ 393 | case "$(srcdir)" in \ 394 | [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ 395 | *) sdir=$(subdir)/$(srcdir) ;; \ 396 | esac; \ 397 | for i in $$list; do \ 398 | if test -f "$$i"; then \ 399 | echo "$(subdir)/$$i"; \ 400 | else \ 401 | echo "$$sdir/$$i"; \ 402 | fi; \ 403 | done >> $(top_builddir)/cscope.files 404 | 405 | distclean-tags: 406 | -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags 407 | 408 | distdir: $(DISTFILES) 409 | @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 410 | topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ 411 | list='$(DISTFILES)'; \ 412 | dist_files=`for file in $$list; do echo $$file; done | \ 413 | sed -e "s|^$$srcdirstrip/||;t" \ 414 | -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ 415 | case $$dist_files in \ 416 | */*) $(MKDIR_P) `echo "$$dist_files" | \ 417 | sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ 418 | sort -u` ;; \ 419 | esac; \ 420 | for file in $$dist_files; do \ 421 | if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ 422 | if test -d $$d/$$file; then \ 423 | dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ 424 | if test -d "$(distdir)/$$file"; then \ 425 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ 426 | fi; \ 427 | if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ 428 | cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ 429 | find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ 430 | fi; \ 431 | cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ 432 | else \ 433 | test -f "$(distdir)/$$file" \ 434 | || cp -p $$d/$$file "$(distdir)/$$file" \ 435 | || exit 1; \ 436 | fi; \ 437 | done 438 | check-am: all-am 439 | check: $(BUILT_SOURCES) 440 | $(MAKE) $(AM_MAKEFLAGS) check-am 441 | all-am: Makefile $(HEADERS) 442 | installdirs: 443 | for dir in "$(DESTDIR)$(includedir)"; do \ 444 | test -z "$$dir" || $(MKDIR_P) "$$dir"; \ 445 | done 446 | install: $(BUILT_SOURCES) 447 | $(MAKE) $(AM_MAKEFLAGS) install-am 448 | install-exec: install-exec-am 449 | install-data: install-data-am 450 | uninstall: uninstall-am 451 | 452 | install-am: all-am 453 | @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am 454 | 455 | installcheck: installcheck-am 456 | install-strip: 457 | if test -z '$(STRIP)'; then \ 458 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ 459 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ 460 | install; \ 461 | else \ 462 | $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ 463 | install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ 464 | "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ 465 | fi 466 | mostlyclean-generic: 467 | 468 | clean-generic: 469 | 470 | distclean-generic: 471 | -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) 472 | -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) 473 | 474 | maintainer-clean-generic: 475 | @echo "This command is intended for maintainers to use" 476 | @echo "it deletes files that may require special tools to rebuild." 477 | -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) 478 | clean-am: clean-generic mostlyclean-am 479 | 480 | distclean: distclean-am 481 | -rm -f Makefile 482 | distclean-am: clean-am distclean-generic distclean-tags 483 | 484 | dvi: dvi-am 485 | 486 | dvi-am: 487 | 488 | html: html-am 489 | 490 | html-am: 491 | 492 | info: info-am 493 | 494 | info-am: 495 | 496 | install-data-am: install-nobase_includeHEADERS 497 | 498 | install-dvi: install-dvi-am 499 | 500 | install-dvi-am: 501 | 502 | install-exec-am: 503 | 504 | install-html: install-html-am 505 | 506 | install-html-am: 507 | 508 | install-info: install-info-am 509 | 510 | install-info-am: 511 | 512 | install-man: 513 | 514 | install-pdf: install-pdf-am 515 | 516 | install-pdf-am: 517 | 518 | install-ps: install-ps-am 519 | 520 | install-ps-am: 521 | 522 | installcheck-am: 523 | 524 | maintainer-clean: maintainer-clean-am 525 | -rm -f Makefile 526 | maintainer-clean-am: distclean-am maintainer-clean-generic 527 | 528 | mostlyclean: mostlyclean-am 529 | 530 | mostlyclean-am: mostlyclean-generic 531 | 532 | pdf: pdf-am 533 | 534 | pdf-am: 535 | 536 | ps: ps-am 537 | 538 | ps-am: 539 | 540 | uninstall-am: uninstall-nobase_includeHEADERS 541 | 542 | .MAKE: all check install install-am install-strip 543 | 544 | .PHONY: CTAGS GTAGS TAGS all all-am check check-am clean clean-generic \ 545 | cscopelist-am ctags ctags-am distclean distclean-generic \ 546 | distclean-tags distdir dvi dvi-am html html-am info info-am \ 547 | install install-am install-data install-data-am install-dvi \ 548 | install-dvi-am install-exec install-exec-am install-html \ 549 | install-html-am install-info install-info-am install-man \ 550 | install-nobase_includeHEADERS install-pdf install-pdf-am \ 551 | install-ps install-ps-am install-strip installcheck \ 552 | installcheck-am installdirs maintainer-clean \ 553 | maintainer-clean-generic mostlyclean mostlyclean-generic pdf \ 554 | pdf-am ps ps-am tags tags-am uninstall uninstall-am \ 555 | uninstall-nobase_includeHEADERS 556 | 557 | 558 | %.rlh: 559 | 560 | %.h: %.rlh 561 | @$(ECHO) Compile $< 562 | $(RL) $(RLFLAGS) $< -p -o $(patsubst %.rlh, %.h, $<) 563 | 564 | clean: 565 | $(RM) -f $(generated_files) 566 | 567 | # Tell versions [3.59,3.63) of GNU make to not export all variables. 568 | # Otherwise a system limit (for SysV at least) may be exceeded. 569 | .NOEXPORT: 570 | -------------------------------------------------------------------------------- /include/jsmincpp/ConstString.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ConstString.h 3 | * 4 | * Created on: 6 сент. 2015 г. 5 | * Author: damon 6 | */ 7 | 8 | #ifndef INCLUDE_CONSTSTRING_H_ 9 | #define INCLUDE_CONSTSTRING_H_ 10 | 11 | #include 12 | 13 | namespace jsmincpp { 14 | 15 | class ConstString { 16 | public: 17 | ConstString( ) 18 | : 19 | _str( nullptr ), 20 | _strLen( 0 ) { 21 | } 22 | ConstString( const char *str ) 23 | : 24 | _str( str ), 25 | _strLen( ::strlen( str ) ) { 26 | } 27 | ConstString( const char *str, uint32_t strLen ) 28 | : 29 | _str( str ), 30 | _strLen( strLen ) { 31 | } 32 | template < uint32_t Len > 33 | ConstString( const char (&str) [ Len ] ) 34 | : 35 | _str( str ), 36 | _strLen( Len ) { 37 | } 38 | 39 | const char * c_str( ) const { 40 | return _str; 41 | } 42 | uint32_t length( ) const { 43 | return _strLen; 44 | } 45 | 46 | private: 47 | const char *_str; 48 | uint32_t _strLen; 49 | 50 | }; 51 | 52 | namespace serialize { 53 | 54 | template < typename S > 55 | bool operator <<( S &serializer, const ConstString &str ) { 56 | const char s [ ] = { "\"" }; 57 | return serializer.GetHandler( )( s, sizeof( s ) - 1 ) 58 | && serializer.GetHandler( )( str.c_str( ), str.length( ) ) 59 | && serializer.GetHandler( )( s, sizeof( s ) - 1 ); 60 | } 61 | 62 | } // namespace serialize 63 | 64 | } // namespace jsmincpp 65 | 66 | #endif // INCLUDE_CONSTSTRING_H_ 67 | -------------------------------------------------------------------------------- /include/jsmincpp/FloatPoint_3x1.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_FLOATPOINT_3X1_H_ 2 | #define INCLUDE_FLOATPOINT_3X1_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace jsmincpp { 9 | 10 | class FloatPoint_3x1 { 11 | public: 12 | FloatPoint_3x1( ) 13 | : 14 | _val( 0.0f ) { 15 | } 16 | 17 | FloatPoint_3x1( float val ) 18 | : 19 | _val( val ) { 20 | } 21 | 22 | float GetValue( ) const { 23 | return _val; 24 | } 25 | 26 | private: 27 | float _val; 28 | 29 | }; 30 | 31 | namespace serialize { 32 | 33 | template < typename S > 34 | bool operator <<( S &serializer, const FloatPoint_3x1 &data ) { 35 | const char f [ ] = "%3.1f"; 36 | char buffer [ 10 ]; 37 | uint32_t len = ::sprintf( buffer, f, data.GetValue( ) ); 38 | return ( len > 0 ) && serializer.GetHandler( )( buffer, len ); 39 | } 40 | 41 | } // namespace serialize 42 | 43 | } // namespace jsmincpp 44 | 45 | #endif // INCLUDE_SERIALIZE_FLOATPOINT_3X1_H_ 46 | -------------------------------------------------------------------------------- /include/jsmincpp/IntegerOverflowControl.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_INTEGEROVERFLOWCONTROL_H_ 2 | #define INCLUDE_INTEGEROVERFLOWCONTROL_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | template< typename T > 9 | struct MaxValues; 10 | 11 | template< > 12 | struct MaxValues< int8_t > { 13 | static const int8_t maxVal = INT8_MAX; 14 | }; 15 | 16 | template< > 17 | struct MaxValues< int16_t > { 18 | static const int16_t maxVal = INT16_MAX; 19 | }; 20 | 21 | template< > 22 | struct MaxValues< int32_t > { 23 | static const int32_t maxVal = INT32_MAX; 24 | }; 25 | 26 | template< > 27 | struct MaxValues< int64_t > { 28 | static const int64_t maxVal = INT64_MAX; 29 | }; 30 | 31 | template< > 32 | struct MaxValues< uint8_t > { 33 | static const uint8_t maxVal = UINT8_MAX; 34 | }; 35 | 36 | template< > 37 | struct MaxValues< uint16_t > { 38 | static const uint16_t maxVal = UINT16_MAX; 39 | }; 40 | 41 | template< > 42 | struct MaxValues< uint32_t > { 43 | static const uint32_t maxVal = UINT32_MAX; 44 | }; 45 | 46 | template< > 47 | struct MaxValues< uint64_t > { 48 | static const uint64_t maxVal = UINT64_MAX; 49 | }; 50 | 51 | /* 52 | * From http://dxdy.ru/topic6934.html 53 | */ 54 | 55 | template< typename T > 56 | struct IntegerOverflowControl { 57 | static T Summ ( T &res, const T a ) 58 | { 59 | if( MaxValues< T >::maxVal - a < res ) 60 | return false; 61 | 62 | res += a; 63 | return true; 64 | } 65 | 66 | static T Mult ( T &res, const T a ) 67 | { 68 | if( MaxValues< T >::maxVal / a < res ) 69 | return false; 70 | 71 | res *= a; 72 | return true; 73 | } 74 | }; 75 | 76 | } // namespace jsmincpp 77 | 78 | #endif /* INCLUDE_INTEGEROVERFLOWCONTROL_H_ */ 79 | -------------------------------------------------------------------------------- /include/jsmincpp/StaticString.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_STATICSTRING_H_ 2 | #define INCLUDE_STATICSTRING_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace jsmincpp { 9 | 10 | template < uint32_t Num > 11 | class StaticString { 12 | public: 13 | StaticString( ) 14 | : 15 | _length( 0 ) { 16 | _buff [ 0 ] = 0; 17 | } 18 | 19 | StaticString( const char *str ) { 20 | Assign( str ); 21 | } 22 | 23 | 24 | bool Add( char symbol ) { 25 | if( Num == _length ) 26 | return false; 27 | _buff[ _length++ ] = symbol; 28 | _buff[ _length ] = 0; 29 | 30 | return true; 31 | } 32 | 33 | bool Add( const char *str ) { 34 | uint32_t strSize = ::strlen( str ); 35 | if( strSize > Num - _length ) 36 | return false; 37 | ::strcpy( _buff, str ); 38 | _length += strSize; 39 | _buff[ _length + 1 ] = 0; 40 | return true; 41 | } 42 | 43 | bool Assign( const char *str ) { 44 | _length = 0; 45 | _buff[ _length ] = 0; 46 | return Add( str ); 47 | } 48 | 49 | const char * GetString( ) { 50 | return _buff; 51 | } 52 | 53 | uint32_t GetLength( ) { 54 | return _length; 55 | } 56 | 57 | private: 58 | uint32_t _length; 59 | char _buff [ Num + 1 ]; 60 | }; 61 | 62 | namespace deserialize { 63 | 64 | template < uint32_t Hash, uint32_t Num > 65 | class StaticStringParam { 66 | public: 67 | enum { 68 | HASH = Hash 69 | }; 70 | 71 | StaticStringParam( StaticString< Num > ¶m ) 72 | : 73 | _param( param ) { 74 | } 75 | 76 | template < typename D > 77 | bool Parse( D &deserializer ) { 78 | return ParseStaticString( _param, deserializer.GetStream( ) ); 79 | } 80 | 81 | private: 82 | StaticString< Num > &_param; 83 | }; 84 | 85 | template < uint32_t Hash, uint32_t Num > 86 | StaticStringParam < Hash, Num > MakeParam( StaticString< Num > ¶m ) { 87 | return StaticStringParam < Hash, Num >( param ); 88 | } 89 | 90 | } //namespace deserialize 91 | 92 | } // namespace jsmincpp 93 | 94 | #endif // INCLUDE_STATICSTRING_H_ 95 | -------------------------------------------------------------------------------- /include/jsmincpp/TypesUtilities.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_TYPESUTILITIES_H_ 2 | #define INCLUDE_TYPESUTILITIES_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | template < typename ... Args > 10 | struct MaxSizeTypes; 11 | 12 | template < typename Head, typename ... Tail > 13 | struct MaxSizeTypes < Head, Tail... > : MaxSizeTypes < Tail... > { 14 | typedef MaxSizeTypes < Tail... > Base_t; 15 | enum { 16 | Size = ( sizeof(Head) > ( size_t ) Base_t::Size ) ? 17 | sizeof(Head) : ( size_t ) Base_t::Size 18 | }; 19 | }; 20 | 21 | template < > 22 | struct MaxSizeTypes < > { 23 | enum { 24 | Size = 0 25 | }; 26 | }; 27 | 28 | /* 29 | * 30 | */ 31 | 32 | template < typename H, typename ... T > 33 | struct FirstType { 34 | typedef H Type_t; 35 | }; 36 | 37 | /* 38 | * 39 | */ 40 | 41 | template < int v > 42 | struct Int2Type 43 | { 44 | enum { 45 | value = v 46 | }; 47 | }; 48 | 49 | /* 50 | * From http://www.dreamincode.net/forums/topic/140936-determining-the-base-class-from-a-derived-class/ 51 | */ 52 | 53 | template < typename BaseT, typename DerivedT > 54 | struct IsRelated { 55 | static DerivedT derived( ); 56 | static char test( const BaseT& ); // sizeof(test()) == sizeof(char) 57 | static char (&test( ...))[ 2 ]; // sizeof(test()) == sizeof(char[2]) 58 | enum { 59 | value = ( sizeof( test( derived( ) ) ) == sizeof(char) ) 60 | }; 61 | }; 62 | 63 | template < typename BaseT, typename DerivedT > 64 | constexpr bool isRelated( const DerivedT& ) 65 | { 66 | return IsRelated < BaseT, DerivedT >::value; 67 | } 68 | 69 | template < typename BaseT, typename DerivedT > 70 | constexpr bool isRelated( DerivedT& ) 71 | { 72 | return IsRelated < BaseT, DerivedT >::value; 73 | } 74 | 75 | } // namespace jsmincpp 76 | 77 | #endif // INCLUDE_TYPESUTILITIES_H_ 78 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/CRC32Hash.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_CRC32HASH_H_ 2 | #define INCLUDE_DESERIALIZE_CRC32HASH_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace deserialize { 9 | 10 | /* 11 | * From http://ru.wikibooks.org/wiki/%D0%A0%D0%B5%D0%B0%D0%BB%D0%B8%D0%B7%D0%B0%D1%86%D0%B8%D0%B8_%D0%B0%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC%D0%BE%D0%B2/%D0%A6%D0%B8%D0%BA%D0%BB%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%B8%D0%B9_%D0%B8%D0%B7%D0%B1%D1%8B%D1%82%D0%BE%D1%87%D0%BD%D1%8B%D0%B9_%D0%BA%D0%BE%D0%B4 12 | */ 13 | 14 | constexpr uint32_t Crc32Table [ 256 ] = { 15 | 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 16 | 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 17 | 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 18 | 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 19 | 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, 20 | 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, 21 | 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, 22 | 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, 23 | 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, 24 | 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, 25 | 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, 26 | 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, 27 | 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, 28 | 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, 29 | 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, 30 | 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, 31 | 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, 32 | 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, 33 | 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, 34 | 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, 35 | 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, 36 | 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, 37 | 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, 38 | 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, 39 | 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, 40 | 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, 41 | 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, 42 | 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, 43 | 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, 44 | 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, 45 | 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, 46 | 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, 47 | 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, 48 | 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, 49 | 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, 50 | 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, 51 | 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, 52 | 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, 53 | 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, 54 | 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, 55 | 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, 56 | 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, 57 | 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, 58 | 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, 59 | 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, 60 | 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, 61 | 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, 62 | 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, 63 | 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, 64 | 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, 65 | 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, 66 | 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, 67 | 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, 68 | 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, 69 | 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, 70 | 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, 71 | 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, 72 | 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, 73 | 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, 74 | 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, 75 | 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, 76 | 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, 77 | 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 78 | 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D 79 | }; 80 | 81 | constexpr uint32_t Crc32Loop( uint32_t crc, const char *str ) { 82 | return 83 | ( static_cast < unsigned char >( *str ) > 0 ) ? 84 | Crc32Loop( 85 | ( crc >> 8 ) 86 | ^ Crc32Table [ ( crc ^ static_cast < unsigned char >( *str ) ) 87 | & 0xFF ], 88 | str + 1 ) : crc; 89 | } 90 | 91 | constexpr uint32_t Crc32( const char *str ) { 92 | return Crc32Loop( 0xFFFFFFFF, str ) ^ 0xFFFFFFFF; 93 | } 94 | 95 | class CRC32Hash { 96 | public: 97 | CRC32Hash( ) 98 | : 99 | m_crc( 0xFFFFFFFF ) { 100 | } 101 | 102 | void Reset( ) { 103 | m_crc = 0xFFFFFFFF; 104 | } 105 | 106 | operator uint32_t( ) { 107 | return m_crc ^ 0xFFFFFFFF; 108 | } 109 | 110 | void operator()( uint8_t byte ) { 111 | uint32_t tmp = ( m_crc ^ byte ) & 0xFF; 112 | for ( uint8_t i = 0; i < 8; i++ ) 113 | tmp = ( tmp & 1 ) ? 114 | ( ( tmp >> 1 ) ^ m_CRCPolynom ) : ( tmp >> 1 ); 115 | m_crc = ( m_crc >> 8 ) ^ tmp; 116 | } 117 | 118 | private: 119 | uint32_t m_crc; 120 | static const uint32_t m_CRCPolynom = 0xEDB88320U; 121 | 122 | }; 123 | 124 | } // namespace deserialize 125 | 126 | } // namespace jsmincpp 127 | 128 | 129 | #endif // INCLUDE_DESERIALIZE_CRC32HASH_H_ 130 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/Deserializer.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_DESERIALIZER_H_ 2 | #define INCLUDE_DESERIALIZE_DESERIALIZER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #define DESERIALIZEOBJ( x ) jsmincpp::deserialize::ObjectParam < jsmincpp::deserialize::Crc32( #x ), x > 12 | #define DESERIALIZE( x ) jsmincpp::deserialize::MakeParam < jsmincpp::deserialize::Crc32( #x ) >( x ) 13 | 14 | namespace jsmincpp { 15 | 16 | namespace deserialize { 17 | 18 | class NullObj { 19 | 20 | }; 21 | 22 | template < uint32_t BuffSize > 23 | class StaticCreator { 24 | public: 25 | uint32_t _buff [ BuffSize / 4 + 1 ]; 26 | 27 | template < typename T > 28 | T * Create( const T & ) { 29 | return new ( _buff ) T; 30 | } 31 | 32 | template < typename T > 33 | void Delete( T * ) { 34 | } 35 | }; 36 | 37 | template < typename Stream, typename ObjList, 38 | typename Creator = StaticCreator < ObjList::MAX_SIZE > > 39 | class Deserializer { 40 | public: 41 | Deserializer( 42 | Stream &stream, 43 | Creator creator = Creator( ) ) 44 | : 45 | _stream( stream ), 46 | _creator( creator ) { 47 | } 48 | 49 | template < typename H > 50 | bool Deserialize( H &handler ) { 51 | ObjList objects; 52 | CRC32Hash hash; 53 | 54 | if ( '{' != *_stream ) { 55 | ++_stream; 56 | return false; 57 | } 58 | ++_stream; 59 | 60 | if ( !GetNameHash( _stream, hash ) ) 61 | return SkipEndJSONString( _stream ); 62 | ++_stream; 63 | 64 | return objects( hash, *this, handler ); 65 | } 66 | 67 | template < typename O > 68 | bool Deserialize( O *obj ) { 69 | return obj->Deserialize( *this ); 70 | } 71 | 72 | bool operator()( ) { 73 | if ( ( 'n' != *_stream ) 74 | || ( 'u' != *( ++_stream ) ) 75 | || ( 'l' != *( ++_stream ) ) 76 | || ( 'l' != *( ++_stream ) ) 77 | ) 78 | return SkipEndJSONString( _stream ); 79 | 80 | ++_stream; 81 | return true; 82 | } 83 | 84 | template < typename ... P > 85 | bool operator()( P ... p ) { 86 | auto params = MakeTuple( p ... ); 87 | 88 | if ( '{' != *_stream ) 89 | return SkipEndJSONString( _stream ); 90 | ++_stream; 91 | 92 | while ( true ) { 93 | CRC32Hash hash; 94 | if ( !GetNameHash( _stream, hash ) ) 95 | return SkipEndJSONString( _stream ); 96 | ++_stream; 97 | 98 | if ( !params( hash, *this ) ) 99 | return SkipEndJSONString( _stream ); 100 | 101 | if ( ',' == *_stream ) { 102 | ++_stream; 103 | continue; 104 | } else if ( '}' == *_stream ) { 105 | ++_stream; 106 | break; 107 | } else 108 | return false; 109 | } 110 | return true; 111 | } 112 | 113 | Creator & GetCreator( ) { 114 | return _creator; 115 | } 116 | 117 | Stream & GetStream( ) { 118 | return _stream; 119 | } 120 | 121 | private: 122 | Stream &_stream; 123 | Creator _creator; 124 | 125 | }; 126 | 127 | } //namespace deserialize 128 | 129 | } // namespace jsmincpp 130 | 131 | #endif // INCLUDE_DESERIALIZE_DESERIALIZER_H_ 132 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/GetNameHash.h: -------------------------------------------------------------------------------- 1 | 2 | #line 1 "include/jsmincpp/deserialize/GetNameHash.rlh" 3 | #ifndef INCLUDE_DESERIALIZE_GETNAME_H_ 4 | #define INCLUDE_DESERIALIZE_GETNAME_H_ 5 | 6 | #include 7 | 8 | #include 9 | 10 | namespace jsmincpp { 11 | 12 | namespace deserialize { 13 | 14 | template < typename S > 15 | bool GetNameHash( S &p, CRC32Hash &h ) { 16 | 17 | 18 | #line 16 "include/jsmincpp/deserialize/GetNameHash.rlh" 19 | 20 | #line 21 "include/jsmincpp/deserialize/GetNameHash.h" 21 | static const int NameParser_start = 1; 22 | static const int NameParser_first_final = 5; 23 | static const int NameParser_error = 0; 24 | 25 | static const int NameParser_en_main = 1; 26 | 27 | 28 | #line 17 "include/jsmincpp/deserialize/GetNameHash.rlh" 29 | 30 | int cs; 31 | S pe = p.End( ); 32 | S eof = p.End( ); 33 | 34 | 35 | #line 36 "include/jsmincpp/deserialize/GetNameHash.h" 36 | { 37 | cs = NameParser_start; 38 | } 39 | 40 | #line 23 "include/jsmincpp/deserialize/GetNameHash.rlh" 41 | 42 | #line 30 "include/jsmincpp/deserialize/GetNameHash.rlh" 43 | 44 | 45 | 46 | #line 47 "include/jsmincpp/deserialize/GetNameHash.h" 47 | { 48 | if ( p == pe ) 49 | goto _test_eof; 50 | switch ( cs ) 51 | { 52 | case 1: 53 | if ( (*p) == 34 ) 54 | goto st2; 55 | goto tr0; 56 | tr0: 57 | #line 26 "include/jsmincpp/deserialize/GetNameHash.rlh" 58 | { h.Reset( ); return false; } 59 | goto st0; 60 | #line 61 "include/jsmincpp/deserialize/GetNameHash.h" 61 | st0: 62 | cs = 0; 63 | goto _out; 64 | st2: 65 | if ( ++p == pe ) 66 | goto _test_eof2; 67 | case 2: 68 | if ( (*p) == 95 ) 69 | goto tr2; 70 | if ( (*p) < 65 ) { 71 | if ( 48 <= (*p) && (*p) <= 49 ) 72 | goto tr2; 73 | } else if ( (*p) > 90 ) { 74 | if ( 97 <= (*p) && (*p) <= 122 ) 75 | goto tr2; 76 | } else 77 | goto tr2; 78 | goto tr0; 79 | tr2: 80 | #line 25 "include/jsmincpp/deserialize/GetNameHash.rlh" 81 | { h( *p ); } 82 | goto st3; 83 | st3: 84 | if ( ++p == pe ) 85 | goto _test_eof3; 86 | case 3: 87 | #line 88 "include/jsmincpp/deserialize/GetNameHash.h" 88 | switch( (*p) ) { 89 | case 34: goto st4; 90 | case 95: goto tr2; 91 | } 92 | if ( (*p) < 65 ) { 93 | if ( 48 <= (*p) && (*p) <= 49 ) 94 | goto tr2; 95 | } else if ( (*p) > 90 ) { 96 | if ( 97 <= (*p) && (*p) <= 122 ) 97 | goto tr2; 98 | } else 99 | goto tr2; 100 | goto tr0; 101 | st4: 102 | if ( ++p == pe ) 103 | goto _test_eof4; 104 | case 4: 105 | if ( (*p) == 58 ) 106 | goto tr4; 107 | goto tr0; 108 | tr4: 109 | #line 27 "include/jsmincpp/deserialize/GetNameHash.rlh" 110 | { return true; } 111 | goto st5; 112 | st5: 113 | if ( ++p == pe ) 114 | goto _test_eof5; 115 | case 5: 116 | #line 117 "include/jsmincpp/deserialize/GetNameHash.h" 117 | goto tr0; 118 | } 119 | _test_eof2: cs = 2; goto _test_eof; 120 | _test_eof3: cs = 3; goto _test_eof; 121 | _test_eof4: cs = 4; goto _test_eof; 122 | _test_eof5: cs = 5; goto _test_eof; 123 | 124 | _test_eof: {} 125 | if ( p == eof ) 126 | { 127 | switch ( cs ) { 128 | case 1: 129 | case 2: 130 | case 3: 131 | case 4: 132 | #line 26 "include/jsmincpp/deserialize/GetNameHash.rlh" 133 | { h.Reset( ); return false; } 134 | break; 135 | #line 136 "include/jsmincpp/deserialize/GetNameHash.h" 136 | } 137 | } 138 | 139 | _out: {} 140 | } 141 | 142 | #line 33 "include/jsmincpp/deserialize/GetNameHash.rlh" 143 | 144 | return true; 145 | } 146 | 147 | } // namespace deserialize 148 | 149 | } // namespace jsmincpp 150 | 151 | #endif // INCLUDE_DESERIALIZE_GETNAME_H_ 152 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/GetNameHash.rlh: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_GETNAME_H_ 2 | #define INCLUDE_DESERIALIZE_GETNAME_H_ 3 | 4 | #include 5 | 6 | #include 7 | 8 | namespace jsmincpp { 9 | 10 | namespace deserialize { 11 | 12 | template < typename S > 13 | bool GetNameHash( S &p, CRC32Hash &h ) { 14 | 15 | %% machine NameParser; 16 | %% write data; 17 | 18 | int cs; 19 | S pe = p.End( ); 20 | S eof = p.End( ); 21 | 22 | %% write init; 23 | %%{ 24 | 25 | action PUSH_SYMBOL { h( *p ); } 26 | action RETURN_ERROR { h.Reset( ); return false; } 27 | action RETURN_HASH { return true; } 28 | main := ( '\"' ( [A-Za-z0-1_]+ ) $PUSH_SYMBOL '\":' ) $!RETURN_ERROR @RETURN_HASH; 29 | 30 | }%% 31 | 32 | %% write exec; 33 | 34 | return true; 35 | } 36 | 37 | } // namespace deserialize 38 | 39 | } // namespace jsmincpp 40 | 41 | #endif // INCLUDE_DESERIALIZE_GETNAME_H_ 42 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/MallocCreator.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_MALLOCCREATOR_H_ 2 | #define INCLUDE_DESERIALIZE_MALLOCCREATOR_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace deserialize { 9 | 10 | struct MallocCreator { 11 | static int32_t m_allocateCounter; 12 | 13 | template< typename T > 14 | static T * Create( const T & ) { 15 | void *buff = ::malloc( sizeof( T ) ); 16 | if( !buff ) 17 | return nullptr; 18 | ++m_allocateCounter; 19 | return new( buff ) T; 20 | } 21 | 22 | static void Delete( void *ptr ) { 23 | ::free( ptr ); 24 | --m_allocateCounter; 25 | } 26 | }; 27 | 28 | } // namespace deserialize 29 | 30 | } // namespace jsmincpp 31 | 32 | #endif // INCLUDE_DESERIALIZE_MALLOCCREATOR_H_ 33 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/Params.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_PARAMS_H_ 2 | #define INCLUDE_DESERIALIZE_PARAMS_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace jsmincpp { 10 | 11 | namespace deserialize { 12 | 13 | template < uint32_t Hash, typename T > 14 | class IntParam { 15 | public: 16 | enum { 17 | HASH = Hash 18 | }; 19 | 20 | IntParam( T ¶m ) 21 | : 22 | _param( param ) { 23 | } 24 | 25 | template < typename D > 26 | bool Parse( D &deserializer ) { 27 | return ParseInt( _param, deserializer.GetStream( ) ); 28 | } 29 | 30 | private: 31 | T &_param; 32 | }; 33 | 34 | template < uint32_t Hash, typename T > 35 | class UIntParam { 36 | public: 37 | enum { 38 | HASH = Hash 39 | }; 40 | 41 | UIntParam( T ¶m ) 42 | : 43 | _param( param ) { 44 | } 45 | 46 | template < typename D > 47 | bool Parse( D &deserializer ) { 48 | return ParseUInt( _param, deserializer.GetStream( ) ); 49 | } 50 | 51 | private: 52 | T &_param; 53 | }; 54 | 55 | template < uint32_t Hash > 56 | class BoolParam { 57 | public: 58 | enum { 59 | HASH = Hash 60 | }; 61 | 62 | BoolParam( bool ¶m ) 63 | : 64 | _param( param ) { 65 | } 66 | 67 | template < typename D > 68 | bool Parse( D &deserializer ) { 69 | return ParseBool( _param, deserializer.GetStream( ) ); 70 | } 71 | 72 | private: 73 | bool &_param; 74 | }; 75 | 76 | template < uint32_t Hash, typename T > 77 | class FloatParam { 78 | public: 79 | enum { 80 | HASH = Hash 81 | }; 82 | 83 | FloatParam( T ¶m ) 84 | : 85 | _param( param ) { 86 | } 87 | 88 | template < typename D > 89 | bool Parse( D &deserializer ) { 90 | return ParseFloat( _param, deserializer.GetStream( ) ); 91 | } 92 | 93 | private: 94 | T &_param; 95 | }; 96 | 97 | template < uint32_t Hash, typename T > 98 | class ObjectParam { 99 | public: 100 | typedef T Object_t; 101 | 102 | enum { 103 | HASH = Hash 104 | }; 105 | 106 | ObjectParam( T ¶m ) 107 | : 108 | _param( param ) { 109 | } 110 | 111 | template < typename D > 112 | bool Parse( D &deserializer ) { 113 | return _param.Deserialize( deserializer ); 114 | } 115 | 116 | private: 117 | T &_param; 118 | }; 119 | 120 | template < uint32_t Hash > 121 | IntParam < Hash, int8_t > MakeParam( int8_t & ); 122 | template < uint32_t Hash > 123 | IntParam < Hash, int16_t > MakeParam( int16_t & ); 124 | template < uint32_t Hash > 125 | IntParam < Hash, int32_t > MakeParam( int32_t & ); 126 | 127 | template < uint32_t Hash > 128 | UIntParam < Hash, uint8_t > MakeParam( uint8_t & ); 129 | template < uint32_t Hash > 130 | UIntParam < Hash, uint16_t > MakeParam( uint16_t & ); 131 | template < uint32_t Hash > 132 | UIntParam < Hash, uint32_t > MakeParam( uint32_t & ); 133 | 134 | template < uint32_t Hash > 135 | BoolParam < Hash > MakeParam( bool & ); 136 | 137 | template < uint32_t Hash > 138 | FloatParam < Hash, float > MakeParam( float & ); 139 | template < uint32_t Hash > 140 | FloatParam < Hash, double > MakeParam( double & ); 141 | 142 | template < uint32_t Hash, typename T > 143 | ObjectParam < Hash, T > MakeParam( T & ); 144 | 145 | 146 | template < uint32_t Hash, typename T, uint32_t Num > 147 | class ArrayParam { 148 | public: 149 | typedef T Object_t; 150 | 151 | enum { 152 | HASH = Hash 153 | }; 154 | 155 | ArrayParam( T ( ¶m )[ Num ] ) 156 | : 157 | _param( param ) { 158 | } 159 | 160 | template < typename D > 161 | bool Parse( D &deserializer ) { 162 | auto &stream = deserializer.GetStream( ); 163 | 164 | if ( '[' != *stream ) 165 | return false; 166 | ++stream; 167 | 168 | for ( uint32_t i = 0; i < Num - 1; ++i ) { 169 | auto param = MakeParam< 0 >( _param[ i ] ); 170 | if ( !param.Parse( deserializer ) ) 171 | return false; 172 | 173 | if ( ',' == *stream ) 174 | ++stream; 175 | else 176 | return false; 177 | } 178 | 179 | auto param = MakeParam< 0 >( _param[ Num - 1 ] ); 180 | if ( !param.Parse( deserializer ) ) 181 | return false; 182 | 183 | if ( ']' != *stream ) 184 | return false; 185 | ++stream; 186 | 187 | return true; 188 | } 189 | 190 | private: 191 | T ( &_param )[ Num ]; 192 | }; 193 | 194 | template < uint32_t Hash > 195 | IntParam < Hash, int8_t > MakeParam( int8_t ¶m ) { 196 | return IntParam < Hash, int8_t >( param ); 197 | } 198 | 199 | template < uint32_t Hash > 200 | IntParam < Hash, int16_t > MakeParam( int16_t ¶m ) { 201 | return IntParam < Hash, int16_t >( param ); 202 | } 203 | 204 | template < uint32_t Hash > 205 | IntParam < Hash, int32_t > MakeParam( int32_t ¶m ) { 206 | return IntParam < Hash, int32_t >( param ); 207 | } 208 | 209 | template < uint32_t Hash > 210 | UIntParam < Hash, uint8_t > MakeParam( uint8_t ¶m ) { 211 | return UIntParam < Hash, uint8_t >( param ); 212 | } 213 | 214 | template < uint32_t Hash > 215 | UIntParam < Hash, uint16_t > MakeParam( uint16_t ¶m ) { 216 | return UIntParam < Hash, uint16_t >( param ); 217 | } 218 | 219 | template < uint32_t Hash > 220 | UIntParam < Hash, uint32_t > MakeParam( uint32_t ¶m ) { 221 | return UIntParam < Hash, uint32_t >( param ); 222 | } 223 | 224 | template < uint32_t Hash > 225 | BoolParam < Hash > MakeParam( bool ¶m ) { 226 | return BoolParam < Hash >( param ); 227 | } 228 | 229 | template < uint32_t Hash > 230 | FloatParam < Hash, float > MakeParam( float ¶m ) { 231 | return FloatParam < Hash, float >( param ); 232 | } 233 | 234 | template < uint32_t Hash > 235 | FloatParam < Hash, double > MakeParam( double ¶m ) { 236 | return FloatParam < Hash, double >( param ); 237 | } 238 | 239 | template < uint32_t Hash, typename T > 240 | ObjectParam < Hash, T > MakeParam( T ¶m ) { 241 | return ObjectParam < Hash, T >( param ); 242 | } 243 | 244 | template < uint32_t Hash, typename T, uint32_t Num > 245 | ArrayParam < Hash, T, Num > MakeParam( T ( ¶m )[ Num ] ) { 246 | return ArrayParam < Hash, T, Num >( param ); 247 | } 248 | 249 | } //namespace deserialize 250 | 251 | } // namespace jsmincpp 252 | 253 | #endif // INCLUDE_DESERIALIZE_PARAMS_H_ 254 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/ParseBool.h: -------------------------------------------------------------------------------- 1 | 2 | #line 1 "include/jsmincpp/deserialize/ParseBool.rlh" 3 | #ifndef INCLUDE_DESERIALIZE_PARSEBOOL_H_ 4 | #define INCLUDE_DESERIALIZE_PARSEBOOL_H_ 5 | 6 | #include 7 | 8 | namespace jsmincpp { 9 | 10 | namespace deserialize { 11 | 12 | template < typename S > 13 | bool ParseBool( bool &data, S &p ) { 14 | 15 | 16 | #line 14 "include/jsmincpp/deserialize/ParseBool.rlh" 17 | 18 | #line 19 "include/jsmincpp/deserialize/ParseBool.h" 19 | static const int BoolParser_start = 1; 20 | static const int BoolParser_first_final = 11; 21 | static const int BoolParser_error = 0; 22 | 23 | static const int BoolParser_en_value = 1; 24 | 25 | 26 | #line 15 "include/jsmincpp/deserialize/ParseBool.rlh" 27 | 28 | int cs; 29 | S pe = p.End( ); 30 | S eof = p.End( ); 31 | 32 | 33 | #line 34 "include/jsmincpp/deserialize/ParseBool.h" 34 | { 35 | cs = BoolParser_start; 36 | } 37 | 38 | #line 21 "include/jsmincpp/deserialize/ParseBool.rlh" 39 | 40 | #line 29 "include/jsmincpp/deserialize/ParseBool.rlh" 41 | 42 | 43 | 44 | #line 45 "include/jsmincpp/deserialize/ParseBool.h" 45 | { 46 | if ( p == pe ) 47 | goto _test_eof; 48 | switch ( cs ) 49 | { 50 | case 1: 51 | switch( (*p) ) { 52 | case 102: goto st2; 53 | case 116: goto st7; 54 | } 55 | goto st0; 56 | tr7: 57 | #line 24 "include/jsmincpp/deserialize/ParseBool.rlh" 58 | { return false; } 59 | goto st0; 60 | #line 61 "include/jsmincpp/deserialize/ParseBool.h" 61 | st0: 62 | cs = 0; 63 | goto _out; 64 | st2: 65 | if ( ++p == pe ) 66 | goto _test_eof2; 67 | case 2: 68 | if ( (*p) == 97 ) 69 | goto st3; 70 | goto st0; 71 | st3: 72 | if ( ++p == pe ) 73 | goto _test_eof3; 74 | case 3: 75 | if ( (*p) == 108 ) 76 | goto st4; 77 | goto st0; 78 | st4: 79 | if ( ++p == pe ) 80 | goto _test_eof4; 81 | case 4: 82 | if ( (*p) == 115 ) 83 | goto st5; 84 | goto st0; 85 | st5: 86 | if ( ++p == pe ) 87 | goto _test_eof5; 88 | case 5: 89 | if ( (*p) == 101 ) 90 | goto st6; 91 | goto st0; 92 | st6: 93 | if ( ++p == pe ) 94 | goto _test_eof6; 95 | case 6: 96 | switch( (*p) ) { 97 | case 44: goto tr8; 98 | case 93: goto tr8; 99 | case 125: goto tr8; 100 | } 101 | goto tr7; 102 | tr8: 103 | #line 26 "include/jsmincpp/deserialize/ParseBool.rlh" 104 | { data = false; } 105 | #line 23 "include/jsmincpp/deserialize/ParseBool.rlh" 106 | { return true; } 107 | goto st11; 108 | tr12: 109 | #line 25 "include/jsmincpp/deserialize/ParseBool.rlh" 110 | { data = true; } 111 | #line 23 "include/jsmincpp/deserialize/ParseBool.rlh" 112 | { return true; } 113 | goto st11; 114 | st11: 115 | if ( ++p == pe ) 116 | goto _test_eof11; 117 | case 11: 118 | #line 119 "include/jsmincpp/deserialize/ParseBool.h" 119 | goto tr7; 120 | st7: 121 | if ( ++p == pe ) 122 | goto _test_eof7; 123 | case 7: 124 | if ( (*p) == 114 ) 125 | goto st8; 126 | goto st0; 127 | st8: 128 | if ( ++p == pe ) 129 | goto _test_eof8; 130 | case 8: 131 | if ( (*p) == 117 ) 132 | goto st9; 133 | goto st0; 134 | st9: 135 | if ( ++p == pe ) 136 | goto _test_eof9; 137 | case 9: 138 | if ( (*p) == 101 ) 139 | goto st10; 140 | goto st0; 141 | st10: 142 | if ( ++p == pe ) 143 | goto _test_eof10; 144 | case 10: 145 | switch( (*p) ) { 146 | case 44: goto tr12; 147 | case 93: goto tr12; 148 | case 125: goto tr12; 149 | } 150 | goto tr7; 151 | } 152 | _test_eof2: cs = 2; goto _test_eof; 153 | _test_eof3: cs = 3; goto _test_eof; 154 | _test_eof4: cs = 4; goto _test_eof; 155 | _test_eof5: cs = 5; goto _test_eof; 156 | _test_eof6: cs = 6; goto _test_eof; 157 | _test_eof11: cs = 11; goto _test_eof; 158 | _test_eof7: cs = 7; goto _test_eof; 159 | _test_eof8: cs = 8; goto _test_eof; 160 | _test_eof9: cs = 9; goto _test_eof; 161 | _test_eof10: cs = 10; goto _test_eof; 162 | 163 | _test_eof: {} 164 | if ( p == eof ) 165 | { 166 | switch ( cs ) { 167 | case 6: 168 | case 10: 169 | #line 24 "include/jsmincpp/deserialize/ParseBool.rlh" 170 | { return false; } 171 | break; 172 | #line 173 "include/jsmincpp/deserialize/ParseBool.h" 173 | } 174 | } 175 | 176 | _out: {} 177 | } 178 | 179 | #line 32 "include/jsmincpp/deserialize/ParseBool.rlh" 180 | 181 | return false; 182 | } 183 | 184 | } // namespace deserialize 185 | 186 | } // namespace jsmincpp 187 | 188 | #endif // INCLUDE_DESERIALIZE_PARSEBOOL_H_ 189 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/ParseBool.rlh: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_PARSEBOOL_H_ 2 | #define INCLUDE_DESERIALIZE_PARSEBOOL_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace deserialize { 9 | 10 | template < typename S > 11 | bool ParseBool( bool &data, S &p ) { 12 | 13 | %% machine BoolParser; 14 | %% write data; 15 | 16 | int cs; 17 | S pe = p.End( ); 18 | S eof = p.End( ); 19 | 20 | %% write init; 21 | %%{ 22 | 23 | action RET_VAL { return true; } 24 | action RET_ERROR { return false; } 25 | action SET_TRUE { data = true; } 26 | action SET_FALSE { data = false; } 27 | value := ( 'true' %SET_TRUE | 'false' %SET_FALSE ) ( ',' | '}' | ']' ) $RET_VAL $!RET_ERROR; 28 | 29 | }%% 30 | 31 | %% write exec; 32 | 33 | return false; 34 | } 35 | 36 | } // namespace deserialize 37 | 38 | } // namespace jsmincpp 39 | 40 | #endif // INCLUDE_DESERIALIZE_PARSEBOOL_H_ 41 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/ParseFloat.h: -------------------------------------------------------------------------------- 1 | 2 | #line 1 "include/jsmincpp/deserialize/ParseFloat.rlh" 3 | #ifndef INCLUDE_DESERIALIZE_PARSEFLOAT_H_ 4 | #define INCLUDE_DESERIALIZE_PARSEFLOAT_H_ 5 | 6 | #include 7 | #include 8 | 9 | namespace jsmincpp { 10 | 11 | namespace deserialize { 12 | 13 | template < typename T,typename S > 14 | bool ParseFloat( T &data, S &p ) { 15 | 16 | 17 | #line 15 "include/jsmincpp/deserialize/ParseFloat.rlh" 18 | 19 | #line 20 "include/jsmincpp/deserialize/ParseFloat.h" 20 | static const int FloatParser_start = 1; 21 | static const int FloatParser_first_final = 9; 22 | static const int FloatParser_error = 0; 23 | 24 | static const int FloatParser_en_value = 1; 25 | 26 | 27 | #line 16 "include/jsmincpp/deserialize/ParseFloat.rlh" 28 | 29 | int cs; 30 | T count = 1.0f; 31 | uint32_t exp = 0; 32 | T negNumber = 1; 33 | T negExp = 1; 34 | 35 | data = 0.0; 36 | S pe = p.End( ); 37 | S eof = p.End( ); 38 | 39 | 40 | #line 41 "include/jsmincpp/deserialize/ParseFloat.h" 41 | { 42 | cs = FloatParser_start; 43 | } 44 | 45 | #line 28 "include/jsmincpp/deserialize/ParseFloat.rlh" 46 | 47 | #line 49 "include/jsmincpp/deserialize/ParseFloat.rlh" 48 | 49 | 50 | 51 | #line 52 "include/jsmincpp/deserialize/ParseFloat.h" 52 | { 53 | if ( p == pe ) 54 | goto _test_eof; 55 | switch ( cs ) 56 | { 57 | case 1: 58 | if ( (*p) == 45 ) 59 | goto tr0; 60 | if ( 48 <= (*p) && (*p) <= 57 ) 61 | goto tr2; 62 | goto st0; 63 | tr3: 64 | #line 46 "include/jsmincpp/deserialize/ParseFloat.rlh" 65 | { return false; } 66 | goto st0; 67 | #line 68 "include/jsmincpp/deserialize/ParseFloat.h" 68 | st0: 69 | cs = 0; 70 | goto _out; 71 | tr0: 72 | #line 44 "include/jsmincpp/deserialize/ParseFloat.rlh" 73 | { negNumber = -1; } 74 | goto st2; 75 | st2: 76 | if ( ++p == pe ) 77 | goto _test_eof2; 78 | case 2: 79 | #line 80 "include/jsmincpp/deserialize/ParseFloat.h" 80 | if ( 48 <= (*p) && (*p) <= 57 ) 81 | goto tr2; 82 | goto st0; 83 | tr2: 84 | #line 41 "include/jsmincpp/deserialize/ParseFloat.rlh" 85 | { data = data * 10 + ( *p - '0' ); } 86 | goto st3; 87 | st3: 88 | if ( ++p == pe ) 89 | goto _test_eof3; 90 | case 3: 91 | #line 92 "include/jsmincpp/deserialize/ParseFloat.h" 92 | switch( (*p) ) { 93 | case 44: goto tr4; 94 | case 46: goto st4; 95 | case 69: goto st6; 96 | case 93: goto tr4; 97 | case 101: goto st6; 98 | case 125: goto tr4; 99 | } 100 | if ( 48 <= (*p) && (*p) <= 57 ) 101 | goto tr2; 102 | goto tr3; 103 | tr4: 104 | #line 45 "include/jsmincpp/deserialize/ParseFloat.rlh" 105 | { data = data * ::pow( 10, exp * negExp ) * negNumber; return true; } 106 | goto st9; 107 | st9: 108 | if ( ++p == pe ) 109 | goto _test_eof9; 110 | case 9: 111 | #line 112 "include/jsmincpp/deserialize/ParseFloat.h" 112 | goto tr3; 113 | st4: 114 | if ( ++p == pe ) 115 | goto _test_eof4; 116 | case 4: 117 | if ( 48 <= (*p) && (*p) <= 57 ) 118 | goto tr7; 119 | goto st0; 120 | tr7: 121 | #line 38 "include/jsmincpp/deserialize/ParseFloat.rlh" 122 | { count /= 10; data += ( ( *p - '0' ) * count ); } 123 | goto st5; 124 | st5: 125 | if ( ++p == pe ) 126 | goto _test_eof5; 127 | case 5: 128 | #line 129 "include/jsmincpp/deserialize/ParseFloat.h" 129 | switch( (*p) ) { 130 | case 44: goto tr4; 131 | case 69: goto st6; 132 | case 93: goto tr4; 133 | case 101: goto st6; 134 | case 125: goto tr4; 135 | } 136 | if ( 48 <= (*p) && (*p) <= 57 ) 137 | goto tr7; 138 | goto tr3; 139 | st6: 140 | if ( ++p == pe ) 141 | goto _test_eof6; 142 | case 6: 143 | switch( (*p) ) { 144 | case 43: goto tr8; 145 | case 45: goto tr8; 146 | } 147 | if ( 48 <= (*p) && (*p) <= 57 ) 148 | goto tr9; 149 | goto st0; 150 | tr8: 151 | #line 32 "include/jsmincpp/deserialize/ParseFloat.rlh" 152 | { if( *p == '-' ) negExp = -1; } 153 | goto st7; 154 | st7: 155 | if ( ++p == pe ) 156 | goto _test_eof7; 157 | case 7: 158 | #line 159 "include/jsmincpp/deserialize/ParseFloat.h" 159 | if ( 48 <= (*p) && (*p) <= 57 ) 160 | goto tr9; 161 | goto st0; 162 | tr9: 163 | #line 35 "include/jsmincpp/deserialize/ParseFloat.rlh" 164 | { exp = exp * 10 + ( *p - '0' ); } 165 | goto st8; 166 | st8: 167 | if ( ++p == pe ) 168 | goto _test_eof8; 169 | case 8: 170 | #line 171 "include/jsmincpp/deserialize/ParseFloat.h" 171 | switch( (*p) ) { 172 | case 44: goto tr4; 173 | case 93: goto tr4; 174 | case 125: goto tr4; 175 | } 176 | if ( 48 <= (*p) && (*p) <= 57 ) 177 | goto tr9; 178 | goto tr3; 179 | } 180 | _test_eof2: cs = 2; goto _test_eof; 181 | _test_eof3: cs = 3; goto _test_eof; 182 | _test_eof9: cs = 9; goto _test_eof; 183 | _test_eof4: cs = 4; goto _test_eof; 184 | _test_eof5: cs = 5; goto _test_eof; 185 | _test_eof6: cs = 6; goto _test_eof; 186 | _test_eof7: cs = 7; goto _test_eof; 187 | _test_eof8: cs = 8; goto _test_eof; 188 | 189 | _test_eof: {} 190 | if ( p == eof ) 191 | { 192 | switch ( cs ) { 193 | case 3: 194 | case 5: 195 | case 8: 196 | #line 46 "include/jsmincpp/deserialize/ParseFloat.rlh" 197 | { return false; } 198 | break; 199 | #line 200 "include/jsmincpp/deserialize/ParseFloat.h" 200 | } 201 | } 202 | 203 | _out: {} 204 | } 205 | 206 | #line 52 "include/jsmincpp/deserialize/ParseFloat.rlh" 207 | 208 | return false; 209 | } 210 | 211 | } // namespace deserialize 212 | 213 | } // namespace jsmincpp 214 | 215 | #endif // INCLUDE_DESERIALIZE_PARSEFLOAT_H_ 216 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/ParseFloat.rlh: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_PARSEFLOAT_H_ 2 | #define INCLUDE_DESERIALIZE_PARSEFLOAT_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace deserialize { 10 | 11 | template < typename T,typename S > 12 | bool ParseFloat( T &data, S &p ) { 13 | 14 | %% machine FloatParser; 15 | %% write data; 16 | 17 | int cs; 18 | T count = 1.0f; 19 | uint32_t exp = 0; 20 | T negNumber = 1; 21 | T negExp = 1; 22 | 23 | data = 0.0; 24 | S pe = p.End( ); 25 | S eof = p.End( ); 26 | 27 | %% write init; 28 | %%{ 29 | 30 | digit1_9 = [0-9]; 31 | 32 | action NEG_EXP { if( *p == '-' ) negExp = -1; } 33 | e = ( 'e' | 'E' ) ( '+' | '-' )? $NEG_EXP; 34 | 35 | action PUSH_EXP { exp = exp * 10 + ( *p - '0' ); } 36 | exp = e digit1_9+ $PUSH_EXP; 37 | 38 | action PUSH_FRAC { count /= 10; data += ( ( *p - '0' ) * count ); } 39 | frac = '.' digit1_9+ $PUSH_FRAC; 40 | 41 | action PUSH_INT { data = data * 10 + ( *p - '0' ); } 42 | int = digit1_9+ $PUSH_INT; 43 | 44 | action NEG_NUM { negNumber = -1; } 45 | action RET_NUM { data = data * ::pow( 10, exp * negExp ) * negNumber; return true; } 46 | action RET_ERROR { return false; } 47 | value := '-'? $NEG_NUM ( int | int frac ) exp? ( ',' | '}' | ']' ) $RET_NUM $!RET_ERROR; 48 | 49 | }%% 50 | 51 | %% write exec; 52 | 53 | return false; 54 | } 55 | 56 | } // namespace deserialize 57 | 58 | } // namespace jsmincpp 59 | 60 | #endif // INCLUDE_DESERIALIZE_PARSEFLOAT_H_ 61 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/ParseInt.h: -------------------------------------------------------------------------------- 1 | 2 | #line 1 "include/jsmincpp/deserialize/ParseInt.rlh" 3 | #ifndef INCLUDE_DESERIALIZE_PARSEINT_H_ 4 | #define INCLUDE_DESERIALIZE_PARSEINT_H_ 5 | 6 | #include 7 | 8 | namespace jsmincpp { 9 | 10 | namespace deserialize { 11 | 12 | template < typename T, typename S > 13 | bool ParseInt( T &data, S &p ) { 14 | 15 | 16 | #line 14 "include/jsmincpp/deserialize/ParseInt.rlh" 17 | 18 | #line 19 "include/jsmincpp/deserialize/ParseInt.h" 19 | static const int IntegerParser_start = 1; 20 | static const int IntegerParser_first_final = 4; 21 | static const int IntegerParser_error = 0; 22 | 23 | static const int IntegerParser_en_value = 1; 24 | 25 | 26 | #line 15 "include/jsmincpp/deserialize/ParseInt.rlh" 27 | 28 | int cs; 29 | S pe = p.End( ); 30 | S eof = p.End( ); 31 | int8_t negNumber = 1; 32 | 33 | 34 | #line 35 "include/jsmincpp/deserialize/ParseInt.h" 35 | { 36 | cs = IntegerParser_start; 37 | } 38 | 39 | #line 22 "include/jsmincpp/deserialize/ParseInt.rlh" 40 | 41 | #line 41 "include/jsmincpp/deserialize/ParseInt.rlh" 42 | 43 | 44 | 45 | #line 46 "include/jsmincpp/deserialize/ParseInt.h" 46 | { 47 | if ( p == pe ) 48 | goto _test_eof; 49 | switch ( cs ) 50 | { 51 | case 1: 52 | if ( (*p) == 45 ) 53 | goto tr0; 54 | if ( 48 <= (*p) && (*p) <= 57 ) 55 | goto tr2; 56 | goto st0; 57 | tr3: 58 | #line 38 "include/jsmincpp/deserialize/ParseInt.rlh" 59 | { return false; } 60 | goto st0; 61 | #line 62 "include/jsmincpp/deserialize/ParseInt.h" 62 | st0: 63 | cs = 0; 64 | goto _out; 65 | tr0: 66 | #line 36 "include/jsmincpp/deserialize/ParseInt.rlh" 67 | { negNumber = -1; } 68 | goto st2; 69 | st2: 70 | if ( ++p == pe ) 71 | goto _test_eof2; 72 | case 2: 73 | #line 74 "include/jsmincpp/deserialize/ParseInt.h" 74 | if ( 48 <= (*p) && (*p) <= 57 ) 75 | goto tr2; 76 | goto st0; 77 | tr2: 78 | #line 26 "include/jsmincpp/deserialize/ParseInt.rlh" 79 | { 80 | if( !jsmincpp::IntegerOverflowControl< T >::Mult( data, 10 ) ) 81 | return false; 82 | if( negNumber == -1 ) --data; 83 | if( !jsmincpp::IntegerOverflowControl< T >::Summ( data, ( *p - '0' ) ) ) 84 | return false; 85 | if( negNumber == -1 ) ++data; 86 | } 87 | goto st3; 88 | st3: 89 | if ( ++p == pe ) 90 | goto _test_eof3; 91 | case 3: 92 | #line 93 "include/jsmincpp/deserialize/ParseInt.h" 93 | switch( (*p) ) { 94 | case 44: goto tr4; 95 | case 93: goto tr4; 96 | case 125: goto tr4; 97 | } 98 | if ( 48 <= (*p) && (*p) <= 57 ) 99 | goto tr2; 100 | goto tr3; 101 | tr4: 102 | #line 37 "include/jsmincpp/deserialize/ParseInt.rlh" 103 | { data = data * negNumber; return true; } 104 | goto st4; 105 | st4: 106 | if ( ++p == pe ) 107 | goto _test_eof4; 108 | case 4: 109 | #line 110 "include/jsmincpp/deserialize/ParseInt.h" 110 | goto tr3; 111 | } 112 | _test_eof2: cs = 2; goto _test_eof; 113 | _test_eof3: cs = 3; goto _test_eof; 114 | _test_eof4: cs = 4; goto _test_eof; 115 | 116 | _test_eof: {} 117 | if ( p == eof ) 118 | { 119 | switch ( cs ) { 120 | case 3: 121 | #line 38 "include/jsmincpp/deserialize/ParseInt.rlh" 122 | { return false; } 123 | break; 124 | #line 125 "include/jsmincpp/deserialize/ParseInt.h" 125 | } 126 | } 127 | 128 | _out: {} 129 | } 130 | 131 | #line 44 "include/jsmincpp/deserialize/ParseInt.rlh" 132 | 133 | return false; 134 | } 135 | 136 | } // namespace deserialize 137 | 138 | } // namespace jsmincpp 139 | 140 | #endif // INCLUDE_DESERIALIZE_PARSEINT_H_ 141 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/ParseInt.rlh: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_PARSEINT_H_ 2 | #define INCLUDE_DESERIALIZE_PARSEINT_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace deserialize { 9 | 10 | template < typename T, typename S > 11 | bool ParseInt( T &data, S &p ) { 12 | 13 | %% machine IntegerParser; 14 | %% write data; 15 | 16 | int cs; 17 | S pe = p.End( ); 18 | S eof = p.End( ); 19 | int8_t negNumber = 1; 20 | 21 | %% write init; 22 | %%{ 23 | 24 | digit1_9 = [0-9]; 25 | 26 | action PUSH_INT { 27 | if( !jsmincpp::IntegerOverflowControl< T >::Mult( data, 10 ) ) 28 | return false; 29 | if( negNumber == -1 ) --data; 30 | if( !jsmincpp::IntegerOverflowControl< T >::Summ( data, ( *p - '0' ) ) ) 31 | return false; 32 | if( negNumber == -1 ) ++data; 33 | } 34 | int = digit1_9+ $PUSH_INT; 35 | 36 | action NEG_NUM { negNumber = -1; } 37 | action RET_NUM { data = data * negNumber; return true; } 38 | action RET_ERROR { return false; } 39 | value := '-'? $NEG_NUM int ( ',' | '}' | ']' ) $RET_NUM $!RET_ERROR; 40 | 41 | }%% 42 | 43 | %% write exec; 44 | 45 | return false; 46 | } 47 | 48 | } // namespace deserialize 49 | 50 | } // namespace jsmincpp 51 | 52 | #endif // INCLUDE_DESERIALIZE_PARSEINT_H_ 53 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/ParseStaticString.h: -------------------------------------------------------------------------------- 1 | 2 | #line 1 "include/jsmincpp/deserialize/ParseStaticString.rlh" 3 | #ifndef INCLUDE_DESERIALIZE_PARSESTATICSTRING_H_ 4 | #define INCLUDE_DESERIALIZE_PARSESTATICSTRING_H_ 5 | 6 | #include 7 | 8 | namespace jsmincpp { 9 | 10 | namespace deserialize { 11 | 12 | template < typename T, typename S > 13 | bool ParseStaticString( T &data, S &p ) { 14 | 15 | 16 | #line 14 "include/jsmincpp/deserialize/ParseStaticString.rlh" 17 | 18 | #line 19 "include/jsmincpp/deserialize/ParseStaticString.h" 19 | static const int StaticStringParser_start = 1; 20 | static const int StaticStringParser_first_final = 3; 21 | static const int StaticStringParser_error = 0; 22 | 23 | static const int StaticStringParser_en_main = 1; 24 | 25 | 26 | #line 15 "include/jsmincpp/deserialize/ParseStaticString.rlh" 27 | 28 | int cs; 29 | S pe = p.End( ); 30 | S eof = p.End( ); 31 | 32 | 33 | #line 34 "include/jsmincpp/deserialize/ParseStaticString.h" 34 | { 35 | cs = StaticStringParser_start; 36 | } 37 | 38 | #line 21 "include/jsmincpp/deserialize/ParseStaticString.rlh" 39 | 40 | #line 28 "include/jsmincpp/deserialize/ParseStaticString.rlh" 41 | 42 | 43 | 44 | #line 45 "include/jsmincpp/deserialize/ParseStaticString.h" 45 | { 46 | if ( p == pe ) 47 | goto _test_eof; 48 | switch ( cs ) 49 | { 50 | case 1: 51 | if ( (*p) == 34 ) 52 | goto st2; 53 | goto tr0; 54 | tr0: 55 | #line 24 "include/jsmincpp/deserialize/ParseStaticString.rlh" 56 | { return false; } 57 | goto st0; 58 | #line 59 "include/jsmincpp/deserialize/ParseStaticString.h" 59 | st0: 60 | cs = 0; 61 | goto _out; 62 | tr2: 63 | #line 23 "include/jsmincpp/deserialize/ParseStaticString.rlh" 64 | { if( !data.Add( *p ) ) return false; } 65 | goto st2; 66 | st2: 67 | if ( ++p == pe ) 68 | goto _test_eof2; 69 | case 2: 70 | #line 71 "include/jsmincpp/deserialize/ParseStaticString.h" 71 | if ( (*p) == 34 ) 72 | goto tr3; 73 | goto tr2; 74 | tr3: 75 | #line 25 "include/jsmincpp/deserialize/ParseStaticString.rlh" 76 | { ++p; return true; } 77 | goto st3; 78 | st3: 79 | if ( ++p == pe ) 80 | goto _test_eof3; 81 | case 3: 82 | #line 83 "include/jsmincpp/deserialize/ParseStaticString.h" 83 | goto tr0; 84 | } 85 | _test_eof2: cs = 2; goto _test_eof; 86 | _test_eof3: cs = 3; goto _test_eof; 87 | 88 | _test_eof: {} 89 | if ( p == eof ) 90 | { 91 | switch ( cs ) { 92 | case 1: 93 | case 2: 94 | #line 24 "include/jsmincpp/deserialize/ParseStaticString.rlh" 95 | { return false; } 96 | break; 97 | #line 98 "include/jsmincpp/deserialize/ParseStaticString.h" 98 | } 99 | } 100 | 101 | _out: {} 102 | } 103 | 104 | #line 31 "include/jsmincpp/deserialize/ParseStaticString.rlh" 105 | 106 | return false; 107 | } 108 | 109 | } // namespace deserialize 110 | 111 | } // namespace jsmincpp 112 | 113 | #endif // INCLUDE_DESERIALIZE_PARSESTATICSTRING_H_ 114 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/ParseStaticString.rlh: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_PARSESTATICSTRING_H_ 2 | #define INCLUDE_DESERIALIZE_PARSESTATICSTRING_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace deserialize { 9 | 10 | template < typename T, typename S > 11 | bool ParseStaticString( T &data, S &p ) { 12 | 13 | %% machine StaticStringParser; 14 | %% write data; 15 | 16 | int cs; 17 | S pe = p.End( ); 18 | S eof = p.End( ); 19 | 20 | %% write init; 21 | %%{ 22 | 23 | action PUSH_SYMBOL { if( !data.Add( *p ) ) return false; } 24 | action RETURN_ERROR { return false; } 25 | action RETURN_STRING { ++p; return true; } 26 | main := ( '\"' ( [^"]* ) $PUSH_SYMBOL '\"' ) $!RETURN_ERROR @RETURN_STRING; 27 | 28 | }%% 29 | 30 | %% write exec; 31 | 32 | return false; 33 | } 34 | 35 | } // namespace deserialize 36 | 37 | } // namespace jsmincpp 38 | 39 | #endif // INCLUDE_DESERIALIZE_PARSESTATICSTRING_H_ 40 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/ParseUInt.h: -------------------------------------------------------------------------------- 1 | 2 | #line 1 "include/jsmincpp/deserialize/ParseUInt.rlh" 3 | #ifndef INCLUDE_DESERIALIZE_PARSEUINT_H_ 4 | #define INCLUDE_DESERIALIZE_PARSEUINT_H_ 5 | 6 | #include 7 | 8 | namespace jsmincpp { 9 | 10 | namespace deserialize { 11 | 12 | template < typename T, typename S > 13 | bool ParseUInt( T &data, S &p ) { 14 | 15 | 16 | #line 14 "include/jsmincpp/deserialize/ParseUInt.rlh" 17 | 18 | #line 19 "include/jsmincpp/deserialize/ParseUInt.h" 19 | static const int UnsignedIntegerParser_start = 1; 20 | static const int UnsignedIntegerParser_first_final = 3; 21 | static const int UnsignedIntegerParser_error = 0; 22 | 23 | static const int UnsignedIntegerParser_en_value = 1; 24 | 25 | 26 | #line 15 "include/jsmincpp/deserialize/ParseUInt.rlh" 27 | 28 | int cs; 29 | S pe = p.End( ); 30 | S eof = p.End( ); 31 | 32 | 33 | #line 34 "include/jsmincpp/deserialize/ParseUInt.h" 34 | { 35 | cs = UnsignedIntegerParser_start; 36 | } 37 | 38 | #line 21 "include/jsmincpp/deserialize/ParseUInt.rlh" 39 | 40 | #line 37 "include/jsmincpp/deserialize/ParseUInt.rlh" 41 | 42 | 43 | 44 | #line 45 "include/jsmincpp/deserialize/ParseUInt.h" 45 | { 46 | if ( p == pe ) 47 | goto _test_eof; 48 | switch ( cs ) 49 | { 50 | case 1: 51 | if ( 48 <= (*p) && (*p) <= 57 ) 52 | goto tr0; 53 | goto st0; 54 | tr2: 55 | #line 34 "include/jsmincpp/deserialize/ParseUInt.rlh" 56 | { return false; } 57 | goto st0; 58 | #line 59 "include/jsmincpp/deserialize/ParseUInt.h" 59 | st0: 60 | cs = 0; 61 | goto _out; 62 | tr0: 63 | #line 25 "include/jsmincpp/deserialize/ParseUInt.rlh" 64 | { 65 | if( !jsmincpp::IntegerOverflowControl< T >::Mult( data, 10 ) ) 66 | return false; 67 | if( !jsmincpp::IntegerOverflowControl< T >::Summ( data, ( *p - '0' ) ) ) 68 | return false; 69 | } 70 | goto st2; 71 | st2: 72 | if ( ++p == pe ) 73 | goto _test_eof2; 74 | case 2: 75 | #line 76 "include/jsmincpp/deserialize/ParseUInt.h" 76 | switch( (*p) ) { 77 | case 44: goto tr3; 78 | case 93: goto tr3; 79 | case 125: goto tr3; 80 | } 81 | if ( 48 <= (*p) && (*p) <= 57 ) 82 | goto tr0; 83 | goto tr2; 84 | tr3: 85 | #line 33 "include/jsmincpp/deserialize/ParseUInt.rlh" 86 | { return true; } 87 | goto st3; 88 | st3: 89 | if ( ++p == pe ) 90 | goto _test_eof3; 91 | case 3: 92 | #line 93 "include/jsmincpp/deserialize/ParseUInt.h" 93 | goto tr2; 94 | } 95 | _test_eof2: cs = 2; goto _test_eof; 96 | _test_eof3: cs = 3; goto _test_eof; 97 | 98 | _test_eof: {} 99 | if ( p == eof ) 100 | { 101 | switch ( cs ) { 102 | case 2: 103 | #line 34 "include/jsmincpp/deserialize/ParseUInt.rlh" 104 | { return false; } 105 | break; 106 | #line 107 "include/jsmincpp/deserialize/ParseUInt.h" 107 | } 108 | } 109 | 110 | _out: {} 111 | } 112 | 113 | #line 40 "include/jsmincpp/deserialize/ParseUInt.rlh" 114 | 115 | return false; 116 | } 117 | 118 | } // namespace deserialize 119 | 120 | } // namespace jsmincpp 121 | 122 | #endif // INCLUDE_DESERIALIZE_PARSEUINT_H_ 123 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/ParseUInt.rlh: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_PARSEUINT_H_ 2 | #define INCLUDE_DESERIALIZE_PARSEUINT_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace deserialize { 9 | 10 | template < typename T, typename S > 11 | bool ParseUInt( T &data, S &p ) { 12 | 13 | %% machine UnsignedIntegerParser; 14 | %% write data; 15 | 16 | int cs; 17 | S pe = p.End( ); 18 | S eof = p.End( ); 19 | 20 | %% write init; 21 | %%{ 22 | 23 | digit1_9 = [0-9]; 24 | 25 | action PUSH_INT { 26 | if( !jsmincpp::IntegerOverflowControl< T >::Mult( data, 10 ) ) 27 | return false; 28 | if( !jsmincpp::IntegerOverflowControl< T >::Summ( data, ( *p - '0' ) ) ) 29 | return false; 30 | } 31 | int = digit1_9+ $PUSH_INT; 32 | 33 | action RET_NUM { return true; } 34 | action RET_ERROR { return false; } 35 | value := int ( ',' | '}' | ']' ) $RET_NUM $!RET_ERROR; 36 | 37 | }%% 38 | 39 | %% write exec; 40 | 41 | return false; 42 | } 43 | 44 | } // namespace deserialize 45 | 46 | } // namespace jsmincpp 47 | 48 | #endif // INCLUDE_DESERIALIZE_PARSEUINT_H_ 49 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/STLSupport/Deque.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_STLSUPPORT_DEQUE_H_ 2 | #define INCLUDE_DESERIALIZE_STLSUPPORT_DEQUE_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace deserialize { 10 | 11 | template < typename T, typename A > 12 | struct DequeTraits { 13 | typedef T value_type; 14 | 15 | static void Push( std::deque < T, A > &a, value_type &d ) { 16 | a.push_back( d ); 17 | } 18 | }; 19 | 20 | template < uint32_t Hash, typename T, typename A > 21 | STLContinerParam < Hash, std::deque < T, A >, DequeTraits < T, A > > MakeParam( 22 | std::deque < T, A > ¶m ) { 23 | return STLContinerParam < Hash, std::deque < T, A >, DequeTraits < T, A > >( 24 | param ); 25 | } 26 | 27 | } //namespace deserialize 28 | 29 | } // namespace jsmincpp 30 | 31 | #endif /* INCLUDE_DESERIALIZE_STLSUPPORT_DEQUE_H_ */ 32 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/STLSupport/ForwardList.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_STLSUPPORT_FORWARDLIST_H_ 2 | #define INCLUDE_DESERIALIZE_STLSUPPORT_FORWARDLIST_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace deserialize { 10 | 11 | template < typename T, typename A > 12 | struct ForwardListTraits { 13 | typedef T value_type; 14 | 15 | static void Push( std::forward_list < T, A > &a, value_type &d ) { 16 | a.push_front( d ); 17 | } 18 | }; 19 | 20 | template < uint32_t Hash, typename T, typename A > 21 | STLContinerParam < Hash, std::forward_list < T, A >, ForwardListTraits < T, A > > MakeParam( 22 | std::forward_list < T, A > ¶m ) { 23 | return STLContinerParam < Hash, std::forward_list < T, A >, 24 | ForwardListTraits < T, A > >( param ); 25 | } 26 | 27 | } //namespace deserialize 28 | 29 | } // namespace jsmincpp 30 | 31 | #endif /* INCLUDE_DESERIALIZE_STLSUPPORT_FORWARDLIST_H_ */ 32 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/STLSupport/List.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_STLSUPPORT_LIST_H_ 2 | #define INCLUDE_DESERIALIZE_STLSUPPORT_LIST_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace deserialize { 10 | 11 | template < typename T, typename A > 12 | struct ListTraits { 13 | typedef T value_type; 14 | 15 | static void Push( std::list < T, A > &a, value_type &d ) { 16 | a.push_back( d ); 17 | } 18 | }; 19 | 20 | template < uint32_t Hash, typename T, typename A > 21 | STLContinerParam < Hash, std::list < T, A >, ListTraits < T, A > > MakeParam( 22 | std::list < T, A > ¶m ) { 23 | return STLContinerParam < Hash, std::list < T, A >, ListTraits < T, A > >( 24 | param ); 25 | } 26 | 27 | } //namespace deserialize 28 | 29 | } // namespace jsmincpp 30 | 31 | #endif /* INCLUDE_DESERIALIZE_STLSUPPORT_LIST_H_ */ 32 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/STLSupport/Map.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_STLSUPPORT_MAP_H_ 2 | #define INCLUDE_DESERIALIZE_STLSUPPORT_MAP_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace deserialize { 10 | 11 | template < typename K, typename T > 12 | struct Pair { 13 | K _key; 14 | T _value; 15 | 16 | Pair( ) 17 | : 18 | _key( ), 19 | _value( ) { 20 | } 21 | 22 | template < typename D > 23 | bool Deserialize( D &deserializer ) { 24 | return deserializer( 25 | MakeParam < Crc32( "key" ) >( _key ), 26 | MakeParam < Crc32( "value" ) >( _value ) 27 | ); 28 | } 29 | 30 | std::pair< K, T > GetPair( ) { 31 | return std::make_pair( _key, _value ); 32 | } 33 | 34 | }; 35 | 36 | template < typename K, typename T, typename C, typename A > 37 | struct MapTraits { 38 | typedef Pair< K, T > value_type; 39 | 40 | static void Push( std::map < K, T, C, A > &a, value_type &d ) { 41 | a.insert( d.GetPair( ) ); 42 | } 43 | }; 44 | 45 | template < typename K, typename T, typename C, typename A > 46 | struct MultiMapTraits { 47 | typedef Pair< K, T > value_type; 48 | 49 | static void Push( std::multimap < K, T, C, A > &a, T &d ) { 50 | a.insert( d.GetPair( ) ); 51 | } 52 | }; 53 | 54 | template < uint32_t Hash, typename K, typename T, typename C, typename A > 55 | STLContinerParam < Hash, std::map < K, T, C, A >, MapTraits < K, T, C, A > > MakeParam( 56 | std::map < K, T, C, A > ¶m ) { 57 | return STLContinerParam < Hash, std::map < K, T, C, A >, 58 | MapTraits < K, T, C, A > >( param ); 59 | } 60 | 61 | template < uint32_t Hash, typename K, typename T, typename C, typename A > 62 | STLContinerParam < Hash, std::multimap < K, T, C, A >, 63 | MultiMapTraits < K, T, C, A > > MakeParam( 64 | std::multimap < K, T, C, A > ¶m ) { 65 | return STLContinerParam < Hash, std::multimap < K, T, C, A >, 66 | MultiMapTraits < K, T, C, A > >( param ); 67 | } 68 | 69 | } //namespace deserialize 70 | 71 | } // namespace jsmincpp 72 | 73 | #endif /* INCLUDE_DESERIALIZE_STLSUPPORT_MAP_H_ */ 74 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/STLSupport/ParseStdString.h: -------------------------------------------------------------------------------- 1 | 2 | #line 1 "include/jsmincpp/deserialize/STLSupport/ParseStdString.rlh" 3 | #ifndef INCLUDE_DESERIALIZE_STLSUPPORT_PARSESTDSTRING_H_ 4 | #define INCLUDE_DESERIALIZE_STLSUPPORT_PARSESTDSTRING_H_ 5 | 6 | #include 7 | 8 | namespace jsmincpp { 9 | 10 | namespace deserialize { 11 | 12 | template < typename T, typename S > 13 | bool ParseStdString( T &data, S &p ) { 14 | 15 | 16 | #line 14 "include/jsmincpp/deserialize/STLSupport/ParseStdString.rlh" 17 | 18 | #line 19 "include/jsmincpp/deserialize/STLSupport/ParseStdString.h" 19 | static const int StdStringParser_start = 1; 20 | static const int StdStringParser_first_final = 3; 21 | static const int StdStringParser_error = 0; 22 | 23 | static const int StdStringParser_en_main = 1; 24 | 25 | 26 | #line 15 "include/jsmincpp/deserialize/STLSupport/ParseStdString.rlh" 27 | 28 | int cs; 29 | S pe = p.End( ); 30 | S eof = p.End( ); 31 | 32 | 33 | #line 34 "include/jsmincpp/deserialize/STLSupport/ParseStdString.h" 34 | { 35 | cs = StdStringParser_start; 36 | } 37 | 38 | #line 21 "include/jsmincpp/deserialize/STLSupport/ParseStdString.rlh" 39 | 40 | #line 28 "include/jsmincpp/deserialize/STLSupport/ParseStdString.rlh" 41 | 42 | 43 | 44 | #line 45 "include/jsmincpp/deserialize/STLSupport/ParseStdString.h" 45 | { 46 | if ( p == pe ) 47 | goto _test_eof; 48 | switch ( cs ) 49 | { 50 | case 1: 51 | if ( (*p) == 34 ) 52 | goto st2; 53 | goto tr0; 54 | tr0: 55 | #line 24 "include/jsmincpp/deserialize/STLSupport/ParseStdString.rlh" 56 | { return false; } 57 | goto st0; 58 | #line 59 "include/jsmincpp/deserialize/STLSupport/ParseStdString.h" 59 | st0: 60 | cs = 0; 61 | goto _out; 62 | tr2: 63 | #line 23 "include/jsmincpp/deserialize/STLSupport/ParseStdString.rlh" 64 | { data += *p; } 65 | goto st2; 66 | st2: 67 | if ( ++p == pe ) 68 | goto _test_eof2; 69 | case 2: 70 | #line 71 "include/jsmincpp/deserialize/STLSupport/ParseStdString.h" 71 | if ( (*p) == 34 ) 72 | goto tr3; 73 | goto tr2; 74 | tr3: 75 | #line 25 "include/jsmincpp/deserialize/STLSupport/ParseStdString.rlh" 76 | { ++p; return true; } 77 | goto st3; 78 | st3: 79 | if ( ++p == pe ) 80 | goto _test_eof3; 81 | case 3: 82 | #line 83 "include/jsmincpp/deserialize/STLSupport/ParseStdString.h" 83 | goto tr0; 84 | } 85 | _test_eof2: cs = 2; goto _test_eof; 86 | _test_eof3: cs = 3; goto _test_eof; 87 | 88 | _test_eof: {} 89 | if ( p == eof ) 90 | { 91 | switch ( cs ) { 92 | case 1: 93 | case 2: 94 | #line 24 "include/jsmincpp/deserialize/STLSupport/ParseStdString.rlh" 95 | { return false; } 96 | break; 97 | #line 98 "include/jsmincpp/deserialize/STLSupport/ParseStdString.h" 98 | } 99 | } 100 | 101 | _out: {} 102 | } 103 | 104 | #line 31 "include/jsmincpp/deserialize/STLSupport/ParseStdString.rlh" 105 | 106 | return false; 107 | } 108 | 109 | } // namespace deserialize 110 | 111 | } // namespace jsmincpp 112 | 113 | #endif /* INCLUDE_DESERIALIZE_STLSUPPORT_PARSESTDSTRING_H_ */ 114 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/STLSupport/ParseStdString.rlh: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_STLSUPPORT_PARSESTDSTRING_H_ 2 | #define INCLUDE_DESERIALIZE_STLSUPPORT_PARSESTDSTRING_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace deserialize { 9 | 10 | template < typename T, typename S > 11 | bool ParseStdString( T &data, S &p ) { 12 | 13 | %% machine StdStringParser; 14 | %% write data; 15 | 16 | int cs; 17 | S pe = p.End( ); 18 | S eof = p.End( ); 19 | 20 | %% write init; 21 | %%{ 22 | 23 | action PUSH_SYMBOL { data += *p; } 24 | action RETURN_ERROR { return false; } 25 | action RETURN_STRING { ++p; return true; } 26 | main := ( '\"' ( [^"]* ) $PUSH_SYMBOL '\"' ) $!RETURN_ERROR @RETURN_STRING; 27 | 28 | }%% 29 | 30 | %% write exec; 31 | 32 | return false; 33 | } 34 | 35 | } // namespace deserialize 36 | 37 | } // namespace jsmincpp 38 | 39 | #endif /* INCLUDE_DESERIALIZE_STLSUPPORT_PARSESTDSTRING_H_ */ 40 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/STLSupport/STLContiners.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_STLSUPPORT_STLCONTINERS_H_ 2 | #define INCLUDE_DESERIALIZE_STLSUPPORT_STLCONTINERS_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace deserialize { 9 | 10 | template < uint32_t Hash, typename Continer, typename Traits > 11 | class STLContinerParam { 12 | public: 13 | enum { 14 | HASH = Hash 15 | }; 16 | 17 | STLContinerParam( Continer ¶m ) 18 | : 19 | _param( param ) { 20 | } 21 | 22 | template < typename D > 23 | bool Parse( D &deserializer ) { 24 | auto &stream = deserializer.GetStream( ); 25 | 26 | if ( '[' != *stream ) 27 | return false; 28 | ++stream; 29 | 30 | while ( true ) { 31 | typename Traits::value_type tmp; 32 | auto param = MakeParam< 0 >( tmp ); 33 | if ( !param.Parse( deserializer ) ) 34 | return false; 35 | Traits::Push( _param, tmp ); 36 | 37 | if ( ',' == *stream ) { 38 | ++stream; 39 | continue; 40 | } else if ( ']' == *stream ) { 41 | ++stream; 42 | break; 43 | } else 44 | return false; 45 | } 46 | return true; 47 | } 48 | 49 | private: 50 | Continer &_param; 51 | }; 52 | 53 | } //namespace deserialize 54 | 55 | } // namespace jsmincpp 56 | 57 | #endif /* INCLUDE_DESERIALIZE_STLSUPPORT_STLCONTINERS_H_ */ 58 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/STLSupport/Set.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_STLSUPPORT_SET_H_ 2 | #define INCLUDE_DESERIALIZE_STLSUPPORT_SET_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace deserialize { 10 | 11 | template < typename T, typename C, typename A > 12 | struct SetTraits { 13 | typedef T value_type; 14 | 15 | static void Push( std::set < T, C, A > &a, value_type &d ) { 16 | a.insert( d ); 17 | } 18 | }; 19 | 20 | template < typename T, typename C, typename A > 21 | struct MultiSetTraits { 22 | typedef T value_type; 23 | 24 | static void Push( std::multiset < T, C, A > &a, T &d ) { 25 | a.insert( d ); 26 | } 27 | }; 28 | 29 | template < uint32_t Hash, typename T, typename C, typename A > 30 | STLContinerParam < Hash, std::set < T, C, A >, SetTraits < T, C, A > > MakeParam( 31 | std::set < T, C, A > ¶m ) { 32 | return STLContinerParam < Hash, std::set < T, C, A >, SetTraits < T, C, A > >( 33 | param ); 34 | } 35 | 36 | template < uint32_t Hash, typename T, typename C, typename A > 37 | STLContinerParam < Hash, std::multiset < T, C, A >, MultiSetTraits < T, C, A > > MakeParam( 38 | std::multiset < T, C, A > ¶m ) { 39 | return STLContinerParam < Hash, std::multiset < T, C, A >, 40 | MultiSetTraits < T, C, A > >( param ); 41 | } 42 | 43 | } //namespace deserialize 44 | 45 | } // namespace jsmincpp 46 | 47 | #endif /* INCLUDE_DESERIALIZE_STLSUPPORT_SET_H_ */ 48 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/STLSupport/SharedPrtCreator.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_SHAREDPRTCREATOR_H_ 2 | #define INCLUDE_DESERIALIZE_SHAREDPRTCREATOR_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace deserialize { 9 | 10 | struct SharedPrtCreator { 11 | template< typename T > 12 | static std::shared_ptr< T > Create( const T & ) { 13 | return std::make_shared< T >( ); 14 | } 15 | 16 | template< typename T > 17 | static void Delete( std::shared_ptr< T > ) { 18 | } 19 | 20 | }; 21 | 22 | } // namespace deserialize 23 | 24 | } // namespace jsmincpp 25 | 26 | #endif /* INCLUDE_DESERIALIZE_SHAREDPRTCREATOR_H_ */ 27 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/STLSupport/String.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_STLSUPPORT_STRING_H_ 2 | #define INCLUDE_DESERIALIZE_STLSUPPORT_STRING_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace deserialize { 10 | 11 | template < uint32_t Hash, typename _CharT, typename _Traits, typename _Alloc > 12 | class StringParam { 13 | public: 14 | enum { 15 | HASH = Hash 16 | }; 17 | 18 | StringParam( std::basic_string < _CharT, _Traits, _Alloc > ¶m ) 19 | : 20 | _param( param ) { 21 | } 22 | 23 | template < typename D > 24 | bool Parse( D &deserializer ) { 25 | return ParseStdString( _param, deserializer.GetStream( ) ); 26 | } 27 | 28 | private: 29 | std::basic_string < _CharT, _Traits, _Alloc > &_param; 30 | 31 | }; 32 | 33 | template < uint32_t Hash, typename _CharT, typename _Traits, typename _Alloc > 34 | StringParam < Hash, _CharT, _Traits, _Alloc > MakeParam( 35 | std::basic_string < _CharT, _Traits, _Alloc > ¶m ) { 36 | return StringParam < Hash, _CharT, _Traits, _Alloc >( param ); 37 | } 38 | 39 | } //namespace deserialize 40 | 41 | } // namespace jsmincpp 42 | 43 | #endif /* INCLUDE_DESERIALIZE_STLSUPPORT_STRING_H_ */ 44 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/STLSupport/Vector.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_STLSUPPORT_VECTOR_H_ 2 | #define INCLUDE_DESERIALIZE_STLSUPPORT_VECTOR_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace deserialize { 10 | 11 | template < typename T, typename A > 12 | struct VectorTraits { 13 | typedef T value_type; 14 | 15 | static void Push( std::vector < T, A > &a, value_type &d ) { 16 | a.push_back( d ); 17 | } 18 | }; 19 | 20 | template < uint32_t Hash, typename T, typename A > 21 | STLContinerParam < Hash, std::vector < T, A >, VectorTraits < T, A > > MakeParam( 22 | std::vector < T, A > ¶m ) { 23 | return STLContinerParam < Hash, std::vector < T, A >, VectorTraits < T, A > >( 24 | param ); 25 | } 26 | 27 | } //namespace deserialize 28 | 29 | } // namespace jsmincpp 30 | 31 | #endif /* INCLUDE_DESERIALIZE_STLSUPPORT_VECTOR_H_ */ 32 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/SkipEndJSONString.h: -------------------------------------------------------------------------------- 1 | 2 | #line 1 "include/jsmincpp/deserialize/SkipEndJSONString.rlh" 3 | #ifndef INCLUDE_DESERIALIZE_SKIPENDJSONSTRING_H_ 4 | #define INCLUDE_DESERIALIZE_SKIPENDJSONSTRING_H_ 5 | 6 | #include 7 | 8 | namespace jsmincpp { 9 | 10 | namespace deserialize { 11 | 12 | template < typename S > 13 | bool SkipEndJSONString( S &p ) { 14 | 15 | 16 | #line 14 "include/jsmincpp/deserialize/SkipEndJSONString.rlh" 17 | 18 | #line 19 "include/jsmincpp/deserialize/SkipEndJSONString.h" 19 | static const int Skip_end_JSON_string_start = 1; 20 | static const int Skip_end_JSON_string_first_final = 2; 21 | static const int Skip_end_JSON_string_error = 0; 22 | 23 | static const int Skip_end_JSON_string_en_main = 1; 24 | 25 | 26 | #line 15 "include/jsmincpp/deserialize/SkipEndJSONString.rlh" 27 | 28 | int cs; 29 | S pe = p.End( ); 30 | S eof = p.End( ); 31 | 32 | 33 | #line 34 "include/jsmincpp/deserialize/SkipEndJSONString.h" 34 | { 35 | cs = Skip_end_JSON_string_start; 36 | } 37 | 38 | #line 21 "include/jsmincpp/deserialize/SkipEndJSONString.rlh" 39 | 40 | #line 27 "include/jsmincpp/deserialize/SkipEndJSONString.rlh" 41 | 42 | 43 | 44 | #line 45 "include/jsmincpp/deserialize/SkipEndJSONString.h" 45 | { 46 | if ( p == pe ) 47 | goto _test_eof; 48 | switch ( cs ) 49 | { 50 | st1: 51 | if ( ++p == pe ) 52 | goto _test_eof1; 53 | case 1: 54 | switch( (*p) ) { 55 | case 123: goto tr1; 56 | case 125: goto tr2; 57 | } 58 | goto st1; 59 | tr1: 60 | #line 23 "include/jsmincpp/deserialize/SkipEndJSONString.rlh" 61 | { ++p; SkipEndJSONString( p ); } 62 | goto st2; 63 | tr2: 64 | #line 24 "include/jsmincpp/deserialize/SkipEndJSONString.rlh" 65 | { ++p; return false; } 66 | goto st2; 67 | st2: 68 | if ( ++p == pe ) 69 | goto _test_eof2; 70 | case 2: 71 | #line 72 "include/jsmincpp/deserialize/SkipEndJSONString.h" 72 | goto st0; 73 | st0: 74 | cs = 0; 75 | goto _out; 76 | } 77 | _test_eof1: cs = 1; goto _test_eof; 78 | _test_eof2: cs = 2; goto _test_eof; 79 | 80 | _test_eof: {} 81 | _out: {} 82 | } 83 | 84 | #line 30 "include/jsmincpp/deserialize/SkipEndJSONString.rlh" 85 | 86 | return false; 87 | } 88 | 89 | } // namespace deserialize 90 | 91 | } // namespace jsmincpp 92 | 93 | #endif // INCLUDE_DESERIALIZE_SKIPENDJSONSTRING_H_ 94 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/SkipEndJSONString.rlh: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_SKIPENDJSONSTRING_H_ 2 | #define INCLUDE_DESERIALIZE_SKIPENDJSONSTRING_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace deserialize { 9 | 10 | template < typename S > 11 | bool SkipEndJSONString( S &p ) { 12 | 13 | %% machine Skip_end_JSON_string; 14 | %% write data; 15 | 16 | int cs; 17 | S pe = p.End( ); 18 | S eof = p.End( ); 19 | 20 | %% write init; 21 | %%{ 22 | 23 | action NEW_LEVEL { ++p; SkipEndJSONString( p ); } 24 | action RETURN { ++p; return false; } 25 | main := [^{}]* ( '{' $NEW_LEVEL | '}' $RETURN ); 26 | 27 | }%% 28 | 29 | %% write exec; 30 | 31 | return false; 32 | } 33 | 34 | } // namespace deserialize 35 | 36 | } // namespace jsmincpp 37 | 38 | #endif // INCLUDE_DESERIALIZE_SKIPENDJSONSTRING_H_ 39 | -------------------------------------------------------------------------------- /include/jsmincpp/deserialize/Tuple.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_DESERIALIZE_TUPLE_H_ 2 | #define INCLUDE_DESERIALIZE_TUPLE_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace deserialize { 9 | 10 | /* 11 | * class Tuple 12 | * From http://habrahabr.ru/post/228031/ 13 | */ 14 | 15 | template < typename ... Args > 16 | struct Tuple; 17 | 18 | template < typename Head, typename ... Tail > 19 | struct Tuple < Head, Tail... > : Tuple < Tail... > { 20 | typedef Head Value_t; 21 | typedef Tuple < Tail... > Base_t; 22 | enum { 23 | SIZE = sizeof(Head), 24 | MAX_SIZE = ( ( SIZE > Base_t::SIZE ) ? 25 | SIZE : Base_t::SIZE ) 26 | }; 27 | 28 | Tuple( Head &h, Tail &... tail ) 29 | : 30 | Tuple < Tail... >( tail... ), 31 | _head( h ) 32 | { 33 | } 34 | 35 | Head &_head; 36 | 37 | template < typename D > 38 | bool operator()( uint32_t hash, D &deserializer ) { 39 | if ( Head::HASH == hash ) 40 | return _head.Parse( deserializer ); 41 | else 42 | return Base_t::operator()( hash, deserializer ); 43 | } 44 | 45 | }; 46 | 47 | template < > 48 | struct Tuple < > 49 | { 50 | enum { 51 | SIZE = 0, 52 | MAX_SIZE = 0 53 | }; 54 | 55 | template < typename D > 56 | bool operator()( uint32_t hash, D &deserializer ) { 57 | return false; 58 | } 59 | }; 60 | 61 | template < typename ... Args > 62 | Tuple < Args ... > MakeTuple( Args &... args ) { 63 | return Tuple < Args ... >( args ... ); 64 | } 65 | 66 | template < typename ... Args > 67 | struct ObjectsList; 68 | 69 | template < typename Head, typename ... Tail > 70 | struct ObjectsList < Head, Tail... > : ObjectsList < Tail... > { 71 | typedef ObjectsList < Tail... > Base_t; 72 | enum { 73 | SIZE = sizeof(typename Head::Object_t), 74 | MAX_SIZE = ( ( SIZE > Base_t::SIZE ) ? 75 | SIZE : Base_t::SIZE ) 76 | }; 77 | 78 | ObjectsList( ) 79 | : 80 | Base_t( ) 81 | { 82 | } 83 | 84 | template < typename D, typename H > 85 | bool operator()( uint32_t hash, D &deserializer, H &handler ) { 86 | if ( Head::HASH == hash ) { 87 | bool ret = true; 88 | auto t = 89 | deserializer.GetCreator( ).Create( typename Head::Object_t( ) ); 90 | if( nullptr == t ) 91 | return false; 92 | 93 | ret &= t->Deserialize( deserializer ); 94 | if ( ret && ( '}' == *( deserializer.GetStream( ) ) ) ) 95 | ret &= handler( t ); 96 | ++deserializer.GetStream( ); 97 | 98 | if( !ret ) 99 | deserializer.GetCreator( ).Delete( t ); 100 | 101 | return ret; 102 | } else 103 | return Base_t::operator()( hash, deserializer, handler ); 104 | } 105 | 106 | }; 107 | 108 | template < > 109 | struct ObjectsList < > 110 | { 111 | enum { 112 | SIZE = 0, 113 | MAX_SIZE = 0 114 | }; 115 | 116 | template < typename D, typename H > 117 | bool operator()( uint32_t hash, D &deserializer, H &handler ) { 118 | return false; 119 | } 120 | }; 121 | 122 | } // namespace deserialize 123 | 124 | } // namespace jsmincpp 125 | 126 | #endif // INCLUDE_DESERIALIZE_TUPLE_H_ 127 | -------------------------------------------------------------------------------- /include/jsmincpp/serialize/JSONSerializer.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SERIALIZE_JSONSERIALIZER_H_ 2 | #define INCLUDE_SERIALIZE_JSONSERIALIZER_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace jsmincpp { 10 | 11 | namespace serialize { 12 | 13 | // 14 | // struct SerializeHandler { 15 | // bool operator()( const char *str, uint32_t len ); 16 | // bool SerializeEnd( ); 17 | // }; 18 | // 19 | // typedef jsmincpp::serialize::Serializer < 20 | // jsmincpp::serialize::JSONSerializer < SerializeHandler > 21 | // > Serializer_t; 22 | // 23 | 24 | template < typename H > 25 | class JSONSerializer { 26 | public: 27 | JSONSerializer( H &handler ) 28 | : 29 | _handler( handler ), 30 | _firstItem( true ), 31 | _firstArrayItem( true ), 32 | _insertedCounter( 0 ) { 33 | } 34 | 35 | bool ParamName( 36 | const char *name, 37 | uint32_t len ) { 38 | 39 | if ( !_firstItem ) 40 | if( !PrintSeparator( ) ) return false; 41 | _firstItem = false; 42 | 43 | const char b [ ] = { "\"" }; 44 | const char e [ ] = { "\":" }; 45 | return _handler( b, sizeof( b ) - 1 ) 46 | && _handler( name, len ) 47 | && _handler( e, sizeof( e ) - 1 ); 48 | } 49 | bool ArrayStart( ) { 50 | _firstArrayItem = true; 51 | 52 | const char str [ ] = { "[" }; 53 | return _handler( str, sizeof( str ) - 1 ); 54 | } 55 | bool ArrayItem( ) { 56 | 57 | if ( !_firstArrayItem ) 58 | if( !PrintSeparator( ) ) return false; 59 | _firstArrayItem = false; 60 | 61 | return true; 62 | } 63 | bool ArrayEnd( ) { 64 | const char str [ ] = { "]" }; 65 | return _handler( str, sizeof( str ) - 1 ); 66 | } 67 | bool ObjectStart( ) { 68 | ++_insertedCounter; 69 | _firstItem = true; 70 | 71 | const char str [ ] = { "{" }; 72 | return _handler( str, sizeof( str ) - 1 ); 73 | } 74 | bool ObjectEnd( ) { 75 | const char str [ ] = { "}" }; 76 | if( !_handler( str, sizeof( str ) - 1 ) ) 77 | return false; 78 | if ( --_insertedCounter == 0 ) 79 | return _handler.SerializeEnd( ); 80 | return true; 81 | } 82 | 83 | H & GetHandler( ) { 84 | return _handler; 85 | } 86 | 87 | private: 88 | H &_handler; 89 | 90 | bool _firstItem; 91 | bool _firstArrayItem; 92 | uint32_t _insertedCounter; 93 | 94 | bool PrintSeparator( ) { 95 | const char str [ ] = { "," }; 96 | return _handler( str, sizeof( str ) - 1 ); 97 | } 98 | }; 99 | 100 | 101 | 102 | template < typename S > 103 | bool operator <<( S &serializer, bool val ) { 104 | const char t [ ] = { "true" }; 105 | const char f [ ] = { "false" }; 106 | if ( val ) 107 | return serializer.GetHandler( )( t, sizeof( t ) - 1 ); 108 | else 109 | return serializer.GetHandler( )( f, sizeof( f ) - 1 ); 110 | } 111 | 112 | 113 | 114 | template < typename S > 115 | bool operator <<( S &serializer, int8_t val ) { 116 | const char f [ ] = "%" PRId8; 117 | char buffer [ 5 ]; 118 | uint32_t len = ::sprintf( buffer, f, val ); 119 | return ( len > 0 ) && serializer.GetHandler( )( buffer, len ); 120 | } 121 | 122 | template < typename S > 123 | bool operator <<( S &serializer, int16_t val ) { 124 | const char f [ ] = "%" PRId16; 125 | char buffer [ 8 ]; 126 | uint32_t len = ::sprintf( buffer, f, val ); 127 | return ( len > 0 ) && serializer.GetHandler( )( buffer, len ); 128 | } 129 | 130 | template < typename S > 131 | bool operator <<( S &serializer, int32_t val ) { 132 | const char f [ ] = "%" PRId32; 133 | char buffer [ 11 ]; 134 | uint32_t len = ::sprintf( buffer, f, val ); 135 | return ( len > 0 ) && serializer.GetHandler( )( buffer, len ); 136 | } 137 | 138 | template < typename S > 139 | bool operator <<( S &serializer, int64_t val ) { 140 | const char f [ ] = "%" PRId64; 141 | char buffer [ 20 ]; 142 | uint32_t len = ::sprintf( buffer, f, val ); 143 | return ( len > 0 ) && serializer.GetHandler( )( buffer, len ); 144 | } 145 | 146 | 147 | 148 | template < typename S > 149 | bool operator <<( S &serializer, uint8_t val ) { 150 | const char f [ ] = "%" PRIu8; 151 | char buffer [ 5 ]; 152 | uint32_t len = ::sprintf( buffer, f, val ); 153 | return ( len > 0 ) && serializer.GetHandler( )( buffer, len ); 154 | } 155 | 156 | template < typename S > 157 | bool operator <<( S &serializer, uint16_t val ) { 158 | const char f [ ] = "%" PRIu16; 159 | char buffer [ 8 ]; 160 | uint32_t len = ::sprintf( buffer, f, val ); 161 | return ( len > 0 ) && serializer.GetHandler( )( buffer, len ); 162 | } 163 | 164 | template < typename S > 165 | bool operator <<( S &serializer, uint32_t val ) { 166 | const char f [ ] = "%" PRIu32; 167 | char buffer [ 11 ]; 168 | uint32_t len = ::sprintf( buffer, f, val ); 169 | return ( len > 0 ) && serializer.GetHandler( )( buffer, len ); 170 | } 171 | 172 | template < typename S > 173 | bool operator <<( S &serializer, uint64_t val ) { 174 | const char f [ ] = "%" PRIu64; 175 | char buffer [ 20 ]; 176 | uint32_t len = ::sprintf( buffer, f, val ); 177 | return ( len > 0 ) && serializer.GetHandler( )( buffer, len ); 178 | } 179 | 180 | 181 | 182 | template < typename S > 183 | bool operator <<( S &serializer, float val ) { 184 | const char f [ ] = "%f"; 185 | char buffer [ 20 ]; 186 | uint32_t len = ::sprintf( buffer, f, val ); 187 | return ( len > 0 ) && serializer.GetHandler( )( buffer, len ); 188 | return true; 189 | } 190 | 191 | template < typename S > 192 | bool operator <<( S &serializer, double val ) { 193 | const char f [ ] = "%lf"; 194 | char buffer [ 20 ]; 195 | uint32_t len = ::sprintf( buffer, f, val ); 196 | return ( len > 0 ) && serializer.GetHandler( )( buffer, len ); 197 | return true; 198 | } 199 | 200 | } // namespace serialize 201 | 202 | } // namespace jsmincpp 203 | 204 | #endif // INCLUDE_SERIALIZE_JSONSERIALIZER_H_ 205 | -------------------------------------------------------------------------------- /include/jsmincpp/serialize/STLSupport/Deque.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SERIALIZE_STLSUPPORT_DEQUE_H_ 2 | #define INCLUDE_SERIALIZE_STLSUPPORT_DEQUE_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace serialize { 9 | 10 | template < typename S, typename T, typename A > 11 | bool operator <<( S &serializer, const std::deque < T, A > &data ) { 12 | if ( !serializer.ArrayStart( ) ) 13 | return false; 14 | 15 | typename std::deque < T, A >::size_type length = data.size( ); 16 | 17 | for ( typename std::deque < T, A >::size_type i = 0; i < length; ++i ) { 18 | if ( !serializer.ArrayItem( ) 19 | || !serializer.Serialize( data [ i ] ) ) 20 | return false; 21 | } 22 | 23 | return serializer.ArrayEnd( ); 24 | } 25 | 26 | } // namespace serialize 27 | 28 | } // namespace jsmincpp 29 | 30 | #endif // INCLUDE_SERIALIZE_STLSUPPORT_DEQUE_H_ 31 | -------------------------------------------------------------------------------- /include/jsmincpp/serialize/STLSupport/ForwardList.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SERIALIZE_STLSUPPORT_FORWARDLIST_H_ 2 | #define INCLUDE_SERIALIZE_STLSUPPORT_FORWARDLIST_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace serialize { 10 | 11 | template < typename S, typename T, typename A > 12 | bool operator <<( S &serializer, const std::forward_list < T, A > &data ) { 13 | if ( !serializer.ArrayStart( ) ) 14 | return false; 15 | 16 | std::find_if_not( data.begin( ), data.end( ), 17 | [ &serializer ] ( const T &elem ) { 18 | return serializer.ArrayItem( ) 19 | && serializer.Serialize( elem ); 20 | } ); 21 | 22 | return serializer.ArrayEnd( ); 23 | } 24 | 25 | } // namespace serialize 26 | 27 | } // namespace jsmincpp 28 | 29 | #endif // INCLUDE_SERIALIZE_STLSUPPORT_FORWARDLIST_H_ 30 | -------------------------------------------------------------------------------- /include/jsmincpp/serialize/STLSupport/List.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SERIALIZE_STLSUPPORT_LIST_H_ 2 | #define INCLUDE_SERIALIZE_STLSUPPORT_LIST_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace serialize { 10 | 11 | template < typename S, typename T, typename A > 12 | bool operator <<( S &serializer, const std::list < T, A > &data ) { 13 | if ( !serializer.ArrayStart( ) ) 14 | return false; 15 | 16 | std::find_if_not( data.begin( ), data.end( ), 17 | [ &serializer ] ( const T &elem ) { 18 | return serializer.ArrayItem( ) 19 | && serializer.Serialize( elem ); 20 | } ); 21 | 22 | return serializer.ArrayEnd( ); 23 | } 24 | 25 | } // namespace serialize 26 | 27 | } // namespace jsmincpp 28 | 29 | #endif // INCLUDE_SERIALIZE_STLSUPPORT_LIST_H_ 30 | -------------------------------------------------------------------------------- /include/jsmincpp/serialize/STLSupport/Map.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SERIALIZE_STLSUPPORT_MAP_H_ 2 | #define INCLUDE_SERIALIZE_STLSUPPORT_MAP_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | namespace jsmincpp { 11 | 12 | namespace serialize { 13 | 14 | template < typename K, typename T > 15 | struct Pair : public Serialized { 16 | const K &key; 17 | const T &value; 18 | 19 | Pair( const K &k, const T &v ) 20 | : 21 | key( k ), 22 | value( v ) { 23 | } 24 | 25 | template < typename S > 26 | bool Serialize( S &serializer ) const { 27 | SERIALIZE( key ); 28 | SERIALIZE( value ); 29 | return true; 30 | } 31 | 32 | }; 33 | 34 | template < typename S, typename K, typename T, typename C, typename A > 35 | bool operator <<( S &serializer, const std::map < K, T, C, A > &data ) { 36 | if ( !serializer.ArrayStart( ) ) 37 | return false; 38 | 39 | std::find_if_not( data.begin( ), data.end( ), 40 | [ &serializer ] ( const std::pair< K, T > &elem ) { 41 | Pair< K, T > p( elem.first, elem.second ); 42 | return serializer.ArrayItem( ) 43 | && serializer.Serialize( p ); 44 | } ); 45 | 46 | return serializer.ArrayEnd( ); 47 | } 48 | 49 | } // namespace serialize 50 | 51 | } // namespace jsmincpp 52 | 53 | #endif // INCLUDE_SERIALIZE_STLSUPPORT_MAP_H_ 54 | -------------------------------------------------------------------------------- /include/jsmincpp/serialize/STLSupport/Set.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SERIALIZE_STLSUPPORT_SET_H_ 2 | #define INCLUDE_SERIALIZE_STLSUPPORT_SET_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace serialize { 10 | 11 | template < typename S, typename T, typename C, typename A > 12 | bool operator <<( S &serializer, const std::set < T, C, A > &data ) { 13 | if ( !serializer.ArrayStart( ) ) 14 | return false; 15 | 16 | std::find_if_not( data.begin( ), data.end( ), 17 | [ &serializer ] ( const T &elem ) { 18 | return ( serializer.ArrayItem( ) 19 | && serializer.Serialize( elem ) ); 20 | } ); 21 | 22 | return serializer.ArrayEnd( ); 23 | } 24 | 25 | } // namespace serialize 26 | 27 | } // namespace jsmincpp 28 | 29 | #endif // INCLUDE_SERIALIZE_STLSUPPORT_SET_H_ 30 | -------------------------------------------------------------------------------- /include/jsmincpp/serialize/STLSupport/String.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SERIALIZE_STLSUPPORT_STRING_H_ 2 | #define INCLUDE_SERIALIZE_STLSUPPORT_STRING_H_ 3 | 4 | #include 5 | #include 6 | 7 | namespace jsmincpp { 8 | 9 | namespace serialize { 10 | 11 | template < typename S, typename C, typename T, typename A > 12 | bool operator <<( S &serializer, const std::basic_string < C, T, A > &data ) { 13 | const char q [ ] = { "\"" }; 14 | 15 | if ( !serializer.GetHandler( )( q, sizeof( q ) - 1 ) 16 | || !serializer.GetHandler( )( data.c_str( ), data.length( ) ) ) 17 | return false; 18 | return serializer.GetHandler( )( q, sizeof( q ) - 1 ); 19 | } 20 | 21 | } // namespace serialize 22 | 23 | } // namespace jsmincpp 24 | 25 | #endif // INCLUDE_SERIALIZE_STLSUPPORT_STRING_H_ 26 | -------------------------------------------------------------------------------- /include/jsmincpp/serialize/STLSupport/Vector.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SERIALIZE_STLSUPPORT_VECTOR_H_ 2 | #define INCLUDE_SERIALIZE_STLSUPPORT_VECTOR_H_ 3 | 4 | #include 5 | 6 | namespace jsmincpp { 7 | 8 | namespace serialize { 9 | 10 | template < typename S, typename T, typename A > 11 | bool operator <<( S &serializer, const std::vector < T, A > &data ) { 12 | if ( !serializer.ArrayStart( ) ) 13 | return false; 14 | 15 | typename std::vector < T, A >::size_type length = data.size( ); 16 | 17 | for ( typename std::vector < T, A >::size_type i = 0; i < length; ++i ) { 18 | if ( !serializer.ArrayItem( ) 19 | || !serializer.Serialize( data [ i ] ) ) 20 | return false; 21 | } 22 | 23 | return serializer.ArrayEnd( ); 24 | } 25 | 26 | } // namespace serialize 27 | 28 | } // namespace jsmincpp 29 | 30 | #endif // INCLUDE_SERIALIZE_STLSUPPORT_VECTOR_H_ 31 | -------------------------------------------------------------------------------- /include/jsmincpp/serialize/Serializer.h: -------------------------------------------------------------------------------- 1 | #ifndef INCLUDE_SERIALIZE_SERIALIZER_H_ 2 | #define INCLUDE_SERIALIZE_SERIALIZER_H_ 3 | 4 | #include 5 | 6 | #define SERIALIZE( x ) ( { \ 7 | const char name[ ] = { #x }; \ 8 | if ( !serializer.Serialize( name, x ) ) return false; \ 9 | } ) 10 | 11 | namespace jsmincpp { 12 | 13 | namespace serialize { 14 | 15 | class Serialized { 16 | }; 17 | 18 | template < typename S > 19 | class AbstractSerialized : public Serialized { 20 | public: 21 | virtual ~AbstractSerialized( ) { 22 | } 23 | virtual bool Serialize( S & ) const = 0; 24 | }; 25 | 26 | template < typename S > 27 | class Serializer : public S { 28 | public: 29 | template < typename H > 30 | Serializer( H &handler ) 31 | : 32 | S( handler ) { 33 | } 34 | 35 | template < typename T > 36 | bool Serialize( const T &data ) { 37 | return Serialize( data, 38 | Int2Type < IsRelated < Serialized, T >::value >( ) ); 39 | } 40 | template < typename T > 41 | bool Serialize( const T &data, const Int2Type < false > & ) { 42 | return *this << data; 43 | } 44 | template < typename T > 45 | bool Serialize( const T &data, const Int2Type < true > & ) { 46 | return ( this->ObjectStart( ) ) 47 | && ( data.Serialize( *this ) ) 48 | && ( this->ObjectEnd( ) ); 49 | } 50 | bool Serialize( AbstractSerialized < Serializer < S > > *data ) { 51 | return ( this->ObjectStart( ) ) 52 | && ( data->Serialize( *this ) ) 53 | && ( this->ObjectEnd( ) ); 54 | } 55 | template < typename T, uint32_t Nums > 56 | bool Serialize( const char (&name) [ Nums ], const T &data ) { 57 | return ( this->ParamName( name, Nums - 1 ) ) 58 | && ( Serialize( data, 59 | Int2Type < IsRelated < Serialized, T >::value >( ) ) ); 60 | } 61 | template < typename T, uint32_t Nums1, uint32_t Nums2 > 62 | bool Serialize( const char (&name) [ Nums1 ], T (&data) [ Nums2 ] ) { 63 | if ( ( !this->ParamName( name, Nums1 - 1 ) ) 64 | || ( !this->ArrayStart( ) ) ) 65 | return false; 66 | for ( uint32_t i = 0; i < Nums2; ++i ) { 67 | if ( ( !this->ArrayItem( ) ) 68 | || ( !Serialize( data [ i ], 69 | Int2Type < IsRelated < Serialized, T >::value >( ) ) ) ) 70 | return false; 71 | } 72 | return this->ArrayEnd( ); 73 | } 74 | 75 | private: 76 | 77 | }; 78 | 79 | } // namespace serialize 80 | 81 | } // namespace jsmincpp 82 | 83 | #endif // INCLUDE_SERIALIZE_SERIALIZER_H_ 84 | -------------------------------------------------------------------------------- /install-sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # install - install a program, script, or datafile 3 | 4 | scriptversion=2011-11-20.07; # UTC 5 | 6 | # This originates from X11R5 (mit/util/scripts/install.sh), which was 7 | # later released in X11R6 (xc/config/util/install.sh) with the 8 | # following copyright and license. 9 | # 10 | # Copyright (C) 1994 X Consortium 11 | # 12 | # Permission is hereby granted, free of charge, to any person obtaining a copy 13 | # of this software and associated documentation files (the "Software"), to 14 | # deal in the Software without restriction, including without limitation the 15 | # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 16 | # sell copies of the Software, and to permit persons to whom the Software is 17 | # furnished to do so, subject to the following conditions: 18 | # 19 | # The above copyright notice and this permission notice shall be included in 20 | # all copies or substantial portions of the Software. 21 | # 22 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 26 | # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- 27 | # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 | # 29 | # Except as contained in this notice, the name of the X Consortium shall not 30 | # be used in advertising or otherwise to promote the sale, use or other deal- 31 | # ings in this Software without prior written authorization from the X Consor- 32 | # tium. 33 | # 34 | # 35 | # FSF changes to this file are in the public domain. 36 | # 37 | # Calling this script install-sh is preferred over install.sh, to prevent 38 | # 'make' implicit rules from creating a file called install from it 39 | # when there is no Makefile. 40 | # 41 | # This script is compatible with the BSD install script, but was written 42 | # from scratch. 43 | 44 | nl=' 45 | ' 46 | IFS=" "" $nl" 47 | 48 | # set DOITPROG to echo to test this script 49 | 50 | # Don't use :- since 4.3BSD and earlier shells don't like it. 51 | doit=${DOITPROG-} 52 | if test -z "$doit"; then 53 | doit_exec=exec 54 | else 55 | doit_exec=$doit 56 | fi 57 | 58 | # Put in absolute file names if you don't have them in your path; 59 | # or use environment vars. 60 | 61 | chgrpprog=${CHGRPPROG-chgrp} 62 | chmodprog=${CHMODPROG-chmod} 63 | chownprog=${CHOWNPROG-chown} 64 | cmpprog=${CMPPROG-cmp} 65 | cpprog=${CPPROG-cp} 66 | mkdirprog=${MKDIRPROG-mkdir} 67 | mvprog=${MVPROG-mv} 68 | rmprog=${RMPROG-rm} 69 | stripprog=${STRIPPROG-strip} 70 | 71 | posix_glob='?' 72 | initialize_posix_glob=' 73 | test "$posix_glob" != "?" || { 74 | if (set -f) 2>/dev/null; then 75 | posix_glob= 76 | else 77 | posix_glob=: 78 | fi 79 | } 80 | ' 81 | 82 | posix_mkdir= 83 | 84 | # Desired mode of installed file. 85 | mode=0755 86 | 87 | chgrpcmd= 88 | chmodcmd=$chmodprog 89 | chowncmd= 90 | mvcmd=$mvprog 91 | rmcmd="$rmprog -f" 92 | stripcmd= 93 | 94 | src= 95 | dst= 96 | dir_arg= 97 | dst_arg= 98 | 99 | copy_on_change=false 100 | no_target_directory= 101 | 102 | usage="\ 103 | Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE 104 | or: $0 [OPTION]... SRCFILES... DIRECTORY 105 | or: $0 [OPTION]... -t DIRECTORY SRCFILES... 106 | or: $0 [OPTION]... -d DIRECTORIES... 107 | 108 | In the 1st form, copy SRCFILE to DSTFILE. 109 | In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. 110 | In the 4th, create DIRECTORIES. 111 | 112 | Options: 113 | --help display this help and exit. 114 | --version display version info and exit. 115 | 116 | -c (ignored) 117 | -C install only if different (preserve the last data modification time) 118 | -d create directories instead of installing files. 119 | -g GROUP $chgrpprog installed files to GROUP. 120 | -m MODE $chmodprog installed files to MODE. 121 | -o USER $chownprog installed files to USER. 122 | -s $stripprog installed files. 123 | -t DIRECTORY install into DIRECTORY. 124 | -T report an error if DSTFILE is a directory. 125 | 126 | Environment variables override the default commands: 127 | CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG 128 | RMPROG STRIPPROG 129 | " 130 | 131 | while test $# -ne 0; do 132 | case $1 in 133 | -c) ;; 134 | 135 | -C) copy_on_change=true;; 136 | 137 | -d) dir_arg=true;; 138 | 139 | -g) chgrpcmd="$chgrpprog $2" 140 | shift;; 141 | 142 | --help) echo "$usage"; exit $?;; 143 | 144 | -m) mode=$2 145 | case $mode in 146 | *' '* | *' '* | *' 147 | '* | *'*'* | *'?'* | *'['*) 148 | echo "$0: invalid mode: $mode" >&2 149 | exit 1;; 150 | esac 151 | shift;; 152 | 153 | -o) chowncmd="$chownprog $2" 154 | shift;; 155 | 156 | -s) stripcmd=$stripprog;; 157 | 158 | -t) dst_arg=$2 159 | # Protect names problematic for 'test' and other utilities. 160 | case $dst_arg in 161 | -* | [=\(\)!]) dst_arg=./$dst_arg;; 162 | esac 163 | shift;; 164 | 165 | -T) no_target_directory=true;; 166 | 167 | --version) echo "$0 $scriptversion"; exit $?;; 168 | 169 | --) shift 170 | break;; 171 | 172 | -*) echo "$0: invalid option: $1" >&2 173 | exit 1;; 174 | 175 | *) break;; 176 | esac 177 | shift 178 | done 179 | 180 | if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then 181 | # When -d is used, all remaining arguments are directories to create. 182 | # When -t is used, the destination is already specified. 183 | # Otherwise, the last argument is the destination. Remove it from $@. 184 | for arg 185 | do 186 | if test -n "$dst_arg"; then 187 | # $@ is not empty: it contains at least $arg. 188 | set fnord "$@" "$dst_arg" 189 | shift # fnord 190 | fi 191 | shift # arg 192 | dst_arg=$arg 193 | # Protect names problematic for 'test' and other utilities. 194 | case $dst_arg in 195 | -* | [=\(\)!]) dst_arg=./$dst_arg;; 196 | esac 197 | done 198 | fi 199 | 200 | if test $# -eq 0; then 201 | if test -z "$dir_arg"; then 202 | echo "$0: no input file specified." >&2 203 | exit 1 204 | fi 205 | # It's OK to call 'install-sh -d' without argument. 206 | # This can happen when creating conditional directories. 207 | exit 0 208 | fi 209 | 210 | if test -z "$dir_arg"; then 211 | do_exit='(exit $ret); exit $ret' 212 | trap "ret=129; $do_exit" 1 213 | trap "ret=130; $do_exit" 2 214 | trap "ret=141; $do_exit" 13 215 | trap "ret=143; $do_exit" 15 216 | 217 | # Set umask so as not to create temps with too-generous modes. 218 | # However, 'strip' requires both read and write access to temps. 219 | case $mode in 220 | # Optimize common cases. 221 | *644) cp_umask=133;; 222 | *755) cp_umask=22;; 223 | 224 | *[0-7]) 225 | if test -z "$stripcmd"; then 226 | u_plus_rw= 227 | else 228 | u_plus_rw='% 200' 229 | fi 230 | cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;; 231 | *) 232 | if test -z "$stripcmd"; then 233 | u_plus_rw= 234 | else 235 | u_plus_rw=,u+rw 236 | fi 237 | cp_umask=$mode$u_plus_rw;; 238 | esac 239 | fi 240 | 241 | for src 242 | do 243 | # Protect names problematic for 'test' and other utilities. 244 | case $src in 245 | -* | [=\(\)!]) src=./$src;; 246 | esac 247 | 248 | if test -n "$dir_arg"; then 249 | dst=$src 250 | dstdir=$dst 251 | test -d "$dstdir" 252 | dstdir_status=$? 253 | else 254 | 255 | # Waiting for this to be detected by the "$cpprog $src $dsttmp" command 256 | # might cause directories to be created, which would be especially bad 257 | # if $src (and thus $dsttmp) contains '*'. 258 | if test ! -f "$src" && test ! -d "$src"; then 259 | echo "$0: $src does not exist." >&2 260 | exit 1 261 | fi 262 | 263 | if test -z "$dst_arg"; then 264 | echo "$0: no destination specified." >&2 265 | exit 1 266 | fi 267 | dst=$dst_arg 268 | 269 | # If destination is a directory, append the input filename; won't work 270 | # if double slashes aren't ignored. 271 | if test -d "$dst"; then 272 | if test -n "$no_target_directory"; then 273 | echo "$0: $dst_arg: Is a directory" >&2 274 | exit 1 275 | fi 276 | dstdir=$dst 277 | dst=$dstdir/`basename "$src"` 278 | dstdir_status=0 279 | else 280 | # Prefer dirname, but fall back on a substitute if dirname fails. 281 | dstdir=` 282 | (dirname "$dst") 2>/dev/null || 283 | expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \ 284 | X"$dst" : 'X\(//\)[^/]' \| \ 285 | X"$dst" : 'X\(//\)$' \| \ 286 | X"$dst" : 'X\(/\)' \| . 2>/dev/null || 287 | echo X"$dst" | 288 | sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ 289 | s//\1/ 290 | q 291 | } 292 | /^X\(\/\/\)[^/].*/{ 293 | s//\1/ 294 | q 295 | } 296 | /^X\(\/\/\)$/{ 297 | s//\1/ 298 | q 299 | } 300 | /^X\(\/\).*/{ 301 | s//\1/ 302 | q 303 | } 304 | s/.*/./; q' 305 | ` 306 | 307 | test -d "$dstdir" 308 | dstdir_status=$? 309 | fi 310 | fi 311 | 312 | obsolete_mkdir_used=false 313 | 314 | if test $dstdir_status != 0; then 315 | case $posix_mkdir in 316 | '') 317 | # Create intermediate dirs using mode 755 as modified by the umask. 318 | # This is like FreeBSD 'install' as of 1997-10-28. 319 | umask=`umask` 320 | case $stripcmd.$umask in 321 | # Optimize common cases. 322 | *[2367][2367]) mkdir_umask=$umask;; 323 | .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;; 324 | 325 | *[0-7]) 326 | mkdir_umask=`expr $umask + 22 \ 327 | - $umask % 100 % 40 + $umask % 20 \ 328 | - $umask % 10 % 4 + $umask % 2 329 | `;; 330 | *) mkdir_umask=$umask,go-w;; 331 | esac 332 | 333 | # With -d, create the new directory with the user-specified mode. 334 | # Otherwise, rely on $mkdir_umask. 335 | if test -n "$dir_arg"; then 336 | mkdir_mode=-m$mode 337 | else 338 | mkdir_mode= 339 | fi 340 | 341 | posix_mkdir=false 342 | case $umask in 343 | *[123567][0-7][0-7]) 344 | # POSIX mkdir -p sets u+wx bits regardless of umask, which 345 | # is incompatible with FreeBSD 'install' when (umask & 300) != 0. 346 | ;; 347 | *) 348 | tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$ 349 | trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0 350 | 351 | if (umask $mkdir_umask && 352 | exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1 353 | then 354 | if test -z "$dir_arg" || { 355 | # Check for POSIX incompatibilities with -m. 356 | # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or 357 | # other-writable bit of parent directory when it shouldn't. 358 | # FreeBSD 6.1 mkdir -m -p sets mode of existing directory. 359 | ls_ld_tmpdir=`ls -ld "$tmpdir"` 360 | case $ls_ld_tmpdir in 361 | d????-?r-*) different_mode=700;; 362 | d????-?--*) different_mode=755;; 363 | *) false;; 364 | esac && 365 | $mkdirprog -m$different_mode -p -- "$tmpdir" && { 366 | ls_ld_tmpdir_1=`ls -ld "$tmpdir"` 367 | test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1" 368 | } 369 | } 370 | then posix_mkdir=: 371 | fi 372 | rmdir "$tmpdir/d" "$tmpdir" 373 | else 374 | # Remove any dirs left behind by ancient mkdir implementations. 375 | rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null 376 | fi 377 | trap '' 0;; 378 | esac;; 379 | esac 380 | 381 | if 382 | $posix_mkdir && ( 383 | umask $mkdir_umask && 384 | $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir" 385 | ) 386 | then : 387 | else 388 | 389 | # The umask is ridiculous, or mkdir does not conform to POSIX, 390 | # or it failed possibly due to a race condition. Create the 391 | # directory the slow way, step by step, checking for races as we go. 392 | 393 | case $dstdir in 394 | /*) prefix='/';; 395 | [-=\(\)!]*) prefix='./';; 396 | *) prefix='';; 397 | esac 398 | 399 | eval "$initialize_posix_glob" 400 | 401 | oIFS=$IFS 402 | IFS=/ 403 | $posix_glob set -f 404 | set fnord $dstdir 405 | shift 406 | $posix_glob set +f 407 | IFS=$oIFS 408 | 409 | prefixes= 410 | 411 | for d 412 | do 413 | test X"$d" = X && continue 414 | 415 | prefix=$prefix$d 416 | if test -d "$prefix"; then 417 | prefixes= 418 | else 419 | if $posix_mkdir; then 420 | (umask=$mkdir_umask && 421 | $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break 422 | # Don't fail if two instances are running concurrently. 423 | test -d "$prefix" || exit 1 424 | else 425 | case $prefix in 426 | *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;; 427 | *) qprefix=$prefix;; 428 | esac 429 | prefixes="$prefixes '$qprefix'" 430 | fi 431 | fi 432 | prefix=$prefix/ 433 | done 434 | 435 | if test -n "$prefixes"; then 436 | # Don't fail if two instances are running concurrently. 437 | (umask $mkdir_umask && 438 | eval "\$doit_exec \$mkdirprog $prefixes") || 439 | test -d "$dstdir" || exit 1 440 | obsolete_mkdir_used=true 441 | fi 442 | fi 443 | fi 444 | 445 | if test -n "$dir_arg"; then 446 | { test -z "$chowncmd" || $doit $chowncmd "$dst"; } && 447 | { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } && 448 | { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false || 449 | test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1 450 | else 451 | 452 | # Make a couple of temp file names in the proper directory. 453 | dsttmp=$dstdir/_inst.$$_ 454 | rmtmp=$dstdir/_rm.$$_ 455 | 456 | # Trap to clean up those temp files at exit. 457 | trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 458 | 459 | # Copy the file name to the temp name. 460 | (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") && 461 | 462 | # and set any options; do chmod last to preserve setuid bits. 463 | # 464 | # If any of these fail, we abort the whole thing. If we want to 465 | # ignore errors from any of these, just make sure not to ignore 466 | # errors from the above "$doit $cpprog $src $dsttmp" command. 467 | # 468 | { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } && 469 | { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } && 470 | { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } && 471 | { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } && 472 | 473 | # If -C, don't bother to copy if it wouldn't change the file. 474 | if $copy_on_change && 475 | old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` && 476 | new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` && 477 | 478 | eval "$initialize_posix_glob" && 479 | $posix_glob set -f && 480 | set X $old && old=:$2:$4:$5:$6 && 481 | set X $new && new=:$2:$4:$5:$6 && 482 | $posix_glob set +f && 483 | 484 | test "$old" = "$new" && 485 | $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1 486 | then 487 | rm -f "$dsttmp" 488 | else 489 | # Rename the file to the real destination. 490 | $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null || 491 | 492 | # The rename failed, perhaps because mv can't rename something else 493 | # to itself, or perhaps because mv is so ancient that it does not 494 | # support -f. 495 | { 496 | # Now remove or move aside any old file at destination location. 497 | # We try this two ways since rm can't unlink itself on some 498 | # systems and the destination file might be busy for other 499 | # reasons. In this case, the final cleanup might fail but the new 500 | # file should still install successfully. 501 | { 502 | test ! -f "$dst" || 503 | $doit $rmcmd -f "$dst" 2>/dev/null || 504 | { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null && 505 | { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; } 506 | } || 507 | { echo "$0: cannot unlink or rename $dst" >&2 508 | (exit 1); exit 1 509 | } 510 | } && 511 | 512 | # Now rename the file to the real destination. 513 | $doit $mvcmd "$dsttmp" "$dst" 514 | } 515 | fi || exit 1 516 | 517 | trap '' 0 518 | fi 519 | done 520 | 521 | # Local variables: 522 | # eval: (add-hook 'write-file-hooks 'time-stamp) 523 | # time-stamp-start: "scriptversion=" 524 | # time-stamp-format: "%:y-%02m-%02d.%02H" 525 | # time-stamp-time-zone: "UTC" 526 | # time-stamp-end: "; # UTC" 527 | # End: 528 | -------------------------------------------------------------------------------- /missing: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Common wrapper for a few potentially missing GNU programs. 3 | 4 | scriptversion=2013-10-28.13; # UTC 5 | 6 | # Copyright (C) 1996-2013 Free Software Foundation, Inc. 7 | # Originally written by Fran,cois Pinard , 1996. 8 | 9 | # This program is free software; you can redistribute it and/or modify 10 | # it under the terms of the GNU General Public License as published by 11 | # the Free Software Foundation; either version 2, or (at your option) 12 | # any later version. 13 | 14 | # This program is distributed in the hope that it will be useful, 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | # GNU General Public License for more details. 18 | 19 | # You should have received a copy of the GNU General Public License 20 | # along with this program. If not, see . 21 | 22 | # As a special exception to the GNU General Public License, if you 23 | # distribute this file as part of a program that contains a 24 | # configuration script generated by Autoconf, you may include it under 25 | # the same distribution terms that you use for the rest of that program. 26 | 27 | if test $# -eq 0; then 28 | echo 1>&2 "Try '$0 --help' for more information" 29 | exit 1 30 | fi 31 | 32 | case $1 in 33 | 34 | --is-lightweight) 35 | # Used by our autoconf macros to check whether the available missing 36 | # script is modern enough. 37 | exit 0 38 | ;; 39 | 40 | --run) 41 | # Back-compat with the calling convention used by older automake. 42 | shift 43 | ;; 44 | 45 | -h|--h|--he|--hel|--help) 46 | echo "\ 47 | $0 [OPTION]... PROGRAM [ARGUMENT]... 48 | 49 | Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due 50 | to PROGRAM being missing or too old. 51 | 52 | Options: 53 | -h, --help display this help and exit 54 | -v, --version output version information and exit 55 | 56 | Supported PROGRAM values: 57 | aclocal autoconf autoheader autom4te automake makeinfo 58 | bison yacc flex lex help2man 59 | 60 | Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and 61 | 'g' are ignored when checking the name. 62 | 63 | Send bug reports to ." 64 | exit $? 65 | ;; 66 | 67 | -v|--v|--ve|--ver|--vers|--versi|--versio|--version) 68 | echo "missing $scriptversion (GNU Automake)" 69 | exit $? 70 | ;; 71 | 72 | -*) 73 | echo 1>&2 "$0: unknown '$1' option" 74 | echo 1>&2 "Try '$0 --help' for more information" 75 | exit 1 76 | ;; 77 | 78 | esac 79 | 80 | # Run the given program, remember its exit status. 81 | "$@"; st=$? 82 | 83 | # If it succeeded, we are done. 84 | test $st -eq 0 && exit 0 85 | 86 | # Also exit now if we it failed (or wasn't found), and '--version' was 87 | # passed; such an option is passed most likely to detect whether the 88 | # program is present and works. 89 | case $2 in --version|--help) exit $st;; esac 90 | 91 | # Exit code 63 means version mismatch. This often happens when the user 92 | # tries to use an ancient version of a tool on a file that requires a 93 | # minimum version. 94 | if test $st -eq 63; then 95 | msg="probably too old" 96 | elif test $st -eq 127; then 97 | # Program was missing. 98 | msg="missing on your system" 99 | else 100 | # Program was found and executed, but failed. Give up. 101 | exit $st 102 | fi 103 | 104 | perl_URL=http://www.perl.org/ 105 | flex_URL=http://flex.sourceforge.net/ 106 | gnu_software_URL=http://www.gnu.org/software 107 | 108 | program_details () 109 | { 110 | case $1 in 111 | aclocal|automake) 112 | echo "The '$1' program is part of the GNU Automake package:" 113 | echo "<$gnu_software_URL/automake>" 114 | echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:" 115 | echo "<$gnu_software_URL/autoconf>" 116 | echo "<$gnu_software_URL/m4/>" 117 | echo "<$perl_URL>" 118 | ;; 119 | autoconf|autom4te|autoheader) 120 | echo "The '$1' program is part of the GNU Autoconf package:" 121 | echo "<$gnu_software_URL/autoconf/>" 122 | echo "It also requires GNU m4 and Perl in order to run:" 123 | echo "<$gnu_software_URL/m4/>" 124 | echo "<$perl_URL>" 125 | ;; 126 | esac 127 | } 128 | 129 | give_advice () 130 | { 131 | # Normalize program name to check for. 132 | normalized_program=`echo "$1" | sed ' 133 | s/^gnu-//; t 134 | s/^gnu//; t 135 | s/^g//; t'` 136 | 137 | printf '%s\n' "'$1' is $msg." 138 | 139 | configure_deps="'configure.ac' or m4 files included by 'configure.ac'" 140 | case $normalized_program in 141 | autoconf*) 142 | echo "You should only need it if you modified 'configure.ac'," 143 | echo "or m4 files included by it." 144 | program_details 'autoconf' 145 | ;; 146 | autoheader*) 147 | echo "You should only need it if you modified 'acconfig.h' or" 148 | echo "$configure_deps." 149 | program_details 'autoheader' 150 | ;; 151 | automake*) 152 | echo "You should only need it if you modified 'Makefile.am' or" 153 | echo "$configure_deps." 154 | program_details 'automake' 155 | ;; 156 | aclocal*) 157 | echo "You should only need it if you modified 'acinclude.m4' or" 158 | echo "$configure_deps." 159 | program_details 'aclocal' 160 | ;; 161 | autom4te*) 162 | echo "You might have modified some maintainer files that require" 163 | echo "the 'autom4te' program to be rebuilt." 164 | program_details 'autom4te' 165 | ;; 166 | bison*|yacc*) 167 | echo "You should only need it if you modified a '.y' file." 168 | echo "You may want to install the GNU Bison package:" 169 | echo "<$gnu_software_URL/bison/>" 170 | ;; 171 | lex*|flex*) 172 | echo "You should only need it if you modified a '.l' file." 173 | echo "You may want to install the Fast Lexical Analyzer package:" 174 | echo "<$flex_URL>" 175 | ;; 176 | help2man*) 177 | echo "You should only need it if you modified a dependency" \ 178 | "of a man page." 179 | echo "You may want to install the GNU Help2man package:" 180 | echo "<$gnu_software_URL/help2man/>" 181 | ;; 182 | makeinfo*) 183 | echo "You should only need it if you modified a '.texi' file, or" 184 | echo "any other file indirectly affecting the aspect of the manual." 185 | echo "You might want to install the Texinfo package:" 186 | echo "<$gnu_software_URL/texinfo/>" 187 | echo "The spurious makeinfo call might also be the consequence of" 188 | echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might" 189 | echo "want to install GNU make:" 190 | echo "<$gnu_software_URL/make/>" 191 | ;; 192 | *) 193 | echo "You might have modified some files without having the proper" 194 | echo "tools for further handling them. Check the 'README' file, it" 195 | echo "often tells you about the needed prerequisites for installing" 196 | echo "this package. You may also peek at any GNU archive site, in" 197 | echo "case some other package contains this missing '$1' program." 198 | ;; 199 | esac 200 | } 201 | 202 | give_advice "$1" | sed -e '1s/^/WARNING: /' \ 203 | -e '2,$s/^/ /' >&2 204 | 205 | # Propagate the correct exit status (expected to be 127 for a program 206 | # not found, 63 for a program that failed due to version mismatch). 207 | exit $st 208 | 209 | # Local variables: 210 | # eval: (add-hook 'write-file-hooks 'time-stamp) 211 | # time-stamp-start: "scriptversion=" 212 | # time-stamp-format: "%:y-%02m-%02d.%02H" 213 | # time-stamp-time-zone: "UTC" 214 | # time-stamp-end: "; # UTC" 215 | # End: 216 | -------------------------------------------------------------------------------- /test-driver: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # test-driver - basic testsuite driver script. 3 | 4 | scriptversion=2013-07-13.22; # UTC 5 | 6 | # Copyright (C) 2011-2013 Free Software Foundation, Inc. 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation; either version 2, or (at your option) 11 | # any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program. If not, see . 20 | 21 | # As a special exception to the GNU General Public License, if you 22 | # distribute this file as part of a program that contains a 23 | # configuration script generated by Autoconf, you may include it under 24 | # the same distribution terms that you use for the rest of that program. 25 | 26 | # This file is maintained in Automake, please report 27 | # bugs to or send patches to 28 | # . 29 | 30 | # Make unconditional expansion of undefined variables an error. This 31 | # helps a lot in preventing typo-related bugs. 32 | set -u 33 | 34 | usage_error () 35 | { 36 | echo "$0: $*" >&2 37 | print_usage >&2 38 | exit 2 39 | } 40 | 41 | print_usage () 42 | { 43 | cat <$log_file 2>&1 108 | estatus=$? 109 | if test $enable_hard_errors = no && test $estatus -eq 99; then 110 | estatus=1 111 | fi 112 | 113 | case $estatus:$expect_failure in 114 | 0:yes) col=$red res=XPASS recheck=yes gcopy=yes;; 115 | 0:*) col=$grn res=PASS recheck=no gcopy=no;; 116 | 77:*) col=$blu res=SKIP recheck=no gcopy=yes;; 117 | 99:*) col=$mgn res=ERROR recheck=yes gcopy=yes;; 118 | *:yes) col=$lgn res=XFAIL recheck=no gcopy=yes;; 119 | *:*) col=$red res=FAIL recheck=yes gcopy=yes;; 120 | esac 121 | 122 | # Report outcome to console. 123 | echo "${col}${res}${std}: $test_name" 124 | 125 | # Register the test result, and other relevant metadata. 126 | echo ":test-result: $res" > $trs_file 127 | echo ":global-test-result: $res" >> $trs_file 128 | echo ":recheck: $recheck" >> $trs_file 129 | echo ":copy-in-global-log: $gcopy" >> $trs_file 130 | 131 | # Local Variables: 132 | # mode: shell-script 133 | # sh-indentation: 2 134 | # eval: (add-hook 'write-file-hooks 'time-stamp) 135 | # time-stamp-start: "scriptversion=" 136 | # time-stamp-format: "%:y-%02m-%02d.%02H" 137 | # time-stamp-time-zone: "UTC" 138 | # time-stamp-end: "; # UTC" 139 | # End: 140 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | check_PROGRAMS = test_jsmincpp 2 | 3 | AM_CPPFLAGS = -I$(top_srcdir)/include -O3 -std=c++11 4 | AM_LDFLAGS = -O3 5 | LIBS += -lstdc++ -lm -lgmock -lgtest -lgtest_main -lpthread 6 | 7 | TESTS = $(check_PROGRAMS) 8 | 9 | test_jsmincpp_SOURCES = \ 10 | MockSerializeHandler.h \ 11 | SymbolStream.h \ 12 | test_GetNameHash.cpp \ 13 | test_JSONParser.cpp \ 14 | test_JSONSerialiser.cpp \ 15 | test_ParseBool.cpp \ 16 | test_ParseFloat.cpp \ 17 | test_ParseInteger.cpp \ 18 | test_SaticString.cpp \ 19 | test_SkipEndJSONString.cpp \ 20 | test_STLContainersDeserialise.cpp \ 21 | test_STLContainersSerialise.cpp 22 | -------------------------------------------------------------------------------- /tests/MockSerializeHandler.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTS_MOCKSERIALIZEHANDLER_H_ 2 | #define TESTS_MOCKSERIALIZEHANDLER_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | class MockSerializeHandler { 10 | public: 11 | bool operator()( const char *str, uint32_t len ) { 12 | std::cout << str; 13 | return handle( str ); 14 | } 15 | MOCK_METHOD1(handle, bool( const char * )); 16 | 17 | bool SerializeEnd( ) { 18 | std::cout << std::endl; 19 | return handle( ); 20 | } 21 | MOCK_METHOD0(handle, bool( )); 22 | }; 23 | 24 | typedef jsmincpp::serialize::Serializer < 25 | jsmincpp::serialize::JSONSerializer < MockSerializeHandler > 26 | > Serializer_t; 27 | 28 | #endif /* TESTS_MOCKSERIALIZEHANDLER_H_ */ 29 | -------------------------------------------------------------------------------- /tests/SymbolStream.h: -------------------------------------------------------------------------------- 1 | #ifndef TESTS_SYMBOLSTREAM_H_ 2 | #define TESTS_SYMBOLSTREAM_H_ 3 | 4 | #include 5 | #include 6 | 7 | class SymbolStream { 8 | public: 9 | SymbolStream( const char *str ) 10 | : 11 | m_eof( false ), 12 | m_counter( 0 ), 13 | p_str( str ), 14 | m_len( ::strlen( p_str ) ) { 15 | } 16 | 17 | SymbolStream End( ) { 18 | SymbolStream end( nullptr ); 19 | end.m_eof = true; 20 | return end; 21 | } 22 | 23 | char operator*( ) { 24 | char sym = p_str [ m_counter ]; 25 | // std::cout 26 | // << "Pos: " << m_counter << ", MaxPos: " 27 | // << m_len - 1 << ", Get symbol: " << sym << std::endl; 28 | return sym; 29 | } 30 | 31 | SymbolStream & operator++( ) { 32 | if ( m_counter++ == m_len - 1 ) 33 | m_eof = true; 34 | return *this; 35 | } 36 | 37 | bool operator==( const SymbolStream &other ) { 38 | bool res = m_eof == other.m_eof; 39 | return res; 40 | } 41 | 42 | private: 43 | bool m_eof; 44 | uint32_t m_counter; 45 | const char *p_str; 46 | uint32_t m_len; 47 | 48 | }; 49 | 50 | #endif /* TESTS_SYMBOLSTREAM_H_ */ 51 | -------------------------------------------------------------------------------- /tests/test_GetNameHash.cpp: -------------------------------------------------------------------------------- 1 | #undef GTEST_LANG_CXX11 2 | 3 | #include "SymbolStream.h" 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace std; 16 | using namespace jsmincpp::deserialize; 17 | using ::testing::ElementsAreArray; 18 | using ::testing::ElementsAre; 19 | using ::testing::InSequence; 20 | using ::testing::TypedEq; 21 | using ::testing::StrEq; 22 | using ::testing::Return; 23 | using ::testing::Invoke; 24 | using ::testing::_; 25 | using ::testing::An; 26 | 27 | TEST (GetNameHashTest, test1) { 28 | const char *name = "\"Object\":{\"First\":"; 29 | SymbolStream s( name ); 30 | CRC32Hash h; 31 | 32 | ASSERT_TRUE( GetNameHash( s, h ) ); 33 | ASSERT_EQ( Crc32( "Object" ), h.operator unsigned int( ) ); 34 | } 35 | 36 | TEST (GetNameHashTest, test2) { 37 | const char *name = "\"First\":20.01,\"Second\""; 38 | SymbolStream s( name ); 39 | CRC32Hash h; 40 | 41 | ASSERT_TRUE( GetNameHash( s, h ) ); 42 | ASSERT_EQ( Crc32( "First" ), h.operator unsigned int( ) ); 43 | } 44 | 45 | TEST (GetNameHashTest, test3) { 46 | const char *name = "Object\":{"; 47 | SymbolStream s( name ); 48 | CRC32Hash h; 49 | 50 | ASSERT_FALSE( GetNameHash( s, h ) ); 51 | } 52 | 53 | TEST (GetNameHashTest, test4) { 54 | const char *name = "\"Fi-rst\":20.01,\"Second\""; 55 | SymbolStream s( name ); 56 | CRC32Hash h; 57 | 58 | ASSERT_FALSE( GetNameHash( s, h ) ); 59 | } 60 | -------------------------------------------------------------------------------- /tests/test_JSONParser.cpp: -------------------------------------------------------------------------------- 1 | #undef GTEST_LANG_CXX11 2 | 3 | #include "SymbolStream.h" 4 | 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | using namespace std; 15 | using namespace jsmincpp::deserialize; 16 | using ::testing::ElementsAreArray; 17 | using ::testing::ElementsAre; 18 | using ::testing::ContainerEq; 19 | using ::testing::InSequence; 20 | using ::testing::TypedEq; 21 | using ::testing::StrEq; 22 | using ::testing::Return; 23 | using ::testing::Invoke; 24 | using ::testing::_; 25 | using ::testing::An; 26 | 27 | struct NullObject { 28 | template < typename D > 29 | bool Deserialize( D &deserializer ) { 30 | return deserializer( ); 31 | } 32 | }; 33 | 34 | struct NullObjectHandler { 35 | bool _recvData; 36 | 37 | NullObjectHandler( ) 38 | : 39 | _recvData( false ) { 40 | } 41 | 42 | bool operator()( NullObject *param ) { 43 | _recvData = true; 44 | // cout << "Receive \"Object\"" << endl; 45 | return true; 46 | } 47 | }; 48 | 49 | struct Include_t { 50 | float Third; 51 | bool Fourth; 52 | 53 | Include_t( ) 54 | : 55 | Third( 10.01 ), 56 | Fourth( true ) { 57 | } 58 | 59 | template < typename D > 60 | bool Deserialize( D &deserializer ) { 61 | return deserializer( 62 | DESERIALIZE( Third ), 63 | DESERIALIZE( Fourth ) 64 | ); 65 | } 66 | }; 67 | 68 | struct Object { 69 | float First; 70 | bool Second; 71 | Include_t Include; 72 | 73 | Object( ) 74 | : 75 | First( 0.01 ), 76 | Second( false ) { 77 | } 78 | 79 | template < typename D > 80 | bool Deserialize( D &deserializer ) { 81 | return deserializer( 82 | DESERIALIZE( First ), 83 | DESERIALIZE( Second ), 84 | DESERIALIZE( Include ) 85 | ); 86 | } 87 | }; 88 | 89 | struct OtherObject { 90 | float One [ 5 ]; 91 | bool Two [ 5 ]; 92 | 93 | OtherObject( ) 94 | : 95 | One { 110.01e-5f, 110.01e5f, 110.01e-5f, 110.01e5f, 110.01e-5f }, 96 | Two { true, false, true, false, true } { 97 | } 98 | 99 | template < typename D > 100 | bool Deserialize( D &deserializer ) { 101 | return deserializer( 102 | DESERIALIZE( One ), 103 | DESERIALIZE( Two ) 104 | ); 105 | } 106 | }; 107 | 108 | struct Handler { 109 | bool m_recvData1; 110 | bool m_recvData2; 111 | Object &p_obj1; 112 | OtherObject &p_obj2; 113 | 114 | Handler( Object &obj1, OtherObject &obj2 ) 115 | : 116 | m_recvData1( false ), 117 | m_recvData2( false ), 118 | p_obj1( obj1 ), 119 | p_obj2( obj2 ) { 120 | } 121 | 122 | bool operator()( Object *param ) { 123 | m_recvData1 = true; 124 | p_obj1 = *param; 125 | // cout << "Receive \"Object\"" << endl; 126 | return true; 127 | } 128 | 129 | bool operator()( OtherObject *param ) { 130 | m_recvData2 = true; 131 | p_obj2 = *param; 132 | // cout << "Receive \"OtherObject\"" << endl; 133 | return true; 134 | } 135 | }; 136 | 137 | struct SharedPrtHandler { 138 | bool m_recvData1; 139 | bool m_recvData2; 140 | Object &p_obj1; 141 | OtherObject &p_obj2; 142 | 143 | SharedPrtHandler( Object &obj1, OtherObject &obj2 ) 144 | : 145 | m_recvData1( false ), 146 | m_recvData2( false ), 147 | p_obj1( obj1 ), 148 | p_obj2( obj2 ) { 149 | } 150 | 151 | bool operator()( shared_ptr < Object > param ) { 152 | m_recvData1 = true; 153 | p_obj1 = *param; 154 | // cout << "Receive \"Object\"" << endl; 155 | return true; 156 | } 157 | 158 | bool operator()( shared_ptr < OtherObject > param ) { 159 | m_recvData2 = true; 160 | p_obj2 = *param; 161 | // cout << "Receive \"OtherObject\"" << endl; 162 | return true; 163 | } 164 | }; 165 | 166 | int32_t MallocCreator::m_allocateCounter = 0; 167 | 168 | TEST (JSONParserTest, NullObject) { 169 | const char *json = 170 | "{\"NullObject\":null}"; 171 | SymbolStream s( json ); 172 | 173 | NullObjectHandler h; 174 | 175 | typedef ObjectsList < 176 | DESERIALIZEOBJ( NullObject ) 177 | > SerializeList_t; 178 | 179 | Deserializer < 180 | SymbolStream, 181 | SerializeList_t 182 | > d( s ); 183 | 184 | // Deserialization message 185 | ASSERT_TRUE( d.Deserialize( h ) ); 186 | ASSERT_TRUE( h._recvData ); 187 | } 188 | 189 | TEST (JSONParserTest, StaticAllocateMemmory) { 190 | const char *json = 191 | // First message 192 | "{\"Object\":{\"First\":20.01,\"Second\":true,\"Include\":{\"Third\":-20.02,\"Fourth\":false}}}" 193 | // Second message 194 | "{\"OtherObject\":{\"One\":[1.0e10,2.0e10,3.0e10,4.0e10,5.0e10],\"Two\":[false,true,false,true,false]}}"; 195 | SymbolStream s( json ); 196 | 197 | Object obj1; 198 | OtherObject obj2; 199 | Handler h( obj1, obj2 ); 200 | 201 | typedef ObjectsList < 202 | DESERIALIZEOBJ( Object ), 203 | DESERIALIZEOBJ( OtherObject ) 204 | > SerializeList_t; 205 | 206 | Deserializer < 207 | SymbolStream, 208 | SerializeList_t 209 | > d( s ); 210 | 211 | // Deserialization first message 212 | ASSERT_TRUE( d.Deserialize( h ) ); 213 | 214 | ASSERT_TRUE( h.m_recvData1 ); 215 | ASSERT_FALSE( h.m_recvData2 ); 216 | 217 | ASSERT_FLOAT_EQ( h.p_obj1.First, 20.01 ); 218 | ASSERT_TRUE( h.p_obj1.Second ); 219 | ASSERT_FLOAT_EQ( h.p_obj1.Include.Third, -20.02 ); 220 | ASSERT_FALSE( h.p_obj1.Include.Fourth ); 221 | 222 | // Deserialization second message 223 | ASSERT_TRUE( d.Deserialize( h ) ); 224 | 225 | ASSERT_TRUE( h.m_recvData1 ); 226 | ASSERT_TRUE( h.m_recvData2 ); 227 | 228 | float checkOne [ ] = { 1.0e10f, 2.0e10f, 3.0e10f, 4.0e10f, 5.0e10f }; 229 | bool checkTwo [ ] = { false, true, false, true, false }; 230 | ASSERT_THAT( h.p_obj2.One, ContainerEq( checkOne ) ); 231 | ASSERT_THAT( h.p_obj2.Two, ContainerEq( checkTwo ) ); 232 | } 233 | 234 | TEST (JSONParserTest, DynamicAllocateMemmory) { 235 | const char *json = 236 | // First message 237 | "{\"Object\":{\"First\":20.01,\"Second\":true,\"Include\":{\"Third\":-20.02,\"Fourth\":false}}}" 238 | // Second message 239 | "{\"OtherObject\":{\"One\":[1.0e10,2.0e10,3.0e10,4.0e10,5.0e10],\"Two\":[false,true,false,true,false]}}"; 240 | SymbolStream s( json ); 241 | 242 | Object obj1; 243 | OtherObject obj2; 244 | SharedPrtHandler h( obj1, obj2 ); 245 | 246 | typedef ObjectsList < 247 | DESERIALIZEOBJ( Object ), 248 | DESERIALIZEOBJ( OtherObject ) 249 | > SerializeList_t; 250 | 251 | Deserializer < 252 | SymbolStream, 253 | SerializeList_t, 254 | SharedPrtCreator 255 | > d( s ); 256 | 257 | // Deserialization first message 258 | ASSERT_TRUE( d.Deserialize( h ) ); 259 | 260 | ASSERT_TRUE( h.m_recvData1 ); 261 | ASSERT_FALSE( h.m_recvData2 ); 262 | 263 | ASSERT_FLOAT_EQ( h.p_obj1.First, 20.01 ); 264 | ASSERT_TRUE( h.p_obj1.Second ); 265 | ASSERT_FLOAT_EQ( h.p_obj1.Include.Third, -20.02 ); 266 | ASSERT_FALSE( h.p_obj1.Include.Fourth ); 267 | 268 | // Deserialization second message 269 | ASSERT_TRUE( d.Deserialize( h ) ); 270 | 271 | ASSERT_TRUE( h.m_recvData1 ); 272 | ASSERT_TRUE( h.m_recvData2 ); 273 | 274 | float checkOne [ ] = { 1.0e10f, 2.0e10f, 3.0e10f, 4.0e10f, 5.0e10f }; 275 | bool checkTwo [ ] = { false, true, false, true, false }; 276 | ASSERT_THAT( h.p_obj2.One, ContainerEq( checkOne ) ); 277 | ASSERT_THAT( h.p_obj2.Two, ContainerEq( checkTwo ) ); 278 | } 279 | 280 | TEST (JSONParserTest, DeserializeToStaticObject) { 281 | const char *json = 282 | "{\"Second\":true,\"First\":20.01,\"Include\":{\"Third\":-20.02,\"Fourth\":false}}"; 283 | SymbolStream s( json ); 284 | 285 | typedef ObjectsList < 286 | DESERIALIZEOBJ(NullObj) 287 | > SerializeList_t; 288 | 289 | Deserializer < 290 | SymbolStream, 291 | SerializeList_t 292 | > d( s ); 293 | 294 | Object obj; 295 | ASSERT_TRUE( d.Deserialize( &obj ) ); 296 | 297 | ASSERT_FLOAT_EQ( obj.First, 20.01 ); 298 | ASSERT_TRUE( obj.Second ); 299 | ASSERT_FLOAT_EQ( obj.Include.Third, -20.02 ); 300 | ASSERT_FALSE( obj.Include.Fourth ); 301 | } 302 | 303 | TEST (JSONParserTest, DeserializeToDynamicObject) { 304 | const char *json = 305 | "{\"Second\":true,\"First\":20.01,\"Include\":{\"Third\":-20.02,\"Fourth\":false}}"; 306 | SymbolStream s( json ); 307 | 308 | typedef ObjectsList < 309 | DESERIALIZEOBJ(NullObj) 310 | > SerializeList_t; 311 | 312 | Deserializer < 313 | SymbolStream, 314 | SerializeList_t 315 | > d( s ); 316 | 317 | auto obj = make_shared < Object >( ); 318 | 319 | ASSERT_TRUE( d.Deserialize( obj.get( ) ) ); 320 | 321 | ASSERT_FLOAT_EQ( obj->First, 20.01 ); 322 | ASSERT_TRUE( obj->Second ); 323 | ASSERT_FLOAT_EQ( obj->Include.Third, -20.02 ); 324 | ASSERT_FALSE( obj->Include.Fourth ); 325 | } 326 | 327 | TEST (JSONParserTest, ErrorHandlingTest1) { 328 | const char *json = 329 | "{\"Object\":{\"First\":20.01,\"Second\";true,\"Include\":{\"Third\":-20.02,\"Fourth\":false}}}!"; 330 | // ^ -- error symbol. 331 | SymbolStream s( json ); 332 | 333 | Object obj1; 334 | OtherObject obj2; 335 | Handler h( obj1, obj2 ); 336 | 337 | typedef ObjectsList < 338 | DESERIALIZEOBJ( Object ), 339 | DESERIALIZEOBJ( OtherObject ) 340 | > SerializeList_t; 341 | 342 | Deserializer < 343 | SymbolStream, 344 | SerializeList_t, 345 | MallocCreator 346 | > d( s ); 347 | 348 | ASSERT_FALSE( d.Deserialize( h ) ); 349 | ASSERT_FALSE( h.m_recvData1 ); 350 | ASSERT_FALSE( h.m_recvData2 ); 351 | ASSERT_EQ( MallocCreator::m_allocateCounter, 0 ); 352 | ASSERT_EQ( *s, '!' ); 353 | } 354 | 355 | TEST (JSONParserTest, ErrorHandlingTest2) { 356 | const char *json = 357 | "{\"Object\":{\"First\":true,\"Second\":20.01,\"Include\":{\"Third\":-20.02,\"Fourth\":false}}}!"; 358 | // ^ ------------- ^ -- error parameters type. 359 | SymbolStream s( json ); 360 | 361 | Object obj1; 362 | OtherObject obj2; 363 | Handler h( obj1, obj2 ); 364 | 365 | typedef ObjectsList < 366 | DESERIALIZEOBJ( Object ), 367 | DESERIALIZEOBJ( OtherObject ) 368 | > SerializeList_t; 369 | 370 | Deserializer < 371 | SymbolStream, 372 | SerializeList_t, 373 | MallocCreator 374 | > d( s ); 375 | 376 | ASSERT_FALSE( d.Deserialize( h ) ); 377 | ASSERT_FALSE( h.m_recvData1 ); 378 | ASSERT_FALSE( h.m_recvData2 ); 379 | ASSERT_EQ( MallocCreator::m_allocateCounter, 0 ); 380 | ASSERT_EQ( *s, '!' ); 381 | } 382 | 383 | TEST (JSONParserTest, ErrorHandlingTest3) { 384 | const char *json = 385 | "{\"Object\":{\"First\":20.01,\"Second\":true,\"Include\":{\"Third\":-20.02,\"Fourth\":\"red\"}}}!"; 386 | // error parameter type. -- ^ 387 | SymbolStream s( json ); 388 | 389 | Object obj1; 390 | OtherObject obj2; 391 | Handler h( obj1, obj2 ); 392 | 393 | typedef ObjectsList < 394 | DESERIALIZEOBJ( Object ), 395 | DESERIALIZEOBJ( OtherObject ) 396 | > SerializeList_t; 397 | 398 | Deserializer < 399 | SymbolStream, 400 | SerializeList_t, 401 | MallocCreator 402 | > d( s ); 403 | 404 | ASSERT_FALSE( d.Deserialize( h ) ); 405 | ASSERT_FALSE( h.m_recvData1 ); 406 | ASSERT_FALSE( h.m_recvData2 ); 407 | ASSERT_EQ( MallocCreator::m_allocateCounter, 0 ); 408 | ASSERT_EQ( *s, '!' ); 409 | } 410 | 411 | TEST (JSONParserTest, ErrorHandlingTest4) { 412 | const char *json = 413 | // Bad message 414 | "{\"Object\":{\"First\":20.01,\"Second\":true,\"Include\":{\"Third\":-20.02,\"Four\":\"red"; 415 | SymbolStream s( json ); 416 | 417 | Object obj1; 418 | OtherObject obj2; 419 | Handler h( obj1, obj2 ); 420 | 421 | typedef ObjectsList < 422 | DESERIALIZEOBJ( Object ), 423 | DESERIALIZEOBJ( OtherObject ) 424 | > SerializeList_t; 425 | 426 | Deserializer < 427 | SymbolStream, 428 | SerializeList_t, 429 | MallocCreator 430 | > d( s ); 431 | 432 | ASSERT_FALSE( d.Deserialize( h ) ); 433 | ASSERT_FALSE( h.m_recvData1 ); 434 | ASSERT_FALSE( h.m_recvData2 ); 435 | ASSERT_EQ( MallocCreator::m_allocateCounter, 0 ); 436 | } 437 | -------------------------------------------------------------------------------- /tests/test_ParseBool.cpp: -------------------------------------------------------------------------------- 1 | #undef GTEST_LANG_CXX11 2 | 3 | #include "SymbolStream.h" 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace jsmincpp::deserialize; 15 | using namespace std; 16 | using ::testing::ElementsAreArray; 17 | using ::testing::ElementsAre; 18 | using ::testing::InSequence; 19 | using ::testing::TypedEq; 20 | using ::testing::StrEq; 21 | using ::testing::Return; 22 | using ::testing::Invoke; 23 | using ::testing::_; 24 | using ::testing::An; 25 | 26 | TEST (ParseBoolTest, test1) { 27 | const char *str = "true,\"value\":"; 28 | SymbolStream s( str ); 29 | bool data = false; 30 | 31 | ASSERT_TRUE( ParseBool( data, s ) ); 32 | ASSERT_TRUE( data ); 33 | ASSERT_EQ( *s, ',' ); 34 | } 35 | 36 | TEST (ParseBoolTest, test2) { 37 | const char *str = "true],\"Second\":"; 38 | SymbolStream s( str ); 39 | bool data = false; 40 | 41 | ASSERT_TRUE( ParseBool( data, s ) ); 42 | ASSERT_TRUE( data ); 43 | ASSERT_EQ( *s, ']' ); 44 | } 45 | 46 | TEST (ParseBoolTest, test3) { 47 | const char *str = "true}"; 48 | SymbolStream s( str ); 49 | bool data = false; 50 | 51 | ASSERT_TRUE( ParseBool( data, s ) ); 52 | ASSERT_TRUE( data ); 53 | ASSERT_EQ( *s, '}' ); 54 | } 55 | -------------------------------------------------------------------------------- /tests/test_ParseFloat.cpp: -------------------------------------------------------------------------------- 1 | #undef GTEST_LANG_CXX11 2 | 3 | #include "SymbolStream.h" 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace jsmincpp::deserialize; 15 | using namespace std; 16 | using ::testing::ElementsAreArray; 17 | using ::testing::ElementsAre; 18 | using ::testing::InSequence; 19 | using ::testing::TypedEq; 20 | using ::testing::StrEq; 21 | using ::testing::Return; 22 | using ::testing::Invoke; 23 | using ::testing::_; 24 | using ::testing::An; 25 | 26 | TEST (ParseFloatTest, test1) { 27 | const char *str = "10.01,\"First\":"; 28 | SymbolStream s( str ); 29 | float data = 0.0f; 30 | 31 | ASSERT_TRUE( ParseFloat( data, s ) ); 32 | ASSERT_FLOAT_EQ( data, 10.01 ); 33 | ASSERT_EQ( *s, ',' ); 34 | } 35 | 36 | TEST (ParseFloatTest, test2) { 37 | const char *str = "-20.02,"; 38 | SymbolStream s( str ); 39 | float data = 0.0f; 40 | 41 | ASSERT_TRUE( ParseFloat( data, s ) ); 42 | ASSERT_FLOAT_EQ( data, -20.02 ); 43 | ASSERT_EQ( *s, ',' ); 44 | } 45 | -------------------------------------------------------------------------------- /tests/test_ParseInteger.cpp: -------------------------------------------------------------------------------- 1 | #undef GTEST_LANG_CXX11 2 | 3 | #include "SymbolStream.h" 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | using namespace jsmincpp::deserialize; 16 | using namespace std; 17 | using ::testing::ElementsAreArray; 18 | using ::testing::ElementsAre; 19 | using ::testing::InSequence; 20 | using ::testing::TypedEq; 21 | using ::testing::StrEq; 22 | using ::testing::Return; 23 | using ::testing::Invoke; 24 | using ::testing::_; 25 | using ::testing::An; 26 | 27 | TEST (ParseIntegerTest, int8) { 28 | const char *str = "127,-128,"; 29 | SymbolStream s( str ); 30 | int8_t data = 0; 31 | 32 | ASSERT_TRUE( ParseInt( data, s ) ); 33 | ASSERT_EQ( data, 127 ); 34 | ASSERT_EQ( *s, ',' ); 35 | 36 | ++s; 37 | data = 0; 38 | ASSERT_TRUE( ParseInt( data, s ) ); 39 | ASSERT_EQ( data, -128 ); 40 | ASSERT_EQ( *s, ',' ); 41 | } 42 | 43 | TEST (ParseIntegerTest, int8_positive_overflow) { 44 | const char *str = "128,\"value\":"; 45 | SymbolStream s( str ); 46 | int8_t data = 0; 47 | 48 | ASSERT_FALSE( ParseInt( data, s ) ); 49 | } 50 | 51 | TEST (ParseIntegerTest, int8_negative_overflow) { 52 | const char *str = "-129,\"value\":"; 53 | SymbolStream s( str ); 54 | int8_t data = 0; 55 | 56 | ASSERT_FALSE( ParseInt( data, s ) ); 57 | } 58 | 59 | TEST (ParseIntegerTest, int32) { 60 | const char *str = "2147483647,-2147483648,"; 61 | SymbolStream s( str ); 62 | int32_t data = 0; 63 | 64 | ASSERT_TRUE( ParseInt( data, s ) ); 65 | ASSERT_EQ( data, 2147483647 ); 66 | ASSERT_EQ( *s, ',' ); 67 | 68 | ++s; 69 | data = 0; 70 | ASSERT_TRUE( ParseInt( data, s ) ); 71 | ASSERT_EQ( data, -2147483648 ); 72 | ASSERT_EQ( *s, ',' ); 73 | } 74 | 75 | TEST (ParseIntegerTest, int32_positive_overflow) { 76 | const char *str = "2147483648,\"value\":"; 77 | SymbolStream s( str ); 78 | int32_t data = 0; 79 | 80 | ASSERT_FALSE( ParseInt( data, s ) ); 81 | } 82 | 83 | TEST (ParseIntegerTest, int32_negative_overflow) { 84 | const char *str = "-2147483649,\"value\":"; 85 | SymbolStream s( str ); 86 | int32_t data = 0; 87 | 88 | ASSERT_FALSE( ParseInt( data, s ) ); 89 | } 90 | 91 | TEST (ParseIntegerTest, uint8) { 92 | const char *str = "255,\"value\":"; 93 | SymbolStream s( str ); 94 | uint8_t data = 0; 95 | 96 | ASSERT_TRUE( ParseInt( data, s ) ); 97 | ASSERT_EQ( data, 255 ); 98 | ASSERT_EQ( *s, ',' ); 99 | } 100 | 101 | TEST (ParseIntegerTest, uint8_overflow) { 102 | const char *str = "256,\"value\":"; 103 | SymbolStream s( str ); 104 | uint8_t data = 0; 105 | 106 | ASSERT_FALSE( ParseInt( data, s ) ); 107 | } 108 | 109 | TEST (ParseIntegerTest, uint32) { 110 | const char *str = "4294967295,\"value\":"; 111 | SymbolStream s( str ); 112 | uint32_t data = 0; 113 | 114 | ASSERT_TRUE( ParseInt( data, s ) ); 115 | ASSERT_EQ( data, 4294967295U ); 116 | ASSERT_EQ( *s, ',' ); 117 | } 118 | 119 | TEST (ParseIntegerTest, uint32_overflow) { 120 | const char *str = "4294967296,\"value\":"; 121 | SymbolStream s( str ); 122 | uint32_t data = 0; 123 | 124 | ASSERT_FALSE( ParseInt( data, s ) ); 125 | } 126 | 127 | -------------------------------------------------------------------------------- /tests/test_STLContainersDeserialise.cpp: -------------------------------------------------------------------------------- 1 | #undef GTEST_LANG_CXX11 2 | 3 | #include "SymbolStream.h" 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | #include 18 | #include 19 | 20 | #include 21 | 22 | using namespace jsmincpp::deserialize; 23 | using namespace std; 24 | using ::testing::ElementsAreArray; 25 | using ::testing::ElementsAre; 26 | using ::testing::ContainerEq; 27 | using ::testing::InSequence; 28 | using ::testing::TypedEq; 29 | using ::testing::StrEq; 30 | using ::testing::Return; 31 | using ::testing::Invoke; 32 | using ::testing::_; 33 | using ::testing::An; 34 | 35 | struct InternalClass { 36 | int8_t One; 37 | uint8_t Two; 38 | 39 | InternalClass( ) 40 | : 41 | One( 0 ), 42 | Two( 0 ) { 43 | } 44 | 45 | InternalClass( int8_t one, uint8_t two ) 46 | : 47 | One( one ), 48 | Two( two ) { 49 | } 50 | 51 | template < typename D > 52 | bool Deserialize( D &deserializer ) { 53 | return deserializer( 54 | DESERIALIZE( One ), 55 | DESERIALIZE( Two ) 56 | ); 57 | } 58 | }; 59 | 60 | bool operator==( const InternalClass &a, const InternalClass &b ) { 61 | return ( a.One == b.One ) && ( a.Two == b.Two ); 62 | } 63 | 64 | template< typename Continer > 65 | struct ContinerTest { 66 | Continer Array; 67 | 68 | template < typename D > 69 | bool Deserialize( D &deserializer ) { 70 | return deserializer( 71 | DESERIALIZE( Array ) 72 | ); 73 | } 74 | }; 75 | 76 | 77 | TEST (STLContainersDeserialiseTest, Vector) { 78 | const char *json = 79 | "{\"Array\":[1.0e10,2.0e10,3.0e10,4.0e10,5.0e10]}"; 80 | SymbolStream s( json ); 81 | 82 | typedef ObjectsList < 83 | DESERIALIZEOBJ(NullObj) 84 | > SerializeList_t; 85 | 86 | Deserializer < 87 | SymbolStream, 88 | SerializeList_t 89 | > d( s ); 90 | 91 | ContinerTest< vector < float > > data; 92 | ASSERT_TRUE( d.Deserialize( &data ) ); 93 | 94 | vector < float > check = { 1.0e10f, 2.0e10f, 3.0e10f, 4.0e10f, 5.0e10f }; 95 | EXPECT_THAT( data.Array, check ); 96 | } 97 | 98 | TEST (STLContainersDeserialiseTest, Deque) { 99 | const char *json = 100 | "{\"Array\":[{\"One\":-10,\"Two\":10},{\"One\":-30,\"Two\":40}]}"; 101 | SymbolStream s( json ); 102 | 103 | typedef ObjectsList < 104 | DESERIALIZEOBJ(NullObj) 105 | > SerializeList_t; 106 | 107 | Deserializer < 108 | SymbolStream, 109 | SerializeList_t 110 | > d( s ); 111 | 112 | ContinerTest< deque < InternalClass > > data; 113 | ASSERT_TRUE( d.Deserialize( &data ) ); 114 | 115 | deque < InternalClass > check = { InternalClass( -10, 10 ), InternalClass( -30, 40 ) }; 116 | EXPECT_THAT( data.Array, check ); 117 | } 118 | 119 | TEST (STLContainersDeserialiseTest, Map) { 120 | const char *json = 121 | "{\"Array\":[{\"key\":1,\"value\":10},{\"key\":30,\"value\":40}]}"; 122 | SymbolStream s( json ); 123 | 124 | typedef ObjectsList < 125 | DESERIALIZEOBJ(NullObj) 126 | > SerializeList_t; 127 | 128 | Deserializer < 129 | SymbolStream, 130 | SerializeList_t 131 | > d( s ); 132 | 133 | ContinerTest< map < uint8_t, uint8_t > > data; 134 | ASSERT_TRUE( d.Deserialize( &data ) ); 135 | 136 | map < uint8_t, uint8_t > check = { 137 | make_pair< uint8_t, uint8_t >( 1, 10 ), 138 | make_pair< uint8_t, uint8_t >( 30, 40 ) 139 | }; 140 | EXPECT_THAT( data.Array, check ); 141 | } 142 | 143 | TEST (STLContainersDeserialiseTest, String) { 144 | const char *json = 145 | "{\"Array\":\"It's work!\"}"; 146 | SymbolStream s( json ); 147 | 148 | typedef ObjectsList < 149 | DESERIALIZEOBJ(NullObj) 150 | > SerializeList_t; 151 | 152 | Deserializer < 153 | SymbolStream, 154 | SerializeList_t 155 | > d( s ); 156 | 157 | ContinerTest< string > data; 158 | ASSERT_TRUE( d.Deserialize( &data ) ); 159 | 160 | string check( "It's work!" ); 161 | EXPECT_THAT( data.Array, check ); 162 | } 163 | 164 | -------------------------------------------------------------------------------- /tests/test_STLContainersSerialise.cpp: -------------------------------------------------------------------------------- 1 | #undef GTEST_LANG_CXX11 2 | 3 | #include "MockSerializeHandler.h" 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | using namespace std; 22 | using namespace jsmincpp; 23 | using namespace jsmincpp::serialize; 24 | using ::testing::ElementsAreArray; 25 | using ::testing::ElementsAre; 26 | using ::testing::ContainerEq; 27 | using ::testing::InSequence; 28 | using ::testing::TypedEq; 29 | using ::testing::StrEq; 30 | using ::testing::Return; 31 | using ::testing::Invoke; 32 | using ::testing::_; 33 | using ::testing::An; 34 | 35 | struct InternalClass : public Serialized { 36 | int8_t One; 37 | uint8_t Two; 38 | 39 | InternalClass( ) 40 | : 41 | One( 0 ), 42 | Two( 0 ) { 43 | } 44 | 45 | InternalClass( int8_t one, uint8_t two ) 46 | : 47 | One( one ), 48 | Two( two ) { 49 | } 50 | 51 | template < typename S > 52 | bool Serialize( S &serializer ) const { 53 | SERIALIZE( One ); 54 | SERIALIZE( Two ); 55 | return true; 56 | } 57 | }; 58 | 59 | template < typename Continer > 60 | struct ContinerTest : public Serialized { 61 | Continer Array; 62 | 63 | template < typename S > 64 | bool Serialize( S &serializer ) const { 65 | SERIALIZE( Array ); 66 | return true; 67 | } 68 | }; 69 | 70 | TEST (STLContainersSerialiseTest, Vector) { 71 | InSequence dummy0; 72 | 73 | MockSerializeHandler mockHandler; 74 | Serializer_t serializer( mockHandler ); 75 | ContinerTest < vector < float > > obj; 76 | 77 | obj.Array.push_back( 10.01f ); 78 | obj.Array.push_back( 20.02f ); 79 | obj.Array.push_back( 30.03f ); 80 | 81 | EXPECT_CALL( mockHandler, handle( StrEq( "{" ) ) ) 82 | .WillOnce( Return( true ) ); 83 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 84 | .WillOnce( Return( true ) ); 85 | EXPECT_CALL( mockHandler, handle( StrEq( "Array" ) ) ) 86 | .WillOnce( Return( true ) ); 87 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 88 | .WillOnce( Return( true ) ); 89 | EXPECT_CALL( mockHandler, handle( StrEq( "[" ) ) ) 90 | .WillOnce( Return( true ) ); 91 | EXPECT_CALL( mockHandler, handle( StrEq( "10.010000" ) ) ) 92 | .WillOnce( Return( true ) ); 93 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 94 | .WillOnce( Return( true ) ); 95 | EXPECT_CALL( mockHandler, handle( StrEq( "20.020000" ) ) ) 96 | .WillOnce( Return( true ) ); 97 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 98 | .WillOnce( Return( true ) ); 99 | EXPECT_CALL( mockHandler, handle( StrEq( "30.030001" ) ) ) 100 | .WillOnce( Return( true ) ); 101 | EXPECT_CALL( mockHandler, handle( StrEq( "]" ) ) ) 102 | .WillOnce( Return( true ) ); 103 | EXPECT_CALL( mockHandler, handle( StrEq( "}" ) ) ) 104 | .WillOnce( Return( true ) ); 105 | 106 | EXPECT_CALL( mockHandler, handle( ) ).WillOnce( Return( true ) ); 107 | 108 | ASSERT_TRUE( serializer.Serialize( obj ) ); 109 | } 110 | 111 | TEST (STLContainersSerialiseTest, Deque) { 112 | InSequence dummy1; 113 | 114 | MockSerializeHandler mockHandler; 115 | Serializer_t serializer( mockHandler ); 116 | ContinerTest < deque < InternalClass > > obj; 117 | 118 | obj.Array.push_back( InternalClass( -10, 10 ) ); 119 | obj.Array.push_back( InternalClass( -20, 20 ) ); 120 | 121 | EXPECT_CALL( mockHandler, handle( StrEq( "{" ) ) ) 122 | .WillOnce( Return( true ) ); 123 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 124 | .WillOnce( Return( true ) ); 125 | EXPECT_CALL( mockHandler, handle( StrEq( "Array" ) ) ) 126 | .WillOnce( Return( true ) ); 127 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 128 | .WillOnce( Return( true ) ); 129 | EXPECT_CALL( mockHandler, handle( StrEq( "[" ) ) ) 130 | .WillOnce( Return( true ) ); 131 | EXPECT_CALL( mockHandler, handle( StrEq( "{" ) ) ) 132 | .WillOnce( Return( true ) ); 133 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 134 | .WillOnce( Return( true ) ); 135 | EXPECT_CALL( mockHandler, handle( StrEq( "One" ) ) ) 136 | .WillOnce( Return( true ) ); 137 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 138 | .WillOnce( Return( true ) ); 139 | EXPECT_CALL( mockHandler, handle( StrEq( "-10" ) ) ) 140 | .WillOnce( Return( true ) ); 141 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 142 | .WillOnce( Return( true ) ); 143 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 144 | .WillOnce( Return( true ) ); 145 | EXPECT_CALL( mockHandler, handle( StrEq( "Two" ) ) ) 146 | .WillOnce( Return( true ) ); 147 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 148 | .WillOnce( Return( true ) ); 149 | EXPECT_CALL( mockHandler, handle( StrEq( "10" ) ) ) 150 | .WillOnce( Return( true ) ); 151 | EXPECT_CALL( mockHandler, handle( StrEq( "}" ) ) ) 152 | .WillOnce( Return( true ) ); 153 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 154 | .WillOnce( Return( true ) ); 155 | EXPECT_CALL( mockHandler, handle( StrEq( "{" ) ) ) 156 | .WillOnce( Return( true ) ); 157 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 158 | .WillOnce( Return( true ) ); 159 | EXPECT_CALL( mockHandler, handle( StrEq( "One" ) ) ) 160 | .WillOnce( Return( true ) ); 161 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 162 | .WillOnce( Return( true ) ); 163 | EXPECT_CALL( mockHandler, handle( StrEq( "-20" ) ) ) 164 | .WillOnce( Return( true ) ); 165 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 166 | .WillOnce( Return( true ) ); 167 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 168 | .WillOnce( Return( true ) ); 169 | EXPECT_CALL( mockHandler, handle( StrEq( "Two" ) ) ) 170 | .WillOnce( Return( true ) ); 171 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 172 | .WillOnce( Return( true ) ); 173 | EXPECT_CALL( mockHandler, handle( StrEq( "20" ) ) ) 174 | .WillOnce( Return( true ) ); 175 | EXPECT_CALL( mockHandler, handle( StrEq( "}" ) ) ) 176 | .WillOnce( Return( true ) ); 177 | EXPECT_CALL( mockHandler, handle( StrEq( "]" ) ) ) 178 | .WillOnce( Return( true ) ); 179 | EXPECT_CALL( mockHandler, handle( StrEq( "}" ) ) ) 180 | .WillOnce( Return( true ) ); 181 | 182 | EXPECT_CALL( mockHandler, handle( ) ).WillOnce( Return( true ) ); 183 | 184 | ASSERT_TRUE( serializer.Serialize( obj ) ); 185 | } 186 | 187 | TEST (STLContainersSerialiseTest, List) { 188 | InSequence dummy0; 189 | 190 | MockSerializeHandler mockHandler; 191 | Serializer_t serializer( mockHandler ); 192 | ContinerTest < list < float > > obj; 193 | 194 | obj.Array.push_back( 10.01f ); 195 | obj.Array.push_back( 20.02f ); 196 | obj.Array.push_back( 30.03f ); 197 | 198 | EXPECT_CALL( mockHandler, handle( StrEq( "{" ) ) ) 199 | .WillOnce( Return( true ) ); 200 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 201 | .WillOnce( Return( true ) ); 202 | EXPECT_CALL( mockHandler, handle( StrEq( "Array" ) ) ) 203 | .WillOnce( Return( true ) ); 204 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 205 | .WillOnce( Return( true ) ); 206 | EXPECT_CALL( mockHandler, handle( StrEq( "[" ) ) ) 207 | .WillOnce( Return( true ) ); 208 | EXPECT_CALL( mockHandler, handle( StrEq( "10.010000" ) ) ) 209 | .WillOnce( Return( true ) ); 210 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 211 | .WillOnce( Return( true ) ); 212 | EXPECT_CALL( mockHandler, handle( StrEq( "20.020000" ) ) ) 213 | .WillOnce( Return( true ) ); 214 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 215 | .WillOnce( Return( true ) ); 216 | EXPECT_CALL( mockHandler, handle( StrEq( "30.030001" ) ) ) 217 | .WillOnce( Return( true ) ); 218 | EXPECT_CALL( mockHandler, handle( StrEq( "]" ) ) ) 219 | .WillOnce( Return( true ) ); 220 | EXPECT_CALL( mockHandler, handle( StrEq( "}" ) ) ) 221 | .WillOnce( Return( true ) ); 222 | 223 | EXPECT_CALL( mockHandler, handle( ) ).WillOnce( Return( true ) ); 224 | 225 | ASSERT_TRUE( serializer.Serialize( obj ) ); 226 | } 227 | 228 | TEST (STLContainersSerialiseTest, String) { 229 | InSequence dummy0; 230 | 231 | MockSerializeHandler mockHandler; 232 | Serializer_t serializer( mockHandler ); 233 | ContinerTest < string > obj; 234 | 235 | obj.Array.assign( "It's work!" ); 236 | 237 | EXPECT_CALL( mockHandler, handle( StrEq( "{" ) ) ) 238 | .WillOnce( Return( true ) ); 239 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 240 | .WillOnce( Return( true ) ); 241 | EXPECT_CALL( mockHandler, handle( StrEq( "Array" ) ) ) 242 | .WillOnce( Return( true ) ); 243 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 244 | .WillOnce( Return( true ) ); 245 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 246 | .WillOnce( Return( true ) ); 247 | EXPECT_CALL( mockHandler, handle( StrEq( "It's work!" ) ) ) 248 | .WillOnce( Return( true ) ); 249 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 250 | .WillOnce( Return( true ) ); 251 | EXPECT_CALL( mockHandler, handle( StrEq( "}" ) ) ) 252 | .WillOnce( Return( true ) ); 253 | 254 | EXPECT_CALL( mockHandler, handle( ) ) 255 | .WillOnce( Return( true ) ); 256 | 257 | ASSERT_TRUE( serializer.Serialize( obj ) ); 258 | } 259 | 260 | TEST (STLContainersSerialiseTest, Map) { 261 | InSequence dummy0; 262 | 263 | MockSerializeHandler mockHandler; 264 | Serializer_t serializer( mockHandler ); 265 | ContinerTest < map < string, uint8_t > > obj; 266 | 267 | obj.Array.insert( make_pair( "A", 1 ) ); 268 | obj.Array.insert( make_pair( "B", 2 ) ); 269 | obj.Array.insert( make_pair( "C", 3 ) ); 270 | 271 | EXPECT_CALL( mockHandler, handle( StrEq( "{" ) ) ) 272 | .WillOnce( Return( true ) ); 273 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 274 | .WillOnce( Return( true ) ); 275 | EXPECT_CALL( mockHandler, handle( StrEq( "Array" ) ) ) 276 | .WillOnce( Return( true ) ); 277 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 278 | .WillOnce( Return( true ) ); 279 | EXPECT_CALL( mockHandler, handle( StrEq( "[" ) ) ) 280 | .WillOnce( Return( true ) ); 281 | 282 | EXPECT_CALL( mockHandler, handle( StrEq( "{" ) ) ) 283 | .WillOnce( Return( true ) ); 284 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 285 | .WillOnce( Return( true ) ); 286 | EXPECT_CALL( mockHandler, handle( StrEq( "key" ) ) ) 287 | .WillOnce( Return( true ) ); 288 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 289 | .WillOnce( Return( true ) ); 290 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 291 | .WillOnce( Return( true ) ); 292 | EXPECT_CALL( mockHandler, handle( StrEq( "A" ) ) ) 293 | .WillOnce( Return( true ) ); 294 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 295 | .WillOnce( Return( true ) ); 296 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 297 | .WillOnce( Return( true ) ); 298 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 299 | .WillOnce( Return( true ) ); 300 | EXPECT_CALL( mockHandler, handle( StrEq( "value" ) ) ) 301 | .WillOnce( Return( true ) ); 302 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 303 | .WillOnce( Return( true ) ); 304 | EXPECT_CALL( mockHandler, handle( StrEq( "1" ) ) ) 305 | .WillOnce( Return( true ) ); 306 | EXPECT_CALL( mockHandler, handle( StrEq( "}" ) ) ) 307 | .WillOnce( Return( true ) ); 308 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 309 | .WillOnce( Return( true ) ); 310 | 311 | EXPECT_CALL( mockHandler, handle( StrEq( "{" ) ) ) 312 | .WillOnce( Return( true ) ); 313 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 314 | .WillOnce( Return( true ) ); 315 | EXPECT_CALL( mockHandler, handle( StrEq( "key" ) ) ) 316 | .WillOnce( Return( true ) ); 317 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 318 | .WillOnce( Return( true ) ); 319 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 320 | .WillOnce( Return( true ) ); 321 | EXPECT_CALL( mockHandler, handle( StrEq( "B" ) ) ) 322 | .WillOnce( Return( true ) ); 323 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 324 | .WillOnce( Return( true ) ); 325 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 326 | .WillOnce( Return( true ) ); 327 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 328 | .WillOnce( Return( true ) ); 329 | EXPECT_CALL( mockHandler, handle( StrEq( "value" ) ) ) 330 | .WillOnce( Return( true ) ); 331 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 332 | .WillOnce( Return( true ) ); 333 | EXPECT_CALL( mockHandler, handle( StrEq( "2" ) ) ) 334 | .WillOnce( Return( true ) ); 335 | EXPECT_CALL( mockHandler, handle( StrEq( "}" ) ) ) 336 | .WillOnce( Return( true ) ); 337 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 338 | .WillOnce( Return( true ) ); 339 | 340 | EXPECT_CALL( mockHandler, handle( StrEq( "{" ) ) ) 341 | .WillOnce( Return( true ) ); 342 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 343 | .WillOnce( Return( true ) ); 344 | EXPECT_CALL( mockHandler, handle( StrEq( "key" ) ) ) 345 | .WillOnce( Return( true ) ); 346 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 347 | .WillOnce( Return( true ) ); 348 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 349 | .WillOnce( Return( true ) ); 350 | EXPECT_CALL( mockHandler, handle( StrEq( "C" ) ) ) 351 | .WillOnce( Return( true ) ); 352 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 353 | .WillOnce( Return( true ) ); 354 | EXPECT_CALL( mockHandler, handle( StrEq( "," ) ) ) 355 | .WillOnce( Return( true ) ); 356 | EXPECT_CALL( mockHandler, handle( StrEq( "\"" ) ) ) 357 | .WillOnce( Return( true ) ); 358 | EXPECT_CALL( mockHandler, handle( StrEq( "value" ) ) ) 359 | .WillOnce( Return( true ) ); 360 | EXPECT_CALL( mockHandler, handle( StrEq( "\":" ) ) ) 361 | .WillOnce( Return( true ) ); 362 | EXPECT_CALL( mockHandler, handle( StrEq( "3" ) ) ) 363 | .WillOnce( Return( true ) ); 364 | EXPECT_CALL( mockHandler, handle( StrEq( "}" ) ) ) 365 | .WillOnce( Return( true ) ); 366 | 367 | EXPECT_CALL( mockHandler, handle( StrEq( "]" ) ) ) 368 | .WillOnce( Return( true ) ); 369 | EXPECT_CALL( mockHandler, handle( StrEq( "}" ) ) ) 370 | .WillOnce( Return( true ) ); 371 | 372 | EXPECT_CALL( mockHandler, handle( ) ).WillOnce( Return( true ) ); 373 | 374 | ASSERT_TRUE( serializer.Serialize( obj ) ); 375 | } 376 | 377 | -------------------------------------------------------------------------------- /tests/test_SaticString.cpp: -------------------------------------------------------------------------------- 1 | #undef GTEST_LANG_CXX11 2 | 3 | #include "SymbolStream.h" 4 | 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | 12 | #include 13 | 14 | using namespace jsmincpp; 15 | using namespace jsmincpp::deserialize; 16 | using namespace std; 17 | using ::testing::ElementsAreArray; 18 | using ::testing::ElementsAre; 19 | using ::testing::ContainerEq; 20 | using ::testing::InSequence; 21 | using ::testing::TypedEq; 22 | using ::testing::StrEq; 23 | using ::testing::Return; 24 | using ::testing::Invoke; 25 | using ::testing::_; 26 | using ::testing::An; 27 | 28 | struct TestStaticString { 29 | StaticString< 20 > String; 30 | 31 | template < typename D > 32 | bool Deserialize( D &deserializer ) { 33 | return deserializer( 34 | DESERIALIZE( String ) 35 | ); 36 | } 37 | }; 38 | 39 | TEST (StaticString, test) { 40 | StaticString < 20 > str( "StaticString" ); 41 | ASSERT_STREQ( str.GetString( ), "StaticString" ); 42 | 43 | str.Assign( "New value" ); 44 | ASSERT_STREQ( str.GetString( ), "New value" ); 45 | 46 | str.Add( '!' ); 47 | ASSERT_STREQ( str.GetString( ), "New value!" ); 48 | } 49 | 50 | TEST (StaticString, Deserialize) { 51 | const char *json = 52 | "{\"String\":\"It's work!\"}"; 53 | SymbolStream s( json ); 54 | 55 | typedef ObjectsList < 56 | DESERIALIZEOBJ(NullObj) 57 | > SerializeList_t; 58 | 59 | Deserializer < 60 | SymbolStream, 61 | SerializeList_t 62 | > d( s ); 63 | 64 | TestStaticString data; 65 | ASSERT_TRUE( d.Deserialize( &data ) ); 66 | ASSERT_STREQ( data.String.GetString( ), "It's work!" ); 67 | } 68 | 69 | TEST (StaticString, LongStringError) { 70 | const char *json = 71 | "{\"String\":\"It's lo-o-o-o-ong string!\"}"; 72 | SymbolStream s( json ); 73 | 74 | typedef ObjectsList < 75 | DESERIALIZEOBJ(NullObj) 76 | > SerializeList_t; 77 | 78 | Deserializer < 79 | SymbolStream, 80 | SerializeList_t 81 | > d( s ); 82 | 83 | TestStaticString data; 84 | ASSERT_FALSE( d.Deserialize( &data ) ); 85 | ASSERT_EQ( data.String.GetLength( ), 20 ); 86 | } 87 | -------------------------------------------------------------------------------- /tests/test_SkipEndJSONString.cpp: -------------------------------------------------------------------------------- 1 | #undef GTEST_LANG_CXX11 2 | 3 | #include "SymbolStream.h" 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace jsmincpp::deserialize; 15 | using namespace std; 16 | using ::testing::ElementsAreArray; 17 | using ::testing::ElementsAre; 18 | using ::testing::InSequence; 19 | using ::testing::TypedEq; 20 | using ::testing::StrEq; 21 | using ::testing::Return; 22 | using ::testing::Invoke; 23 | using ::testing::_; 24 | using ::testing::An; 25 | 26 | TEST (SkipEndJSONStringTest, test1) { 27 | const char *json = 28 | "-20.02,\"Fourth\":false}!"; 29 | SymbolStream s( json ); 30 | 31 | SkipEndJSONString( s ); 32 | 33 | ASSERT_EQ( *s, '!' ); 34 | } 35 | 36 | TEST (SkipEndJSONStringTest, test2) { 37 | const char *json = 38 | "ond\":true,\"Include\":{\"Third\":-20.02,\"Fourth\":false}}!"; 39 | SymbolStream s( json ); 40 | 41 | SkipEndJSONString( s ); 42 | 43 | ASSERT_EQ( *s, '!' ); 44 | } 45 | 46 | TEST (SkipEndJSONStringTest, test3) { 47 | const char *json = 48 | ":{\"Object\":{\"First\":20.01,\"Second\":true,\"Include\":{\"Third\":-20.02,\"Fourth\":false}}}}!"; 49 | SymbolStream s( json ); 50 | 51 | SkipEndJSONString( s ); 52 | 53 | ASSERT_EQ( *s, '!' ); 54 | } 55 | 56 | --------------------------------------------------------------------------------