ooxml_crypt 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/ext/ooxml_crypt/extconf.rb +18 -0
- data/ext/ooxml_crypt/ooxml_crypt.c +27 -0
- data/ext/ooxml_crypt/ooxml_crypt.h +7 -0
- data/lib/ooxml_crypt/version.rb +5 -0
- data/lib/ooxml_crypt.rb +75 -0
- data/vendor/cybozulib/.github/workflows/main.yml +12 -0
- data/vendor/cybozulib/.gitignore +5 -0
- data/vendor/cybozulib/CMakeLists.txt +6 -0
- data/vendor/cybozulib/COPYRIGHT +27 -0
- data/vendor/cybozulib/Makefile +26 -0
- data/vendor/cybozulib/bin/libeay32.dll +0 -0
- data/vendor/cybozulib/bin/libmecab.dll +0 -0
- data/vendor/cybozulib/bin/ssleay32.dll +0 -0
- data/vendor/cybozulib/common.mk +116 -0
- data/vendor/cybozulib/common.props +25 -0
- data/vendor/cybozulib/cybozulib.sln +286 -0
- data/vendor/cybozulib/debug.props +14 -0
- data/vendor/cybozulib/include/cybozu/array.hpp +197 -0
- data/vendor/cybozulib/include/cybozu/atoi.hpp +238 -0
- data/vendor/cybozulib/include/cybozu/atomic.hpp +146 -0
- data/vendor/cybozulib/include/cybozu/base64.hpp +210 -0
- data/vendor/cybozulib/include/cybozu/benchmark.hpp +212 -0
- data/vendor/cybozulib/include/cybozu/bfd.hpp +105 -0
- data/vendor/cybozulib/include/cybozu/bit_operation.hpp +139 -0
- data/vendor/cybozulib/include/cybozu/bitvector.hpp +358 -0
- data/vendor/cybozulib/include/cybozu/condition_variable.hpp +113 -0
- data/vendor/cybozulib/include/cybozu/condition_variable_cs.hpp +74 -0
- data/vendor/cybozulib/include/cybozu/config.hpp +392 -0
- data/vendor/cybozulib/include/cybozu/critical_section.hpp +60 -0
- data/vendor/cybozulib/include/cybozu/crypto.hpp +321 -0
- data/vendor/cybozulib/include/cybozu/csucvector.hpp +624 -0
- data/vendor/cybozulib/include/cybozu/csv.hpp +294 -0
- data/vendor/cybozulib/include/cybozu/data_type.hpp +27 -0
- data/vendor/cybozulib/include/cybozu/endian.hpp +224 -0
- data/vendor/cybozulib/include/cybozu/env.hpp +63 -0
- data/vendor/cybozulib/include/cybozu/event.hpp +122 -0
- data/vendor/cybozulib/include/cybozu/exception.hpp +253 -0
- data/vendor/cybozulib/include/cybozu/file.hpp +626 -0
- data/vendor/cybozulib/include/cybozu/fmindex.hpp +291 -0
- data/vendor/cybozulib/include/cybozu/format.hpp +93 -0
- data/vendor/cybozulib/include/cybozu/frequency.hpp +264 -0
- data/vendor/cybozulib/include/cybozu/hash.hpp +67 -0
- data/vendor/cybozulib/include/cybozu/inttype.hpp +174 -0
- data/vendor/cybozulib/include/cybozu/itoa.hpp +336 -0
- data/vendor/cybozulib/include/cybozu/json.hpp +120 -0
- data/vendor/cybozulib/include/cybozu/line_stream.hpp +149 -0
- data/vendor/cybozulib/include/cybozu/link_libeay32.hpp +21 -0
- data/vendor/cybozulib/include/cybozu/link_mpir.hpp +18 -0
- data/vendor/cybozulib/include/cybozu/link_ssleay32.hpp +19 -0
- data/vendor/cybozulib/include/cybozu/log.hpp +237 -0
- data/vendor/cybozulib/include/cybozu/minixml.hpp +452 -0
- data/vendor/cybozulib/include/cybozu/mmap.hpp +143 -0
- data/vendor/cybozulib/include/cybozu/mutex.hpp +144 -0
- data/vendor/cybozulib/include/cybozu/nlp/mecab.hpp +96 -0
- data/vendor/cybozulib/include/cybozu/nlp/plsi.hpp +315 -0
- data/vendor/cybozulib/include/cybozu/nlp/random.hpp +74 -0
- data/vendor/cybozulib/include/cybozu/nlp/sparse.hpp +529 -0
- data/vendor/cybozulib/include/cybozu/nlp/svd.hpp +486 -0
- data/vendor/cybozulib/include/cybozu/nlp/tfidf.hpp +226 -0
- data/vendor/cybozulib/include/cybozu/nlp/top_score.hpp +75 -0
- data/vendor/cybozulib/include/cybozu/option.hpp +743 -0
- data/vendor/cybozulib/include/cybozu/parallel.hpp +88 -0
- data/vendor/cybozulib/include/cybozu/pcg.hpp +72 -0
- data/vendor/cybozulib/include/cybozu/process.hpp +324 -0
- data/vendor/cybozulib/include/cybozu/quit_signal_handler.hpp +66 -0
- data/vendor/cybozulib/include/cybozu/random_generator.hpp +144 -0
- data/vendor/cybozulib/include/cybozu/regex.hpp +463 -0
- data/vendor/cybozulib/include/cybozu/select8.hpp +279 -0
- data/vendor/cybozulib/include/cybozu/serializer.hpp +363 -0
- data/vendor/cybozulib/include/cybozu/sha1.hpp +209 -0
- data/vendor/cybozulib/include/cybozu/sha2.hpp +506 -0
- data/vendor/cybozulib/include/cybozu/siphash.hpp +105 -0
- data/vendor/cybozulib/include/cybozu/socket.hpp +785 -0
- data/vendor/cybozulib/include/cybozu/ssl.hpp +203 -0
- data/vendor/cybozulib/include/cybozu/stacktrace.hpp +291 -0
- data/vendor/cybozulib/include/cybozu/stream.hpp +269 -0
- data/vendor/cybozulib/include/cybozu/string.hpp +1746 -0
- data/vendor/cybozulib/include/cybozu/string_operation.hpp +365 -0
- data/vendor/cybozulib/include/cybozu/sucvector.hpp +378 -0
- data/vendor/cybozulib/include/cybozu/test.hpp +373 -0
- data/vendor/cybozulib/include/cybozu/thread.hpp +229 -0
- data/vendor/cybozulib/include/cybozu/time.hpp +281 -0
- data/vendor/cybozulib/include/cybozu/tls.hpp +115 -0
- data/vendor/cybozulib/include/cybozu/unordered_map.hpp +13 -0
- data/vendor/cybozulib/include/cybozu/unordered_set.hpp +13 -0
- data/vendor/cybozulib/include/cybozu/v128.hpp +376 -0
- data/vendor/cybozulib/include/cybozu/wavelet_matrix.hpp +345 -0
- data/vendor/cybozulib/include/cybozu/xorshift.hpp +189 -0
- data/vendor/cybozulib/include/cybozu/zlib.hpp +325 -0
- data/vendor/cybozulib/include/sais.hxx +364 -0
- data/vendor/cybozulib/misc/make_select8tbl.cpp +26 -0
- data/vendor/cybozulib/mk.bat +37 -0
- data/vendor/cybozulib/readme.md +29 -0
- data/vendor/cybozulib/release.props +12 -0
- data/vendor/cybozulib/sample/Makefile +30 -0
- data/vendor/cybozulib/sample/csucvector_smpl.cpp +42 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.S +4 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.U +4 -0
- data/vendor/cybozulib/sample/data/svd/org/test1.V +6 -0
- data/vendor/cybozulib/sample/data/svd/test1 +4 -0
- data/vendor/cybozulib/sample/data/svd/test2 +4 -0
- data/vendor/cybozulib/sample/desymbol.cpp +127 -0
- data/vendor/cybozulib/sample/exception_smpl.cpp +46 -0
- data/vendor/cybozulib/sample/fmindex_smpl.cpp +231 -0
- data/vendor/cybozulib/sample/log_smpl.cpp +19 -0
- data/vendor/cybozulib/sample/mecab_smpl.cpp +37 -0
- data/vendor/cybozulib/sample/option2_smpl.cpp +68 -0
- data/vendor/cybozulib/sample/option_smpl.cpp +42 -0
- data/vendor/cybozulib/sample/plsi_smpl.cpp +207 -0
- data/vendor/cybozulib/sample/proj/exception_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/proj/mecab_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/proj/ssl_smpl/ssl_smpl.vcxproj +85 -0
- data/vendor/cybozulib/sample/proj/ssl_smpl.vcproj +347 -0
- data/vendor/cybozulib/sample/proj/stacktrace_smpl/stacktrace_smpl.vcxproj +85 -0
- data/vendor/cybozulib/sample/proj/svd_smpl.vcproj +184 -0
- data/vendor/cybozulib/sample/quit_signal_handler.cpp +30 -0
- data/vendor/cybozulib/sample/serializer_smpl.cpp +196 -0
- data/vendor/cybozulib/sample/socket_smpl.cpp +82 -0
- data/vendor/cybozulib/sample/ssl_smpl.cpp +39 -0
- data/vendor/cybozulib/sample/stacktrace_smpl.cpp +52 -0
- data/vendor/cybozulib/sample/svd_bench_smpl.cpp +143 -0
- data/vendor/cybozulib/sample/svd_smpl.cpp +94 -0
- data/vendor/cybozulib/sample/wm_bench_smpl.cpp +182 -0
- data/vendor/cybozulib/sample/zlib_smpl.cpp +41 -0
- data/vendor/cybozulib/src/Makefile +8 -0
- data/vendor/cybozulib/src/base/Makefile +19 -0
- data/vendor/cybozulib/test/Makefile +12 -0
- data/vendor/cybozulib/test/base/Makefile +37 -0
- data/vendor/cybozulib/test/base/array_test.cpp +173 -0
- data/vendor/cybozulib/test/base/atoi_test.cpp +774 -0
- data/vendor/cybozulib/test/base/atomic_test.cpp +49 -0
- data/vendor/cybozulib/test/base/base64_test.cpp +113 -0
- data/vendor/cybozulib/test/base/bit_operation_test.cpp +134 -0
- data/vendor/cybozulib/test/base/bitvector_test.cpp +204 -0
- data/vendor/cybozulib/test/base/condition_variable_cs_test.cpp +92 -0
- data/vendor/cybozulib/test/base/condition_variable_test.cpp +88 -0
- data/vendor/cybozulib/test/base/config_test.cpp +236 -0
- data/vendor/cybozulib/test/base/crypto_test.cpp +122 -0
- data/vendor/cybozulib/test/base/csucvector_test.cpp +63 -0
- data/vendor/cybozulib/test/base/csv_test.cpp +182 -0
- data/vendor/cybozulib/test/base/data/a.xml +26 -0
- data/vendor/cybozulib/test/base/endian_test.cpp +56 -0
- data/vendor/cybozulib/test/base/env_test.cpp +22 -0
- data/vendor/cybozulib/test/base/event_test.cpp +41 -0
- data/vendor/cybozulib/test/base/file_test.cpp +233 -0
- data/vendor/cybozulib/test/base/fmindex_test.cpp +118 -0
- data/vendor/cybozulib/test/base/format_test.cpp +12 -0
- data/vendor/cybozulib/test/base/frequency_test.cpp +104 -0
- data/vendor/cybozulib/test/base/itoa_test.cpp +522 -0
- data/vendor/cybozulib/test/base/line_stream_test.cpp +208 -0
- data/vendor/cybozulib/test/base/mecab_test.cpp +41 -0
- data/vendor/cybozulib/test/base/minixml_test.cpp +103 -0
- data/vendor/cybozulib/test/base/mmap_test.cpp +15 -0
- data/vendor/cybozulib/test/base/option_test.cpp +487 -0
- data/vendor/cybozulib/test/base/parallel_test.cpp +48 -0
- data/vendor/cybozulib/test/base/proj/array_test/array_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/atoi_test/atoi_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/atomic_test/atomic_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/base64_test/base64_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/condition_variable_cs_test/condition_variable_cs_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/condition_variable_test/condition_variable_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/config_test/config_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/csv_test/csv_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/endian_test/endian_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/env_test/env_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/event_test/event_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/file_test/file_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/itoa_test/itoa_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/mecab_test/mecab_test.vcxproj +88 -0
- data/vendor/cybozulib/test/base/proj/minixml_test/minixml_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/mmap_test/mmap_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/serializer_test/serializer_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/sha1_test/sha1_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/stream_test/stream_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/string_operation_test/string_operation_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/string_test/string_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/thread_test/thread_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/time_test/time_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/tls_test/tls_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/proj/zlib_test/zlib_test.vcxproj +86 -0
- data/vendor/cybozulib/test/base/random_generator_test.cpp +28 -0
- data/vendor/cybozulib/test/base/regex_test.cpp +74 -0
- data/vendor/cybozulib/test/base/serializer_test.cpp +483 -0
- data/vendor/cybozulib/test/base/sha1_test.cpp +61 -0
- data/vendor/cybozulib/test/base/sha2_test.cpp +191 -0
- data/vendor/cybozulib/test/base/siphash_test.cpp +33 -0
- data/vendor/cybozulib/test/base/socket_test.cpp +76 -0
- data/vendor/cybozulib/test/base/stream_test.cpp +101 -0
- data/vendor/cybozulib/test/base/string_operation_test.cpp +340 -0
- data/vendor/cybozulib/test/base/string_test.cpp +1705 -0
- data/vendor/cybozulib/test/base/sucvector_test.cpp +312 -0
- data/vendor/cybozulib/test/base/thread_test.cpp +62 -0
- data/vendor/cybozulib/test/base/time_test.cpp +164 -0
- data/vendor/cybozulib/test/base/tls_test.cpp +50 -0
- data/vendor/cybozulib/test/base/wavelet_matrix_test.cpp +145 -0
- data/vendor/cybozulib/test/base/zlib_test.cpp +371 -0
- data/vendor/cybozulib/test/nlp/Makefile +27 -0
- data/vendor/cybozulib/test/nlp/proj/random_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/proj/sparse_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/proj/svd_test.vcproj +184 -0
- data/vendor/cybozulib/test/nlp/random_test.cpp +62 -0
- data/vendor/cybozulib/test/nlp/sparse_test.cpp +347 -0
- data/vendor/cybozulib/test/nlp/svd_test.cpp +234 -0
- data/vendor/cybozulib/test/nlp/top_score_test.cpp +40 -0
- data/vendor/cybozulib/tool/create_vcproj.py +186 -0
- data/vendor/cybozulib/tool/vcproj_tmpl.py +185 -0
- data/vendor/msoffice/COPYRIGHT +27 -0
- data/vendor/msoffice/Makefile +29 -0
- data/vendor/msoffice/bin/64/msoc.dll +0 -0
- data/vendor/msoffice/bin/64/msocsample.exe +0 -0
- data/vendor/msoffice/bin/64/msoffice-crypt.exe +0 -0
- data/vendor/msoffice/bin/msoc.dll +0 -0
- data/vendor/msoffice/bin/msocsample.exe +0 -0
- data/vendor/msoffice/bin/msoffice-crypt.exe +0 -0
- data/vendor/msoffice/common.mk +71 -0
- data/vendor/msoffice/common.props +26 -0
- data/vendor/msoffice/debug.props +14 -0
- data/vendor/msoffice/include/attack.hpp +211 -0
- data/vendor/msoffice/include/cfb.hpp +777 -0
- data/vendor/msoffice/include/crypto_util.hpp +450 -0
- data/vendor/msoffice/include/custom_sha1.hpp +342 -0
- data/vendor/msoffice/include/decode.hpp +240 -0
- data/vendor/msoffice/include/encode.hpp +221 -0
- data/vendor/msoffice/include/make_dataspace.hpp +316 -0
- data/vendor/msoffice/include/msoc.h +129 -0
- data/vendor/msoffice/include/resource.hpp +7 -0
- data/vendor/msoffice/include/standard_encryption.hpp +145 -0
- data/vendor/msoffice/include/uint32vec.hpp +179 -0
- data/vendor/msoffice/include/util.hpp +212 -0
- data/vendor/msoffice/lib/.emptydir +0 -0
- data/vendor/msoffice/misc/decrypt-xls.vbs +46 -0
- data/vendor/msoffice/mk.bat +1 -0
- data/vendor/msoffice/mkdll.bat +3 -0
- data/vendor/msoffice/msoc.def +13 -0
- data/vendor/msoffice/msocsample.py +178 -0
- data/vendor/msoffice/msoffice12.sln +31 -0
- data/vendor/msoffice/readme.md +110 -0
- data/vendor/msoffice/release.props +28 -0
- data/vendor/msoffice/src/Makefile +19 -0
- data/vendor/msoffice/src/attack.cpp +124 -0
- data/vendor/msoffice/src/cfb_test.cpp +77 -0
- data/vendor/msoffice/src/minisample.c +54 -0
- data/vendor/msoffice/src/msocdll.cpp +276 -0
- data/vendor/msoffice/src/msocsample.c +136 -0
- data/vendor/msoffice/src/msoffice-crypt.cpp +219 -0
- data/vendor/msoffice/src/proj/attack/attack.vcxproj +88 -0
- data/vendor/msoffice/src/proj/main/msoffice-crypt.vcxproj +88 -0
- data/vendor/msoffice/src/sha1.cpp +234 -0
- data/vendor/msoffice/test/Makefile +20 -0
- data/vendor/msoffice/test/cfb_test.cpp +74 -0
- data/vendor/msoffice/test/hash_test.cpp +59 -0
- data/vendor/msoffice/test/proj/cfb/cfb_test.vcxproj +90 -0
- data/vendor/msoffice/test/proj/hash/hash_test.vcxproj +90 -0
- data/vendor/msoffice/test/sampl.bat +8 -0
- data/vendor/msoffice/test_all.py +46 -0
- data/vendor/update +4 -0
- metadata +351 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
/**
|
|
3
|
+
@file
|
|
4
|
+
@brief int type definition and macros
|
|
5
|
+
@author MITSUNARI Shigeo(@herumi)
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
#if defined(_MSC_VER) && (MSC_VER <= 1500) && !defined(CYBOZU_DEFINED_INTXX)
|
|
9
|
+
#define CYBOZU_DEFINED_INTXX
|
|
10
|
+
typedef __int64 int64_t;
|
|
11
|
+
typedef unsigned __int64 uint64_t;
|
|
12
|
+
typedef unsigned int uint32_t;
|
|
13
|
+
typedef int int32_t;
|
|
14
|
+
typedef unsigned short uint16_t;
|
|
15
|
+
typedef short int16_t;
|
|
16
|
+
typedef unsigned char uint8_t;
|
|
17
|
+
typedef signed char int8_t;
|
|
18
|
+
#else
|
|
19
|
+
#include <stdint.h>
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
#ifdef _MSC_VER
|
|
23
|
+
#ifndef CYBOZU_DEFINED_SSIZE_T
|
|
24
|
+
#define CYBOZU_DEFINED_SSIZE_T
|
|
25
|
+
#ifdef _WIN64
|
|
26
|
+
typedef int64_t ssize_t;
|
|
27
|
+
#else
|
|
28
|
+
typedef int32_t ssize_t;
|
|
29
|
+
#endif
|
|
30
|
+
#endif
|
|
31
|
+
#else
|
|
32
|
+
#include <unistd.h> // for ssize_t
|
|
33
|
+
#endif
|
|
34
|
+
|
|
35
|
+
#ifndef CYBOZU_ALIGN
|
|
36
|
+
#ifdef _MSC_VER
|
|
37
|
+
#define CYBOZU_ALIGN(x) __declspec(align(x))
|
|
38
|
+
#else
|
|
39
|
+
#define CYBOZU_ALIGN(x) __attribute__((aligned(x)))
|
|
40
|
+
#endif
|
|
41
|
+
#endif
|
|
42
|
+
#ifndef CYBOZU_FORCE_INLINE
|
|
43
|
+
#ifdef _MSC_VER
|
|
44
|
+
#define CYBOZU_FORCE_INLINE __forceinline
|
|
45
|
+
#else
|
|
46
|
+
#define CYBOZU_FORCE_INLINE __attribute__((always_inline))
|
|
47
|
+
#endif
|
|
48
|
+
#endif
|
|
49
|
+
#ifndef CYBOZU_UNUSED
|
|
50
|
+
#ifdef __GNUC__
|
|
51
|
+
#define CYBOZU_UNUSED __attribute__((unused))
|
|
52
|
+
#else
|
|
53
|
+
#define CYBOZU_UNUSED
|
|
54
|
+
#endif
|
|
55
|
+
#endif
|
|
56
|
+
#ifndef CYBOZU_ALLOCA
|
|
57
|
+
#ifdef _MSC_VER
|
|
58
|
+
#include <malloc.h>
|
|
59
|
+
#define CYBOZU_ALLOCA(x) _malloca(x)
|
|
60
|
+
#else
|
|
61
|
+
#define CYBOZU_ALLOCA(x) __builtin_alloca(x)
|
|
62
|
+
#endif
|
|
63
|
+
#endif
|
|
64
|
+
#ifndef CYBOZU_NUM_OF_ARRAY
|
|
65
|
+
#define CYBOZU_NUM_OF_ARRAY(x) (sizeof(x) / sizeof(*x))
|
|
66
|
+
#endif
|
|
67
|
+
#ifndef CYBOZU_SNPRINTF
|
|
68
|
+
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
|
69
|
+
#define CYBOZU_SNPRINTF(x, len, ...) (void)_snprintf_s(x, len, len - 1, __VA_ARGS__)
|
|
70
|
+
#else
|
|
71
|
+
#define CYBOZU_SNPRINTF(x, len, ...) (void)snprintf(x, len, __VA_ARGS__)
|
|
72
|
+
#endif
|
|
73
|
+
#endif
|
|
74
|
+
|
|
75
|
+
// LLONG_MIN in limits.h is not defined in some env.
|
|
76
|
+
#define CYBOZU_LLONG_MIN (-9223372036854775807ll-1)
|
|
77
|
+
|
|
78
|
+
#define CYBOZU_CPP_VERSION_CPP03 0
|
|
79
|
+
#define CYBOZU_CPP_VERSION_TR1 1
|
|
80
|
+
#define CYBOZU_CPP_VERSION_CPP11 2
|
|
81
|
+
#define CYBOZU_CPP_VERSION_CPP14 3
|
|
82
|
+
#define CYBOZU_CPP_VERSION_CPP17 4
|
|
83
|
+
|
|
84
|
+
#ifdef __GNUC__
|
|
85
|
+
#define CYBOZU_GNUC_PREREQ(major, minor) ((__GNUC__) * 100 + (__GNUC_MINOR__) >= (major) * 100 + (minor))
|
|
86
|
+
#else
|
|
87
|
+
#define CYBOZU_GNUC_PREREQ(major, minor) 0
|
|
88
|
+
#endif
|
|
89
|
+
|
|
90
|
+
#if (__cplusplus >= 201703)
|
|
91
|
+
#define CYBOZU_CPP_VERSION CYBOZU_CPP_VERSION_CPP17
|
|
92
|
+
#elif (__cplusplus >= 201402)
|
|
93
|
+
#define CYBOZU_CPP_VERSION CYBOZU_CPP_VERSION_CPP14
|
|
94
|
+
#elif (__cplusplus >= 201103) || (defined(_MSC_VER) && _MSC_VER >= 1500) || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
|
95
|
+
#if defined(_MSC_VER) && (_MSC_VER <= 1600)
|
|
96
|
+
#define CYBOZU_CPP_VERSION CYBOZU_CPP_VERSION_TR1
|
|
97
|
+
#else
|
|
98
|
+
#define CYBOZU_CPP_VERSION CYBOZU_CPP_VERSION_CPP11
|
|
99
|
+
#endif
|
|
100
|
+
#elif CYBOZU_GNUC_PREREQ(4, 5) || (CYBOZU_GNUC_PREREQ(4, 2) && (defined(__GLIBCXX__) &&__GLIBCXX__ >= 20070719)) || defined(__INTEL_COMPILER) || (__clang_major__ >= 3)
|
|
101
|
+
#define CYBOZU_CPP_VERSION CYBOZU_CPP_VERSION_TR1
|
|
102
|
+
#else
|
|
103
|
+
#define CYBOZU_CPP_VERSION CYBOZU_CPP_VERSION_CPP03
|
|
104
|
+
#endif
|
|
105
|
+
|
|
106
|
+
#ifdef CYBOZU_USE_BOOST
|
|
107
|
+
#define CYBOZU_NAMESPACE_STD boost
|
|
108
|
+
#define CYBOZU_NAMESPACE_TR1_BEGIN
|
|
109
|
+
#define CYBOZU_NAMESPACE_TR1_END
|
|
110
|
+
#elif (CYBOZU_CPP_VERSION == CYBOZU_CPP_VERSION_TR1) && !defined(__APPLE__)
|
|
111
|
+
#define CYBOZU_NAMESPACE_STD std::tr1
|
|
112
|
+
#define CYBOZU_NAMESPACE_TR1_BEGIN namespace tr1 {
|
|
113
|
+
#define CYBOZU_NAMESPACE_TR1_END }
|
|
114
|
+
#else
|
|
115
|
+
#define CYBOZU_NAMESPACE_STD std
|
|
116
|
+
#define CYBOZU_NAMESPACE_TR1_BEGIN
|
|
117
|
+
#define CYBOZU_NAMESPACE_TR1_END
|
|
118
|
+
#endif
|
|
119
|
+
|
|
120
|
+
#ifndef CYBOZU_OS_BIT
|
|
121
|
+
#if defined(_WIN64) || defined(__x86_64__) || defined(__AARCH64EL__) || defined(__EMSCRIPTEN__) || defined(__LP64__)
|
|
122
|
+
#define CYBOZU_OS_BIT 64
|
|
123
|
+
#else
|
|
124
|
+
#define CYBOZU_OS_BIT 32
|
|
125
|
+
#endif
|
|
126
|
+
#endif
|
|
127
|
+
|
|
128
|
+
#ifndef CYBOZU_HOST
|
|
129
|
+
#define CYBOZU_HOST_UNKNOWN 0
|
|
130
|
+
#define CYBOZU_HOST_INTEL 1
|
|
131
|
+
#define CYBOZU_HOST_ARM 2
|
|
132
|
+
#if defined(_M_IX86) || defined(_M_AMD64) || defined(__x86_64__) || defined(__i386__)
|
|
133
|
+
#define CYBOZU_HOST CYBOZU_HOST_INTEL
|
|
134
|
+
#elif defined(__arm__) || defined(__AARCH64EL__)
|
|
135
|
+
#define CYBOZU_HOST CYBOZU_HOST_ARM
|
|
136
|
+
#else
|
|
137
|
+
#define CYBOZU_HOST CYBOZU_HOST_UNKNOWN
|
|
138
|
+
#endif
|
|
139
|
+
#endif
|
|
140
|
+
|
|
141
|
+
#ifndef CYBOZU_ENDIAN
|
|
142
|
+
#define CYBOZU_ENDIAN_UNKNOWN 0
|
|
143
|
+
#define CYBOZU_ENDIAN_LITTLE 1
|
|
144
|
+
#define CYBOZU_ENDIAN_BIG 2
|
|
145
|
+
#if (CYBOZU_HOST == CYBOZU_HOST_INTEL)
|
|
146
|
+
#define CYBOZU_ENDIAN CYBOZU_ENDIAN_LITTLE
|
|
147
|
+
#elif (CYBOZU_HOST == CYBOZU_HOST_ARM) && (defined(__ARM_EABI__) || defined(__AARCH64EL__))
|
|
148
|
+
#define CYBOZU_ENDIAN CYBOZU_ENDIAN_LITTLE
|
|
149
|
+
#elif defined(__s390x__)
|
|
150
|
+
#define CYBOZU_ENDIAN CYBOZU_ENDIAN_BIG
|
|
151
|
+
#else
|
|
152
|
+
#define CYBOZU_ENDIAN CYBOZU_ENDIAN_UNKNOWN
|
|
153
|
+
#endif
|
|
154
|
+
#endif
|
|
155
|
+
|
|
156
|
+
#if CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11
|
|
157
|
+
#define CYBOZU_NOEXCEPT noexcept
|
|
158
|
+
#define CYBOZU_NULLPTR nullptr
|
|
159
|
+
#define CYBOZU_OVERRIDE override
|
|
160
|
+
#define CYBOZU_FINAL final
|
|
161
|
+
#else
|
|
162
|
+
#define CYBOZU_NOEXCEPT throw()
|
|
163
|
+
#define CYBOZU_NULLPTR 0
|
|
164
|
+
#define CYBOZU_OVERRIDE
|
|
165
|
+
#define CYBOZU_FINAL
|
|
166
|
+
#endif
|
|
167
|
+
namespace cybozu {
|
|
168
|
+
template<class T>
|
|
169
|
+
void disable_warning_unused_variable(const T&) { }
|
|
170
|
+
template<class T, class S>
|
|
171
|
+
T cast(const S* ptr) { return static_cast<T>(static_cast<const void*>(ptr)); }
|
|
172
|
+
template<class T, class S>
|
|
173
|
+
T cast(S* ptr) { return static_cast<T>(static_cast<void*>(ptr)); }
|
|
174
|
+
} // cybozu
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
/**
|
|
3
|
+
@file
|
|
4
|
+
@brief convert integer to string(ascii)
|
|
5
|
+
|
|
6
|
+
@author MITSUNARI Shigeo(@herumi)
|
|
7
|
+
*/
|
|
8
|
+
#ifndef CYBOZU_DONT_USE_STRING
|
|
9
|
+
#include <string>
|
|
10
|
+
#endif
|
|
11
|
+
#include <memory.h>
|
|
12
|
+
#include <cybozu/inttype.hpp>
|
|
13
|
+
#include <cybozu/bit_operation.hpp>
|
|
14
|
+
|
|
15
|
+
namespace cybozu {
|
|
16
|
+
|
|
17
|
+
template<class T>
|
|
18
|
+
size_t getHexLength(T x)
|
|
19
|
+
{
|
|
20
|
+
return x == 0 ? 1 : cybozu::bsr(x) / 4 + 1;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
template<class T>
|
|
24
|
+
size_t getBinLength(T x)
|
|
25
|
+
{
|
|
26
|
+
return x == 0 ? 1 : cybozu::bsr(x) + 1;
|
|
27
|
+
}
|
|
28
|
+
/*
|
|
29
|
+
convert x to hex string with len
|
|
30
|
+
@note out should have getHexLength(x) size
|
|
31
|
+
out is not NUL terminated
|
|
32
|
+
*/
|
|
33
|
+
template<class T>
|
|
34
|
+
void itohex(char *out, size_t len, T x, bool upCase = true)
|
|
35
|
+
{
|
|
36
|
+
static const char *hexTbl[] = {
|
|
37
|
+
"0123456789abcdef",
|
|
38
|
+
"0123456789ABCDEF"
|
|
39
|
+
};
|
|
40
|
+
const char *tbl = hexTbl[upCase];
|
|
41
|
+
for (size_t i = 0; i < len; i++) {
|
|
42
|
+
out[len - i - 1] = tbl[x % 16];
|
|
43
|
+
x /= 16;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/*
|
|
47
|
+
convert x to bin string with len
|
|
48
|
+
@note out should have getBinLength(x) size
|
|
49
|
+
out is not NUL terminated
|
|
50
|
+
*/
|
|
51
|
+
template<class T>
|
|
52
|
+
void itobin(char *out, size_t len, T x)
|
|
53
|
+
{
|
|
54
|
+
for (size_t i = 0; i < len; i++) {
|
|
55
|
+
out[len - i - 1] = '0' + (x & 1);
|
|
56
|
+
x >>= 1;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
namespace itoa_local {
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
convert x to dec
|
|
64
|
+
use buf[0, bufSize)
|
|
65
|
+
return 0 if false
|
|
66
|
+
return writtenSize which is not terminated
|
|
67
|
+
@REMARK the top of string is buf + bufSize - writtenSize
|
|
68
|
+
*/
|
|
69
|
+
template<class UT>
|
|
70
|
+
size_t uintToDec(char *buf, size_t bufSize, UT x)
|
|
71
|
+
{
|
|
72
|
+
for (size_t i = 0; i < bufSize; i++) {
|
|
73
|
+
buf[bufSize - 1 - i] = '0' + static_cast<int>(x % 10);
|
|
74
|
+
x /= 10;
|
|
75
|
+
if (x == 0) return i + 1;
|
|
76
|
+
}
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/*
|
|
81
|
+
convert x to hex
|
|
82
|
+
use buf[0, bufSize)
|
|
83
|
+
return 0 if false
|
|
84
|
+
return writtenSize which is not terminated
|
|
85
|
+
@REMARK the top of string is buf + bufSize - writtenSize
|
|
86
|
+
*/
|
|
87
|
+
template<class UT>
|
|
88
|
+
size_t uintToHex(char *buf, size_t bufSize, UT x, bool upCase = true)
|
|
89
|
+
{
|
|
90
|
+
static const char *hexTbl[] = {
|
|
91
|
+
"0123456789abcdef",
|
|
92
|
+
"0123456789ABCDEF"
|
|
93
|
+
};
|
|
94
|
+
const char *tbl = hexTbl[upCase];
|
|
95
|
+
for (size_t i = 0; i < bufSize; i++) {
|
|
96
|
+
buf[bufSize - 1 - i] = tbl[x % 16];
|
|
97
|
+
x /= 16;
|
|
98
|
+
if (x == 0) return i + 1;
|
|
99
|
+
}
|
|
100
|
+
return 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/*
|
|
104
|
+
convert x to bin
|
|
105
|
+
use buf[0, bufSize)
|
|
106
|
+
return 0 if false
|
|
107
|
+
return writtenSize which is not terminated
|
|
108
|
+
@REMARK the top of string is buf + bufSize - writtenSize
|
|
109
|
+
*/
|
|
110
|
+
template<class UT>
|
|
111
|
+
size_t uintToBin(char *buf, size_t bufSize, UT x)
|
|
112
|
+
{
|
|
113
|
+
for (size_t i = 0; i < bufSize; i++) {
|
|
114
|
+
buf[bufSize - 1 - i] = '0' + (x & 1);
|
|
115
|
+
x >>= 1;
|
|
116
|
+
if (x == 0) return i + 1;
|
|
117
|
+
}
|
|
118
|
+
return 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
template<class T>
|
|
122
|
+
size_t intToDec(char *buf, size_t bufSize, T x)
|
|
123
|
+
{
|
|
124
|
+
if (x == CYBOZU_LLONG_MIN) {
|
|
125
|
+
const char minStr[] = "-9223372036854775808";
|
|
126
|
+
const size_t minStrLen = sizeof(minStr) - 1;
|
|
127
|
+
if (bufSize < minStrLen) {
|
|
128
|
+
return 0;
|
|
129
|
+
} else {
|
|
130
|
+
memcpy(buf + bufSize - minStrLen, minStr, minStrLen);
|
|
131
|
+
return minStrLen;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
bool negative = x < 0;
|
|
135
|
+
uint64_t absX = negative ? -x : x;
|
|
136
|
+
size_t n = uintToDec(buf, bufSize, absX);
|
|
137
|
+
if (n == 0) return 0;
|
|
138
|
+
if (negative) {
|
|
139
|
+
if (bufSize == n) return 0;
|
|
140
|
+
n++;
|
|
141
|
+
buf[bufSize - n] = '-';
|
|
142
|
+
}
|
|
143
|
+
return n;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
#ifndef CYBOZU_DONT_USE_STRING
|
|
147
|
+
template<typename T>
|
|
148
|
+
void convertFromUint(std::string& out, T x)
|
|
149
|
+
{
|
|
150
|
+
char buf[40];
|
|
151
|
+
size_t n = uintToDec(buf, sizeof(buf), x);
|
|
152
|
+
assert(n > 0);
|
|
153
|
+
out.assign(buf + sizeof(buf) - n, n);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
inline void convertFromInt(std::string& out, long long x)
|
|
157
|
+
{
|
|
158
|
+
char buf[40];
|
|
159
|
+
size_t n = intToDec(buf, sizeof(buf), x);
|
|
160
|
+
assert(n > 0);
|
|
161
|
+
out.assign(buf + sizeof(buf) - n, n);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
template<typename T>
|
|
165
|
+
void itohexLocal(std::string& out, T x, bool upCase, bool withZero)
|
|
166
|
+
{
|
|
167
|
+
const size_t size = withZero ? sizeof(T) * 2 : getHexLength(x);
|
|
168
|
+
out.resize(size);
|
|
169
|
+
itohex(&out[0], size, x, upCase);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
template<class T>
|
|
173
|
+
void itobinLocal(std::string& out, T x, bool withZero)
|
|
174
|
+
{
|
|
175
|
+
const size_t size = withZero ? sizeof(T) * 8 : getBinLength(x);
|
|
176
|
+
out.resize(size);
|
|
177
|
+
itobin(&out[0], size, x);
|
|
178
|
+
}
|
|
179
|
+
#endif
|
|
180
|
+
|
|
181
|
+
} // itoa_local
|
|
182
|
+
|
|
183
|
+
#ifndef CYBOZU_DONT_USE_STRING
|
|
184
|
+
/**
|
|
185
|
+
convert int to string
|
|
186
|
+
@param out [out] string
|
|
187
|
+
@param x [in] int
|
|
188
|
+
*/
|
|
189
|
+
inline void itoa(std::string& out, int x)
|
|
190
|
+
{
|
|
191
|
+
itoa_local::convertFromInt(out, x);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
convert long long to string
|
|
196
|
+
@param out [out] string
|
|
197
|
+
@param x [in] long long
|
|
198
|
+
*/
|
|
199
|
+
inline void itoa(std::string& out, long long x)
|
|
200
|
+
{
|
|
201
|
+
itoa_local::convertFromInt(out, x);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
convert unsigned int to string
|
|
206
|
+
@param out [out] string
|
|
207
|
+
@param x [in] unsigned int
|
|
208
|
+
*/
|
|
209
|
+
inline void itoa(std::string& out, unsigned int x)
|
|
210
|
+
{
|
|
211
|
+
itoa_local::convertFromUint(out, x);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
convert unsigned long long to string
|
|
216
|
+
@param out [out] string
|
|
217
|
+
@param x [in] unsigned long long
|
|
218
|
+
*/
|
|
219
|
+
inline void itoa(std::string& out, unsigned long long x)
|
|
220
|
+
{
|
|
221
|
+
itoa_local::convertFromUint(out, x);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
#if defined(__SIZEOF_LONG__) && (__SIZEOF_LONG__ == 8)
|
|
225
|
+
inline void itoa(std::string& out, long x) { itoa(out, static_cast<long long>(x)); }
|
|
226
|
+
inline void itoa(std::string& out, unsigned long x) { itoa(out, static_cast<unsigned long long>(x)); }
|
|
227
|
+
#else
|
|
228
|
+
inline void itoa(std::string& out, long x) { itoa(out, static_cast<int>(x)); }
|
|
229
|
+
inline void itoa(std::string& out, unsigned long x) { itoa(out, static_cast<int>(x)); }
|
|
230
|
+
#endif
|
|
231
|
+
/**
|
|
232
|
+
convert integer to string
|
|
233
|
+
@param x [in] int
|
|
234
|
+
*/
|
|
235
|
+
template<typename T>
|
|
236
|
+
inline std::string itoa(T x)
|
|
237
|
+
{
|
|
238
|
+
std::string ret;
|
|
239
|
+
itoa(ret, x);
|
|
240
|
+
return ret;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
inline void itohex(std::string& out, unsigned char x, bool upCase = true, bool withZero = true)
|
|
244
|
+
{
|
|
245
|
+
itoa_local::itohexLocal(out, x, upCase, withZero);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
inline void itohex(std::string& out, unsigned short x, bool upCase = true, bool withZero = true)
|
|
249
|
+
{
|
|
250
|
+
itoa_local::itohexLocal(out, x, upCase, withZero);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
inline void itohex(std::string& out, unsigned int x, bool upCase = true, bool withZero = true)
|
|
254
|
+
{
|
|
255
|
+
itoa_local::itohexLocal(out, x, upCase, withZero);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
inline void itohex(std::string& out, unsigned long x, bool upCase = true, bool withZero = true)
|
|
259
|
+
{
|
|
260
|
+
itoa_local::itohexLocal(out, x, upCase, withZero);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
inline void itohex(std::string& out, unsigned long long x, bool upCase = true, bool withZero = true)
|
|
264
|
+
{
|
|
265
|
+
itoa_local::itohexLocal(out, x, upCase, withZero);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
template<typename T>
|
|
269
|
+
inline std::string itobin(T x, bool withZero = true)
|
|
270
|
+
{
|
|
271
|
+
std::string out;
|
|
272
|
+
itoa_local::itobinLocal(out, x, withZero);
|
|
273
|
+
return out;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
inline void itobin(std::string& out, unsigned char x, bool withZero = true)
|
|
277
|
+
{
|
|
278
|
+
itoa_local::itobinLocal(out, x, withZero);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
inline void itobin(std::string& out, unsigned short x, bool withZero = true)
|
|
282
|
+
{
|
|
283
|
+
itoa_local::itobinLocal(out, x, withZero);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
inline void itobin(std::string& out, unsigned int x, bool withZero = true)
|
|
287
|
+
{
|
|
288
|
+
itoa_local::itobinLocal(out, x, withZero);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
inline void itobin(std::string& out, unsigned long x, bool withZero = true)
|
|
292
|
+
{
|
|
293
|
+
itoa_local::itobinLocal(out, x, withZero);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
inline void itobin(std::string& out, unsigned long long x, bool withZero = true)
|
|
297
|
+
{
|
|
298
|
+
itoa_local::itobinLocal(out, x, withZero);
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
template<typename T>
|
|
302
|
+
inline std::string itohex(T x, bool upCase = true, bool withZero = true)
|
|
303
|
+
{
|
|
304
|
+
std::string out;
|
|
305
|
+
itohex(out, x, upCase, withZero);
|
|
306
|
+
return out;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
convert integer to string with zero padding
|
|
310
|
+
@param x [in] int
|
|
311
|
+
@param len [in] minimum lengh of string
|
|
312
|
+
@param c [in] padding character
|
|
313
|
+
@note
|
|
314
|
+
itoa(12, 4) == "0012"
|
|
315
|
+
itoa(1234, 4) == "1234"
|
|
316
|
+
itoa(12345, 4) == "12345"
|
|
317
|
+
itoa(-12, 4) == "-012"
|
|
318
|
+
*/
|
|
319
|
+
template<typename T>
|
|
320
|
+
inline std::string itoaWithZero(T x, size_t len, char c = '0')
|
|
321
|
+
{
|
|
322
|
+
std::string ret;
|
|
323
|
+
itoa(ret, x);
|
|
324
|
+
if (ret.size() < len) {
|
|
325
|
+
std::string zero(len - ret.size(), c);
|
|
326
|
+
if (x >= 0) {
|
|
327
|
+
ret = zero + ret;
|
|
328
|
+
} else {
|
|
329
|
+
ret = "-" + zero + ret.substr(1);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return ret;
|
|
333
|
+
}
|
|
334
|
+
#endif
|
|
335
|
+
|
|
336
|
+
} // cybozu
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
/**
|
|
3
|
+
@file
|
|
4
|
+
@brief json parser
|
|
5
|
+
|
|
6
|
+
@author MITSUNARI Shigeo(@herumi)
|
|
7
|
+
*/
|
|
8
|
+
#include <assert.h>
|
|
9
|
+
#include <vector>
|
|
10
|
+
#include <map>
|
|
11
|
+
#include <cybozu/exception.hpp>
|
|
12
|
+
|
|
13
|
+
namespace cybozu {
|
|
14
|
+
|
|
15
|
+
class Json {
|
|
16
|
+
public:
|
|
17
|
+
enum Type {
|
|
18
|
+
T_Null,
|
|
19
|
+
T_String,
|
|
20
|
+
T_Object,
|
|
21
|
+
T_Array,
|
|
22
|
+
T_Number,
|
|
23
|
+
T_Bool
|
|
24
|
+
};
|
|
25
|
+
struct Object;
|
|
26
|
+
struct Array;
|
|
27
|
+
struct Value {
|
|
28
|
+
Type type_;
|
|
29
|
+
union {
|
|
30
|
+
std::string *str_;
|
|
31
|
+
Object *obj_;
|
|
32
|
+
Array *arr_;
|
|
33
|
+
bool b_;
|
|
34
|
+
double num_;
|
|
35
|
+
uint64_t ptn_;
|
|
36
|
+
};
|
|
37
|
+
Value() : type_(T_Null), ptn_(0) {}
|
|
38
|
+
~Value()
|
|
39
|
+
{
|
|
40
|
+
switch (type_) {
|
|
41
|
+
case T_String: delete str_; break;
|
|
42
|
+
case T_Object: delete obj_; break;
|
|
43
|
+
case T_Array: delete arr_; break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
explicit Value(double num)
|
|
47
|
+
: type_(T_Number)
|
|
48
|
+
{
|
|
49
|
+
num_ = num;
|
|
50
|
+
}
|
|
51
|
+
explicit Value(const std::string& str)
|
|
52
|
+
: type_(T_String)
|
|
53
|
+
{
|
|
54
|
+
str_ = new std::string(str);
|
|
55
|
+
}
|
|
56
|
+
explicit Value(const char *str)
|
|
57
|
+
: type_(T_String)
|
|
58
|
+
{
|
|
59
|
+
str_ = new std::string(str);
|
|
60
|
+
}
|
|
61
|
+
explicit Value(bool b)
|
|
62
|
+
: type_(T_Bool)
|
|
63
|
+
{
|
|
64
|
+
b_ = b;
|
|
65
|
+
}
|
|
66
|
+
explicit Value(const Array& arr)
|
|
67
|
+
: type_(T_Array)
|
|
68
|
+
{
|
|
69
|
+
arr_ = new Array(arr);
|
|
70
|
+
}
|
|
71
|
+
explicit Value(const Object& obj)
|
|
72
|
+
: type_(T_Object)
|
|
73
|
+
{
|
|
74
|
+
obj_ = new Object(obj);
|
|
75
|
+
}
|
|
76
|
+
void swap(Value& rhs) CYBOZU_NOEXCEPT
|
|
77
|
+
{
|
|
78
|
+
std::swap(type_, rhs.type_);
|
|
79
|
+
std::swap(ptn_, rhs.ptn_);
|
|
80
|
+
}
|
|
81
|
+
Value(const Value& rhs)
|
|
82
|
+
: type_(rhs.type_)
|
|
83
|
+
{
|
|
84
|
+
switch (type_) {
|
|
85
|
+
case T_Null: ptn_ = 0; break;
|
|
86
|
+
case T_String: str_ = new std::string(*rhs.str_); break;
|
|
87
|
+
case T_Object: obj_ = new Object(*rhs.obj_); break;
|
|
88
|
+
case T_Array: arr_ = new Array(*rhs.arr_); break;
|
|
89
|
+
case T_Number: num_ = rhs.num_; break;
|
|
90
|
+
case T_Bool: b_ = rhs.b_; break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
bool isNull() const { return type_ == T_Null; }
|
|
94
|
+
bool isString() const { return type_ == T_String; }
|
|
95
|
+
bool isObject() const { return type_ == T_Object; }
|
|
96
|
+
bool isArray() const { return type_ == T_Array; }
|
|
97
|
+
bool isBool() const { return type_ == T_Bool; }
|
|
98
|
+
bool isNumber() const { return type_ == T_Number; }
|
|
99
|
+
|
|
100
|
+
const std::string& getString() const { assert(isString()); return *str_; }
|
|
101
|
+
const Object& getObject() const { assert(isObject()); return *obj_; }
|
|
102
|
+
const Array& getArray() const { assert(isArray()); return *arr_; }
|
|
103
|
+
bool getBool() const { assert(isBool()); return b_; }
|
|
104
|
+
double getNumber() const { assert(isNumber()); return num_; }
|
|
105
|
+
|
|
106
|
+
Value& operator=(const Value& rhs)
|
|
107
|
+
{
|
|
108
|
+
Value tmp(rhs);
|
|
109
|
+
swap(tmp);
|
|
110
|
+
return *this;
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
struct Object : std::map<std::string, Value> {
|
|
114
|
+
};
|
|
115
|
+
struct Array : std::vector<Value> {
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
} // cybozu
|