├── .dockerignore ├── Dockerfile ├── LICENSE ├── Makefile.am ├── README.md ├── configure.ac ├── external └── rapidjson │ ├── .gitattributes │ ├── .gitignore │ ├── .gitmodules │ ├── .travis.yml │ ├── CHANGELOG.md │ ├── CMakeLists.txt │ ├── CMakeModules │ └── FindGTestSrc.cmake │ ├── RapidJSON.pc.in │ ├── RapidJSONConfig.cmake.in │ ├── RapidJSONConfigVersion.cmake.in │ ├── appveyor.yml │ ├── bin │ ├── data │ │ ├── abcde.txt │ │ ├── glossary.json │ │ ├── menu.json │ │ ├── readme.txt │ │ ├── sample.json │ │ ├── webapp.json │ │ └── widget.json │ ├── encodings │ │ ├── utf16be.json │ │ ├── utf16bebom.json │ │ ├── utf16le.json │ │ ├── utf16lebom.json │ │ ├── utf32be.json │ │ ├── utf32bebom.json │ │ ├── utf32le.json │ │ ├── utf32lebom.json │ │ ├── utf8.json │ │ └── utf8bom.json │ ├── jsonchecker │ │ ├── fail1.json │ │ ├── fail10.json │ │ ├── fail11.json │ │ ├── fail12.json │ │ ├── fail13.json │ │ ├── fail14.json │ │ ├── fail15.json │ │ ├── fail16.json │ │ ├── fail17.json │ │ ├── fail18.json │ │ ├── fail19.json │ │ ├── fail2.json │ │ ├── fail20.json │ │ ├── fail21.json │ │ ├── fail22.json │ │ ├── fail23.json │ │ ├── fail24.json │ │ ├── fail25.json │ │ ├── fail26.json │ │ ├── fail27.json │ │ ├── fail28.json │ │ ├── fail29.json │ │ ├── fail3.json │ │ ├── fail30.json │ │ ├── fail31.json │ │ ├── fail32.json │ │ ├── fail33.json │ │ ├── fail4.json │ │ ├── fail5.json │ │ ├── fail6.json │ │ ├── fail7.json │ │ ├── fail8.json │ │ ├── fail9.json │ │ ├── pass1.json │ │ ├── pass2.json │ │ ├── pass3.json │ │ └── readme.txt │ └── types │ │ ├── booleans.json │ │ ├── floats.json │ │ ├── guids.json │ │ ├── integers.json │ │ ├── mixed.json │ │ ├── nulls.json │ │ ├── paragraphs.json │ │ └── readme.txt │ ├── contrib │ └── natvis │ │ ├── LICENSE │ │ ├── README.md │ │ └── rapidjson.natvis │ ├── doc │ ├── CMakeLists.txt │ ├── Doxyfile.in │ ├── Doxyfile.zh-cn.in │ ├── diagram │ │ ├── architecture.dot │ │ ├── architecture.png │ │ ├── insituparsing.dot │ │ ├── insituparsing.png │ │ ├── iterative-parser-states-diagram.dot │ │ ├── iterative-parser-states-diagram.png │ │ ├── makefile │ │ ├── move1.dot │ │ ├── move1.png │ │ ├── move2.dot │ │ ├── move2.png │ │ ├── move3.dot │ │ ├── move3.png │ │ ├── normalparsing.dot │ │ ├── normalparsing.png │ │ ├── simpledom.dot │ │ ├── simpledom.png │ │ ├── tutorial.dot │ │ ├── tutorial.png │ │ ├── utilityclass.dot │ │ └── utilityclass.png │ ├── dom.md │ ├── dom.zh-cn.md │ ├── encoding.md │ ├── encoding.zh-cn.md │ ├── faq.md │ ├── faq.zh-cn.md │ ├── features.md │ ├── features.zh-cn.md │ ├── internals.md │ ├── internals.zh-cn.md │ ├── logo │ │ ├── rapidjson.png │ │ └── rapidjson.svg │ ├── misc │ │ ├── DoxygenLayout.xml │ │ ├── doxygenextra.css │ │ ├── footer.html │ │ └── header.html │ ├── npm.md │ ├── performance.md │ ├── performance.zh-cn.md │ ├── pointer.md │ ├── pointer.zh-cn.md │ ├── sax.md │ ├── sax.zh-cn.md │ ├── schema.md │ ├── schema.zh-cn.md │ ├── stream.md │ ├── stream.zh-cn.md │ ├── tutorial.md │ └── tutorial.zh-cn.md │ ├── docker │ └── debian │ │ └── Dockerfile │ ├── example │ ├── CMakeLists.txt │ ├── archiver │ │ ├── archiver.cpp │ │ ├── archiver.h │ │ └── archivertest.cpp │ ├── capitalize │ │ └── capitalize.cpp │ ├── condense │ │ └── condense.cpp │ ├── filterkey │ │ └── filterkey.cpp │ ├── filterkeydom │ │ └── filterkeydom.cpp │ ├── jsonx │ │ └── jsonx.cpp │ ├── lookaheadparser │ │ └── lookaheadparser.cpp │ ├── messagereader │ │ └── messagereader.cpp │ ├── parsebyparts │ │ └── parsebyparts.cpp │ ├── pretty │ │ └── pretty.cpp │ ├── prettyauto │ │ └── prettyauto.cpp │ ├── schemavalidator │ │ └── schemavalidator.cpp │ ├── serialize │ │ └── serialize.cpp │ ├── simpledom │ │ └── simpledom.cpp │ ├── simplepullreader │ │ └── simplepullreader.cpp │ ├── simplereader │ │ └── simplereader.cpp │ ├── simplewriter │ │ └── simplewriter.cpp │ ├── sortkeys │ │ └── sortkeys.cpp │ └── tutorial │ │ └── tutorial.cpp │ ├── include │ └── rapidjson │ │ ├── .writer.h.swp │ │ ├── allocators.h │ │ ├── cursorstreamwrapper.h │ │ ├── document.h │ │ ├── encodedstream.h │ │ ├── encodings.h │ │ ├── error │ │ ├── en.h │ │ └── error.h │ │ ├── filereadstream.h │ │ ├── filewritestream.h │ │ ├── fwd.h │ │ ├── internal │ │ ├── biginteger.h │ │ ├── clzll.h │ │ ├── diyfp.h │ │ ├── dtoa.h │ │ ├── ieee754.h │ │ ├── itoa.h │ │ ├── meta.h │ │ ├── pow10.h │ │ ├── regex.h │ │ ├── stack.h │ │ ├── strfunc.h │ │ ├── strtod.h │ │ └── swap.h │ │ ├── istreamwrapper.h │ │ ├── memorybuffer.h │ │ ├── memorystream.h │ │ ├── msinttypes │ │ ├── inttypes.h │ │ └── stdint.h │ │ ├── ostreamwrapper.h │ │ ├── pointer.h │ │ ├── prettywriter.h │ │ ├── rapidjson.h │ │ ├── reader.h │ │ ├── schema.h │ │ ├── stream.h │ │ ├── stringbuffer.h │ │ └── writer.h │ ├── include_dirs.js │ ├── library.json │ ├── license.txt │ ├── package.json │ ├── rapidjson.autopkg │ ├── readme.md │ ├── readme.zh-cn.md │ ├── test │ ├── CMakeLists.txt │ ├── perftest │ │ ├── CMakeLists.txt │ │ ├── misctest.cpp │ │ ├── perftest.cpp │ │ ├── perftest.h │ │ ├── platformtest.cpp │ │ ├── rapidjsontest.cpp │ │ └── schematest.cpp │ ├── unittest │ │ ├── CMakeLists.txt │ │ ├── allocatorstest.cpp │ │ ├── bigintegertest.cpp │ │ ├── clzlltest.cpp │ │ ├── cursorstreamwrappertest.cpp │ │ ├── documenttest.cpp │ │ ├── dtoatest.cpp │ │ ├── encodedstreamtest.cpp │ │ ├── encodingstest.cpp │ │ ├── filestreamtest.cpp │ │ ├── fwdtest.cpp │ │ ├── istreamwrappertest.cpp │ │ ├── itoatest.cpp │ │ ├── jsoncheckertest.cpp │ │ ├── namespacetest.cpp │ │ ├── ostreamwrappertest.cpp │ │ ├── pointertest.cpp │ │ ├── prettywritertest.cpp │ │ ├── readertest.cpp │ │ ├── regextest.cpp │ │ ├── schematest.cpp │ │ ├── simdtest.cpp │ │ ├── strfunctest.cpp │ │ ├── stringbuffertest.cpp │ │ ├── strtodtest.cpp │ │ ├── unittest.cpp │ │ ├── unittest.h │ │ ├── valuetest.cpp │ │ └── writertest.cpp │ └── valgrind.supp │ └── travis-doxygen.sh └── src ├── ascii_table.hpp ├── byte_slice.cpp ├── byte_slice.hpp ├── byte_stream.cpp ├── byte_stream.hpp ├── display ├── colors.cpp ├── colors.hpp ├── exit.hpp ├── falling_text.cpp ├── falling_text.hpp ├── loading_messages.hpp ├── string.hpp ├── sync_meter.cpp ├── sync_meter.hpp ├── system_warning.cpp ├── system_warning.hpp ├── window.cpp └── window.hpp ├── engine.cpp ├── engine.hpp ├── error.cpp ├── error.hpp ├── expect.cpp ├── expect.hpp ├── hex.cpp ├── hex.hpp ├── main.cpp ├── method.cpp ├── method.hpp ├── monero_data.cpp ├── monero_data.hpp ├── pub.cpp ├── pub.hpp ├── rpc └── json.hpp ├── span.hpp ├── wire.hpp ├── wire ├── error.cpp ├── error.hpp ├── field.hpp ├── fwd.hpp ├── json.hpp ├── json │ ├── base.hpp │ ├── error.cpp │ ├── error.hpp │ ├── fwd.hpp │ ├── read.cpp │ ├── read.hpp │ ├── write.cpp │ └── write.hpp ├── traits.hpp └── vector.hpp ├── zmq.cpp └── zmq.hpp /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | Dockerfile 3 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:20.04 2 | 3 | WORKDIR /srv 4 | 5 | RUN apt-get update && apt-get install -y \ 6 | build-essential automake libzmq3-dev libncurses-dev 7 | 8 | COPY . ./ 9 | 10 | RUN autoreconf -i && mkdir build && cd build && CXXFLAGS="-O2 -DNDEBUG" ../configure && make 11 | 12 | RUN install /srv/build/motrix /usr/local/bin 13 | 14 | ENTRYPOINT ["motrix"] 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020, Lee Clagett 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its contributors 16 | may be used to endorse or promote products derived from this software without 17 | specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 20 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | 30 | 31 | 32 | Parts of this project are originally copyright (c) The Monero Project: 33 | 34 | Copyright (c) 2018-2020, The Monero Project 35 | 36 | All rights reserved. 37 | 38 | Redistribution and use in source and binary forms, with or without 39 | modification, are permitted provided that the following conditions are met: 40 | 41 | 1. Redistributions of source code must retain the above copyright notice, this 42 | list of conditions and the following disclaimer. 43 | 44 | 2. Redistributions in binary form must reproduce the above copyright notice, 45 | this list of conditions and the following disclaimer in the documentation 46 | and/or other materials provided with the distribution. 47 | 48 | 3. Neither the name of the copyright holder nor the names of its contributors 49 | may be used to endorse or promote products derived from this software without 50 | specific prior written permission. 51 | 52 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 53 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 54 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 55 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 56 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 57 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 58 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 59 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 60 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 61 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 | 63 | 64 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | 2 | bin_PROGRAMS = motrix 3 | motrix_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/external/rapidjson/include 4 | motrix_SOURCES = \ 5 | external/rapidjson/include/rapidjson/allocators.h \ 6 | external/rapidjson/include/rapidjson/encodedstream.h \ 7 | external/rapidjson/include/rapidjson/encodings.h \ 8 | external/rapidjson/include/rapidjson/error/en.h \ 9 | external/rapidjson/include/rapidjson/error/error.h \ 10 | external/rapidjson/include/rapidjson/fwd.h \ 11 | external/rapidjson/include/rapidjson/internal/biginteger.h \ 12 | external/rapidjson/include/rapidjson/internal/clzll.h \ 13 | external/rapidjson/include/rapidjson/internal/diyfp.h \ 14 | external/rapidjson/include/rapidjson/internal/dtoa.h \ 15 | external/rapidjson/include/rapidjson/internal/ieee754.h \ 16 | external/rapidjson/include/rapidjson/internal/itoa.h \ 17 | external/rapidjson/include/rapidjson/internal/meta.h \ 18 | external/rapidjson/include/rapidjson/internal/pow10.h \ 19 | external/rapidjson/include/rapidjson/internal/regex.h \ 20 | external/rapidjson/include/rapidjson/internal/stack.h \ 21 | external/rapidjson/include/rapidjson/internal/strfunc.h \ 22 | external/rapidjson/include/rapidjson/internal/strtod.h \ 23 | external/rapidjson/include/rapidjson/internal/swap.h \ 24 | external/rapidjson/include/rapidjson/memorystream.h \ 25 | external/rapidjson/include/rapidjson/pointer.h \ 26 | external/rapidjson/include/rapidjson/rapidjson.h \ 27 | external/rapidjson/include/rapidjson/reader.h \ 28 | external/rapidjson/include/rapidjson/stream.h \ 29 | external/rapidjson/include/rapidjson/stringbuffer.h \ 30 | external/rapidjson/include/rapidjson/writer.h \ 31 | external/rapidjson/license.txt \ 32 | src/ascii_table.hpp \ 33 | src/byte_slice.cpp \ 34 | src/byte_slice.hpp \ 35 | src/byte_stream.cpp \ 36 | src/byte_stream.hpp \ 37 | src/display/colors.cpp \ 38 | src/display/colors.hpp \ 39 | src/display/exit.hpp \ 40 | src/display/falling_text.cpp \ 41 | src/display/falling_text.hpp \ 42 | src/display/loading_messages.hpp \ 43 | src/display/string.hpp \ 44 | src/display/sync_meter.cpp \ 45 | src/display/sync_meter.hpp \ 46 | src/display/system_warning.cpp \ 47 | src/display/system_warning.hpp \ 48 | src/display/window.cpp \ 49 | src/display/window.hpp \ 50 | src/engine.cpp \ 51 | src/engine.hpp \ 52 | src/error.cpp \ 53 | src/error.hpp \ 54 | src/expect.cpp \ 55 | src/expect.hpp \ 56 | src/hex.cpp \ 57 | src/hex.hpp \ 58 | src/main.cpp \ 59 | src/method.cpp \ 60 | src/method.hpp \ 61 | src/monero_data.cpp \ 62 | src/monero_data.hpp \ 63 | src/pub.cpp \ 64 | src/pub.hpp \ 65 | src/rpc/json.hpp \ 66 | src/span.hpp \ 67 | src/wire.hpp \ 68 | src/wire/error.cpp \ 69 | src/wire/error.hpp \ 70 | src/wire/field.hpp \ 71 | src/wire/fwd.hpp \ 72 | src/wire/json.hpp \ 73 | src/wire/json/base.hpp \ 74 | src/wire/json/error.cpp \ 75 | src/wire/json/error.hpp \ 76 | src/wire/json/fwd.hpp \ 77 | src/wire/json/read.cpp \ 78 | src/wire/json/read.hpp \ 79 | src/wire/json/write.cpp \ 80 | src/wire/json/write.hpp \ 81 | src/wire/traits.hpp \ 82 | src/wire/vector.hpp \ 83 | src/zmq.cpp \ 84 | src/zmq.hpp 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # The Motrix 2 | 3 | > Unfortunately, no one can be told what Monero is. You'll have to see it for 4 | > yourself. 5 | 6 | Watch real-value exchanges just like our ancestors did - in Matrix terminals. 7 | 8 | ![macOS standard color scheme](https://raw.githubusercontent.com/vtnerd/motrix/screencaps-0.1.1/macos-standard-720p.gif) 9 | 10 | # About 11 | 12 | This is a terminal (ncurses) visualizer for the [monero daemon](https://github.com/monero-project/monero). 13 | Data is pushed in real-time from the daemon, then displayed in the matrix "motif" 14 | (falling text) using z85 encoding. The information displayed depends on the 15 | current state of the local monero daemon. 16 | 17 | When the monero daemon is synchronizing with the blockchain, the falling text 18 | background contains recently processed block hashes. The foreground is a 19 | progress meter with useless SimCity 3000 loading messages. 20 | 21 | When the monero daemon is synchronized, the falling text contains transactions 22 | currently in the mempool with nothing in the foreground. When a new block 23 | arrives, the screen pauses to display information about the latest block, then 24 | unfreezes to continue the mempool display. 25 | 26 | This also serves as example application for developers interested in using ZeroMQ 27 | Pub/Sub to get information quickly from the daemon without polling. 28 | 29 | ## License 30 | 31 | See [LICENSE](LICENSE). 32 | 33 | ## Building 34 | 35 | A C++11 compiler, and development libraries for ncurses and ZeroMQ 4.0+ are 36 | required. They should be available in any package manager. 37 | 38 | from tarball: 39 | ```bash 40 | cd motrix-0.1.1 41 | CXXFLAGS="-O2 -DNDEBUG" ./configure && make 42 | ``` 43 | 44 | from git repo: 45 | ```bash 46 | cd motrix 47 | autoreconf -i 48 | mkdir build && cd build 49 | CXXFLAGS="-O2 -DNDEBUG" ../configure && make 50 | ``` 51 | 52 | ## Running 53 | 54 | A development build of the monero daemon is needed. The daemon should be started 55 | with an additional flag: `--zmq-pub tcp://127.0.0.1:5000` (or any port of your 56 | choice). Unix IPC is also supported: `--zmq-pub ipc:///home/monero`, which has 57 | added security benefits. 58 | 59 | The motrix executable can then be started: 60 | ```bash 61 | ./motrix ipc:///home/monero tcp://127.0.0.1:18082 62 | ``` 63 | The daemon does not yet support Unix IPC for ZeroMQ RPC. Testnet RPC port 64 | defaults to 28082 instead of 18081 65 | 66 | ### Docker 67 | 68 | A Dockerfile has been provided for those who may run their nodes or tools using Docker containers. Be sure to utilize `host` networking so that you can reach remote nodes. 69 | 70 | ``` 71 | docker build -t motrix . 72 | docker run --rm -it --net=host motrix tcp://127.0.0.1:18081 tcp://127.0.0.1:18082 auto 73 | ``` 74 | 75 | ### Color Scheme 76 | 77 | Motrix will auto-detect the number of colors available on your terminal. If 78 | the terminal supports 256+ colors, then it defaults to Monero logo colors 79 | for the text. Otherwise it falls back to green (the "matrix" motif). 80 | 81 | The current color scheme options: (1) `monero`, (2) `monero_alt`, (3) `standard` 82 | or (4) `auto` and is the third option to the executable. 83 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([motrix], [0.1], [code@leeclagett.com], [motrix], [https://code.leeclagett.com/motrix]) 2 | AM_INIT_AUTOMAKE([foreign subdir-objects dist-bzip2 dist-xz]) 3 | 4 | #LT_INIT 5 | AC_PROG_CXX 6 | AC_LANG(C++) 7 | 8 | AC_MSG_CHECKING([c++11 enable-if type traits]) 9 | AC_COMPILE_IFELSE( 10 | [AC_LANG_SOURCE([[#include typename std::enable_if::type foo();]])], AC_MSG_RESULT([yes]), AC_MSG_ERROR([failed]) 11 | ) 12 | 13 | AC_MSG_CHECKING([c++11 variadic template support]) 14 | AC_COMPILE_IFELSE( 15 | [AC_LANG_SOURCE([[template void foo(T...) {}]])], AC_MSG_RESULT([yes]), AC_MSG_ERROR([failed]) 16 | ) 17 | 18 | AC_CHECK_HEADER([zmq.h], [], AC_MSG_ERROR([Unable to find ZeroMQ header])) 19 | AC_CHECK_HEADER([ncurses.h], [], AC_MSG_ERROR([Unable to find ncurses header])) 20 | 21 | AC_SEARCH_LIBS([zmq_z85_encode], [zmq], [], AC_MSG_ERROR([Unable to find ZeroMQ lib with z85 functions])) 22 | AC_SEARCH_LIBS([curs_set], [tinfo ncurses], [], AC_MSG_ERROR([Unable to find tinfo compatible ilb])) 23 | AC_SEARCH_LIBS([newwin], [ncurses], [], AC_MSG_ERROR([Unable to find ncurses compatible lib])) 24 | 25 | AC_CONFIG_FILES([Makefile]) 26 | AC_OUTPUT 27 | -------------------------------------------------------------------------------- /external/rapidjson/.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files you want to always be normalized and converted 5 | # to native line endings on checkout. 6 | *.cpp text 7 | *.h text 8 | *.txt text 9 | *.md text 10 | *.cmake text 11 | *.svg text 12 | *.dot text 13 | *.yml text 14 | *.in text 15 | *.sh text 16 | *.autopkg text 17 | Dockerfile text 18 | 19 | # Denote all files that are truly binary and should not be modified. 20 | *.png binary 21 | *.jpg binary 22 | *.json binary -------------------------------------------------------------------------------- /external/rapidjson/.gitignore: -------------------------------------------------------------------------------- 1 | /bin/* 2 | !/bin/data 3 | !/bin/encodings 4 | !/bin/jsonchecker 5 | !/bin/types 6 | /build 7 | /doc/html 8 | /doc/doxygen_*.db 9 | *.a 10 | 11 | # Temporary files created during CMake build 12 | CMakeCache.txt 13 | CMakeFiles 14 | cmake_install.cmake 15 | CTestTestfile.cmake 16 | Makefile 17 | RapidJSON*.cmake 18 | RapidJSON.pc 19 | Testing 20 | /googletest 21 | install_manifest.txt 22 | Doxyfile 23 | Doxyfile.zh-cn 24 | DartConfiguration.tcl 25 | *.nupkg 26 | 27 | # Files created by OS 28 | *.DS_Store 29 | -------------------------------------------------------------------------------- /external/rapidjson/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "thirdparty/gtest"] 2 | path = thirdparty/gtest 3 | url = https://github.com/google/googletest.git 4 | -------------------------------------------------------------------------------- /external/rapidjson/CMakeModules/FindGTestSrc.cmake: -------------------------------------------------------------------------------- 1 | 2 | SET(GTEST_SEARCH_PATH 3 | "${GTEST_SOURCE_DIR}" 4 | "${CMAKE_CURRENT_LIST_DIR}/../thirdparty/gtest/googletest") 5 | 6 | IF(UNIX) 7 | IF(RAPIDJSON_BUILD_THIRDPARTY_GTEST) 8 | LIST(APPEND GTEST_SEARCH_PATH "/usr/src/gtest") 9 | ELSE() 10 | LIST(INSERT GTEST_SEARCH_PATH 1 "/usr/src/gtest") 11 | ENDIF() 12 | ENDIF() 13 | 14 | FIND_PATH(GTEST_SOURCE_DIR 15 | NAMES CMakeLists.txt src/gtest_main.cc 16 | PATHS ${GTEST_SEARCH_PATH}) 17 | 18 | 19 | # Debian installs gtest include directory in /usr/include, thus need to look 20 | # for include directory separately from source directory. 21 | FIND_PATH(GTEST_INCLUDE_DIR 22 | NAMES gtest/gtest.h 23 | PATH_SUFFIXES include 24 | HINTS ${GTEST_SOURCE_DIR} 25 | PATHS ${GTEST_SEARCH_PATH}) 26 | 27 | INCLUDE(FindPackageHandleStandardArgs) 28 | find_package_handle_standard_args(GTestSrc DEFAULT_MSG 29 | GTEST_SOURCE_DIR 30 | GTEST_INCLUDE_DIR) 31 | -------------------------------------------------------------------------------- /external/rapidjson/RapidJSON.pc.in: -------------------------------------------------------------------------------- 1 | includedir=@INCLUDE_INSTALL_DIR@ 2 | 3 | Name: @PROJECT_NAME@ 4 | Description: A fast JSON parser/generator for C++ with both SAX/DOM style API 5 | Version: @LIB_VERSION_STRING@ 6 | URL: https://github.com/Tencent/rapidjson 7 | Cflags: -I${includedir} 8 | -------------------------------------------------------------------------------- /external/rapidjson/RapidJSONConfig.cmake.in: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # CMake minimum version required 3 | cmake_minimum_required(VERSION 3.0) 4 | 5 | ################################################################################ 6 | # RapidJSON source dir 7 | set( RapidJSON_SOURCE_DIR "@CONFIG_SOURCE_DIR@") 8 | 9 | ################################################################################ 10 | # RapidJSON build dir 11 | set( RapidJSON_DIR "@CONFIG_DIR@") 12 | 13 | ################################################################################ 14 | # Compute paths 15 | get_filename_component(RapidJSON_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 16 | 17 | set( RapidJSON_INCLUDE_DIR "@RapidJSON_INCLUDE_DIR@" ) 18 | set( RapidJSON_INCLUDE_DIRS "@RapidJSON_INCLUDE_DIR@" ) 19 | message(STATUS "RapidJSON found. Headers: ${RapidJSON_INCLUDE_DIRS}") 20 | 21 | if(NOT TARGET rapidjson) 22 | add_library(rapidjson INTERFACE IMPORTED) 23 | set_property(TARGET rapidjson PROPERTY 24 | INTERFACE_INCLUDE_DIRECTORIES ${RapidJSON_INCLUDE_DIRS}) 25 | endif() 26 | -------------------------------------------------------------------------------- /external/rapidjson/RapidJSONConfigVersion.cmake.in: -------------------------------------------------------------------------------- 1 | SET(PACKAGE_VERSION "@LIB_VERSION_STRING@") 2 | 3 | IF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) 4 | SET(PACKAGE_VERSION_EXACT "true") 5 | ENDIF (PACKAGE_FIND_VERSION VERSION_EQUAL PACKAGE_VERSION) 6 | IF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) 7 | SET(PACKAGE_VERSION_COMPATIBLE "true") 8 | ELSE (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) 9 | SET(PACKAGE_VERSION_UNSUITABLE "true") 10 | ENDIF (NOT PACKAGE_FIND_VERSION VERSION_GREATER PACKAGE_VERSION) 11 | -------------------------------------------------------------------------------- /external/rapidjson/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: 1.1.0.{build} 2 | 3 | configuration: 4 | - Debug 5 | - Release 6 | 7 | environment: 8 | matrix: 9 | # - VS_VERSION: 9 2008 10 | # VS_PLATFORM: win32 11 | # - VS_VERSION: 9 2008 12 | # VS_PLATFORM: x64 13 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 14 | VS_VERSION: 10 2010 15 | VS_PLATFORM: win32 16 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 17 | VS_VERSION: 10 2010 18 | VS_PLATFORM: x64 19 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 20 | VS_VERSION: 11 2012 21 | VS_PLATFORM: win32 22 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 23 | VS_VERSION: 11 2012 24 | VS_PLATFORM: x64 25 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 26 | VS_VERSION: 12 2013 27 | VS_PLATFORM: win32 28 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 29 | VS_VERSION: 12 2013 30 | VS_PLATFORM: x64 31 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 32 | VS_VERSION: 14 2015 33 | VS_PLATFORM: win32 34 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 35 | VS_VERSION: 14 2015 36 | VS_PLATFORM: x64 37 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 38 | VS_VERSION: 15 2017 39 | VS_PLATFORM: win32 40 | - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 41 | VS_VERSION: 15 2017 42 | VS_PLATFORM: x64 43 | 44 | before_build: 45 | - git submodule update --init --recursive 46 | - cmake -H. -BBuild/VS -G "Visual Studio %VS_VERSION%" -DCMAKE_GENERATOR_PLATFORM=%VS_PLATFORM% -DCMAKE_VERBOSE_MAKEFILE=ON -DBUILD_SHARED_LIBS=true -Wno-dev 47 | 48 | build: 49 | project: Build\VS\RapidJSON.sln 50 | parallel: true 51 | verbosity: minimal 52 | 53 | test_script: 54 | - cd Build\VS && if %CONFIGURATION%==Debug (ctest --verbose -E perftest --build-config %CONFIGURATION%) else (ctest --verbose --build-config %CONFIGURATION%) 55 | -------------------------------------------------------------------------------- /external/rapidjson/bin/data/abcde.txt: -------------------------------------------------------------------------------- 1 | abcde -------------------------------------------------------------------------------- /external/rapidjson/bin/data/glossary.json: -------------------------------------------------------------------------------- 1 | { 2 | "glossary": { 3 | "title": "example glossary", 4 | "GlossDiv": { 5 | "title": "S", 6 | "GlossList": { 7 | "GlossEntry": { 8 | "ID": "SGML", 9 | "SortAs": "SGML", 10 | "GlossTerm": "Standard Generalized Markup Language", 11 | "Acronym": "SGML", 12 | "Abbrev": "ISO 8879:1986", 13 | "GlossDef": { 14 | "para": "A meta-markup language, used to create markup languages such as DocBook.", 15 | "GlossSeeAlso": ["GML", "XML"] 16 | }, 17 | "GlossSee": "markup" 18 | } 19 | } 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /external/rapidjson/bin/data/menu.json: -------------------------------------------------------------------------------- 1 | {"menu": { 2 | "header": "SVG Viewer", 3 | "items": [ 4 | {"id": "Open"}, 5 | {"id": "OpenNew", "label": "Open New"}, 6 | null, 7 | {"id": "ZoomIn", "label": "Zoom In"}, 8 | {"id": "ZoomOut", "label": "Zoom Out"}, 9 | {"id": "OriginalView", "label": "Original View"}, 10 | null, 11 | {"id": "Quality"}, 12 | {"id": "Pause"}, 13 | {"id": "Mute"}, 14 | null, 15 | {"id": "Find", "label": "Find..."}, 16 | {"id": "FindAgain", "label": "Find Again"}, 17 | {"id": "Copy"}, 18 | {"id": "CopyAgain", "label": "Copy Again"}, 19 | {"id": "CopySVG", "label": "Copy SVG"}, 20 | {"id": "ViewSVG", "label": "View SVG"}, 21 | {"id": "ViewSource", "label": "View Source"}, 22 | {"id": "SaveAs", "label": "Save As"}, 23 | null, 24 | {"id": "Help"}, 25 | {"id": "About", "label": "About Adobe CVG Viewer..."} 26 | ] 27 | }} -------------------------------------------------------------------------------- /external/rapidjson/bin/data/readme.txt: -------------------------------------------------------------------------------- 1 | sample.json is obtained from http://code.google.com/p/json-test-suite/downloads/detail?name=sample.zip 2 | -------------------------------------------------------------------------------- /external/rapidjson/bin/data/widget.json: -------------------------------------------------------------------------------- 1 | {"widget": { 2 | "debug": "on", 3 | "window": { 4 | "title": "Sample Konfabulator Widget", 5 | "name": "main_window", 6 | "width": 500, 7 | "height": 500 8 | }, 9 | "image": { 10 | "src": "Images/Sun.png", 11 | "name": "sun1", 12 | "hOffset": 250, 13 | "vOffset": 250, 14 | "alignment": "center" 15 | }, 16 | "text": { 17 | "data": "Click Here", 18 | "size": 36, 19 | "style": "bold", 20 | "name": "text1", 21 | "hOffset": 250, 22 | "vOffset": 100, 23 | "alignment": "center", 24 | "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;" 25 | } 26 | }} -------------------------------------------------------------------------------- /external/rapidjson/bin/encodings/utf16be.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/bin/encodings/utf16be.json -------------------------------------------------------------------------------- /external/rapidjson/bin/encodings/utf16bebom.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/bin/encodings/utf16bebom.json -------------------------------------------------------------------------------- /external/rapidjson/bin/encodings/utf16le.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/bin/encodings/utf16le.json -------------------------------------------------------------------------------- /external/rapidjson/bin/encodings/utf16lebom.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/bin/encodings/utf16lebom.json -------------------------------------------------------------------------------- /external/rapidjson/bin/encodings/utf32be.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/bin/encodings/utf32be.json -------------------------------------------------------------------------------- /external/rapidjson/bin/encodings/utf32bebom.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/bin/encodings/utf32bebom.json -------------------------------------------------------------------------------- /external/rapidjson/bin/encodings/utf32le.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/bin/encodings/utf32le.json -------------------------------------------------------------------------------- /external/rapidjson/bin/encodings/utf32lebom.json: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/bin/encodings/utf32lebom.json -------------------------------------------------------------------------------- /external/rapidjson/bin/encodings/utf8.json: -------------------------------------------------------------------------------- 1 | { 2 | "en":"I can eat glass and it doesn't hurt me.", 3 | "zh-Hant":"我能吞下玻璃而不傷身體。", 4 | "zh-Hans":"我能吞下玻璃而不伤身体。", 5 | "ja":"私はガラスを食べられます。それは私を傷つけません。", 6 | "ko":"나는 유리를 먹을 수 있어요. 그래도 아프지 않아요" 7 | } -------------------------------------------------------------------------------- /external/rapidjson/bin/encodings/utf8bom.json: -------------------------------------------------------------------------------- 1 | { 2 | "en":"I can eat glass and it doesn't hurt me.", 3 | "zh-Hant":"我能吞下玻璃而不傷身體。", 4 | "zh-Hans":"我能吞下玻璃而不伤身体。", 5 | "ja":"私はガラスを食べられます。それは私を傷つけません。", 6 | "ko":"나는 유리를 먹을 수 있어요. 그래도 아프지 않아요" 7 | } -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail1.json: -------------------------------------------------------------------------------- 1 | "A JSON payload should be an object or array, not a string." -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail10.json: -------------------------------------------------------------------------------- 1 | {"Extra value after close": true} "misplaced quoted value" -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail11.json: -------------------------------------------------------------------------------- 1 | {"Illegal expression": 1 + 2} -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail12.json: -------------------------------------------------------------------------------- 1 | {"Illegal invocation": alert()} -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail13.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot have leading zeroes": 013} -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail14.json: -------------------------------------------------------------------------------- 1 | {"Numbers cannot be hex": 0x14} -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail15.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \x15"] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail16.json: -------------------------------------------------------------------------------- 1 | [\naked] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail17.json: -------------------------------------------------------------------------------- 1 | ["Illegal backslash escape: \017"] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail18.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[[["Too deep"]]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail19.json: -------------------------------------------------------------------------------- 1 | {"Missing colon" null} -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail2.json: -------------------------------------------------------------------------------- 1 | ["Unclosed array" -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail20.json: -------------------------------------------------------------------------------- 1 | {"Double colon":: null} -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail21.json: -------------------------------------------------------------------------------- 1 | {"Comma instead of colon", null} -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail22.json: -------------------------------------------------------------------------------- 1 | ["Colon instead of comma": false] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail23.json: -------------------------------------------------------------------------------- 1 | ["Bad value", truth] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail24.json: -------------------------------------------------------------------------------- 1 | ['single quote'] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail25.json: -------------------------------------------------------------------------------- 1 | [" tab character in string "] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail26.json: -------------------------------------------------------------------------------- 1 | ["tab\ character\ in\ string\ "] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail27.json: -------------------------------------------------------------------------------- 1 | ["line 2 | break"] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail28.json: -------------------------------------------------------------------------------- 1 | ["line\ 2 | break"] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail29.json: -------------------------------------------------------------------------------- 1 | [0e] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail3.json: -------------------------------------------------------------------------------- 1 | {unquoted_key: "keys must be quoted"} -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail30.json: -------------------------------------------------------------------------------- 1 | [0e+] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail31.json: -------------------------------------------------------------------------------- 1 | [0e+-1] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail32.json: -------------------------------------------------------------------------------- 1 | {"Comma instead if closing brace": true, -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail33.json: -------------------------------------------------------------------------------- 1 | ["mismatch"} -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail4.json: -------------------------------------------------------------------------------- 1 | ["extra comma",] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail5.json: -------------------------------------------------------------------------------- 1 | ["double extra comma",,] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail6.json: -------------------------------------------------------------------------------- 1 | [ , "<-- missing value"] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail7.json: -------------------------------------------------------------------------------- 1 | ["Comma after the close"], -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail8.json: -------------------------------------------------------------------------------- 1 | ["Extra close"]] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/fail9.json: -------------------------------------------------------------------------------- 1 | {"Extra comma": true,} -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/pass1.json: -------------------------------------------------------------------------------- 1 | [ 2 | "JSON Test Pattern pass1", 3 | {"object with 1 member":["array with 1 element"]}, 4 | {}, 5 | [], 6 | -42, 7 | true, 8 | false, 9 | null, 10 | { 11 | "integer": 1234567890, 12 | "real": -9876.543210, 13 | "e": 0.123456789e-12, 14 | "E": 1.234567890E+34, 15 | "": 23456789012E66, 16 | "zero": 0, 17 | "one": 1, 18 | "space": " ", 19 | "quote": "\"", 20 | "backslash": "\\", 21 | "controls": "\b\f\n\r\t", 22 | "slash": "/ & \/", 23 | "alpha": "abcdefghijklmnopqrstuvwyz", 24 | "ALPHA": "ABCDEFGHIJKLMNOPQRSTUVWYZ", 25 | "digit": "0123456789", 26 | "0123456789": "digit", 27 | "special": "`1~!@#$%^&*()_+-={':[,]}|;.?", 28 | "hex": "\u0123\u4567\u89AB\uCDEF\uabcd\uef4A", 29 | "true": true, 30 | "false": false, 31 | "null": null, 32 | "array":[ ], 33 | "object":{ }, 34 | "address": "50 St. James Street", 35 | "url": "http://www.JSON.org/", 36 | "comment": "// /* */": " ", 38 | " s p a c e d " :[1,2 , 3 39 | 40 | , 41 | 42 | 4 , 5 , 6 ,7 ],"compact":[1,2,3,4,5,6,7], 43 | "jsontext": "{\"object with 1 member\":[\"array with 1 element\"]}", 44 | "quotes": "" \u0022 %22 0x22 034 "", 45 | "\/\\\"\uCAFE\uBABE\uAB98\uFCDE\ubcda\uef4A\b\f\n\r\t`1~!@#$%^&*()_+-=[]{}|;:',./<>?" 46 | : "A key can be any string" 47 | }, 48 | 0.5 ,98.6 49 | , 50 | 99.44 51 | , 52 | 53 | 1066, 54 | 1e1, 55 | 0.1e1, 56 | 1e-1, 57 | 1e00,2e+00,2e-00 58 | ,"rosebud"] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/pass2.json: -------------------------------------------------------------------------------- 1 | [[[[[[[[[[[[[[[[[[["Not too deep"]]]]]]]]]]]]]]]]]]] -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/pass3.json: -------------------------------------------------------------------------------- 1 | { 2 | "JSON Test Pattern pass3": { 3 | "The outermost value": "must be an object or array.", 4 | "In this test": "It is an object." 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /external/rapidjson/bin/jsonchecker/readme.txt: -------------------------------------------------------------------------------- 1 | Test suite from http://json.org/JSON_checker/. 2 | 3 | If the JSON_checker is working correctly, it must accept all of the pass*.json files and reject all of the fail*.json files. 4 | -------------------------------------------------------------------------------- /external/rapidjson/bin/types/booleans.json: -------------------------------------------------------------------------------- 1 | [ 2 | true, 3 | true, 4 | false, 5 | false, 6 | true, 7 | true, 8 | true, 9 | false, 10 | false, 11 | true, 12 | false, 13 | false, 14 | true, 15 | false, 16 | false, 17 | false, 18 | true, 19 | false, 20 | false, 21 | true, 22 | true, 23 | false, 24 | true, 25 | true, 26 | true, 27 | false, 28 | false, 29 | false, 30 | true, 31 | false, 32 | true, 33 | false, 34 | false, 35 | true, 36 | true, 37 | true, 38 | true, 39 | true, 40 | true, 41 | false, 42 | false, 43 | true, 44 | false, 45 | false, 46 | false, 47 | true, 48 | true, 49 | false, 50 | true, 51 | true, 52 | false, 53 | true, 54 | false, 55 | true, 56 | true, 57 | true, 58 | false, 59 | false, 60 | false, 61 | true, 62 | false, 63 | false, 64 | false, 65 | true, 66 | true, 67 | false, 68 | true, 69 | true, 70 | true, 71 | true, 72 | true, 73 | true, 74 | true, 75 | true, 76 | false, 77 | false, 78 | false, 79 | false, 80 | false, 81 | true, 82 | true, 83 | true, 84 | true, 85 | true, 86 | true, 87 | true, 88 | false, 89 | false, 90 | false, 91 | true, 92 | false, 93 | false, 94 | false, 95 | true, 96 | true, 97 | true, 98 | false, 99 | false, 100 | true, 101 | false 102 | ] -------------------------------------------------------------------------------- /external/rapidjson/bin/types/floats.json: -------------------------------------------------------------------------------- 1 | [ 2 | 135.747111636, 3 | 123.377054008, 4 | 140.527504552, 5 | -72.299143906, 6 | -23.851678949, 7 | 73.586193519, 8 | -158.299382442, 9 | 177.477876032, 10 | 32.268518982, 11 | -139.560009969, 12 | 115.203105183, 13 | -106.025823607, 14 | 167.224138231, 15 | 103.378383732, 16 | -97.498486285, 17 | 18.184723416, 18 | 69.137075711, 19 | 33.849002681, 20 | -120.185228215, 21 | -20.841408615, 22 | -172.659492727, 23 | -2.691464061, 24 | 22.426164066, 25 | -98.416909437, 26 | -31.603082708, 27 | -85.072296561, 28 | 108.620987395, 29 | -43.127078238, 30 | -126.473562057, 31 | -158.595489097, 32 | -57.890678254, 33 | -13.254016573, 34 | -85.024504709, 35 | 171.663552644, 36 | -146.495558248, 37 | -10.606748276, 38 | -118.786969354, 39 | 153.352057804, 40 | -45.215545083, 41 | 37.038725288, 42 | 106.344071897, 43 | -64.607402031, 44 | 85.148030911, 45 | 28.897784566, 46 | 39.51082061, 47 | 20.450382102, 48 | -113.174943618, 49 | 71.60785784, 50 | -168.202648062, 51 | -157.338200017, 52 | 10.879588527, 53 | -114.261694831, 54 | -5.622927072, 55 | -173.330830616, 56 | -29.47002003, 57 | -39.829034201, 58 | 50.031545162, 59 | 82.815735508, 60 | -119.188760828, 61 | -48.455928081, 62 | 163.964263034, 63 | 46.30378861, 64 | -26.248889762, 65 | -47.354615322, 66 | 155.388677633, 67 | -166.710356904, 68 | 42.987233558, 69 | 144.275297374, 70 | 37.394383186, 71 | -122.550388725, 72 | 177.469945914, 73 | 101.104677413, 74 | 109.429869885, 75 | -104.919625624, 76 | 147.522756541, 77 | -81.294703727, 78 | 122.744731363, 79 | 81.803603684, 80 | 26.321556167, 81 | 147.045441354, 82 | 147.256895816, 83 | -174.211095908, 84 | 52.518769316, 85 | -78.58250334, 86 | -173.356685435, 87 | -107.728209264, 88 | -69.982325771, 89 | -113.776095893, 90 | -35.785267074, 91 | -105.748545976, 92 | -30.206523864, 93 | -76.185311723, 94 | -126.400112781, 95 | -26.864958639, 96 | 56.840053629, 97 | 93.781553535, 98 | -116.002949803, 99 | -46.617140948, 100 | 176.846840093, 101 | -144.24821335 102 | ] 103 | -------------------------------------------------------------------------------- /external/rapidjson/bin/types/integers.json: -------------------------------------------------------------------------------- 1 | [ 2 | 8125686, 3 | 8958709, 4 | 5976222, 5 | 1889524, 6 | 7968493, 7 | 1357486, 8 | 118415, 9 | 7081097, 10 | 4635968, 11 | 7555332, 12 | 2270233, 13 | 3428352, 14 | 8699968, 15 | 2087333, 16 | 7861337, 17 | 7554440, 18 | 2017031, 19 | 7981692, 20 | 6060687, 21 | 1877715, 22 | 3297474, 23 | 8373177, 24 | 6158629, 25 | 7853641, 26 | 3004441, 27 | 9650406, 28 | 2695251, 29 | 1180761, 30 | 4988426, 31 | 6043805, 32 | 8063373, 33 | 6103218, 34 | 2848339, 35 | 8188690, 36 | 9235573, 37 | 5949816, 38 | 6116081, 39 | 6471138, 40 | 3354531, 41 | 4787414, 42 | 9660600, 43 | 942529, 44 | 7278535, 45 | 7967399, 46 | 554292, 47 | 1436493, 48 | 267319, 49 | 2606657, 50 | 7900601, 51 | 4276634, 52 | 7996757, 53 | 8544466, 54 | 7266469, 55 | 3301373, 56 | 4005350, 57 | 6437652, 58 | 7717672, 59 | 7126292, 60 | 8588394, 61 | 2127902, 62 | 7410190, 63 | 1517806, 64 | 4583602, 65 | 3123440, 66 | 7747613, 67 | 5029464, 68 | 9834390, 69 | 3087227, 70 | 4913822, 71 | 7550487, 72 | 4518144, 73 | 5862588, 74 | 1778599, 75 | 9493290, 76 | 5588455, 77 | 3638706, 78 | 7394293, 79 | 4294719, 80 | 3837830, 81 | 6381878, 82 | 7175866, 83 | 8575492, 84 | 1415229, 85 | 1453733, 86 | 6972404, 87 | 9782571, 88 | 4234063, 89 | 7117418, 90 | 7293130, 91 | 8057071, 92 | 9345285, 93 | 7626648, 94 | 3358911, 95 | 4574537, 96 | 9371826, 97 | 7627107, 98 | 6154093, 99 | 5392367, 100 | 5398105, 101 | 6956377 102 | ] -------------------------------------------------------------------------------- /external/rapidjson/bin/types/nulls.json: -------------------------------------------------------------------------------- 1 | [ 2 | null, 3 | null, 4 | null, 5 | null, 6 | null, 7 | null, 8 | null, 9 | null, 10 | null, 11 | null, 12 | null, 13 | null, 14 | null, 15 | null, 16 | null, 17 | null, 18 | null, 19 | null, 20 | null, 21 | null, 22 | null, 23 | null, 24 | null, 25 | null, 26 | null, 27 | null, 28 | null, 29 | null, 30 | null, 31 | null, 32 | null, 33 | null, 34 | null, 35 | null, 36 | null, 37 | null, 38 | null, 39 | null, 40 | null, 41 | null, 42 | null, 43 | null, 44 | null, 45 | null, 46 | null, 47 | null, 48 | null, 49 | null, 50 | null, 51 | null, 52 | null, 53 | null, 54 | null, 55 | null, 56 | null, 57 | null, 58 | null, 59 | null, 60 | null, 61 | null, 62 | null, 63 | null, 64 | null, 65 | null, 66 | null, 67 | null, 68 | null, 69 | null, 70 | null, 71 | null, 72 | null, 73 | null, 74 | null, 75 | null, 76 | null, 77 | null, 78 | null, 79 | null, 80 | null, 81 | null, 82 | null, 83 | null, 84 | null, 85 | null, 86 | null, 87 | null, 88 | null, 89 | null, 90 | null, 91 | null, 92 | null, 93 | null, 94 | null, 95 | null, 96 | null, 97 | null, 98 | null, 99 | null, 100 | null, 101 | null 102 | ] -------------------------------------------------------------------------------- /external/rapidjson/bin/types/readme.txt: -------------------------------------------------------------------------------- 1 | Test data obtained from https://github.com/xpol/lua-rapidjson/tree/master/performance 2 | -------------------------------------------------------------------------------- /external/rapidjson/contrib/natvis/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Bart Muzzin 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | Derived from: 24 | 25 | The MIT License (MIT) 26 | 27 | Copyright (c) 2015 mojmir svoboda 28 | 29 | Permission is hereby granted, free of charge, to any person obtaining a copy 30 | of this software and associated documentation files (the "Software"), to deal 31 | in the Software without restriction, including without limitation the rights 32 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 33 | copies of the Software, and to permit persons to whom the Software is 34 | furnished to do so, subject to the following conditions: 35 | 36 | The above copyright notice and this permission notice shall be included in all 37 | copies or substantial portions of the Software. 38 | 39 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 40 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 41 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 42 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 43 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 44 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 45 | SOFTWARE. 46 | -------------------------------------------------------------------------------- /external/rapidjson/contrib/natvis/README.md: -------------------------------------------------------------------------------- 1 | # rapidjson.natvis 2 | 3 | This file can be used as a [Visual Studio Visualizer](https://docs.microsoft.com/en-gb/visualstudio/debugger/create-custom-views-of-native-objects) to aid in visualizing rapidjson structures within the Visual Studio debugger. Natvis visualizers are supported in Visual Studio 2012 and later. To install, copy the file into this directory: 4 | 5 | `%USERPROFILE%\Documents\Visual Studio 2012\Visualizers` 6 | 7 | Each version of Visual Studio has a similar directory, it must be copied into each directory to be used with that particular version. In Visual Studio 2015 and later, this can be done without restarting Visual Studio (a new debugging session must be started). 8 | -------------------------------------------------------------------------------- /external/rapidjson/contrib/natvis/rapidjson.natvis: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | null 6 | true 7 | false 8 | {(const Ch*)data_.ss.str,na} 9 | {(const Ch*)((size_t)data_.s.str & 0x0000FFFFFFFFFFFF),na} 10 | {data_.n.i.i} 11 | {data_.n.u.u} 12 | {data_.n.i64} 13 | {data_.n.u64} 14 | {data_.n.d} 15 | Object members={data_.o.size} 16 | Array members={data_.a.size} 17 | 18 | data_.o.size 19 | data_.o.capacity 20 | 21 | data_.o.size 22 | 23 | (rapidjson::GenericMember<$T1,$T2>*)(((size_t)data_.o.members) & 0x0000FFFFFFFFFFFF) 24 | 25 | 26 | data_.a.size 27 | data_.a.capacity 28 | 29 | data_.a.size 30 | 31 | (rapidjson::GenericValue<$T1,$T2>*)(((size_t)data_.a.elements) & 0x0000FFFFFFFFFFFF) 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /external/rapidjson/doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(Doxygen) 2 | 3 | IF(NOT DOXYGEN_FOUND) 4 | MESSAGE(STATUS "No Doxygen found. Documentation won't be built") 5 | ELSE() 6 | file(GLOB SOURCES ${CMAKE_CURRENT_LIST_DIR}/../include/*) 7 | file(GLOB MARKDOWN_DOC ${CMAKE_CURRENT_LIST_DIR}/../doc/*.md) 8 | list(APPEND MARKDOWN_DOC ${CMAKE_CURRENT_LIST_DIR}/../readme.md) 9 | 10 | CONFIGURE_FILE(Doxyfile.in Doxyfile @ONLY) 11 | CONFIGURE_FILE(Doxyfile.zh-cn.in Doxyfile.zh-cn @ONLY) 12 | 13 | file(GLOB DOXYFILES ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile*) 14 | 15 | add_custom_command(OUTPUT html 16 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile 17 | COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.zh-cn 18 | COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/html 19 | DEPENDS ${MARKDOWN_DOC} ${SOURCES} ${DOXYFILES} 20 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/../ 21 | ) 22 | 23 | add_custom_target(doc ALL DEPENDS html) 24 | install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html 25 | DESTINATION ${DOC_INSTALL_DIR} 26 | COMPONENT doc) 27 | ENDIF() 28 | -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/architecture.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | nodesep=0.5 8 | penwidth=0.5 9 | colorscheme=spectral7 10 | 11 | node [shape=box, fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5, style=filled, fillcolor=white] 12 | edge [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 13 | 14 | subgraph cluster1 { 15 | margin="10,10" 16 | labeljust="left" 17 | label = "SAX" 18 | style=filled 19 | fillcolor=6 20 | 21 | Reader -> Writer [style=invis] 22 | } 23 | 24 | subgraph cluster2 { 25 | margin="10,10" 26 | labeljust="left" 27 | label = "DOM" 28 | style=filled 29 | fillcolor=7 30 | 31 | Value 32 | Document 33 | } 34 | 35 | Handler [label="<>\nHandler"] 36 | 37 | { 38 | edge [arrowtail=onormal, dir=back] 39 | Value -> Document 40 | Handler -> Document 41 | Handler -> Writer 42 | } 43 | 44 | { 45 | edge [arrowhead=vee, style=dashed, constraint=false] 46 | Reader -> Handler [label="calls"] 47 | Value -> Handler [label="calls"] 48 | Document -> Reader [label="uses"] 49 | } 50 | } -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/doc/diagram/architecture.png -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/insituparsing.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 11 | 12 | { 13 | node [shape=record, fontsize="8", margin="0.04", height=0.2, color=gray] 14 | oldjson [label="\{|\"|m|s|g|\"|:|\"|H|e|l|l|o|\\|n|W|o|r|l|d|!|\"|,|\"|\\|u|0|0|7|3|t|a|r|s|\"|:|1|0|\}", xlabel="Before Parsing"] 15 | //newjson [label="\{|\"|m|s|g|\\0|:|\"|H|e|l|l|o|\\n|W|o|r|l|d|!|\\0|\"|,|\"|s|t|a|r|s|\\0|t|a|r|s|:|1|0|\}", xlabel="After Parsing"] 16 | newjson [shape=plaintext, label=< 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
{"msg\\0:"Hello\\nWorld!\\0","stars\\0tars:10}
28 | >, xlabel="After Parsing"] 29 | } 30 | 31 | subgraph cluster1 { 32 | margin="10,10" 33 | labeljust="left" 34 | label = "Document by In situ Parsing" 35 | style=filled 36 | fillcolor=gray95 37 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 38 | 39 | root [label="{object|}", fillcolor=3] 40 | 41 | { 42 | msg [label="{string|
}", fillcolor=5] 43 | helloworld [label="{string|}", fillcolor=5] 44 | stars [label="{string|}", fillcolor=5] 45 | ten [label="{number|10}", fillcolor=6] 46 | } 47 | } 48 | 49 | oldjson -> root [label=" ParseInsitu()" lhead="cluster1"] 50 | edge [arrowhead=vee] 51 | root -> { msg; stars } 52 | 53 | edge [arrowhead="none"] 54 | msg -> helloworld 55 | stars -> ten 56 | 57 | { 58 | edge [arrowhead=vee, arrowtail=dot, arrowsize=0.5, dir=both, tailclip=false] 59 | msg:a:c -> newjson:a 60 | helloworld:a:c -> newjson:b 61 | stars:a:c -> newjson:c 62 | } 63 | 64 | //oldjson -> newjson [style=invis] 65 | } -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/insituparsing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/doc/diagram/insituparsing.png -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/iterative-parser-states-diagram.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | fontname="Inconsolata, Consolas" 3 | fontsize=10 4 | margin="0,0" 5 | penwidth=0.0 6 | 7 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 8 | edge [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 9 | 10 | node [shape = doublecircle]; Start; Finish; 11 | node [shape = box; style = "rounded, filled"; fillcolor=white ]; 12 | 13 | Start -> ArrayInitial [label=" ["]; 14 | Start -> ObjectInitial [label=" {"]; 15 | 16 | subgraph clusterArray { 17 | margin="10,10" 18 | style=filled 19 | fillcolor=gray95 20 | label = "Array" 21 | 22 | ArrayInitial; Element; ElementDelimiter; ArrayFinish; 23 | } 24 | 25 | subgraph clusterObject { 26 | margin="10,10" 27 | style=filled 28 | fillcolor=gray95 29 | label = "Object" 30 | 31 | ObjectInitial; MemberKey; KeyValueDelimiter; MemberValue; MemberDelimiter; ObjectFinish; 32 | } 33 | 34 | ArrayInitial -> ArrayInitial [label="["]; 35 | ArrayInitial -> ArrayFinish [label=" ]"]; 36 | ArrayInitial -> ObjectInitial [label="{", constraint=false]; 37 | ArrayInitial -> Element [label="string\nfalse\ntrue\nnull\nnumber"]; 38 | 39 | Element -> ArrayFinish [label="]"]; 40 | Element -> ElementDelimiter [label=","]; 41 | 42 | ElementDelimiter -> ArrayInitial [label=" ["]; 43 | ElementDelimiter -> ObjectInitial [label="{"]; 44 | ElementDelimiter -> Element [label="string\nfalse\ntrue\nnull\nnumber"]; 45 | 46 | ObjectInitial -> ObjectFinish [label=" }"]; 47 | ObjectInitial -> MemberKey [label=" string "]; 48 | 49 | MemberKey -> KeyValueDelimiter [label=":"]; 50 | 51 | KeyValueDelimiter -> ArrayInitial [label="["]; 52 | KeyValueDelimiter -> ObjectInitial [label=" {"]; 53 | KeyValueDelimiter -> MemberValue [label=" string\n false\n true\n null\n number"]; 54 | 55 | MemberValue -> ObjectFinish [label="}"]; 56 | MemberValue -> MemberDelimiter [label=","]; 57 | 58 | MemberDelimiter -> MemberKey [label=" string "]; 59 | 60 | ArrayFinish -> Finish; 61 | ObjectFinish -> Finish; 62 | } 63 | -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/iterative-parser-states-diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/doc/diagram/iterative-parser-states-diagram.png -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/makefile: -------------------------------------------------------------------------------- 1 | %.pdf: %.dot 2 | dot $< -Tpdf -o $@ 3 | 4 | %.png: %.dot 5 | dot $< -Tpng -o $@ 6 | 7 | DOTFILES = $(basename $(wildcard *.dot)) 8 | all: $(addsuffix .png, $(DOTFILES)) $(addsuffix .pdf, $(DOTFILES)) 9 | -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/move1.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 11 | 12 | subgraph cluster1 { 13 | margin="10,10" 14 | labeljust="left" 15 | label = "Before" 16 | style=filled 17 | fillcolor=gray95 18 | 19 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 20 | 21 | { 22 | rank = same 23 | b1 [label="{b:number|456}", fillcolor=6] 24 | a1 [label="{a:number|123}", fillcolor=6] 25 | } 26 | 27 | a1 -> b1 [style="dashed", label="Move", dir=back] 28 | } 29 | 30 | subgraph cluster2 { 31 | margin="10,10" 32 | labeljust="left" 33 | label = "After" 34 | style=filled 35 | fillcolor=gray95 36 | 37 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 38 | 39 | { 40 | rank = same 41 | b2 [label="{b:null|}", fillcolor=1] 42 | a2 [label="{a:number|456}", fillcolor=6] 43 | } 44 | a2 -> b2 [style=invis, dir=back] 45 | } 46 | b1 -> b2 [style=invis] 47 | } -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/move1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/doc/diagram/move1.png -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/move2.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 11 | 12 | subgraph cluster1 { 13 | margin="10,10" 14 | labeljust="left" 15 | label = "Before Copying (Hypothetic)" 16 | style=filled 17 | fillcolor=gray95 18 | 19 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 20 | 21 | c1 [label="{contacts:array|}", fillcolor=4] 22 | c11 [label="{|}"] 23 | c12 [label="{|}"] 24 | c13 [shape="none", label="...", style="solid"] 25 | o1 [label="{o:object|}", fillcolor=3] 26 | ghost [label="{o:object|}", style=invis] 27 | 28 | c1 -> o1 [style="dashed", label="AddMember", constraint=false] 29 | 30 | edge [arrowhead=vee] 31 | c1 -> { c11; c12; c13 } 32 | o1 -> ghost [style=invis] 33 | } 34 | 35 | subgraph cluster2 { 36 | margin="10,10" 37 | labeljust="left" 38 | label = "After Copying (Hypothetic)" 39 | style=filled 40 | fillcolor=gray95 41 | 42 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 43 | 44 | c2 [label="{contacts:array|}", fillcolor=4] 45 | c3 [label="{array|}", fillcolor=4] 46 | c21 [label="{|}"] 47 | c22 [label="{|}"] 48 | c23 [shape=none, label="...", style="solid"] 49 | o2 [label="{o:object|}", fillcolor=3] 50 | cs [label="{string|\"contacts\"}", fillcolor=5] 51 | c31 [label="{|}"] 52 | c32 [label="{|}"] 53 | c33 [shape="none", label="...", style="solid"] 54 | 55 | edge [arrowhead=vee] 56 | c2 -> { c21; c22; c23 } 57 | o2 -> cs 58 | cs -> c3 [arrowhead=none] 59 | c3 -> { c31; c32; c33 } 60 | } 61 | ghost -> o2 [style=invis] 62 | } 63 | -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/move2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/doc/diagram/move2.png -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/move3.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | forcelabels=true 9 | 10 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 11 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 12 | 13 | subgraph cluster1 { 14 | margin="10,10" 15 | labeljust="left" 16 | label = "Before Moving" 17 | style=filled 18 | fillcolor=gray95 19 | 20 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 21 | 22 | c1 [label="{contacts:array|}", fillcolor=4] 23 | c11 [label="{|}"] 24 | c12 [label="{|}"] 25 | c13 [shape=none, label="...", style="solid"] 26 | o1 [label="{o:object|}", fillcolor=3] 27 | ghost [label="{o:object|}", style=invis] 28 | 29 | c1 -> o1 [style="dashed", constraint=false, label="AddMember"] 30 | 31 | edge [arrowhead=vee] 32 | c1 -> { c11; c12; c13 } 33 | o1 -> ghost [style=invis] 34 | } 35 | 36 | subgraph cluster2 { 37 | margin="10,10" 38 | labeljust="left" 39 | label = "After Moving" 40 | style=filled 41 | fillcolor=gray95 42 | 43 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 44 | 45 | c2 [label="{contacts:null|}", fillcolor=1] 46 | c3 [label="{array|}", fillcolor=4] 47 | c21 [label="{|}"] 48 | c22 [label="{|}"] 49 | c23 [shape="none", label="...", style="solid"] 50 | o2 [label="{o:object|}", fillcolor=3] 51 | cs [label="{string|\"contacts\"}", fillcolor=5] 52 | c2 -> o2 [style="dashed", constraint=false, label="AddMember", style=invis] 53 | 54 | edge [arrowhead=vee] 55 | c3 -> { c21; c22; c23 } 56 | o2 -> cs 57 | cs -> c3 [arrowhead=none] 58 | } 59 | ghost -> o2 [style=invis] 60 | } 61 | -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/move3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/doc/diagram/move3.png -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/normalparsing.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 11 | 12 | { 13 | node [shape=record, fontsize="8", margin="0.04", height=0.2, color=gray] 14 | normaljson [label="\{|\"|m|s|g|\"|:|\"|H|e|l|l|o|\\|n|W|o|r|l|d|!|\"|,|\"|\\|u|0|0|7|3|t|a|r|s\"|:|1|0|\}"] 15 | 16 | { 17 | rank = same 18 | msgstring [label="m|s|g|\\0"] 19 | helloworldstring [label="H|e|l|l|o|\\n|W|o|r|l|d|!|\\0"] 20 | starsstring [label="s|t|a|r|s\\0"] 21 | } 22 | } 23 | 24 | subgraph cluster1 { 25 | margin="10,10" 26 | labeljust="left" 27 | label = "Document by Normal Parsing" 28 | style=filled 29 | fillcolor=gray95 30 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 31 | 32 | root [label="{object|}", fillcolor=3] 33 | 34 | { 35 | msg [label="{string|}", fillcolor=5] 36 | helloworld [label="{string|}", fillcolor=5] 37 | stars [label="{string|}", fillcolor=5] 38 | ten [label="{number|10}", fillcolor=6] 39 | } 40 | } 41 | 42 | normaljson -> root [label=" Parse()" lhead="cluster1"] 43 | edge [arrowhead=vee] 44 | root -> { msg; stars } 45 | 46 | edge [arrowhead="none"] 47 | msg -> helloworld 48 | stars -> ten 49 | 50 | edge [arrowhead=vee, arrowtail=dot, arrowsize=0.5, dir=both, tailclip=false] 51 | msg:a:c -> msgstring:w 52 | helloworld:a:c -> helloworldstring:w 53 | stars:a:c -> starsstring:w 54 | 55 | msgstring -> helloworldstring -> starsstring [style=invis] 56 | } -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/normalparsing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/doc/diagram/normalparsing.png -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/simpledom.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10, arrowhead=normal] 11 | 12 | { 13 | node [shape=record, fontsize="8", margin="0.04", height=0.2, color=gray] 14 | srcjson [label="\{|\"|p|r|o|j|e|c|t|\"|:|\"|r|a|p|i|d|j|s|o|n|\"|,|\"|s|t|a|r|s|\"|:|1|0|\}"] 15 | dstjson [label="\{|\"|p|r|o|j|e|c|t|\"|:|\"|r|a|p|i|d|j|s|o|n|\"|,|\"|s|t|a|r|s|\"|:|1|1|\}"] 16 | } 17 | 18 | { 19 | node [shape="box", style="filled", fillcolor="gray95"] 20 | Document2 [label="(Modified) Document"] 21 | Writer 22 | } 23 | 24 | subgraph cluster1 { 25 | margin="10,10" 26 | labeljust="left" 27 | label = "Document" 28 | style=filled 29 | fillcolor=gray95 30 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 31 | 32 | root [label="{object|}", fillcolor=3] 33 | 34 | { 35 | project [label="{string|\"project\"}", fillcolor=5] 36 | rapidjson [label="{string|\"rapidjson\"}", fillcolor=5] 37 | stars [label="{string|\"stars\"}", fillcolor=5] 38 | ten [label="{number|10}", fillcolor=6] 39 | } 40 | 41 | edge [arrowhead=vee] 42 | root -> { project; stars } 43 | 44 | edge [arrowhead="none"] 45 | project -> rapidjson 46 | stars -> ten 47 | } 48 | 49 | srcjson -> root [label=" Parse()", lhead="cluster1"] 50 | 51 | ten -> Document2 [label=" Increase \"stars\"", ltail="cluster1" ] 52 | Document2 -> Writer [label=" Traverse DOM by Accept()"] 53 | Writer -> dstjson [label=" Output to StringBuffer"] 54 | } -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/simpledom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/doc/diagram/simpledom.png -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/tutorial.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | compound=true 3 | fontname="Inconsolata, Consolas" 4 | fontsize=10 5 | margin="0,0" 6 | ranksep=0.2 7 | penwidth=0.5 8 | 9 | node [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 10 | edge [fontname="Inconsolata, Consolas", fontsize=10] 11 | 12 | subgraph cluster1 { 13 | margin="10,10" 14 | labeljust="left" 15 | label = "Document" 16 | style=filled 17 | fillcolor=gray95 18 | node [shape=Mrecord, style=filled, colorscheme=spectral7] 19 | 20 | root [label="{object|}", fillcolor=3] 21 | 22 | { 23 | hello [label="{string|\"hello\"}", fillcolor=5] 24 | t [label="{string|\"t\"}", fillcolor=5] 25 | f [label="{string|\"f\"}", fillcolor=5] 26 | n [label="{string|\"n\"}", fillcolor=5] 27 | i [label="{string|\"i\"}", fillcolor=5] 28 | pi [label="{string|\"pi\"}", fillcolor=5] 29 | a [label="{string|\"a\"}", fillcolor=5] 30 | 31 | world [label="{string|\"world\"}", fillcolor=5] 32 | true [label="{true|}", fillcolor=7] 33 | false [label="{false|}", fillcolor=2] 34 | null [label="{null|}", fillcolor=1] 35 | i1 [label="{number|123}", fillcolor=6] 36 | pi1 [label="{number|3.1416}", fillcolor=6] 37 | array [label="{array|size=4}", fillcolor=4] 38 | 39 | a1 [label="{number|1}", fillcolor=6] 40 | a2 [label="{number|2}", fillcolor=6] 41 | a3 [label="{number|3}", fillcolor=6] 42 | a4 [label="{number|4}", fillcolor=6] 43 | } 44 | 45 | edge [arrowhead=vee] 46 | root -> { hello; t; f; n; i; pi; a } 47 | array -> { a1; a2; a3; a4 } 48 | 49 | edge [arrowhead=none] 50 | hello -> world 51 | t -> true 52 | f -> false 53 | n -> null 54 | i -> i1 55 | pi -> pi1 56 | a -> array 57 | } 58 | } -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/tutorial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/doc/diagram/tutorial.png -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/utilityclass.dot: -------------------------------------------------------------------------------- 1 | digraph { 2 | rankdir=LR 3 | compound=true 4 | fontname="Inconsolata, Consolas" 5 | fontsize=10 6 | margin="0,0" 7 | ranksep=0.3 8 | nodesep=0.15 9 | penwidth=0.5 10 | colorscheme=spectral7 11 | 12 | node [shape=box, fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5, style=filled, fillcolor=white] 13 | edge [fontname="Inconsolata, Consolas", fontsize=10, penwidth=0.5] 14 | 15 | subgraph cluster0 { 16 | style=filled 17 | fillcolor=4 18 | 19 | Encoding [label="<>\nEncoding"] 20 | 21 | edge [arrowtail=onormal, dir=back] 22 | Encoding -> { UTF8; UTF16; UTF32; ASCII; AutoUTF } 23 | UTF16 -> { UTF16LE; UTF16BE } 24 | UTF32 -> { UTF32LE; UTF32BE } 25 | } 26 | 27 | subgraph cluster1 { 28 | style=filled 29 | fillcolor=5 30 | 31 | Stream [label="<>\nStream"] 32 | InputByteStream [label="<>\nInputByteStream"] 33 | OutputByteStream [label="<>\nOutputByteStream"] 34 | 35 | edge [arrowtail=onormal, dir=back] 36 | Stream -> { 37 | StringStream; InsituStringStream; StringBuffer; 38 | EncodedInputStream; EncodedOutputStream; 39 | AutoUTFInputStream; AutoUTFOutputStream 40 | InputByteStream; OutputByteStream 41 | } 42 | 43 | InputByteStream -> { MemoryStream; FlieReadStream } 44 | OutputByteStream -> { MemoryBuffer; FileWriteStream } 45 | } 46 | 47 | subgraph cluster2 { 48 | style=filled 49 | fillcolor=3 50 | 51 | Allocator [label="<>\nAllocator"] 52 | 53 | edge [arrowtail=onormal, dir=back] 54 | Allocator -> { CrtAllocator; MemoryPoolAllocator } 55 | } 56 | 57 | { 58 | edge [arrowtail=odiamond, arrowhead=vee, dir=both] 59 | EncodedInputStream -> InputByteStream 60 | EncodedOutputStream -> OutputByteStream 61 | AutoUTFInputStream -> InputByteStream 62 | AutoUTFOutputStream -> OutputByteStream 63 | MemoryPoolAllocator -> Allocator [label="base", tailport=s] 64 | } 65 | 66 | { 67 | edge [arrowhead=vee, style=dashed] 68 | AutoUTFInputStream -> AutoUTF 69 | AutoUTFOutputStream -> AutoUTF 70 | } 71 | 72 | //UTF32LE -> Stream [style=invis] 73 | } -------------------------------------------------------------------------------- /external/rapidjson/doc/diagram/utilityclass.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/doc/diagram/utilityclass.png -------------------------------------------------------------------------------- /external/rapidjson/doc/features.zh-cn.md: -------------------------------------------------------------------------------- 1 | # 特点 2 | 3 | ## 总体 4 | 5 | * 跨平台 6 | * 编译器:Visual Studio、gcc、clang 等 7 | * 架构:x86、x64、ARM 等 8 | * 操作系统:Windows、Mac OS X、Linux、iOS、Android 等 9 | * 容易安装 10 | * 只有头文件的库。只需把头文件复制至你的项目中。 11 | * 独立、最小依赖 12 | * 不需依赖 STL、BOOST 等。 13 | * 只包含 ``, ``, ``, ``, ``, ``。 14 | * 没使用 C++ 异常、RTTI 15 | * 高性能 16 | * 使用模版及内联函数去降低函数调用开销。 17 | * 内部经优化的 Grisu2 及浮点数解析实现。 18 | * 可选的 SSE2/SSE4.2 支持。 19 | 20 | ## 符合标准 21 | 22 | * RapidJSON 应完全符合 RFC4627/ECMA-404 标准。 23 | * 支持 JSON Pointer (RFC6901). 24 | * 支持 JSON Schema Draft v4. 25 | * 支持 Unicode 代理对(surrogate pair)。 26 | * 支持空字符(`"\u0000"`)。 27 | * 例如,可以优雅地解析及处理 `["Hello\u0000World"]`。含读写字符串长度的 API。 28 | * 支持可选的放宽语法 29 | * 单行(`// ...`)及多行(`/* ... */`) 注释 (`kParseCommentsFlag`)。 30 | * 在对象和数组结束前含逗号 (`kParseTrailingCommasFlag`)。 31 | * `NaN`、`Inf`、`Infinity`、`-Inf` 及 `-Infinity` 作为 `double` 值 (`kParseNanAndInfFlag`) 32 | * [NPM 兼容](https://github.com/Tencent/rapidjson/blob/master/doc/npm.md). 33 | 34 | ## Unicode 35 | 36 | * 支持 UTF-8、UTF-16、UTF-32 编码,包括小端序和大端序。 37 | * 这些编码用于输入输出流,以及内存中的表示。 38 | * 支持从输入流自动检测编码。 39 | * 内部支持编码的转换。 40 | * 例如,你可以读取一个 UTF-8 文件,让 RapidJSON 把 JSON 字符串转换至 UTF-16 的 DOM。 41 | * 内部支持编码校验。 42 | * 例如,你可以读取一个 UTF-8 文件,让 RapidJSON 检查是否所有 JSON 字符串是合法的 UTF-8 字节序列。 43 | * 支持自定义的字符类型。 44 | * 预设的字符类型是:UTF-8 为 `char`,UTF-16 为 `wchar_t`,UTF32 为 `uint32_t`。 45 | * 支持自定义的编码。 46 | 47 | ## API 风格 48 | 49 | * SAX(Simple API for XML)风格 API 50 | * 类似于 [SAX](http://en.wikipedia.org/wiki/Simple_API_for_XML), RapidJSON 提供一个事件循序访问的解析器 API(`rapidjson::GenericReader`)。RapidJSON 也提供一个生成器 API(`rapidjson::Writer`),可以处理相同的事件集合。 51 | * DOM(Document Object Model)风格 API 52 | * 类似于 HTML/XML 的 [DOM](http://en.wikipedia.org/wiki/Document_Object_Model),RapidJSON 可把 JSON 解析至一个 DOM 表示方式(`rapidjson::GenericDocument`),以方便操作。如有需要,可把 DOM 转换(stringify)回 JSON。 53 | * DOM 风格 API(`rapidjson::GenericDocument`)实际上是由 SAX 风格 API(`rapidjson::GenericReader`)实现的。SAX 更快,但有时 DOM 更易用。用户可根据情况作出选择。 54 | 55 | ## 解析 56 | 57 | * 递归式(预设)及迭代式解析器 58 | * 递归式解析器较快,但在极端情况下可出现堆栈溢出。 59 | * 迭代式解析器使用自定义的堆栈去维持解析状态。 60 | * 支持原位(*in situ*)解析。 61 | * 把 JSON 字符串的值解析至原 JSON 之中,然后让 DOM 指向那些字符串。 62 | * 比常规分析更快:不需字符串的内存分配、不需复制(如字符串不含转义符)、缓存友好。 63 | * 对于 JSON 数字类型,支持 32-bit/64-bit 的有号/无号整数,以及 `double`。 64 | * 错误处理 65 | * 支持详尽的解析错误代号。 66 | * 支持本地化错误信息。 67 | 68 | ## DOM (Document) 69 | 70 | * RapidJSON 在类型转换时会检查数值的范围。 71 | * 字符串字面量的优化 72 | * 只储存指针,不作复制 73 | * 优化“短”字符串 74 | * 在 `Value` 内储存短字符串,无需额外分配。 75 | * 对 UTF-8 字符串来说,32 位架构下可存储最多 11 字符,64 位下 21 字符(x86-64 下 13 字符)。 76 | * 可选地支持 `std::string`(定义 `RAPIDJSON_HAS_STDSTRING=1`) 77 | 78 | ## 生成 79 | 80 | * 支持 `rapidjson::PrettyWriter` 去加入换行及缩进。 81 | 82 | ## 输入输出流 83 | 84 | * 支持 `rapidjson::GenericStringBuffer`,把输出的 JSON 储存于字符串内。 85 | * 支持 `rapidjson::FileReadStream` 及 `rapidjson::FileWriteStream`,使用 `FILE` 对象作输入输出。 86 | * 支持自定义输入输出流。 87 | 88 | ## 内存 89 | 90 | * 最小化 DOM 的内存开销。 91 | * 对大部分 32/64 位机器而言,每个 JSON 值只占 16 或 20 字节(不包含字符串)。 92 | * 支持快速的预设分配器。 93 | * 它是一个堆栈形式的分配器(顺序分配,不容许单独释放,适合解析过程之用)。 94 | * 使用者也可提供一个预分配的缓冲区。(有可能达至无需 CRT 分配就能解析多个 JSON) 95 | * 支持标准 CRT(C-runtime)分配器。 96 | * 支持自定义分配器。 97 | 98 | ## 其他 99 | 100 | * 一些 C++11 的支持(可选) 101 | * 右值引用(rvalue reference) 102 | * `noexcept` 修饰符 103 | * 范围 for 循环 104 | -------------------------------------------------------------------------------- /external/rapidjson/doc/logo/rapidjson.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/doc/logo/rapidjson.png -------------------------------------------------------------------------------- /external/rapidjson/doc/misc/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /external/rapidjson/doc/misc/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | $extrastylesheet 18 | 19 | 20 |
21 |
22 | $searchbox 23 | 24 | 25 | -------------------------------------------------------------------------------- /external/rapidjson/doc/npm.md: -------------------------------------------------------------------------------- 1 | ## NPM 2 | 3 | # package.json {#package} 4 | 5 | ~~~~~~~~~~js 6 | { 7 | ... 8 | "dependencies": { 9 | ... 10 | "rapidjson": "git@github.com:Tencent/rapidjson.git" 11 | }, 12 | ... 13 | "gypfile": true 14 | } 15 | ~~~~~~~~~~ 16 | 17 | # binding.gyp {#binding} 18 | 19 | ~~~~~~~~~~js 20 | { 21 | ... 22 | 'targets': [ 23 | { 24 | ... 25 | 'include_dirs': [ 26 | ' 12 | #include 13 | 14 | using namespace rapidjson; 15 | 16 | template 17 | struct CapitalizeFilter { 18 | CapitalizeFilter(OutputHandler& out) : out_(out), buffer_() {} 19 | 20 | bool Null() { return out_.Null(); } 21 | bool Bool(bool b) { return out_.Bool(b); } 22 | bool Int(int i) { return out_.Int(i); } 23 | bool Uint(unsigned u) { return out_.Uint(u); } 24 | bool Int64(int64_t i) { return out_.Int64(i); } 25 | bool Uint64(uint64_t u) { return out_.Uint64(u); } 26 | bool Double(double d) { return out_.Double(d); } 27 | bool RawNumber(const char* str, SizeType length, bool copy) { return out_.RawNumber(str, length, copy); } 28 | bool String(const char* str, SizeType length, bool) { 29 | buffer_.clear(); 30 | for (SizeType i = 0; i < length; i++) 31 | buffer_.push_back(static_cast(std::toupper(str[i]))); 32 | return out_.String(&buffer_.front(), length, true); // true = output handler need to copy the string 33 | } 34 | bool StartObject() { return out_.StartObject(); } 35 | bool Key(const char* str, SizeType length, bool copy) { return String(str, length, copy); } 36 | bool EndObject(SizeType memberCount) { return out_.EndObject(memberCount); } 37 | bool StartArray() { return out_.StartArray(); } 38 | bool EndArray(SizeType elementCount) { return out_.EndArray(elementCount); } 39 | 40 | OutputHandler& out_; 41 | std::vector buffer_; 42 | 43 | private: 44 | CapitalizeFilter(const CapitalizeFilter&); 45 | CapitalizeFilter& operator=(const CapitalizeFilter&); 46 | }; 47 | 48 | int main(int, char*[]) { 49 | // Prepare JSON reader and input stream. 50 | Reader reader; 51 | char readBuffer[65536]; 52 | FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); 53 | 54 | // Prepare JSON writer and output stream. 55 | char writeBuffer[65536]; 56 | FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); 57 | Writer writer(os); 58 | 59 | // JSON reader parse from the input stream and let writer generate the output. 60 | CapitalizeFilter > filter(writer); 61 | if (!reader.Parse(is, filter)) { 62 | fprintf(stderr, "\nError(%u): %s\n", static_cast(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); 63 | return 1; 64 | } 65 | 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /external/rapidjson/example/condense/condense.cpp: -------------------------------------------------------------------------------- 1 | // JSON condenser example 2 | 3 | // This example parses JSON text from stdin with validation, 4 | // and re-output the JSON content to stdout without whitespace. 5 | 6 | #include "rapidjson/reader.h" 7 | #include "rapidjson/writer.h" 8 | #include "rapidjson/filereadstream.h" 9 | #include "rapidjson/filewritestream.h" 10 | #include "rapidjson/error/en.h" 11 | 12 | using namespace rapidjson; 13 | 14 | int main(int, char*[]) { 15 | // Prepare JSON reader and input stream. 16 | Reader reader; 17 | char readBuffer[65536]; 18 | FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); 19 | 20 | // Prepare JSON writer and output stream. 21 | char writeBuffer[65536]; 22 | FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); 23 | Writer writer(os); 24 | 25 | // JSON reader parse from the input stream and let writer generate the output. 26 | if (!reader.Parse(is, writer)) { 27 | fprintf(stderr, "\nError(%u): %s\n", static_cast(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); 28 | return 1; 29 | } 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /external/rapidjson/example/messagereader/messagereader.cpp: -------------------------------------------------------------------------------- 1 | // Reading a message JSON with Reader (SAX-style API). 2 | // The JSON should be an object with key-string pairs. 3 | 4 | #include "rapidjson/reader.h" 5 | #include "rapidjson/error/en.h" 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | using namespace rapidjson; 12 | 13 | typedef map MessageMap; 14 | 15 | #if defined(__GNUC__) 16 | RAPIDJSON_DIAG_PUSH 17 | RAPIDJSON_DIAG_OFF(effc++) 18 | #endif 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(switch-enum) 23 | #endif 24 | 25 | struct MessageHandler 26 | : public BaseReaderHandler, MessageHandler> { 27 | MessageHandler() : messages_(), state_(kExpectObjectStart), name_() {} 28 | 29 | bool StartObject() { 30 | switch (state_) { 31 | case kExpectObjectStart: 32 | state_ = kExpectNameOrObjectEnd; 33 | return true; 34 | default: 35 | return false; 36 | } 37 | } 38 | 39 | bool String(const char* str, SizeType length, bool) { 40 | switch (state_) { 41 | case kExpectNameOrObjectEnd: 42 | name_ = string(str, length); 43 | state_ = kExpectValue; 44 | return true; 45 | case kExpectValue: 46 | messages_.insert(MessageMap::value_type(name_, string(str, length))); 47 | state_ = kExpectNameOrObjectEnd; 48 | return true; 49 | default: 50 | return false; 51 | } 52 | } 53 | 54 | bool EndObject(SizeType) { return state_ == kExpectNameOrObjectEnd; } 55 | 56 | bool Default() { return false; } // All other events are invalid. 57 | 58 | MessageMap messages_; 59 | enum State { 60 | kExpectObjectStart, 61 | kExpectNameOrObjectEnd, 62 | kExpectValue 63 | }state_; 64 | std::string name_; 65 | }; 66 | 67 | #if defined(__GNUC__) 68 | RAPIDJSON_DIAG_POP 69 | #endif 70 | 71 | #ifdef __clang__ 72 | RAPIDJSON_DIAG_POP 73 | #endif 74 | 75 | static void ParseMessages(const char* json, MessageMap& messages) { 76 | Reader reader; 77 | MessageHandler handler; 78 | StringStream ss(json); 79 | if (reader.Parse(ss, handler)) 80 | messages.swap(handler.messages_); // Only change it if success. 81 | else { 82 | ParseErrorCode e = reader.GetParseErrorCode(); 83 | size_t o = reader.GetErrorOffset(); 84 | cout << "Error: " << GetParseError_En(e) << endl;; 85 | cout << " at offset " << o << " near '" << string(json).substr(o, 10) << "...'" << endl; 86 | } 87 | } 88 | 89 | int main() { 90 | MessageMap messages; 91 | 92 | const char* json1 = "{ \"greeting\" : \"Hello!\", \"farewell\" : \"bye-bye!\" }"; 93 | cout << json1 << endl; 94 | ParseMessages(json1, messages); 95 | 96 | for (MessageMap::const_iterator itr = messages.begin(); itr != messages.end(); ++itr) 97 | cout << itr->first << ": " << itr->second << endl; 98 | 99 | cout << endl << "Parse a JSON with invalid schema." << endl; 100 | const char* json2 = "{ \"greeting\" : \"Hello!\", \"farewell\" : \"bye-bye!\", \"foo\" : {} }"; 101 | cout << json2 << endl; 102 | ParseMessages(json2, messages); 103 | 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /external/rapidjson/example/pretty/pretty.cpp: -------------------------------------------------------------------------------- 1 | // JSON pretty formatting example 2 | // This example can only handle UTF-8. For handling other encodings, see prettyauto example. 3 | 4 | #include "rapidjson/reader.h" 5 | #include "rapidjson/prettywriter.h" 6 | #include "rapidjson/filereadstream.h" 7 | #include "rapidjson/filewritestream.h" 8 | #include "rapidjson/error/en.h" 9 | 10 | using namespace rapidjson; 11 | 12 | int main(int, char*[]) { 13 | // Prepare reader and input stream. 14 | Reader reader; 15 | char readBuffer[65536]; 16 | FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); 17 | 18 | // Prepare writer and output stream. 19 | char writeBuffer[65536]; 20 | FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); 21 | PrettyWriter writer(os); 22 | 23 | // JSON reader parse from the input stream and let writer generate the output. 24 | if (!reader.Parse(is, writer)) { 25 | fprintf(stderr, "\nError(%u): %s\n", static_cast(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); 26 | return 1; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /external/rapidjson/example/prettyauto/prettyauto.cpp: -------------------------------------------------------------------------------- 1 | // JSON pretty formatting example 2 | // This example can handle UTF-8/UTF-16LE/UTF-16BE/UTF-32LE/UTF-32BE. 3 | // The input firstly convert to UTF8, and then write to the original encoding with pretty formatting. 4 | 5 | #include "rapidjson/reader.h" 6 | #include "rapidjson/prettywriter.h" 7 | #include "rapidjson/filereadstream.h" 8 | #include "rapidjson/filewritestream.h" 9 | #include "rapidjson/encodedstream.h" // NEW 10 | #include "rapidjson/error/en.h" 11 | #ifdef _WIN32 12 | #include 13 | #include 14 | #endif 15 | 16 | using namespace rapidjson; 17 | 18 | int main(int, char*[]) { 19 | #ifdef _WIN32 20 | // Prevent Windows converting between CR+LF and LF 21 | _setmode(_fileno(stdin), _O_BINARY); // NEW 22 | _setmode(_fileno(stdout), _O_BINARY); // NEW 23 | #endif 24 | 25 | // Prepare reader and input stream. 26 | //Reader reader; 27 | GenericReader, UTF8<> > reader; // CHANGED 28 | char readBuffer[65536]; 29 | FileReadStream is(stdin, readBuffer, sizeof(readBuffer)); 30 | AutoUTFInputStream eis(is); // NEW 31 | 32 | // Prepare writer and output stream. 33 | char writeBuffer[65536]; 34 | FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); 35 | 36 | #if 1 37 | // Use the same Encoding of the input. Also use BOM according to input. 38 | typedef AutoUTFOutputStream OutputStream; // NEW 39 | OutputStream eos(os, eis.GetType(), eis.HasBOM()); // NEW 40 | PrettyWriter, AutoUTF > writer(eos); // CHANGED 41 | #else 42 | // You may also use static bound encoding type, such as output to UTF-16LE with BOM 43 | typedef EncodedOutputStream,FileWriteStream> OutputStream; // NEW 44 | OutputStream eos(os, true); // NEW 45 | PrettyWriter, UTF16LE<> > writer(eos); // CHANGED 46 | #endif 47 | 48 | // JSON reader parse from the input stream and let writer generate the output. 49 | //if (!reader.Parse(is, writer)) { 50 | if (!reader.Parse(eis, writer)) { // CHANGED 51 | fprintf(stderr, "\nError(%u): %s\n", static_cast(reader.GetErrorOffset()), GetParseError_En(reader.GetParseErrorCode())); 52 | return 1; 53 | } 54 | 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /external/rapidjson/example/schemavalidator/schemavalidator.cpp: -------------------------------------------------------------------------------- 1 | // Schema Validator example 2 | 3 | // The example validates JSON text from stdin with a JSON schema specified in the argument. 4 | 5 | #include "rapidjson/error/en.h" 6 | #include "rapidjson/filereadstream.h" 7 | #include "rapidjson/schema.h" 8 | #include "rapidjson/stringbuffer.h" 9 | #include "rapidjson/prettywriter.h" 10 | 11 | using namespace rapidjson; 12 | 13 | int main(int argc, char *argv[]) { 14 | if (argc != 2) { 15 | fprintf(stderr, "Usage: schemavalidator schema.json < input.json\n"); 16 | return EXIT_FAILURE; 17 | } 18 | 19 | // Read a JSON schema from file into Document 20 | Document d; 21 | char buffer[4096]; 22 | 23 | { 24 | FILE *fp = fopen(argv[1], "r"); 25 | if (!fp) { 26 | printf("Schema file '%s' not found\n", argv[1]); 27 | return -1; 28 | } 29 | FileReadStream fs(fp, buffer, sizeof(buffer)); 30 | d.ParseStream(fs); 31 | if (d.HasParseError()) { 32 | fprintf(stderr, "Schema file '%s' is not a valid JSON\n", argv[1]); 33 | fprintf(stderr, "Error(offset %u): %s\n", 34 | static_cast(d.GetErrorOffset()), 35 | GetParseError_En(d.GetParseError())); 36 | fclose(fp); 37 | return EXIT_FAILURE; 38 | } 39 | fclose(fp); 40 | } 41 | 42 | // Then convert the Document into SchemaDocument 43 | SchemaDocument sd(d); 44 | 45 | // Use reader to parse the JSON in stdin, and forward SAX events to validator 46 | SchemaValidator validator(sd); 47 | Reader reader; 48 | FileReadStream is(stdin, buffer, sizeof(buffer)); 49 | if (!reader.Parse(is, validator) && reader.GetParseErrorCode() != kParseErrorTermination) { 50 | // Schema validator error would cause kParseErrorTermination, which will handle it in next step. 51 | fprintf(stderr, "Input is not a valid JSON\n"); 52 | fprintf(stderr, "Error(offset %u): %s\n", 53 | static_cast(reader.GetErrorOffset()), 54 | GetParseError_En(reader.GetParseErrorCode())); 55 | } 56 | 57 | // Check the validation result 58 | if (validator.IsValid()) { 59 | printf("Input JSON is valid.\n"); 60 | return EXIT_SUCCESS; 61 | } 62 | else { 63 | printf("Input JSON is invalid.\n"); 64 | StringBuffer sb; 65 | validator.GetInvalidSchemaPointer().StringifyUriFragment(sb); 66 | fprintf(stderr, "Invalid schema: %s\n", sb.GetString()); 67 | fprintf(stderr, "Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword()); 68 | sb.Clear(); 69 | validator.GetInvalidDocumentPointer().StringifyUriFragment(sb); 70 | fprintf(stderr, "Invalid document: %s\n", sb.GetString()); 71 | // Detailed violation report is available as a JSON value 72 | sb.Clear(); 73 | PrettyWriter w(sb); 74 | validator.GetError().Accept(w); 75 | fprintf(stderr, "Error report:\n%s\n", sb.GetString()); 76 | return EXIT_FAILURE; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /external/rapidjson/example/simpledom/simpledom.cpp: -------------------------------------------------------------------------------- 1 | // JSON simple example 2 | // This example does not handle errors. 3 | 4 | #include "rapidjson/document.h" 5 | #include "rapidjson/writer.h" 6 | #include "rapidjson/stringbuffer.h" 7 | #include 8 | 9 | using namespace rapidjson; 10 | 11 | int main() { 12 | // 1. Parse a JSON string into DOM. 13 | const char* json = "{\"project\":\"rapidjson\",\"stars\":10}"; 14 | Document d; 15 | d.Parse(json); 16 | 17 | // 2. Modify it by DOM. 18 | Value& s = d["stars"]; 19 | s.SetInt(s.GetInt() + 1); 20 | 21 | // 3. Stringify the DOM 22 | StringBuffer buffer; 23 | Writer writer(buffer); 24 | d.Accept(writer); 25 | 26 | // Output {"project":"rapidjson","stars":11} 27 | std::cout << buffer.GetString() << std::endl; 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /external/rapidjson/example/simplepullreader/simplepullreader.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidjson/reader.h" 2 | #include 3 | #include 4 | 5 | using namespace rapidjson; 6 | using namespace std; 7 | 8 | // If you can require C++11, you could use std::to_string here 9 | template std::string stringify(T x) { 10 | std::stringstream ss; 11 | ss << x; 12 | return ss.str(); 13 | } 14 | 15 | struct MyHandler { 16 | const char* type; 17 | std::string data; 18 | 19 | MyHandler() : type(), data() {} 20 | 21 | bool Null() { type = "Null"; data.clear(); return true; } 22 | bool Bool(bool b) { type = "Bool:"; data = b? "true": "false"; return true; } 23 | bool Int(int i) { type = "Int:"; data = stringify(i); return true; } 24 | bool Uint(unsigned u) { type = "Uint:"; data = stringify(u); return true; } 25 | bool Int64(int64_t i) { type = "Int64:"; data = stringify(i); return true; } 26 | bool Uint64(uint64_t u) { type = "Uint64:"; data = stringify(u); return true; } 27 | bool Double(double d) { type = "Double:"; data = stringify(d); return true; } 28 | bool RawNumber(const char* str, SizeType length, bool) { type = "Number:"; data = std::string(str, length); return true; } 29 | bool String(const char* str, SizeType length, bool) { type = "String:"; data = std::string(str, length); return true; } 30 | bool StartObject() { type = "StartObject"; data.clear(); return true; } 31 | bool Key(const char* str, SizeType length, bool) { type = "Key:"; data = std::string(str, length); return true; } 32 | bool EndObject(SizeType memberCount) { type = "EndObject:"; data = stringify(memberCount); return true; } 33 | bool StartArray() { type = "StartArray"; data.clear(); return true; } 34 | bool EndArray(SizeType elementCount) { type = "EndArray:"; data = stringify(elementCount); return true; } 35 | private: 36 | MyHandler(const MyHandler& noCopyConstruction); 37 | MyHandler& operator=(const MyHandler& noAssignment); 38 | }; 39 | 40 | int main() { 41 | const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "; 42 | 43 | MyHandler handler; 44 | Reader reader; 45 | StringStream ss(json); 46 | reader.IterativeParseInit(); 47 | while (!reader.IterativeParseComplete()) { 48 | reader.IterativeParseNext(ss, handler); 49 | cout << handler.type << handler.data << endl; 50 | } 51 | 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /external/rapidjson/example/simplereader/simplereader.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidjson/reader.h" 2 | #include 3 | 4 | using namespace rapidjson; 5 | using namespace std; 6 | 7 | struct MyHandler { 8 | bool Null() { cout << "Null()" << endl; return true; } 9 | bool Bool(bool b) { cout << "Bool(" << boolalpha << b << ")" << endl; return true; } 10 | bool Int(int i) { cout << "Int(" << i << ")" << endl; return true; } 11 | bool Uint(unsigned u) { cout << "Uint(" << u << ")" << endl; return true; } 12 | bool Int64(int64_t i) { cout << "Int64(" << i << ")" << endl; return true; } 13 | bool Uint64(uint64_t u) { cout << "Uint64(" << u << ")" << endl; return true; } 14 | bool Double(double d) { cout << "Double(" << d << ")" << endl; return true; } 15 | bool RawNumber(const char* str, SizeType length, bool copy) { 16 | cout << "Number(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl; 17 | return true; 18 | } 19 | bool String(const char* str, SizeType length, bool copy) { 20 | cout << "String(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl; 21 | return true; 22 | } 23 | bool StartObject() { cout << "StartObject()" << endl; return true; } 24 | bool Key(const char* str, SizeType length, bool copy) { 25 | cout << "Key(" << str << ", " << length << ", " << boolalpha << copy << ")" << endl; 26 | return true; 27 | } 28 | bool EndObject(SizeType memberCount) { cout << "EndObject(" << memberCount << ")" << endl; return true; } 29 | bool StartArray() { cout << "StartArray()" << endl; return true; } 30 | bool EndArray(SizeType elementCount) { cout << "EndArray(" << elementCount << ")" << endl; return true; } 31 | }; 32 | 33 | int main() { 34 | const char json[] = " { \"hello\" : \"world\", \"t\" : true , \"f\" : false, \"n\": null, \"i\":123, \"pi\": 3.1416, \"a\":[1, 2, 3, 4] } "; 35 | 36 | MyHandler handler; 37 | Reader reader; 38 | StringStream ss(json); 39 | reader.Parse(ss, handler); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /external/rapidjson/example/simplewriter/simplewriter.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidjson/writer.h" 2 | #include "rapidjson/stringbuffer.h" 3 | #include 4 | 5 | using namespace rapidjson; 6 | using namespace std; 7 | 8 | int main() { 9 | StringBuffer s; 10 | Writer writer(s); 11 | 12 | writer.StartObject(); // Between StartObject()/EndObject(), 13 | writer.Key("hello"); // output a key, 14 | writer.String("world"); // follow by a value. 15 | writer.Key("t"); 16 | writer.Bool(true); 17 | writer.Key("f"); 18 | writer.Bool(false); 19 | writer.Key("n"); 20 | writer.Null(); 21 | writer.Key("i"); 22 | writer.Uint(123); 23 | writer.Key("pi"); 24 | writer.Double(3.1416); 25 | writer.Key("a"); 26 | writer.StartArray(); // Between StartArray()/EndArray(), 27 | for (unsigned i = 0; i < 4; i++) 28 | writer.Uint(i); // all values are elements of the array. 29 | writer.EndArray(); 30 | writer.EndObject(); 31 | 32 | // {"hello":"world","t":true,"f":false,"n":null,"i":123,"pi":3.1416,"a":[0,1,2,3]} 33 | cout << s.GetString() << endl; 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /external/rapidjson/example/sortkeys/sortkeys.cpp: -------------------------------------------------------------------------------- 1 | #include "rapidjson/document.h" 2 | #include "rapidjson/filewritestream.h" 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | using namespace rapidjson; 9 | using namespace std; 10 | 11 | static void printIt(const Value &doc) { 12 | char writeBuffer[65536]; 13 | FileWriteStream os(stdout, writeBuffer, sizeof(writeBuffer)); 14 | PrettyWriter writer(os); 15 | doc.Accept(writer); 16 | cout << endl; 17 | } 18 | 19 | struct NameComparator { 20 | bool operator()(const Value::Member &lhs, const Value::Member &rhs) const { 21 | return (strcmp(lhs.name.GetString(), rhs.name.GetString()) < 0); 22 | } 23 | }; 24 | 25 | int main() { 26 | Document d(kObjectType); 27 | Document::AllocatorType &allocator = d.GetAllocator(); 28 | 29 | d.AddMember("zeta", Value().SetBool(false), allocator); 30 | d.AddMember("gama", Value().SetString("test string", allocator), allocator); 31 | d.AddMember("delta", Value().SetInt(123), allocator); 32 | d.AddMember("alpha", Value(kArrayType).Move(), allocator); 33 | 34 | printIt(d); 35 | 36 | /* 37 | { 38 | "zeta": false, 39 | "gama": "test string", 40 | "delta": 123, 41 | "alpha": [] 42 | } 43 | */ 44 | 45 | // C++11 supports std::move() of Value so it always have no problem for std::sort(). 46 | // Some C++03 implementations of std::sort() requires copy constructor which causes compilation error. 47 | // Needs a sorting function only depends on std::swap() instead. 48 | #if __cplusplus >= 201103L || (!defined(__GLIBCXX__) && (!defined(_MSC_VER) || _MSC_VER >= 1900)) 49 | std::sort(d.MemberBegin(), d.MemberEnd(), NameComparator()); 50 | 51 | printIt(d); 52 | 53 | /* 54 | { 55 | "alpha": [], 56 | "delta": 123, 57 | "gama": "test string", 58 | "zeta": false 59 | } 60 | */ 61 | #endif 62 | } 63 | -------------------------------------------------------------------------------- /external/rapidjson/include/rapidjson/.writer.h.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vtnerd/motrix/49292321c085b21ad67da8aff44d3ea0d600589d/external/rapidjson/include/rapidjson/.writer.h.swp -------------------------------------------------------------------------------- /external/rapidjson/include/rapidjson/cursorstreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_CURSORSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_CURSORSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | 20 | #if defined(__GNUC__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | 25 | #if defined(_MSC_VER) && _MSC_VER <= 1800 26 | RAPIDJSON_DIAG_PUSH 27 | RAPIDJSON_DIAG_OFF(4702) // unreachable code 28 | RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated 29 | #endif 30 | 31 | RAPIDJSON_NAMESPACE_BEGIN 32 | 33 | 34 | //! Cursor stream wrapper for counting line and column number if error exists. 35 | /*! 36 | \tparam InputStream Any stream that implements Stream Concept 37 | */ 38 | template > 39 | class CursorStreamWrapper : public GenericStreamWrapper { 40 | public: 41 | typedef typename Encoding::Ch Ch; 42 | 43 | CursorStreamWrapper(InputStream& is): 44 | GenericStreamWrapper(is), line_(1), col_(0) {} 45 | 46 | // counting line and column number 47 | Ch Take() { 48 | Ch ch = this->is_.Take(); 49 | if(ch == '\n') { 50 | line_ ++; 51 | col_ = 0; 52 | } else { 53 | col_ ++; 54 | } 55 | return ch; 56 | } 57 | 58 | //! Get the error line number, if error exists. 59 | size_t GetLine() const { return line_; } 60 | //! Get the error column number, if error exists. 61 | size_t GetColumn() const { return col_; } 62 | 63 | private: 64 | size_t line_; //!< Current Line 65 | size_t col_; //!< Current Column 66 | }; 67 | 68 | #if defined(_MSC_VER) && _MSC_VER <= 1800 69 | RAPIDJSON_DIAG_POP 70 | #endif 71 | 72 | #if defined(__GNUC__) 73 | RAPIDJSON_DIAG_POP 74 | #endif 75 | 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_CURSORSTREAMWRAPPER_H_ 79 | -------------------------------------------------------------------------------- /external/rapidjson/include/rapidjson/internal/clzll.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_CLZLL_H_ 16 | #define RAPIDJSON_CLZLL_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(_MSC_VER) && !defined(UNDER_CE) 21 | #include 22 | #if defined(_WIN64) 23 | #pragma intrinsic(_BitScanReverse64) 24 | #else 25 | #pragma intrinsic(_BitScanReverse) 26 | #endif 27 | #endif 28 | 29 | RAPIDJSON_NAMESPACE_BEGIN 30 | namespace internal { 31 | 32 | inline uint32_t clzll(uint64_t x) { 33 | // Passing 0 to __builtin_clzll is UB in GCC and results in an 34 | // infinite loop in the software implementation. 35 | RAPIDJSON_ASSERT(x != 0); 36 | 37 | #if defined(_MSC_VER) && !defined(UNDER_CE) 38 | unsigned long r = 0; 39 | #if defined(_WIN64) 40 | _BitScanReverse64(&r, x); 41 | #else 42 | // Scan the high 32 bits. 43 | if (_BitScanReverse(&r, static_cast(x >> 32))) 44 | return 63 - (r + 32); 45 | 46 | // Scan the low 32 bits. 47 | _BitScanReverse(&r, static_cast(x & 0xFFFFFFFF)); 48 | #endif // _WIN64 49 | 50 | return 63 - r; 51 | #elif (defined(__GNUC__) && __GNUC__ >= 4) || RAPIDJSON_HAS_BUILTIN(__builtin_clzll) 52 | // __builtin_clzll wrapper 53 | return static_cast(__builtin_clzll(x)); 54 | #else 55 | // naive version 56 | uint32_t r = 0; 57 | while (!(x & (static_cast(1) << 63))) { 58 | x <<= 1; 59 | ++r; 60 | } 61 | 62 | return r; 63 | #endif // _MSC_VER 64 | } 65 | 66 | #define RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll 67 | 68 | } // namespace internal 69 | RAPIDJSON_NAMESPACE_END 70 | 71 | #endif // RAPIDJSON_CLZLL_H_ 72 | -------------------------------------------------------------------------------- /external/rapidjson/include/rapidjson/internal/ieee754.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_IEEE754_ 16 | #define RAPIDJSON_IEEE754_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | class Double { 24 | public: 25 | Double() {} 26 | Double(double d) : d_(d) {} 27 | Double(uint64_t u) : u_(u) {} 28 | 29 | double Value() const { return d_; } 30 | uint64_t Uint64Value() const { return u_; } 31 | 32 | double NextPositiveDouble() const { 33 | RAPIDJSON_ASSERT(!Sign()); 34 | return Double(u_ + 1).Value(); 35 | } 36 | 37 | bool Sign() const { return (u_ & kSignMask) != 0; } 38 | uint64_t Significand() const { return u_ & kSignificandMask; } 39 | int Exponent() const { return static_cast(((u_ & kExponentMask) >> kSignificandSize) - kExponentBias); } 40 | 41 | bool IsNan() const { return (u_ & kExponentMask) == kExponentMask && Significand() != 0; } 42 | bool IsInf() const { return (u_ & kExponentMask) == kExponentMask && Significand() == 0; } 43 | bool IsNanOrInf() const { return (u_ & kExponentMask) == kExponentMask; } 44 | bool IsNormal() const { return (u_ & kExponentMask) != 0 || Significand() == 0; } 45 | bool IsZero() const { return (u_ & (kExponentMask | kSignificandMask)) == 0; } 46 | 47 | uint64_t IntegerSignificand() const { return IsNormal() ? Significand() | kHiddenBit : Significand(); } 48 | int IntegerExponent() const { return (IsNormal() ? Exponent() : kDenormalExponent) - kSignificandSize; } 49 | uint64_t ToBias() const { return (u_ & kSignMask) ? ~u_ + 1 : u_ | kSignMask; } 50 | 51 | static int EffectiveSignificandSize(int order) { 52 | if (order >= -1021) 53 | return 53; 54 | else if (order <= -1074) 55 | return 0; 56 | else 57 | return order + 1074; 58 | } 59 | 60 | private: 61 | static const int kSignificandSize = 52; 62 | static const int kExponentBias = 0x3FF; 63 | static const int kDenormalExponent = 1 - kExponentBias; 64 | static const uint64_t kSignMask = RAPIDJSON_UINT64_C2(0x80000000, 0x00000000); 65 | static const uint64_t kExponentMask = RAPIDJSON_UINT64_C2(0x7FF00000, 0x00000000); 66 | static const uint64_t kSignificandMask = RAPIDJSON_UINT64_C2(0x000FFFFF, 0xFFFFFFFF); 67 | static const uint64_t kHiddenBit = RAPIDJSON_UINT64_C2(0x00100000, 0x00000000); 68 | 69 | union { 70 | double d_; 71 | uint64_t u_; 72 | }; 73 | }; 74 | 75 | } // namespace internal 76 | RAPIDJSON_NAMESPACE_END 77 | 78 | #endif // RAPIDJSON_IEEE754_ 79 | -------------------------------------------------------------------------------- /external/rapidjson/include/rapidjson/internal/strfunc.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_ 16 | #define RAPIDJSON_INTERNAL_STRFUNC_H_ 17 | 18 | #include "../stream.h" 19 | #include 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | namespace internal { 23 | 24 | //! Custom strlen() which works on different character types. 25 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 26 | \param s Null-terminated input string. 27 | \return Number of characters in the string. 28 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints. 29 | */ 30 | template 31 | inline SizeType StrLen(const Ch* s) { 32 | RAPIDJSON_ASSERT(s != 0); 33 | const Ch* p = s; 34 | while (*p) ++p; 35 | return SizeType(p - s); 36 | } 37 | 38 | template <> 39 | inline SizeType StrLen(const char* s) { 40 | return SizeType(std::strlen(s)); 41 | } 42 | 43 | template <> 44 | inline SizeType StrLen(const wchar_t* s) { 45 | return SizeType(std::wcslen(s)); 46 | } 47 | 48 | //! Returns number of code points in a encoded string. 49 | template 50 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 51 | RAPIDJSON_ASSERT(s != 0); 52 | RAPIDJSON_ASSERT(outCount != 0); 53 | GenericStringStream is(s); 54 | const typename Encoding::Ch* end = s + length; 55 | SizeType count = 0; 56 | while (is.src_ < end) { 57 | unsigned codepoint; 58 | if (!Encoding::Decode(is, &codepoint)) 59 | return false; 60 | count++; 61 | } 62 | *outCount = count; 63 | return true; 64 | } 65 | 66 | } // namespace internal 67 | RAPIDJSON_NAMESPACE_END 68 | 69 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 70 | -------------------------------------------------------------------------------- /external/rapidjson/include/rapidjson/internal/swap.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_INTERNAL_SWAP_H_ 16 | #define RAPIDJSON_INTERNAL_SWAP_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #if defined(__clang__) 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(c++98-compat) 23 | #endif 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | //! Custom swap() to avoid dependency on C++ header 29 | /*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only. 30 | \note This has the same semantics as std::swap(). 31 | */ 32 | template 33 | inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT { 34 | T tmp = a; 35 | a = b; 36 | b = tmp; 37 | } 38 | 39 | } // namespace internal 40 | RAPIDJSON_NAMESPACE_END 41 | 42 | #if defined(__clang__) 43 | RAPIDJSON_DIAG_POP 44 | #endif 45 | 46 | #endif // RAPIDJSON_INTERNAL_SWAP_H_ 47 | -------------------------------------------------------------------------------- /external/rapidjson/include/rapidjson/memorybuffer.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYBUFFER_H_ 16 | #define RAPIDJSON_MEMORYBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | RAPIDJSON_NAMESPACE_BEGIN 22 | 23 | //! Represents an in-memory output byte stream. 24 | /*! 25 | This class is mainly for being wrapped by EncodedOutputStream or AutoUTFOutputStream. 26 | 27 | It is similar to FileWriteBuffer but the destination is an in-memory buffer instead of a file. 28 | 29 | Differences between MemoryBuffer and StringBuffer: 30 | 1. StringBuffer has Encoding but MemoryBuffer is only a byte buffer. 31 | 2. StringBuffer::GetString() returns a null-terminated string. MemoryBuffer::GetBuffer() returns a buffer without terminator. 32 | 33 | \tparam Allocator type for allocating memory buffer. 34 | \note implements Stream concept 35 | */ 36 | template 37 | struct GenericMemoryBuffer { 38 | typedef char Ch; // byte 39 | 40 | GenericMemoryBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 41 | 42 | void Put(Ch c) { *stack_.template Push() = c; } 43 | void Flush() {} 44 | 45 | void Clear() { stack_.Clear(); } 46 | void ShrinkToFit() { stack_.ShrinkToFit(); } 47 | Ch* Push(size_t count) { return stack_.template Push(count); } 48 | void Pop(size_t count) { stack_.template Pop(count); } 49 | 50 | const Ch* GetBuffer() const { 51 | return stack_.template Bottom(); 52 | } 53 | 54 | size_t GetSize() const { return stack_.GetSize(); } 55 | 56 | static const size_t kDefaultCapacity = 256; 57 | mutable internal::Stack stack_; 58 | }; 59 | 60 | typedef GenericMemoryBuffer<> MemoryBuffer; 61 | 62 | //! Implement specialized version of PutN() with memset() for better performance. 63 | template<> 64 | inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) { 65 | std::memset(memoryBuffer.stack_.Push(n), c, n * sizeof(c)); 66 | } 67 | 68 | RAPIDJSON_NAMESPACE_END 69 | 70 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 71 | -------------------------------------------------------------------------------- /external/rapidjson/include/rapidjson/memorystream.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_MEMORYSTREAM_H_ 16 | #define RAPIDJSON_MEMORYSTREAM_H_ 17 | 18 | #include "stream.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(unreachable-code) 23 | RAPIDJSON_DIAG_OFF(missing-noreturn) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Represents an in-memory input byte stream. 29 | /*! 30 | This class is mainly for being wrapped by EncodedInputStream or AutoUTFInputStream. 31 | 32 | It is similar to FileReadBuffer but the source is an in-memory buffer instead of a file. 33 | 34 | Differences between MemoryStream and StringStream: 35 | 1. StringStream has encoding but MemoryStream is a byte stream. 36 | 2. MemoryStream needs size of the source buffer and the buffer don't need to be null terminated. StringStream assume null-terminated string as source. 37 | 3. MemoryStream supports Peek4() for encoding detection. StringStream is specified with an encoding so it should not have Peek4(). 38 | \note implements Stream concept 39 | */ 40 | struct MemoryStream { 41 | typedef char Ch; // byte 42 | 43 | MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {} 44 | 45 | Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; } 46 | Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; } 47 | size_t Tell() const { return static_cast(src_ - begin_); } 48 | 49 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 50 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 51 | void Flush() { RAPIDJSON_ASSERT(false); } 52 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 53 | 54 | // For encoding detection only. 55 | const Ch* Peek4() const { 56 | return Tell() + 4 <= size_ ? src_ : 0; 57 | } 58 | 59 | const Ch* src_; //!< Current read position. 60 | const Ch* begin_; //!< Original head of the string. 61 | const Ch* end_; //!< End of stream. 62 | size_t size_; //!< Size of the stream. 63 | }; 64 | 65 | RAPIDJSON_NAMESPACE_END 66 | 67 | #ifdef __clang__ 68 | RAPIDJSON_DIAG_POP 69 | #endif 70 | 71 | #endif // RAPIDJSON_MEMORYBUFFER_H_ 72 | -------------------------------------------------------------------------------- /external/rapidjson/include/rapidjson/ostreamwrapper.h: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #ifndef RAPIDJSON_OSTREAMWRAPPER_H_ 16 | #define RAPIDJSON_OSTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of \c std::basic_ostream into RapidJSON's Stream concept. 29 | /*! 30 | The classes can be wrapped including but not limited to: 31 | 32 | - \c std::ostringstream 33 | - \c std::stringstream 34 | - \c std::wpstringstream 35 | - \c std::wstringstream 36 | - \c std::ifstream 37 | - \c std::fstream 38 | - \c std::wofstream 39 | - \c std::wfstream 40 | 41 | \tparam StreamType Class derived from \c std::basic_ostream. 42 | */ 43 | 44 | template 45 | class BasicOStreamWrapper { 46 | public: 47 | typedef typename StreamType::char_type Ch; 48 | BasicOStreamWrapper(StreamType& stream) : stream_(stream) {} 49 | 50 | void Put(Ch c) { 51 | stream_.put(c); 52 | } 53 | 54 | void Flush() { 55 | stream_.flush(); 56 | } 57 | 58 | // Not implemented 59 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 60 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 61 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 62 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 63 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 64 | 65 | private: 66 | BasicOStreamWrapper(const BasicOStreamWrapper&); 67 | BasicOStreamWrapper& operator=(const BasicOStreamWrapper&); 68 | 69 | StreamType& stream_; 70 | }; 71 | 72 | typedef BasicOStreamWrapper OStreamWrapper; 73 | typedef BasicOStreamWrapper WOStreamWrapper; 74 | 75 | #ifdef __clang__ 76 | RAPIDJSON_DIAG_POP 77 | #endif 78 | 79 | RAPIDJSON_NAMESPACE_END 80 | 81 | #endif // RAPIDJSON_OSTREAMWRAPPER_H_ 82 | -------------------------------------------------------------------------------- /external/rapidjson/include_dirs.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | console.log(path.join(path.relative('.', __dirname), 'include')); 3 | -------------------------------------------------------------------------------- /external/rapidjson/library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RapidJSON", 3 | "version": "1.1.0", 4 | "keywords": "json, sax, dom, parser, generator", 5 | "description": "A fast JSON parser/generator for C++ with both SAX/DOM style API", 6 | "export": { 7 | "include": "include" 8 | }, 9 | "examples": "example/*/*.cpp", 10 | "repository": 11 | { 12 | "type": "git", 13 | "url": "https://github.com/Tencent/rapidjson" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /external/rapidjson/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "rapidjson", 3 | "version": "1.0.4", 4 | "description": "![](doc/logo/rapidjson.png)", 5 | "main": "include_dirs.js", 6 | "directories": { 7 | "doc": "doc", 8 | "example": "example", 9 | "test": "test" 10 | }, 11 | "scripts": { 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/Tencent/rapidjson.git" 17 | }, 18 | "author": "", 19 | "license": "ISC", 20 | "bugs": { 21 | "url": "https://github.com/Tencent/rapidjson/issues" 22 | }, 23 | "homepage": "https://github.com/Tencent/rapidjson#readme" 24 | } 25 | -------------------------------------------------------------------------------- /external/rapidjson/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | find_package(GTestSrc) 2 | 3 | IF(GTESTSRC_FOUND) 4 | enable_testing() 5 | 6 | if (WIN32 AND (NOT CYGWIN) AND (NOT MINGW)) 7 | set(gtest_disable_pthreads ON) 8 | set(gtest_force_shared_crt ON) 9 | endif() 10 | 11 | add_subdirectory(${GTEST_SOURCE_DIR} ${CMAKE_BINARY_DIR}/googletest) 12 | include_directories(SYSTEM ${GTEST_INCLUDE_DIR}) 13 | 14 | set(TEST_LIBRARIES gtest gtest_main) 15 | 16 | add_custom_target(tests ALL) 17 | add_subdirectory(perftest) 18 | add_subdirectory(unittest) 19 | 20 | ENDIF(GTESTSRC_FOUND) 21 | -------------------------------------------------------------------------------- /external/rapidjson/test/perftest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(PERFTEST_SOURCES 2 | misctest.cpp 3 | perftest.cpp 4 | platformtest.cpp 5 | rapidjsontest.cpp 6 | schematest.cpp) 7 | 8 | add_executable(perftest ${PERFTEST_SOURCES}) 9 | target_link_libraries(perftest ${TEST_LIBRARIES}) 10 | 11 | add_dependencies(tests perftest) 12 | 13 | find_program(CCACHE_FOUND ccache) 14 | if(CCACHE_FOUND) 15 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) 16 | set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) 17 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") 18 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") 19 | endif() 20 | endif(CCACHE_FOUND) 21 | 22 | set_property(DIRECTORY PROPERTY COMPILE_OPTIONS ${EXTRA_CXX_FLAGS}) 23 | 24 | IF(NOT (CMAKE_BUILD_TYPE STREQUAL "Debug")) 25 | add_test(NAME perftest 26 | COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/perftest 27 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) 28 | ENDIF() 29 | -------------------------------------------------------------------------------- /external/rapidjson/test/perftest/perftest.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "perftest.h" 16 | 17 | int main(int argc, char **argv) { 18 | #if _MSC_VER 19 | _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); 20 | //void *testWhetherMemoryLeakDetectionWorks = malloc(1); 21 | #endif 22 | ::testing::InitGoogleTest(&argc, argv); 23 | return RUN_ALL_TESTS(); 24 | } 25 | -------------------------------------------------------------------------------- /external/rapidjson/test/unittest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | include(CheckCXXCompilerFlag) 2 | 3 | set(UNITTEST_SOURCES 4 | allocatorstest.cpp 5 | bigintegertest.cpp 6 | clzlltest.cpp 7 | cursorstreamwrappertest.cpp 8 | documenttest.cpp 9 | dtoatest.cpp 10 | encodedstreamtest.cpp 11 | encodingstest.cpp 12 | fwdtest.cpp 13 | filestreamtest.cpp 14 | itoatest.cpp 15 | istreamwrappertest.cpp 16 | jsoncheckertest.cpp 17 | namespacetest.cpp 18 | pointertest.cpp 19 | prettywritertest.cpp 20 | ostreamwrappertest.cpp 21 | readertest.cpp 22 | regextest.cpp 23 | schematest.cpp 24 | simdtest.cpp 25 | strfunctest.cpp 26 | stringbuffertest.cpp 27 | strtodtest.cpp 28 | unittest.cpp 29 | valuetest.cpp 30 | writertest.cpp) 31 | 32 | find_program(CCACHE_FOUND ccache) 33 | if(CCACHE_FOUND) 34 | set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) 35 | set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) 36 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") 37 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Qunused-arguments -fcolor-diagnostics") 38 | endif() 39 | endif(CCACHE_FOUND) 40 | 41 | set_property(DIRECTORY PROPERTY COMPILE_OPTIONS ${EXTRA_CXX_FLAGS}) 42 | 43 | if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") 44 | # If the user is running a newer version of Clang that includes the 45 | # -Wdouble-promotion, we will ignore that warning. 46 | if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.7) 47 | CHECK_CXX_COMPILER_FLAG("-Wno-double-promotion" HAS_NO_DOUBLE_PROMOTION) 48 | if (HAS_NO_DOUBLE_PROMOTION) 49 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-double-promotion") 50 | endif() 51 | endif() 52 | elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 53 | # Force to always compile with /W4 54 | if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]") 55 | string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 56 | else() 57 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4") 58 | endif() 59 | 60 | # Force to always compile with /WX 61 | if(CMAKE_CXX_FLAGS MATCHES "/WX-") 62 | string(REGEX REPLACE "/WX-" "/WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") 63 | else() 64 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /WX") 65 | endif() 66 | endif() 67 | 68 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DRAPIDJSON_HAS_STDSTRING=1") 69 | 70 | add_library(namespacetest STATIC namespacetest.cpp) 71 | 72 | add_executable(unittest ${UNITTEST_SOURCES}) 73 | target_link_libraries(unittest ${TEST_LIBRARIES} namespacetest) 74 | 75 | add_dependencies(tests unittest) 76 | 77 | add_test(NAME unittest 78 | COMMAND ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest 79 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) 80 | 81 | if(NOT MSVC) 82 | # Not running SIMD.* unit test cases for Valgrind 83 | add_test(NAME valgrind_unittest 84 | COMMAND valgrind --suppressions=${CMAKE_SOURCE_DIR}/test/valgrind.supp --leak-check=full --error-exitcode=1 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/unittest --gtest_filter=-SIMD.* 85 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) 86 | 87 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") 88 | add_test(NAME symbol_check 89 | COMMAND sh -c "objdump -t -C libnamespacetest.a | grep rapidjson ; test $? -ne 0" 90 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) 91 | endif(CMAKE_BUILD_TYPE STREQUAL "Debug") 92 | 93 | endif(NOT MSVC) 94 | -------------------------------------------------------------------------------- /external/rapidjson/test/unittest/clzlltest.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "unittest.h" 16 | #include "rapidjson/internal/clzll.h" 17 | 18 | #ifdef __GNUC__ 19 | RAPIDJSON_DIAG_PUSH 20 | #endif 21 | 22 | using namespace rapidjson::internal; 23 | 24 | TEST(clzll, normal) { 25 | EXPECT_EQ(clzll(1), 63U); 26 | EXPECT_EQ(clzll(2), 62U); 27 | EXPECT_EQ(clzll(12), 60U); 28 | EXPECT_EQ(clzll(0x0000000080000001UL), 32U); 29 | EXPECT_EQ(clzll(0x8000000000000001UL), 0U); 30 | } 31 | 32 | #ifdef __GNUC__ 33 | RAPIDJSON_DIAG_POP 34 | #endif 35 | -------------------------------------------------------------------------------- /external/rapidjson/test/unittest/namespacetest.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "unittest.h" 16 | 17 | // test another instantiation of RapidJSON in a different namespace 18 | 19 | #define RAPIDJSON_NAMESPACE my::rapid::json 20 | #define RAPIDJSON_NAMESPACE_BEGIN namespace my { namespace rapid { namespace json { 21 | #define RAPIDJSON_NAMESPACE_END } } } 22 | 23 | // include lots of RapidJSON files 24 | 25 | #include "rapidjson/document.h" 26 | #include "rapidjson/writer.h" 27 | #include "rapidjson/filereadstream.h" 28 | #include "rapidjson/filewritestream.h" 29 | #include "rapidjson/encodedstream.h" 30 | #include "rapidjson/stringbuffer.h" 31 | 32 | static const char json[] = "{\"hello\":\"world\",\"t\":true,\"f\":false,\"n\":null,\"i\":123,\"pi\":3.1416,\"a\":[1,2,3,4]}"; 33 | 34 | TEST(NamespaceTest,Using) { 35 | using namespace RAPIDJSON_NAMESPACE; 36 | typedef GenericDocument, CrtAllocator> DocumentType; 37 | DocumentType doc; 38 | 39 | doc.Parse(json); 40 | EXPECT_TRUE(!doc.HasParseError()); 41 | } 42 | 43 | TEST(NamespaceTest,Direct) { 44 | typedef RAPIDJSON_NAMESPACE::Document Document; 45 | typedef RAPIDJSON_NAMESPACE::Reader Reader; 46 | typedef RAPIDJSON_NAMESPACE::StringStream StringStream; 47 | typedef RAPIDJSON_NAMESPACE::StringBuffer StringBuffer; 48 | typedef RAPIDJSON_NAMESPACE::Writer WriterType; 49 | 50 | StringStream s(json); 51 | StringBuffer buffer; 52 | WriterType writer(buffer); 53 | buffer.ShrinkToFit(); 54 | Reader reader; 55 | reader.Parse(s, writer); 56 | 57 | EXPECT_STREQ(json, buffer.GetString()); 58 | EXPECT_EQ(sizeof(json)-1, buffer.GetSize()); 59 | EXPECT_TRUE(writer.IsComplete()); 60 | 61 | Document doc; 62 | doc.Parse(buffer.GetString()); 63 | EXPECT_TRUE(!doc.HasParseError()); 64 | 65 | buffer.Clear(); 66 | writer.Reset(buffer); 67 | doc.Accept(writer); 68 | EXPECT_STREQ(json, buffer.GetString()); 69 | EXPECT_TRUE(writer.IsComplete()); 70 | } 71 | -------------------------------------------------------------------------------- /external/rapidjson/test/unittest/ostreamwrappertest.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "unittest.h" 16 | 17 | #include "rapidjson/ostreamwrapper.h" 18 | #include "rapidjson/encodedstream.h" 19 | #include "rapidjson/document.h" 20 | #include 21 | #include 22 | 23 | using namespace rapidjson; 24 | using namespace std; 25 | 26 | template 27 | static void TestStringStream() { 28 | typedef typename StringStreamType::char_type Ch; 29 | 30 | Ch s[] = { 'A', 'B', 'C', '\0' }; 31 | StringStreamType oss(s); 32 | BasicOStreamWrapper os(oss); 33 | for (size_t i = 0; i < 3; i++) 34 | os.Put(s[i]); 35 | os.Flush(); 36 | for (size_t i = 0; i < 3; i++) 37 | EXPECT_EQ(s[i], oss.str()[i]); 38 | } 39 | 40 | TEST(OStreamWrapper, ostringstream) { 41 | TestStringStream(); 42 | } 43 | 44 | TEST(OStreamWrapper, stringstream) { 45 | TestStringStream(); 46 | } 47 | 48 | TEST(OStreamWrapper, wostringstream) { 49 | TestStringStream(); 50 | } 51 | 52 | TEST(OStreamWrapper, wstringstream) { 53 | TestStringStream(); 54 | } 55 | 56 | TEST(OStreamWrapper, cout) { 57 | OStreamWrapper os(cout); 58 | const char* s = "Hello World!\n"; 59 | while (*s) 60 | os.Put(*s++); 61 | os.Flush(); 62 | } 63 | 64 | template 65 | static void TestFileStream() { 66 | char filename[L_tmpnam]; 67 | FILE* fp = TempFile(filename); 68 | fclose(fp); 69 | 70 | const char* s = "Hello World!\n"; 71 | { 72 | FileStreamType ofs(filename, ios::out | ios::binary); 73 | BasicOStreamWrapper osw(ofs); 74 | for (const char* p = s; *p; p++) 75 | osw.Put(*p); 76 | osw.Flush(); 77 | } 78 | 79 | fp = fopen(filename, "r"); 80 | ASSERT_TRUE( fp != NULL ); 81 | for (const char* p = s; *p; p++) 82 | EXPECT_EQ(*p, static_cast(fgetc(fp))); 83 | fclose(fp); 84 | } 85 | 86 | TEST(OStreamWrapper, ofstream) { 87 | TestFileStream(); 88 | } 89 | 90 | TEST(OStreamWrapper, fstream) { 91 | TestFileStream(); 92 | } 93 | -------------------------------------------------------------------------------- /external/rapidjson/test/unittest/strfunctest.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "unittest.h" 16 | #include "rapidjson/internal/strfunc.h" 17 | 18 | using namespace rapidjson; 19 | using namespace rapidjson::internal; 20 | 21 | TEST(StrFunc, CountStringCodePoint) { 22 | SizeType count; 23 | EXPECT_TRUE(CountStringCodePoint >("", 0, &count)); 24 | EXPECT_EQ(0u, count); 25 | EXPECT_TRUE(CountStringCodePoint >("Hello", 5, &count)); 26 | EXPECT_EQ(5u, count); 27 | EXPECT_TRUE(CountStringCodePoint >("\xC2\xA2\xE2\x82\xAC\xF0\x9D\x84\x9E", 9, &count)); // cents euro G-clef 28 | EXPECT_EQ(3u, count); 29 | EXPECT_FALSE(CountStringCodePoint >("\xC2\xA2\xE2\x82\xAC\xF0\x9D\x84\x9E\x80", 10, &count)); 30 | } 31 | -------------------------------------------------------------------------------- /external/rapidjson/test/unittest/unittest.cpp: -------------------------------------------------------------------------------- 1 | // Tencent is pleased to support the open source community by making RapidJSON available. 2 | // 3 | // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip. All rights reserved. 4 | // 5 | // Licensed under the MIT License (the "License"); you may not use this file except 6 | // in compliance with the License. You may obtain a copy of the License at 7 | // 8 | // http://opensource.org/licenses/MIT 9 | // 10 | // Unless required by applicable law or agreed to in writing, software distributed 11 | // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 12 | // CONDITIONS OF ANY KIND, either express or implied. See the License for the 13 | // specific language governing permissions and limitations under the License. 14 | 15 | #include "unittest.h" 16 | #include "rapidjson/rapidjson.h" 17 | 18 | #ifdef __clang__ 19 | #pragma GCC diagnostic push 20 | #if __has_warning("-Wdeprecated") 21 | #pragma GCC diagnostic ignored "-Wdeprecated" 22 | #endif 23 | #endif 24 | 25 | AssertException::~AssertException() throw() {} 26 | 27 | #ifdef __clang__ 28 | #pragma GCC diagnostic pop 29 | #endif 30 | 31 | int main(int argc, char **argv) { 32 | ::testing::InitGoogleTest(&argc, argv); 33 | 34 | std::cout << "RapidJSON v" << RAPIDJSON_VERSION_STRING << std::endl; 35 | 36 | #ifdef _MSC_VER 37 | _CrtMemState memoryState = { 0 }; 38 | (void)memoryState; 39 | _CrtMemCheckpoint(&memoryState); 40 | //_CrtSetBreakAlloc(X); 41 | //void *testWhetherMemoryLeakDetectionWorks = malloc(1); 42 | #endif 43 | 44 | int ret = RUN_ALL_TESTS(); 45 | 46 | #ifdef _MSC_VER 47 | // Current gtest constantly leak 2 blocks at exit 48 | _CrtMemDumpAllObjectsSince(&memoryState); 49 | #endif 50 | return ret; 51 | } 52 | -------------------------------------------------------------------------------- /external/rapidjson/test/valgrind.supp: -------------------------------------------------------------------------------- 1 | { 2 | Suppress wcslen valgrind report 1 3 | Memcheck:Cond 4 | fun:__wcslen_sse2 5 | } 6 | 7 | { 8 | Suppress wcslen valgrind report 2 9 | Memcheck:Addr8 10 | fun:__wcslen_sse2 11 | } 12 | 13 | { 14 | Suppress wcslen valgrind report 3 15 | Memcheck:Value8 16 | fun:__wcslen_sse2 17 | } 18 | -------------------------------------------------------------------------------- /src/byte_stream.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "byte_stream.hpp" 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | void byte_stream::overflow(const std::size_t requested) 36 | { 37 | // Recalculating `need` bytes removes at least one instruction from every 38 | // inlined `put` call in header 39 | 40 | assert(available() < requested); 41 | const std::size_t need = requested - available(); 42 | 43 | const std::size_t len = size(); 44 | const std::size_t cap = capacity(); 45 | const std::size_t increase = std::max(need, increase_size()); 46 | 47 | next_write_ = nullptr; 48 | end_ = nullptr; 49 | 50 | buffer_ = byte_buffer_increase(std::move(buffer_), cap, increase); 51 | if (!buffer_) 52 | throw std::bad_alloc{}; 53 | 54 | next_write_ = buffer_.get() + len; 55 | end_ = buffer_.get() + cap + increase; 56 | } 57 | 58 | byte_stream::byte_stream(byte_stream&& rhs) noexcept 59 | : buffer_(std::move(rhs.buffer_)), 60 | next_write_(rhs.next_write_), 61 | end_(rhs.end_), 62 | increase_size_(rhs.increase_size_) 63 | { 64 | rhs.next_write_ = nullptr; 65 | rhs.end_ = nullptr; 66 | } 67 | 68 | byte_stream& byte_stream::operator=(byte_stream&& rhs) noexcept 69 | { 70 | if (this != std::addressof(rhs)) 71 | { 72 | buffer_ = std::move(rhs.buffer_); 73 | next_write_ = rhs.next_write_; 74 | end_ = rhs.end_; 75 | increase_size_ = rhs.increase_size_; 76 | rhs.next_write_ = nullptr; 77 | rhs.end_ = nullptr; 78 | } 79 | return *this; 80 | } 81 | 82 | byte_buffer byte_stream::take_buffer() noexcept 83 | { 84 | byte_buffer out{std::move(buffer_)}; 85 | next_write_ = nullptr; 86 | end_ = nullptr; 87 | return out; 88 | } 89 | -------------------------------------------------------------------------------- /src/display/colors.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "display/colors.hpp" 30 | 31 | namespace display 32 | { 33 | void paint_window(WINDOW* win, color_pair color) noexcept 34 | { 35 | if (!win) 36 | return; 37 | 38 | int lines, cols; 39 | getmaxyx(win, lines, cols); 40 | 41 | wattron(win, COLOR_PAIR(color)); 42 | for (int i = 0; i < lines; ++i) 43 | mvwhline(win, i, 0, ' ', cols); 44 | wattroff(win, COLOR_PAIR(color)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/display/colors.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_DISPLAY_COLORS_HPP 30 | #define MOTRIX_DISPLAY_COLORS_HPP 31 | 32 | #include 33 | 34 | namespace display 35 | { 36 | enum color_pair 37 | { 38 | kInfoText = 1, kProgressMeterNoHighlight, kProgressMeterHighlight, kFallingText1, kFallingText2 39 | }; 40 | } 41 | 42 | #endif // MOTRIX_DISPLAY_COLORS_HPP 43 | -------------------------------------------------------------------------------- /src/display/exit.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_DISPLAY_EXIT_HPP 30 | #define MOTRIX_DISPLAY_EXIT_HPP 31 | 32 | #include 33 | 34 | namespace display 35 | { 36 | struct exit 37 | { 38 | ~exit() noexcept { endwin(); } 39 | }; 40 | } 41 | 42 | #endif // MOTRIX_DISPLAY_EXIT_HPP 43 | -------------------------------------------------------------------------------- /src/display/falling_text.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_DISPLAY_FALLING_TEXT_HPP 30 | #define MOTRIX_DISPLAY_FALLING_TEXT_HPP 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "display/window.hpp" 39 | 40 | namespace display 41 | { 42 | struct falling_text_location; 43 | struct falling_text_group; 44 | class falling_text 45 | { 46 | display::window win_; 47 | std::vector groups_; 48 | std::vector locations_; 49 | std::chrono::steady_clock::time_point next_; 50 | std::size_t offset_; 51 | std::mt19937 rand_; 52 | 53 | void next_text(std::chrono::steady_clock::time_point now); 54 | 55 | public: 56 | using clock = std::chrono::steady_clock; 57 | 58 | falling_text(); 59 | 60 | falling_text(const falling_text&) = delete; 61 | ~falling_text() noexcept; 62 | falling_text& operator=(const falling_text&) = delete; 63 | 64 | WINDOW* handle() const noexcept { return win_.get(); } 65 | 66 | void add_text(const std::array& src); 67 | 68 | clock::time_point next_fall() const noexcept { return next_; } 69 | bool draw_next(clock::time_point now); 70 | }; 71 | } 72 | 73 | #endif // MOTRIX_DISPLAY_FALLING_TEXT_HPP 74 | -------------------------------------------------------------------------------- /src/display/string.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_DISPLAY_STRING_HPP 30 | #define MOTRIX_DISPLAY_STRING_HPP 31 | 32 | namespace display 33 | { 34 | template 35 | constexpr std::size_t static_length(const char (&)[N]) noexcept { return N - 1; } 36 | } 37 | 38 | #endif // MOTRIX_DISPLAY_STRING_HPP 39 | -------------------------------------------------------------------------------- /src/display/sync_meter.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_DISPLAY_SYNC_METER_HPP 30 | #define MOTRIX_DISPLAY_SYNC_METER_HPP 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include "display/window.hpp" 39 | 40 | namespace display 41 | { 42 | class sync_meter 43 | { 44 | const display::window win_; 45 | std::vector messages_; 46 | std::uint64_t current_; 47 | std::uint64_t target_; 48 | std::chrono::steady_clock::time_point last_footer_; 49 | unsigned progress_; 50 | 51 | public: 52 | sync_meter(); 53 | 54 | sync_meter(const sync_meter&) = delete; 55 | ~sync_meter() noexcept; 56 | sync_meter& operator=(const sync_meter&) = delete; 57 | 58 | WINDOW* handle() const noexcept { return win_.get(); } 59 | 60 | void set_header(const char* chain_type, const char* address); 61 | void set_progress(std::uint64_t current, std::uint64_t target); 62 | }; 63 | } 64 | 65 | #endif // MOTRIX_DISPLAY_SYNC_METER_HPP 66 | -------------------------------------------------------------------------------- /src/display/system_warning.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "system_warning.hpp" 30 | 31 | #include 32 | #include 33 | 34 | #include "display/string.hpp" 35 | #include "hex.hpp" 36 | 37 | namespace display 38 | { 39 | system_warning::system_warning(const monero::hash& id, const std::uint64_t height, const std::size_t tx_count) 40 | : win_(make_center_box(characters{80}, characters{5}, kInfoText)) 41 | { 42 | static constexpr const char header[] = "SYSTEM FAILURE"; 43 | static constexpr const char txes_msg[] = "%u transaction(s) processed by Monero"; 44 | static constexpr const char height_msg[] = "Case Number: %u"; 45 | static constexpr const char id_msg[] = "Reference ID: %s"; 46 | if (!win_) 47 | throw std::runtime_error{"Failed to create new curses window"}; 48 | 49 | const auto hex = to_hex::array(id); 50 | 51 | std::array hack; 52 | std::copy(hex.begin(), hex.end(), hack.begin()); 53 | hack[64] = 0; 54 | 55 | print_center(handle(), characters{static_length(header)}, 0, header); 56 | print_center(handle(), characters{static_length(txes_msg)}, 1, txes_msg, unsigned(tx_count)); 57 | print_center(handle(), characters{static_length(height_msg) - 2 + 6}, 2, height_msg, unsigned(height)); 58 | print_center(handle(), characters{static_length(id_msg) - 2 + 64}, 3, id_msg, hack.data()); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/display/system_warning.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_DISPLAY_SYSTEM_WARNING_HPP 30 | #define MOTRIX_DISPLAY_SYSTEM_WARNING_HPP 31 | 32 | #include "display/window.hpp" 33 | #include "monero_data.hpp" 34 | 35 | namespace display 36 | { 37 | class system_warning 38 | { 39 | display::window win_; 40 | public: 41 | explicit system_warning(const monero::hash& id, std::uint64_t height, std::size_t tx_count); 42 | WINDOW* handle() const noexcept { return win_.get(); } 43 | }; 44 | } 45 | 46 | #endif // MOTRIX_DISPLAY_SYSTEM_WARNING_HPP 47 | 48 | 49 | -------------------------------------------------------------------------------- /src/display/window.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "display/window.hpp" 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | namespace display 37 | { 38 | namespace 39 | { 40 | void do_print_center(WINDOW* win, const characters expected, const unsigned y, const char* fmt, va_list args) noexcept 41 | { 42 | assert(win != nullptr); 43 | 44 | int lines, cols; 45 | getmaxyx(win, lines, cols); 46 | 47 | const auto text_start = expected.compute_center(std::max(0, cols)); 48 | 49 | wmove(win, y, text_start.begin); 50 | vw_printw(win, fmt, args); 51 | } 52 | } 53 | 54 | centering percent::compute_center(const unsigned total) const noexcept 55 | { 56 | const unsigned clamped = std::min(100u, value); 57 | const unsigned characters = (static_cast(clamped) * total) / 100u; 58 | const unsigned offset = (total - characters) / 2; 59 | return {offset, characters}; 60 | } 61 | 62 | void print_center(WINDOW* win, const characters expected, const unsigned y, const char* fmt, ...) 63 | { 64 | if (!win) 65 | throw std::logic_error{"display_center given nullptr"}; 66 | 67 | std::va_list args{}; 68 | va_start(args, fmt); 69 | do_print_center(win, expected, y, fmt, args); 70 | va_end(args); 71 | } 72 | 73 | window do_make_center_box(const centering x, const centering y, const color_pair color) 74 | { 75 | window win{newwin(y.characters, x.characters, y.begin, x.begin)}; 76 | 77 | if (!win) 78 | throw std::runtime_error{"Failed to create ncurses window"}; 79 | 80 | wbkgd(win.get(), COLOR_PAIR(color)); 81 | box(win.get(), 0, 0); 82 | 83 | return win; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/display/window.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_DISPLAY_WINDOW_HPP 30 | #define MOTRIX_DISPLAY_WINDOW_HPP 31 | 32 | #include 33 | #include 34 | 35 | #include "display/colors.hpp" 36 | 37 | namespace display 38 | { 39 | struct window_deleter 40 | { 41 | void operator()(WINDOW* ptr) const noexcept 42 | { 43 | if (ptr) 44 | delwin(ptr); 45 | } 46 | }; 47 | using window = std::unique_ptr; 48 | 49 | struct centering 50 | { 51 | unsigned begin; 52 | unsigned characters; 53 | }; 54 | struct characters 55 | { 56 | unsigned value; 57 | 58 | centering compute_center(const unsigned total) const noexcept 59 | { 60 | return {(total - value) / 2, value}; 61 | } 62 | }; 63 | struct percent 64 | { 65 | unsigned value; 66 | 67 | centering compute_center(const unsigned total) const noexcept; 68 | }; 69 | 70 | void print_center(WINDOW*, const characters expected, const unsigned y, const char* fmt, ...); 71 | window do_make_center_box(centering x, centering y, color_pair color); 72 | 73 | template 74 | inline window make_center_box(const X x, const Y y, color_pair color) 75 | { 76 | return do_make_center_box(x.compute_center(COLS), y.compute_center(LINES), color); 77 | } 78 | } 79 | 80 | #endif // MOTRIX_DISPLAY_WINDOW_HPP 81 | -------------------------------------------------------------------------------- /src/engine.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MONRIX_ENGINE_HPP 30 | #define MONRIX_ENGINE_HPP 31 | 32 | #include 33 | 34 | class engine 35 | { 36 | static int exit_fd_; 37 | static std::atomic running_; 38 | 39 | public: 40 | static void run(const char* pub_address, const char* rpc_address, const char* color_scheme); 41 | 42 | static int exit_fd() noexcept { return exit_fd_; } 43 | static bool is_running() noexcept { return running_; } 44 | }; 45 | 46 | #endif // MONRIX_ENGINE_HPP 47 | -------------------------------------------------------------------------------- /src/error.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #include "error.hpp" 28 | 29 | #include 30 | 31 | namespace 32 | { 33 | struct category final : std::error_category 34 | { 35 | virtual const char* name() const noexcept override final 36 | { 37 | return "common_category()"; 38 | } 39 | 40 | virtual std::string message(int value) const override final 41 | { 42 | switch (common_error(value)) 43 | { 44 | case common_error::kInvalidArgument: 45 | return make_error_code(std::errc::invalid_argument).message(); 46 | case common_error::kInvalidErrorCode: 47 | return "expect was given an error value of zero"; 48 | default: 49 | break; 50 | } 51 | return "Unknown basic_category() value"; 52 | } 53 | 54 | virtual std::error_condition default_error_condition(int value) const noexcept override final 55 | { 56 | // maps specific errors to generic `std::errc` cases. 57 | switch (common_error(value)) 58 | { 59 | case common_error::kInvalidArgument: 60 | case common_error::kInvalidErrorCode: 61 | return std::errc::invalid_argument; 62 | default: 63 | break; 64 | } 65 | return std::error_condition{value, *this}; 66 | } 67 | }; 68 | } 69 | 70 | std::error_category const& common_category() noexcept 71 | { 72 | static const category instance{}; 73 | return instance; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /src/error.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2018, The Monero Project 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | #pragma once 28 | 29 | #include 30 | #include 31 | 32 | enum class common_error : int 33 | { 34 | // 0 is reserved for no error, as per expect 35 | kInvalidArgument = 1, //!< A function argument is invalid 36 | kInvalidErrorCode //!< Default `std::error_code` given to `expect` 37 | }; 38 | 39 | std::error_category const& common_category() noexcept; 40 | 41 | inline std::error_code make_error_code(::common_error value) noexcept 42 | { 43 | return std::error_code{int(value), common_category()}; 44 | } 45 | 46 | namespace std 47 | { 48 | template<> 49 | struct is_error_code_enum<::common_error> 50 | : true_type 51 | {}; 52 | } 53 | -------------------------------------------------------------------------------- /src/expect.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without modification, are 5 | // permitted provided that the following conditions are met: 6 | // 7 | // 1. Redistributions of source code must retain the above copyright notice, this list of 8 | // conditions and the following disclaimer. 9 | // 10 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 11 | // of conditions and the following disclaimer in the documentation and/or other 12 | // materials provided with the distribution. 13 | // 14 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 15 | // used to endorse or promote products derived from this software without specific 16 | // prior written permission. 17 | // 18 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 19 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 20 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 23 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 25 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 26 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | #include "expect.hpp" 29 | 30 | #include 31 | #include 32 | 33 | namespace detail 34 | { 35 | namespace 36 | { 37 | std::string generate_error(const char* msg, const char* file, unsigned line) 38 | { 39 | std::string error_msg{}; 40 | if (msg) 41 | { 42 | error_msg.append(msg); 43 | if (file) 44 | error_msg.append(" ("); 45 | } 46 | if (file) 47 | { 48 | error_msg.append("thrown at "); 49 | 50 | // remove path, get just filename + extension 51 | const char* just_file = std::strrchr(file, '/'); 52 | if (!just_file) 53 | just_file = file; 54 | 55 | error_msg.append(just_file); 56 | error_msg.push_back(':'); 57 | error_msg.append(std::to_string(line)); 58 | } 59 | if (msg && file) 60 | error_msg.push_back(')'); 61 | return error_msg; 62 | } 63 | } 64 | 65 | void expect::throw_(std::error_code ec, const char* msg, const char* file, unsigned line) 66 | { 67 | if (msg || file) 68 | throw std::system_error{ec, generate_error(msg, file, line)}; 69 | throw std::system_error{ec}; 70 | } 71 | } // detail 72 | -------------------------------------------------------------------------------- /src/hex.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2017-2019, The Monero Project 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "hex.hpp" 30 | 31 | #include 32 | #include "ascii_table.hpp" 33 | 34 | namespace 35 | { 36 | template 37 | void write_hex(T&& out, const span src) 38 | { 39 | static constexpr const char hex[] = u8"0123456789abcdef"; 40 | static_assert(sizeof(hex) == 17, "bad string size"); 41 | for (const std::uint8_t byte : src) 42 | { 43 | *out = hex[byte >> 4]; 44 | ++out; 45 | *out = hex[byte & 0x0F]; 46 | ++out; 47 | } 48 | } 49 | } 50 | 51 | void to_hex::buffer_unchecked(char* out, const span src) noexcept 52 | { 53 | return write_hex(out, src); 54 | } 55 | 56 | bool from_hex::to_buffer(span out, const span src) noexcept 57 | { 58 | if (src.size() / 2 != out.size()) 59 | return false; 60 | return to_buffer_unchecked(out.data(), src); 61 | } 62 | 63 | bool from_hex::to_buffer_unchecked(std::uint8_t* dst, const span s) noexcept 64 | { 65 | if (s.size() % 2 != 0) 66 | return false; 67 | 68 | const unsigned char *src = (const unsigned char *)s.data(); 69 | for(size_t i = 0; i < s.size(); i += 2) 70 | { 71 | int tmp = *src++; 72 | tmp = ascii::isx[tmp]; 73 | if (tmp == 0xff) return false; 74 | int t2 = *src++; 75 | t2 = ascii::isx[t2]; 76 | if (t2 == 0xff) return false; 77 | *dst++ = (tmp << 4) | t2; 78 | } 79 | 80 | return true; 81 | } 82 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include 30 | #include 31 | 32 | #include "engine.hpp" 33 | 34 | int main(int argc, char** argv) 35 | { 36 | try 37 | { 38 | const char* rpc_address = "tcp://127.0.0.1:18082"; 39 | const char* color_scheme = "auto"; 40 | 41 | if (argc < 1) 42 | throw std::runtime_error{"No process name provided"}; 43 | if (argc < 2) 44 | throw std::runtime_error{"Usage: " + std::string{argv[0]} + " [zmq_rpc_address] [color_scheme]"}; 45 | if (3 <= argc) 46 | rpc_address = argv[2]; 47 | if (4 <= argc) 48 | color_scheme = argv[3]; 49 | 50 | engine::run(argv[1], rpc_address, color_scheme); 51 | } 52 | catch (const std::exception& e) 53 | { 54 | std::cerr << "Runtime exception: " << e.what() << std::endl; 55 | return -1; 56 | } 57 | catch (...) 58 | { 59 | std::cerr << "Unknown runtime exception" << std::endl; 60 | return -1; 61 | } 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /src/method.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "method.hpp" 30 | 31 | #include "wire/field.hpp" 32 | #include "wire/json/read.hpp" 33 | #include "wire/json/write.hpp" 34 | #include "wire/vector.hpp" 35 | 36 | namespace method 37 | { 38 | void write_bytes(wire::json_writer& dest, const get_info::request&) 39 | { 40 | wire::object(dest); 41 | } 42 | void read_bytes(wire::json_reader& source, get_info::data& self) 43 | { 44 | wire::object( 45 | source, 46 | WIRE_FIELD(height), 47 | WIRE_FIELD(target_height), 48 | WIRE_FIELD(outgoing_connections_count), 49 | WIRE_FIELD(incoming_connections_count), 50 | WIRE_FIELD(top_block_hash), 51 | WIRE_FIELD(mainnet), 52 | WIRE_FIELD(testnet), 53 | WIRE_FIELD(stagenet) 54 | ); 55 | } 56 | void read_bytes(wire::json_reader& source, get_info::response& self) 57 | { 58 | wire::object(source, WIRE_FIELD(info)); 59 | } 60 | 61 | void write_bytes(wire::json_writer& dest, const get_transaction_pool::request&) 62 | { 63 | wire::object(dest); 64 | } 65 | void read_bytes(wire::json_reader& source, get_transaction_pool::entry& self) 66 | { 67 | wire::object(source, WIRE_FIELD(tx_hash)); 68 | } 69 | void read_bytes(wire::json_reader& source, get_transaction_pool::response& self) 70 | { 71 | wire::object(source, WIRE_FIELD(transactions)); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/method.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_METHOD_HPP 30 | #define MOTRIX_METHOD_HPP 31 | 32 | #include 33 | #include 34 | 35 | #include "monero_data.hpp" 36 | #include "wire/json/fwd.hpp" 37 | 38 | namespace method 39 | { 40 | struct get_info 41 | { 42 | struct data 43 | { 44 | data() = delete; 45 | std::uint64_t height; 46 | std::uint64_t target_height; 47 | std::uint64_t outgoing_connections_count; 48 | std::uint64_t incoming_connections_count; 49 | monero::hash top_block_hash; 50 | bool mainnet; 51 | bool testnet; 52 | bool stagenet; 53 | }; 54 | 55 | static constexpr const char* name() noexcept { return "get_info"; } 56 | struct request {}; 57 | struct response 58 | { 59 | response() = delete; 60 | data info; 61 | }; 62 | }; 63 | void write_bytes(wire::json_writer&, const get_info::request&); 64 | void read_bytes(wire::json_reader&, get_info::response&); 65 | 66 | struct get_transaction_pool 67 | { 68 | struct entry 69 | { 70 | entry() 71 | : tx_hash{} 72 | {} 73 | 74 | monero::hash tx_hash; 75 | }; 76 | 77 | static constexpr const char* name() noexcept { return "get_transaction_pool"; } 78 | struct request {}; 79 | struct response 80 | { 81 | response() = delete; 82 | std::vector transactions; 83 | }; 84 | }; 85 | void write_bytes(wire::json_writer&, const get_transaction_pool::request&); 86 | void read_bytes(wire::json_reader&, get_transaction_pool::response&); 87 | } 88 | 89 | #endif // MOTRIX_METHOD_HPP 90 | -------------------------------------------------------------------------------- /src/monero_data.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "monero_data.hpp" 30 | 31 | #include 32 | 33 | #include "wire.hpp" 34 | 35 | namespace 36 | { 37 | template 38 | void minimal_tx_map(F& format, T& self) 39 | { 40 | wire::object(format, WIRE_FIELD(id)); 41 | } 42 | } 43 | 44 | namespace monero 45 | { 46 | WIRE_DEFINE_OBJECT(minimal_tx, minimal_tx_map); 47 | 48 | void read_bytes(wire::json_reader& source, block& self) 49 | { 50 | wire::object(source, WIRE_FIELD(tx_hashes), WIRE_FIELD(prev_id)); 51 | } 52 | 53 | int compare(const hash& left, const hash& right) noexcept 54 | { 55 | return std::memcmp(left.data, right.data, sizeof(left.data)); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/monero_data.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_MONERO_DATA_HPP 30 | #define MOTRIX_MONERO_DATA_HPP 31 | 32 | #include 33 | #include 34 | 35 | #include "wire/fwd.hpp" 36 | #include "wire/traits.hpp" 37 | #include "wire/vector.hpp" 38 | 39 | namespace monero 40 | { 41 | struct hash 42 | { 43 | std::uint8_t data[32]; 44 | }; 45 | 46 | int compare(const hash& left, const hash& right) noexcept; 47 | inline bool operator<(const hash& left, const hash& right) noexcept 48 | { 49 | return compare(left, right) < 0; 50 | } 51 | inline bool operator==(const hash& left, const hash& right) noexcept 52 | { 53 | return compare(left, right) == 0; 54 | } 55 | inline bool operator!=(const hash& left, const hash& right) noexcept 56 | { 57 | return compare(left, right) != 0; 58 | } 59 | 60 | struct block 61 | { 62 | std::vector tx_hashes; 63 | monero::hash prev_id; 64 | }; 65 | void read_bytes(wire::json_reader&, block&); 66 | 67 | struct minimal_tx 68 | { 69 | monero::hash id; 70 | }; 71 | WIRE_DECLARE_OBJECT(minimal_tx); 72 | } 73 | 74 | namespace wire 75 | { 76 | template<> 77 | struct is_blob 78 | : std::true_type 79 | {}; 80 | } 81 | 82 | #endif // MOTRIX_MONERO_DATA_HPP 83 | -------------------------------------------------------------------------------- /src/pub.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #include "pub.hpp" 30 | 31 | #include 32 | #include 33 | 34 | #include "wire/field.hpp" 35 | #include "wire/json/read.hpp" 36 | 37 | namespace pub 38 | { 39 | message::message(byte_slice&& raw) noexcept 40 | : topic(), 41 | contents(std::move(raw)) 42 | { 43 | void const* const split = std::memchr(contents.data(), ':', contents.size()); 44 | if (split) 45 | { 46 | topic = contents.take_slice(static_cast(split) - contents.data()); 47 | contents.remove_prefix(1); 48 | } 49 | } 50 | 51 | void read_bytes(wire::json_reader& source, minimal_chain& self) 52 | { 53 | wire::object(source, WIRE_FIELD(first_height), WIRE_FIELD(ids), WIRE_FIELD(first_prev_id)); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/pub.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_PUB_HPP 30 | #define MOTRIX_PUB_HPP 31 | 32 | #include 33 | #include 34 | 35 | #include "byte_slice.hpp" 36 | #include "monero_data.hpp" 37 | #include "wire/json/fwd.hpp" 38 | #include "wire/vector.hpp" 39 | 40 | namespace pub 41 | { 42 | //! A ZMQ/Pub message from the Monero daemon. 43 | struct message 44 | { 45 | //! Construct from raw ZMQ/Sub socket message 46 | explicit message(byte_slice&& raw) noexcept; 47 | 48 | byte_slice topic; 49 | byte_slice contents; 50 | }; 51 | 52 | struct minimal_chain 53 | { 54 | std::uint64_t first_height; 55 | std::vector ids; 56 | monero::hash first_prev_id; 57 | }; 58 | void read_bytes(wire::json_reader&, minimal_chain&); 59 | 60 | using full_chain = std::vector; 61 | using minimal_txpool = std::vector; 62 | } 63 | 64 | #endif // MOTRIX_PUB_HPP 65 | -------------------------------------------------------------------------------- /src/rpc/json.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MOTRIX_JSON_RPC_HPP 2 | #define MOTRIX_JSON_RPC_HPP 3 | 4 | #include 5 | 6 | #include "wire/field.hpp" 7 | #include "wire/json.hpp" 8 | 9 | namespace rpc 10 | { 11 | struct json_request_base 12 | { 13 | static constexpr const char jsonrpc[] = "2.0"; 14 | 15 | //! `method` must be in static memory. 16 | explicit json_request_base(const char* method) 17 | : id(0), method(method) 18 | {} 19 | 20 | unsigned id; 21 | const char* method; //!< Must be in static memory 22 | }; 23 | const char json_request_base::jsonrpc[]; 24 | 25 | //! \tparam W implements the WRITE concept \tparam M implements the METHOD concept 26 | template 27 | struct json_request : json_request_base 28 | { 29 | template 30 | explicit json_request(U&&... args) 31 | : json_request_base(M::name()), 32 | params{std::forward(args)...} 33 | {} 34 | 35 | W params; 36 | }; 37 | 38 | template 39 | inline void write_bytes(wire::json_writer& dest, const json_request& self) 40 | { 41 | // pull fields from base class into the same object 42 | wire::object(dest, WIRE_FIELD_COPY(id), WIRE_FIELD_COPY(jsonrpc), WIRE_FIELD_COPY(method), WIRE_FIELD(params)); 43 | } 44 | 45 | 46 | //! \tparam R implements the READ concept 47 | template 48 | struct json_response 49 | { 50 | json_response() = delete; 51 | 52 | unsigned id; 53 | R result; 54 | }; 55 | 56 | template 57 | inline void read_bytes(wire::json_reader& source, json_response& self) 58 | { 59 | wire::object(source, WIRE_FIELD(id), WIRE_FIELD(result)); 60 | } 61 | 62 | 63 | /*! Implements the RPC concept (JSON-RPC 2.0). 64 | \tparam M must implement the METHOD concept. */ 65 | template 66 | struct json 67 | { 68 | using wire_type = wire::json; 69 | using request = json_request; 70 | using response = json_response; 71 | }; 72 | } 73 | 74 | #endif // MOTRIX_JSON_RPC_HPP 75 | -------------------------------------------------------------------------------- /src/wire.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_WIRE_HPP 30 | #define MOTRIX_WIRE_HPP 31 | 32 | #include "wire/json.hpp" 33 | 34 | #define WIRE_DEFINE_OBJECT(type, map) \ 35 | WIRE_JSON_DEFINE_OBJECT(type, map) 36 | 37 | #endif // MOTRIX_WIRE_HPP 38 | -------------------------------------------------------------------------------- /src/wire/fwd.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_WIRE_FWD_HPP 30 | #define MOTRIX_WIRE_FWD_HPP 31 | 32 | #include "wire/json/fwd.hpp" 33 | 34 | #define WIRE_DECLARE_OBJECT(type) \ 35 | WIRE_JSON_DECLARE_OBJECT(type) 36 | 37 | 38 | #endif // MOTRIX_WIRE_FWD_HPP 39 | -------------------------------------------------------------------------------- /src/wire/json.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_WIRE_JSON_HPP 30 | #define MOTRIX_WIRE_JSON_HPP 31 | 32 | #include "hex.hpp" 33 | #include "span.hpp" 34 | #include "wire/json/base.hpp" 35 | #include "wire/json/read.hpp" 36 | #include "wire/json/write.hpp" 37 | 38 | #define WIRE_JSON_DEFINE_OBJECT(type, map) \ 39 | void read_bytes(::wire::json_reader& source, type& dest) \ 40 | { \ 41 | map(source, dest); \ 42 | } \ 43 | void write_bytes(::wire::json_writer& dest, const type& source) \ 44 | { \ 45 | map(dest, source); \ 46 | } 47 | 48 | #endif // MOTRIX_WIRE_JSON_HPP 49 | -------------------------------------------------------------------------------- /src/wire/json/base.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_WIRE_JSON_BASE_HPP 30 | #define MOTRIX_WIRE_JSON_BASE_HPP 31 | 32 | #include "byte_slice.hpp" 33 | #include "wire/json/fwd.hpp" 34 | 35 | namespace wire 36 | { 37 | struct json 38 | { 39 | using input_type = json_reader; 40 | using output_type = json_writer; 41 | 42 | template 43 | static T from_bytes(byte_slice source); 44 | 45 | template 46 | static byte_slice to_bytes(const T& source); 47 | }; 48 | } 49 | 50 | #endif // MOTRIX_WIRE_JSON_BASE_HPP 51 | -------------------------------------------------------------------------------- /src/wire/json/error.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_WIRE_JSON_ERROR_HPP 30 | #define MOTRIX_WIRE_JSON_ERROR_HPP 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | namespace wire 37 | { 38 | namespace error 39 | { 40 | enum class rapidjson_e : int {}; 41 | 42 | //! \return String for `value`. 43 | const char* get_string(rapidjson_e value) noexcept; 44 | 45 | //! \return Category for rapidjson generated errors. 46 | const std::error_category& rapidjson_category() noexcept; 47 | 48 | //! \return Error code with `value` and `rapidjson_category()`. 49 | inline std::error_code make_error_code(rapidjson_e value) noexcept 50 | { 51 | return std::error_code{int(value), rapidjson_category()}; 52 | } 53 | } 54 | } 55 | 56 | namespace std 57 | { 58 | template<> 59 | struct is_error_code_enum 60 | : std::true_type 61 | {}; 62 | } 63 | 64 | #endif // MOTRIX_WIRE_JSON_ERROR_HPP 65 | -------------------------------------------------------------------------------- /src/wire/json/fwd.hpp: -------------------------------------------------------------------------------- 1 | #ifndef MOTRIX_WIRE_JSON_FWD_HPP 2 | #define MOTRIX_WIRE_JSON_FWD_HPP 3 | 4 | #define WIRE_JSON_DECLARE_OBJECT(type) \ 5 | void read_bytes(::wire::json_reader&, type&); \ 6 | void write_bytes(::wire::json_writer&, const type&) 7 | 8 | namespace wire 9 | { 10 | struct json; 11 | class json_reader; 12 | class json_writer; 13 | } 14 | 15 | #endif // MOTRIX_WIRE_JSON_FWD_HPP 16 | -------------------------------------------------------------------------------- /src/wire/traits.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_WIRE_TRAITS_HPP 30 | #define MOTRIX_WIRE_TRAITS_HPP 31 | 32 | #include 33 | 34 | namespace wire 35 | { 36 | template 37 | struct is_array : std::false_type 38 | {}; 39 | 40 | template 41 | struct is_blob : std::false_type 42 | {}; 43 | } 44 | 45 | #endif // MOTRIX_WIRE_TRAITS_HPP 46 | -------------------------------------------------------------------------------- /src/wire/vector.hpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2020, Lee Clagett 2 | // 3 | // All rights reserved. 4 | // 5 | // Redistribution and use in source and binary forms, with or without modification, are 6 | // permitted provided that the following conditions are met: 7 | // 8 | // 1. Redistributions of source code must retain the above copyright notice, this list of 9 | // conditions and the following disclaimer. 10 | // 11 | // 2. Redistributions in binary form must reproduce the above copyright notice, this list 12 | // of conditions and the following disclaimer in the documentation and/or other 13 | // materials provided with the distribution. 14 | // 15 | // 3. Neither the name of the copyright holder nor the names of its contributors may be 16 | // used to endorse or promote products derived from this software without specific 17 | // prior written permission. 18 | // 19 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 20 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 22 | // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 | // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 26 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 27 | // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | 29 | #ifndef MOTRIX_WIRE_VECTOR_HPP 30 | #define MOTRIX_WIRE_VECTOR_HPP 31 | 32 | #include 33 | #include 34 | 35 | #include "wire/traits.hpp" 36 | 37 | namespace wire 38 | { 39 | template 40 | struct is_array> : 41 | std::true_type 42 | {}; 43 | } 44 | 45 | #endif // MOTRIX_WIRE_VECTOR_HPP 46 | --------------------------------------------------------------------------------