├── .gitattributes ├── .gitignore ├── CppStackerBox.cpp ├── CppStackerBox.h ├── EmscriptenImgui ├── .gitignore ├── Makefile ├── README.md ├── readme.txt ├── shell_minimal.html └── webMain.cpp ├── LICENSE ├── README.md ├── ShaderBox.cpp ├── ShaderBox.h ├── StackerDemo.cpp ├── StackerUI.cpp ├── StackerUI.h ├── WindowsImgui ├── .gitignore ├── Icon.ico ├── ImStacker.sln ├── ImStacker.vcxproj ├── ImStacker.vcxproj.filters ├── ImStacker.vcxproj.user ├── todo.txt └── winMain.cpp └── external ├── glfw ├── LICENSE.md ├── README.md ├── include │ └── GLFW │ │ ├── glfw3.h │ │ └── glfw3native.h └── lib-vc2019 │ ├── glfw3.dll │ ├── glfw3.lib │ ├── glfw3_mt.lib │ └── glfw3dll.lib ├── imgui ├── imconfig.h ├── imgui.cpp ├── imgui.h ├── imgui_demo.cpp ├── imgui_draw.cpp ├── imgui_impl_glfw.cpp ├── imgui_impl_glfw.h ├── imgui_impl_opengl3.cpp ├── imgui_impl_opengl3.h ├── imgui_impl_opengl3_loader.h ├── imgui_impl_sdl.cpp ├── imgui_impl_sdl.h ├── imgui_internal.h ├── imgui_stdlib.cpp ├── imgui_stdlib.h ├── imgui_tables.cpp ├── imgui_widgets.cpp ├── imstb_rectpack.h ├── imstb_textedit.h └── imstb_truetype.h └── rapidjson ├── 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 ├── uri.h └── writer.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | WindowsImgui/imgui.ini 3 | -------------------------------------------------------------------------------- /CppStackerBox.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "StackerUI.h" 4 | 5 | // index is serialized 6 | // update CppStackerBox::getType() if you add a new entry 7 | enum EDataType { 8 | EDT_Void, 9 | // 32bit int 10 | EDT_Int, 11 | // 32bit float 12 | EDT_Float, 13 | // two floats x,y 14 | EDT_Float2, 15 | // three floats x,y,z 16 | EDT_Float3, 17 | // four floats, x,y,z,w 18 | EDT_Float4, 19 | // -------------- 20 | EDT_MAX, 21 | }; 22 | 23 | // index is serialized so only add in end 24 | // update CppAppConnection::openContextMenu() 25 | // and CppStackerBox::generateCode() 26 | // and enumToCStr() 27 | // if you add a new entry 28 | enum ENodeType { 29 | NT_Unknown, 30 | NT_IntVariable, NT_FloatVariable, 31 | NT_Add, NT_Sub, NT_Mul, NT_Div, NT_Pow, 32 | NT_Sin, NT_Cos, NT_Frac, NT_Saturate, NT_Lerp, NT_Dot, NT_Sqrt, NT_OneMinusX, 33 | NT_Swizzle, // like UE4 ComponentMask and Append in one 34 | NT_Rand, 35 | NT_Time, 36 | NT_FragCoord, 37 | NT_ScreenUV, 38 | NT_RGBOutput, 39 | // ----------------- 40 | NT_NodeTypeTerminator 41 | }; 42 | 43 | // return 0 if internal error 44 | inline const char* enumToCStr(const ENodeType nodeType) { 45 | const char* tab[] = { 46 | "Unknown", 47 | "IntVariable", "FloatVariable", 48 | "Add", "Sub", "Mul", "Div", "Pow", 49 | "Sin", "Cos", "Frac", "Saturate", "Lerp", "Dot", "Sqrt", "1-x", 50 | "Swizzle", 51 | "Rand", 52 | "Time", 53 | "FragCoord", 54 | "ScreenUV", 55 | "RGBOutput", 56 | }; 57 | 58 | if (nodeType < sizeof(tab) / sizeof(tab[0])) 59 | return tab[nodeType]; 60 | // sync tab[] with ENodeTab 61 | assert(0); 62 | return nullptr; 63 | } 64 | 65 | class CppStackerBox : public StackerBox { 66 | public: 67 | // for user/debugging, not needed to function 68 | std::string name; 69 | // 70 | EDataType dataType = EDT_Float; 71 | // 72 | ENodeType nodeType = NT_Unknown; 73 | 74 | int32 castTo(GenerateCodeContext& context, const EDataType dstDataType) const; 75 | 76 | // interface StackerBox --------------------------------- 77 | 78 | virtual const char* getType() const override { return "CppStackerBox"; } 79 | virtual bool imGui() override; 80 | virtual bool isVariable() const override { return false; } 81 | virtual bool generateCode(GenerateCodeContext& context) override; 82 | virtual bool load(const rapidjson::Document::ValueType& doc) override; 83 | virtual void save(rapidjson::Document& d, rapidjson::Value& objValue) const override; 84 | virtual void drawBox(const StackerUI& stackerUI, const ImVec2 minR, const ImVec2 maxR) override; 85 | virtual void validate() const override; 86 | }; 87 | 88 | // @return name used in generated code e.g. "vec4" 89 | const char* getGLSLTypeName(const EDataType dataType); 90 | 91 | // ------------------------------------------------------------------- 92 | 93 | class CppStackerBoxConstant : public CppStackerBox { 94 | public: 95 | enum EConstantType { 96 | ECT_Float, 97 | ECT_Float2, 98 | ECT_Float3, 99 | ECT_Float4, 100 | ECT_ColorRGB, 101 | ECT_ColorRGBA, 102 | }; 103 | static constexpr const char* constantTypeUI = (char*)"Float\0" "Float2\0" "Float3\0" "Float4\0" "ColorRGB\0" "ColorRGBA\0" ; 104 | 105 | EConstantType constantType = ECT_Float; 106 | 107 | ImVec4 value = {}; 108 | float minSlider = 0.0f; 109 | float maxSlider = 2.0f; 110 | 111 | EDataType getDataType() const; 112 | 113 | // interface StackerBox --------------------------------- 114 | 115 | virtual const char* getType() const override { return "CppStackerBoxConstant"; } 116 | virtual bool imGui() override; 117 | virtual bool isVariable() const override { return true; } 118 | virtual bool canHaveInput() const override { return false; } 119 | virtual bool generateCode(GenerateCodeContext& context) override; 120 | virtual bool load(const rapidjson::Document::ValueType& doc) override; 121 | virtual void save(rapidjson::Document& d, rapidjson::Value& objValue) const override; 122 | virtual void drawBox(const StackerUI& stackerUI, const ImVec2 minR, const ImVec2 maxR) override; 123 | }; 124 | 125 | // ------------------------------------------------------------------- 126 | 127 | class CppAppConnection : public StackerUI::IAppConnection { 128 | public: 129 | std::string generatedCode; 130 | std::string warningsAndErrors; 131 | 132 | virtual void openContextMenu(StackerUI& stackerUI, const StackerBoxRect& rect); 133 | virtual StackerBox* createNode(const char* className); 134 | virtual const char* getWarningsAndErrors() { return warningsAndErrors.c_str(); } 135 | virtual void startCompile(); 136 | virtual void endCompile(); 137 | virtual void reCompile(); 138 | virtual std::string* code() { return &generatedCode; } 139 | }; 140 | 141 | // ------------------------------------------------------------------- 142 | 143 | class CppStackerBoxSwizzle : public CppStackerBox { 144 | public: 145 | // 0 terminated, to be valid it must only use xyzw and the input must have those 146 | char xyzw[5] = { 'x', 'y', 0, 0, 0 }; 147 | 148 | // @return EDT_Void means the swizzle failed 149 | EDataType computeOutputDataType(const EDataType inputDataType) const; 150 | 151 | // interface StackerBox --------------------------------- 152 | 153 | virtual const char* getType() const override { return "CppStackerBoxSwizzle"; } 154 | virtual bool imGui() override; 155 | virtual bool load(const rapidjson::Document::ValueType& doc) override; 156 | virtual void save(rapidjson::Document& d, rapidjson::Value& objValue) const override; 157 | }; 158 | -------------------------------------------------------------------------------- /EmscriptenImgui/.gitignore: -------------------------------------------------------------------------------- 1 | *.o 2 | web/** -------------------------------------------------------------------------------- /EmscriptenImgui/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile to use with emscripten 3 | # See https://emscripten.org/docs/getting_started/downloads.html 4 | # for installation instructions. 5 | # 6 | # This Makefile assumes you have loaded emscripten's environment. 7 | # (On Windows, you may need to execute emsdk_env.bat or encmdprompt.bat ahead) 8 | # 9 | # Running `make` will produce three files: 10 | # - web/index.html 11 | # - web/index.js 12 | # - web/index.wasm 13 | # 14 | # All three are needed to run the demo. 15 | 16 | CC = emcc 17 | CXX = em++ 18 | WEB_DIR = web 19 | EXE = $(WEB_DIR)/index.html 20 | IMGUI_DIR = ../external/imgui 21 | SOURCES = webMain.cpp 22 | SOURCES += ../CppStackerBox.cpp 23 | SOURCES += ../StackerDemo.cpp 24 | SOURCES += ../StackerUI.cpp 25 | SOURCES += ../ShaderBox.cpp 26 | SOURCES += $(IMGUI_DIR)/imgui.cpp $(IMGUI_DIR)/imgui_demo.cpp $(IMGUI_DIR)/imgui_draw.cpp $(IMGUI_DIR)/imgui_tables.cpp $(IMGUI_DIR)/imgui_widgets.cpp $(IMGUI_DIR)/imgui_stdlib.cpp 27 | SOURCES += $(IMGUI_DIR)/backends/imgui_impl_sdl.cpp $(IMGUI_DIR)/backends/imgui_impl_opengl3.cpp 28 | OBJS = $(addsuffix .o, $(basename $(notdir $(SOURCES)))) 29 | UNAME_S := $(shell uname -s) 30 | # for rapidjson 31 | CPPFLAGS = -I../external 32 | LDFLAGS = 33 | EMS = 34 | 35 | ##--------------------------------------------------------------------- 36 | ## EMSCRIPTEN OPTIONS 37 | ##--------------------------------------------------------------------- 38 | 39 | # ("EMS" options gets added to both CPPFLAGS and LDFLAGS, whereas some options are for linker only) 40 | EMS += -s USE_SDL=2 41 | EMS += -s DISABLE_EXCEPTION_CATCHING=1 42 | LDFLAGS += -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s NO_EXIT_RUNTIME=0 -s ASSERTIONS=1 43 | 44 | # needed? 45 | LDFLAGS += -s USE_GLFW=3 -s FULL_ES2=1 46 | 47 | # Uncomment next line to fix possible rendering bugs with Emscripten version older then 1.39.0 (https://github.com/ocornut/imgui/issues/2877) 48 | #EMS += -s BINARYEN_TRAP_MODE=clamp 49 | #EMS += -s SAFE_HEAP=1 ## Adds overhead 50 | 51 | # Emscripten allows preloading a file or folder to be accessible at runtime. 52 | # The Makefile for this example project suggests embedding the misc/fonts/ folder into our application, it will then be accessible as "/fonts" 53 | # See documentation for more details: https://emscripten.org/docs/porting/files/packaging_files.html 54 | # (Default value is 0. Set to 1 to enable file-system and include the misc/fonts/ folder as part of the build.) 55 | USE_FILE_SYSTEM ?= 1 56 | ifeq ($(USE_FILE_SYSTEM), 0) 57 | LDFLAGS += -s NO_FILESYSTEM=1 58 | CPPFLAGS += -DIMGUI_DISABLE_FILE_FUNCTIONS 59 | endif 60 | ifeq ($(USE_FILE_SYSTEM), 1) 61 | #LDFLAGS += --no-heap-copy --preload-file ../../misc/fonts@/fonts 62 | LDFLAGS += --no-heap-copy 63 | CPPFLAGS += -DIMGUI_DISABLE_FILE_FUNCTIONS 64 | endif 65 | 66 | ##--------------------------------------------------------------------- 67 | ## FINAL BUILD FLAGS 68 | ##--------------------------------------------------------------------- 69 | 70 | CPPFLAGS += -I$(IMGUI_DIR) -I$(IMGUI_DIR)/backends 71 | #CPPFLAGS += -g 72 | CPPFLAGS += -Wall -Wformat -Os $(EMS) 73 | LDFLAGS += --shell-file shell_minimal.html $(EMS) 74 | 75 | ##--------------------------------------------------------------------- 76 | ## BUILD RULES 77 | ##--------------------------------------------------------------------- 78 | 79 | %.o:%.cpp 80 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 81 | 82 | %.o:../%.cpp 83 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 84 | 85 | %.o:$(IMGUI_DIR)/%.cpp 86 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 87 | 88 | %.o:$(IMGUI_DIR)/backends/%.cpp 89 | $(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $< 90 | 91 | all: $(EXE) 92 | @echo Build complete for $(EXE) 93 | 94 | $(WEB_DIR): 95 | mkdir $@ 96 | 97 | serve: all 98 | python3 -m http.server -d $(WEB_DIR) 99 | 100 | $(EXE): $(OBJS) $(WEB_DIR) 101 | $(CXX) -o $@ $(OBJS) $(LDFLAGS) 102 | 103 | clean: 104 | #non windows rm -rf $(OBJS) $(WEB_DIR) 105 | del /Q $(OBJS) $(WEB_DIR) -------------------------------------------------------------------------------- /EmscriptenImgui/README.md: -------------------------------------------------------------------------------- 1 | ## How to Build 2 | 3 | - You need to install Emscripten from https://emscripten.org/docs/getting_started/downloads.html, and have the environment variables set, as described in https://emscripten.org/docs/getting_started/downloads.html#installation-instructions 4 | 5 | - Depending on your configuration, in Windows you may need to run `emsdk/emsdk_env.bat` in your console to access the Emscripten command-line tools. 6 | 7 | - You may also refer to our [Continuous Integration setup](https://github.com/ocornut/imgui/tree/master/.github/workflows) for Emscripten setup. 8 | 9 | - Then build using `make` while in the `example_emscripten_opengl3/` directory. 10 | 11 | ## How to Run 12 | 13 | To run on a local machine: 14 | - `make serve` will use Python3 to spawn a local webserver, you can then browse http://localhost:8000 to access your build. 15 | - Otherwise, generally you will need a local webserver: 16 | - Quoting [https://emscripten.org/docs/getting_started](https://emscripten.org/docs/getting_started/Tutorial.html#generating-html):
17 | _"Unfortunately several browsers (including Chrome, Safari, and Internet Explorer) do not support file:// [XHR](https://emscripten.org/docs/site/glossary.html#term-xhr) requests, and can’t load extra files needed by the HTML (like a .wasm file, or packaged file data as mentioned lower down). For these browsers you’ll need to serve the files using a [local webserver](https://emscripten.org/docs/getting_started/FAQ.html#faq-local-webserver) and then open http://localhost:8000/hello.html."_ 18 | - Emscripten SDK has a handy `emrun` command: `emrun web/example_emscripten_opengl3.html --browser firefox` which will spawn a temporary local webserver (in Firefox). See https://emscripten.org/docs/compiling/Running-html-files-with-emrun.html for details. 19 | - You may use Python 3 builtin webserver: `python -m http.server -d web` (this is what `make serve` uses). 20 | - You may use Python 2 builtin webserver: `cd web && python -m SimpleHTTPServer`. 21 | - If you are accessing the files over a network, certain browsers, such as Firefox, will restrict Gamepad API access to secure contexts only (e.g. https only). 22 | 23 | ## Obsolete features: 24 | 25 | - Emscripten 2.0 (August 2020) obsoleted the fastcomp backend, only llvm is supported. 26 | - Emscripten 1.39.0 (October 2019) obsoleted the `BINARYEN_TRAP_MODE=clamp` compilation flag which was required with version older than 1.39.0 to avoid rendering artefacts. See [#2877](https://github.com/ocornut/imgui/issues/2877) for details. If you use an older version, uncomment this line in the Makefile: `#EMS += -s BINARYEN_TRAP_MODE=clamp` 27 | -------------------------------------------------------------------------------- /EmscriptenImgui/readme.txt: -------------------------------------------------------------------------------- 1 | setup: 2 | 3 | don't use PowerShell.exe, use cmd.exe 4 | 5 | D:\Github\emsdk\emsdk_env.bat 6 | 7 | make clean 8 | make 9 | 10 | use FileZilla to upload 11 | 12 | copy to /kosmokleaner/temp/stacker... 13 | index.html 14 | index.js 15 | index.wasm 16 | 17 | // see https://emscripten.org/docs/porting/Debugging.html for 18 | // same size .wasm but more log during compile 19 | set EMCC_DEBUG=1 20 | // much bigger .wasm 21 | set EMCC_AUTODEBUG=1 22 | 23 | on "process_begin: CreateProcess(NULL, uname -s, ...) failed." error: 24 | https://github.com/ThomasMertes/seed7/blob/master/src/read_me.txt 25 | 26 | 27 | emrun --no_browser web/index.html 28 | 29 | e.g. http://localhost:6931/web -------------------------------------------------------------------------------- /EmscriptenImgui/shell_minimal.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Dear ImGui Emscripten example 7 | 29 | 30 | 31 | 32 | 62 | {{{ SCRIPT }}} 63 | 64 | 65 | -------------------------------------------------------------------------------- /EmscriptenImgui/webMain.cpp: -------------------------------------------------------------------------------- 1 | // Dear ImGui: standalone example application for Emscripten, using SDL2 + OpenGL3 2 | // (Emscripten is a C++-to-javascript compiler, used to publish executables for the web. See https://emscripten.org/) 3 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 4 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 5 | 6 | // This is mostly the same code as the SDL2 + OpenGL3 example, simply with the modifications needed to run on Emscripten. 7 | // It is possible to combine both code into a single source file that will compile properly on Desktop and using Emscripten. 8 | // See https://github.com/ocornut/imgui/pull/2492 as an example on how to do just that. 9 | 10 | #include "../external/imgui/imgui.h" 11 | #include "../external/imgui/imgui_impl_sdl.h" 12 | #include "../external/imgui/imgui_impl_opengl3.h" 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | // Emscripten requires to have full control over the main loop. We're going to store our SDL book-keeping variables globally. 19 | // Having a single function that acts as a loop prevents us to store state in the stack of said function. So we need some location for this. 20 | SDL_Window* g_Window = NULL; 21 | SDL_GLContext g_GLContext = NULL; 22 | 23 | // For clarity, our main loop code is declared at the end. 24 | static void main_loop(void*); 25 | 26 | int main(int, char**) 27 | { 28 | printf("webMain\n"); 29 | 30 | // Setup SDL 31 | if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) 32 | { 33 | printf("Error: %s\n", SDL_GetError()); 34 | return -1; 35 | } 36 | 37 | // For the browser using Emscripten, we are going to use WebGL1 with GL ES2. See the Makefile. for requirement details. 38 | // It is very likely the generated file won't work in many browsers. Firefox is the only sure bet, but I have successfully 39 | // run this code on Chrome for Android for example. 40 | const char* glsl_version = "#version 100"; 41 | //const char* glsl_version = "#version 300 es"; 42 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0); 43 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); 44 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); 45 | SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0); 46 | 47 | // Create window with graphics context 48 | SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 49 | SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); 50 | SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8); 51 | SDL_DisplayMode current; 52 | SDL_GetCurrentDisplayMode(0, ¤t); 53 | // SDL_WINDOW_ALLOW_HIGHDPI, https://github.com/ocornut/imgui/issues/4768 54 | SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI); 55 | 56 | 57 | if (!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1")) 58 | { 59 | printf("Warning: Linear texture filtering not enabled!"); 60 | } 61 | 62 | #ifdef __EMSCRIPTEN__ 63 | int width = 1024; 64 | int height = 768; 65 | // emscripten_set_canvas_element_size("#canvas", width, height); 66 | // EmscriptenFullscreenChangeEvent fs = 0; 67 | // emscripten_set_canvas_element_size("#canvas", width, height); 68 | // emscripten_get_canvas_element_size(&width, &height, &fs); 69 | // emscripten_get_canvas_element_size("#canvas", &width, &height); 70 | // emscripten_get_fullscreen_status(&fs); 71 | 72 | // emscripten_set_canvas_size(width, height); // using SDL_SetVideoMode 73 | #endif 74 | 75 | g_Window = SDL_CreateWindow("ImStacker Emscripten example", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, window_flags); 76 | g_GLContext = SDL_GL_CreateContext(g_Window); 77 | 78 | if (!g_GLContext) 79 | { 80 | fprintf(stderr, "Failed to initialize WebGL context!\n"); 81 | return 1; 82 | } 83 | SDL_GL_SetSwapInterval(1); // Enable vsync 84 | 85 | // Setup Dear ImGui context 86 | IMGUI_CHECKVERSION(); 87 | ImGui::CreateContext(); 88 | ImGuiIO& io = ImGui::GetIO(); (void)io; 89 | io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls 90 | //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls 91 | 92 | // For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file. 93 | // You may manually call LoadIniSettingsFromMemory() to load settings from your own storage. 94 | io.IniFilename = NULL; 95 | 96 | // Setup Dear ImGui style 97 | ImGui::StyleColorsDark(); 98 | //ImGui::StyleColorsClassic(); 99 | 100 | // Setup Platform/Renderer backends 101 | ImGui_ImplSDL2_InitForOpenGL(g_Window, g_GLContext); 102 | ImGui_ImplOpenGL3_Init(glsl_version); 103 | 104 | // Load Fonts 105 | // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. 106 | // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. 107 | // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). 108 | // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. 109 | // - Read 'docs/FONTS.md' for more instructions and details. 110 | // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! 111 | // - Emscripten allows preloading a file or folder to be accessible at runtime. See Makefile for details. 112 | //io.Fonts->AddFontDefault(); 113 | #ifndef IMGUI_DISABLE_FILE_FUNCTIONS 114 | io.Fonts->AddFontFromFileTTF("fonts/Roboto-Medium.ttf", 16.0f); 115 | //io.Fonts->AddFontFromFileTTF("fonts/Cousine-Regular.ttf", 15.0f); 116 | //io.Fonts->AddFontFromFileTTF("fonts/DroidSans.ttf", 16.0f); 117 | //io.Fonts->AddFontFromFileTTF("fonts/ProggyTiny.ttf", 10.0f); 118 | //ImFont* font = io.Fonts->AddFontFromFileTTF("fonts/ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); 119 | //IM_ASSERT(font != NULL); 120 | #endif 121 | 122 | // This function call won't return, and will engage in an infinite loop, processing events from the browser, and dispatching them. 123 | emscripten_set_main_loop_arg(main_loop, NULL, 0, true); 124 | } 125 | 126 | static void main_loop(void* arg) 127 | { 128 | ImGuiIO& io = ImGui::GetIO(); 129 | IM_UNUSED(arg); // We can pass this argument as the second parameter of emscripten_set_main_loop_arg(), but we don't use that. 130 | 131 | // Our state (make them static = more or less global) as a convenience to keep the example terse. 132 | static ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); 133 | 134 | // Poll and handle events (inputs, window resize, etc.) 135 | // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. 136 | // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data. 137 | // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data. 138 | // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. 139 | SDL_Event event; 140 | while (SDL_PollEvent(&event)) 141 | { 142 | ImGui_ImplSDL2_ProcessEvent(&event); 143 | // Capture events here, based on io.WantCaptureMouse and io.WantCaptureKeyboard 144 | } 145 | 146 | // Start the Dear ImGui frame 147 | ImGui_ImplOpenGL3_NewFrame(); 148 | ImGui_ImplSDL2_NewFrame(); 149 | ImGui::NewFrame(); 150 | 151 | void stacker_demo(); 152 | stacker_demo(); 153 | 154 | // Rendering 155 | ImGui::Render(); 156 | 157 | SDL_GL_MakeCurrent(g_Window, g_GLContext); 158 | glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y); 159 | glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); 160 | glClear(GL_COLOR_BUFFER_BIT); 161 | 162 | printf("drawDemo\n"); 163 | void drawDemo(int, int); 164 | drawDemo((int)io.DisplaySize.x, (int)io.DisplaySize.y); 165 | 166 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); 167 | SDL_GL_SwapWindow(g_Window); 168 | } 169 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Martin Mittring 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Docs](https://github.com/AMDResearch/omniperf/actions/workflows/pages/pages-build-deployment/badge.svg?branch=gh-pages)](https://amdresearch.github.io/omniperf/) [![GitHub commits since last release](https://img.shields.io/github/commits-since/AMDResearch/omniperf/latest/dev.svg)](https://github.com/AMDResearch/omniperf/compare/main...dev) 2 | 3 | # ImStacker V0.5 4 | 5 | ImStacker is a simple WIP node based graph editor without “wires” using the ImGui library. It runs on Windows and in the Browser. A demo is included. MIT license 6 | 7 | drawing\ 8 | The radial gradient was created interactively in less than a minute. 9 | 10 | 11 | Live Web Demo: http://www.kosmokleaner.de/temp/stacker4 12 | 13 | 14 | ## What is ImStacker ? 15 | 16 | ImStacker is C++ code that implements a **simple graph editor** but while most such editors use lines to connect boxes we make use of the 2d location and use the stacking (hence the name) location to connect the boxes. This results in a more compact and visually less complex result (no crossed wires). The stacking concept was borrowed from a tool named Werkzeug developed by the demo coder group Farbrausch. 17 | 18 | drawing drawing\ 19 | Node graphs using lines can get messy when getting more complex. 20 | 21 | **ImStacker** is implemented on top of Dear ImGui which is a very popular UI library for desktop game development. The node data and connectivity is stored internally (stateful), but the UI part is immediate (stateless) making it work well with existing ImGui code. This is where the “Im” part of the name comes from. 22 | 23 | drawing\ 24 | from https://github.com/ocornut/imgui 25 | 26 | ImStacker is meant to be usable for a wide range of applications (e.g. shader graph, 2D scripting languages, calculator, post processing graph, …) so it requires integration with code that defines node properties, the connectivity options and how the output is generated. We implemented a demo application for a simple GLSL shader graph editor. 27 | 28 | The **ImStacker demo** uses OpenGL and GLFW to be mostly platform independent. The 64Bit Windows OpenGL version can be compiled with Visual Studio. The 32Bit Webassembly version runs in most browsers and can be compiled with Emscripten (C++ to WebAssembly). 29 | 30 | ![image5](https://user-images.githubusercontent.com/44132/204689029-bb97ced7-5598-40f2-a430-48e4830e9b4b.png) 31 | 32 | The code was implemented to demonstrate and refine the idea and is work in progress. It has not reached the maturity of a shipping product. Feel free to take the idea to the next level. ImStacker needs a strong driving application to mature and multiple diverse applications to keep developing a strong common core. 33 | 34 | All code so far was written by Martin Mittring and released under the MIT license. That should make integration in other projects easy. 35 | 36 | 37 | ## Examples 38 | You can get the best impression by seeing it live, try the following and experiment with it: 39 | 40 | drawing\ 41 | Hello World 42 | 43 | drawing\ 44 | A more interesting / animated example 45 | 46 | 47 | ## Goals of ImStacker 48 | * Simple implementation over performance and production quality\ 49 | => For fast code iteration, no localization or polished visuals 50 | * Simple to integrate\ 51 | => abstracted node implementation, C++ 52 | * Live web GL demo\ 53 | => To get wider reach within coder community and demo to anyone in minutes 54 | 55 | ## ImStacker design choices 56 | * **Stacker Panel window** (to create and place nodes) 57 | * Interactive for fast iteration, compile should be in background thread, not blocking UI 58 | * 2D visual grid and snapping to reduce urge to polish and simpler snapping 59 | * Nodes have rounded corners to indicate in / out, arrows to indicate flow (downwards)\ 60 | ![image7](https://user-images.githubusercontent.com/44132/204689158-67e27512-579b-4da9-bd16-3f68df71261a.png) 61 | * Data flow type between is nodes is cast if possible. This needs more polish / testing. 62 | * Resize handles 63 | * Visuals: left and right handles 64 | * Function: 4 corners to resize element + center to move 65 | * Right mouse button / Context menu (Cut Copy Paste), Create new node\ 66 | ![image6](https://user-images.githubusercontent.com/44132/204689171-cb5bef59-7fae-4109-a484-6f4a22398a57.png) 67 | * Multiple node selection (left mouse drag for box, shift for add / remove individuals) 68 | * Selection to copy / move / edit / delete multiple nodes 69 | * Red cross to show localized errors 70 | * **Properties window** (to editor node properties)\ 71 | ![image1](https://user-images.githubusercontent.com/44132/204689232-ede902d6-e9bc-4c2c-bd4b-fe08254c3f33.png) 72 | * Node name as optional documentation (like variable name) 73 | * Data type 74 | * **Stacker Code window** (mostly needed during development)\ 75 | ![image4](https://user-images.githubusercontent.com/44132/204689251-e406c4e6-962b-4fac-81ad-fd41165ecfec.png) 76 | * UI for new / load / save 77 | * Show generated shader code for inspection 78 | * The generated code is editable to quickly iterate on shader errors without restart. 79 | 80 | # Future 81 | * Fix bugs e.g. 82 | * Overlapping nodes are not selected correctly 83 | * Some data types are not propagated correctly 84 | * Polish UI 85 | * Web preview background is not filling the full window 86 | * StackerCode window resize has no effect on window elements 87 | * Show data type between nodes 88 | * Undo / Redo (can use existing serialization) 89 | * Make production usable 90 | * Key bindings to creates common nodes faster 91 | * We need variables to reuse data easier 92 | * We need functions to hide complexity with a simple interface 93 | * Automated unit and integration tests 94 | * Need driving application[s] 95 | * .. for more see todo.txt 96 | 97 | ## Classes 98 | * **ImStacker:** 99 | * **class StackerUI**\ 100 | To store the state and connect to the application 101 | * **class StackerBox**\ 102 | Base class for the node 103 | * **struct IAppConnection**\ 104 | to connect to the application e.g. compile graph / generate output 105 | * **ImStacker demo:** 106 | * **class CppStackerBox** : public StackerBox\ 107 | Node class implementing most functions 108 | * **class CppStackerBoxConstant** : public CppStackerBox\ 109 | Node class implementing a int / float / float2 / float3 / float4 constant 110 | * **class CppStackerBoxSwizzle** : public CppStackerBox\ 111 | Node class implementing a swizzle operation (glsl / hlsl operation) 112 | * **class CppAppConnection** : public StackerUI::IAppConnection\ 113 | to implement compiling glsl code and rendering the output as background 114 | 115 | # Files 116 | * **todo.txt**\ 117 | Itemized tasks for future updates 118 | * **winMain.cpp, ImStacker.vcproj**\ 119 | for running on Windows 120 | * **webMain.cpp, makefile**\ 121 | for running in the browser with Emscripten 122 | * **Readme.me**\ 123 | Markup documentation (single image for now, will be generated from this document) 124 | 125 | ## ImStacker Version History: 126 | * V0.1 127 | * Cloned Windows ImGui demo project 128 | * ImStacker state internals, basic UI 129 | * Added math demo (Basic function) 130 | * V0.3 131 | * Serialization (Load / Save / Copy & Paste) 132 | * Added OpenGL shader demo (ShaderToy inspired) 133 | * V0.5 134 | * Web browser through Emscripten 135 | * More Shader nodes, polished visuals 136 | 137 | ## Third Party / External Libraries 138 | * **Dear ImGui** User Interface library, MIT license 139 | * **GLFW** OpenGL OS abstraction, zlib/libpng license 140 | * **RapidJson** Serialization (Load / Save / Copy & Paste), MIT license 141 | 142 | 143 | ## Links 144 | * **Art and technology of the demoscene**\ 145 | https://www.youtube.com/watch?v=GswISjlquoU \ 146 | How to work with “Tooll”, a spiritual successor of Werkzeug 147 | -------------------------------------------------------------------------------- /ShaderBox.cpp: -------------------------------------------------------------------------------- 1 | #include "imgui.h" 2 | #include 3 | #include "ShaderBox.h" 4 | 5 | #ifdef EMSCRIPTEN 6 | #define IMGL3W_IMPL 7 | #endif 8 | 9 | 10 | #ifdef __EMSCRIPTEN__ 11 | #include "SDL.h" 12 | #include 13 | #include 14 | #include "SDL_opengles2.h" 15 | #else 16 | #include 17 | #endif 18 | 19 | #ifdef EMSCRIPTEN 20 | const char* vertex_shader_text = 21 | "precision mediump float;\n" 22 | "attribute vec3 aPos; // the position variable has attribute position 0\n" 23 | "\n" 24 | "varying vec4 vertexColor;\n" 25 | "\n" 26 | "void main()\n" 27 | "{\n" 28 | " gl_Position = vec4(aPos, 1.0);\n" 29 | " vertexColor = vec4(0.5, 0.0, 0.0, 1.0);\n" 30 | "}\n" 31 | "\n"; 32 | 33 | const char* fragment_shader_text0 = 34 | "precision mediump float;\n" 35 | "\n" 36 | "uniform mat4 uniform0;\n" 37 | "varying vec4 vertexColor; // from vertex shader\n" 38 | "\n" 39 | "void main()\n" 40 | "{\n" 41 | " vec2 checker2 = vec2(floor(gl_FragCoord.x / 16.0), floor(gl_FragCoord.y / 16.0));\n" 42 | " float checker1a = fract(checker2.x * 0.5) * 2.0;\n" 43 | " float checker1b = fract(checker2.y * 0.5) * 2.0;\n" 44 | " float checker1 = mix(checker1a, 1.0 - checker1a, checker1b);\n" 45 | " vec4 ret = vec4(1.0, 1.0, 1.0, 1.0) * mix(0.45, 0.55, checker1);\n\n"; 46 | 47 | const char* fragment_shader_text1 = 48 | " gl_FragColor = ret;\n" 49 | "}\n" 50 | "\n"; 51 | 52 | #else 53 | const char* vertex_shader_text = 54 | "#version 330 core\n" 55 | "layout(location = 0) in vec3 aPos; // the position variable has attribute position 0\n" 56 | "\n" 57 | "out vec4 vertexColor;\n" 58 | "\n" 59 | "void main()\n" 60 | "{\n" 61 | " gl_Position = vec4(aPos, 1.0);\n" 62 | " vertexColor = vec4(0.5, 0.0, 0.0, 1.0);\n" 63 | "}\n" 64 | "\n"; 65 | 66 | const char* fragment_shader_text0 = 67 | "#version 330 core\n" 68 | "out vec4 FragColor; \n" 69 | "\n" 70 | "uniform mat4 uniform0;\n" 71 | "in vec4 vertexColor; // from vertex shader\n" 72 | "in vec4 gl_FragCoord; // (pixel.x+0.5, pixel.y+0.5, z, w)\n" 73 | "\n" 74 | "void main()\n" 75 | "{\n" 76 | " uvec2 checker2 = uvec2(gl_FragCoord.xy / 16.0);\n" 77 | " uint checker1 = (checker2.x & 1u) ^ (checker2.y & 1u);\n" 78 | " vec4 ret = vec4(1.0, 1.0f, 1.0, 1.0) * mix(0.45f, 0.55f, checker1);\n\n"; 79 | 80 | const char* fragment_shader_text1 = 81 | " FragColor = ret;\n" 82 | "}\n" 83 | "\n"; 84 | #endif 85 | 86 | 87 | 88 | #if SHADER_SUPPORT == 1 89 | 90 | // https://www.khronos.org/registry/OpenGL/api/GL/glext.h 91 | #define GL_STATIC_DRAW 0x88E4 92 | 93 | //#define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" 94 | //#define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" 95 | 96 | // but for gl_FragCoord we need more than 100, see https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/gl_FragCoord.xhtml 97 | 98 | static GLuint vertex_shader = (GLuint)-1; 99 | static GLuint g_program = (GLuint)-1; 100 | static GLuint g_vbo = (GLuint)-1; 101 | static GLuint g_idx = (GLuint)-1; 102 | // 0 is a valid uniform index, -1 can mean it was compiled out 103 | static GLuint uniform0 = (GLuint)-1; 104 | 105 | 106 | // If you get an error please report on GitHub. You may try different GL context version or GLSL version. 107 | // @param whatToCheck GL_LINK_STATUS for program or GL_COMPILE_STATUS for shaders 108 | static bool checkProgram(GLuint handle, GLuint whatToCheck, const char* desc, std::string& warningsAndErrors) { 109 | warningsAndErrors.clear(); 110 | 111 | GLint status = 0, log_length = 0; 112 | glGetProgramiv(handle, whatToCheck, &status); 113 | glGetProgramiv(handle, GL_INFO_LOG_LENGTH, &log_length); 114 | if ((GLboolean)status == GL_FALSE) { 115 | #ifdef WIN32 116 | OutputDebugStringA("ERROR: "); 117 | OutputDebugStringA(desc); 118 | OutputDebugStringA("\n"); 119 | #else 120 | fprintf(stderr, "ERROR: "); 121 | fprintf(stderr, "%s", desc); 122 | fprintf(stderr, "\n"); 123 | #endif 124 | } 125 | if (log_length > 1) 126 | { 127 | ImVector buf; 128 | buf.resize((int)(log_length + 1)); 129 | glGetProgramInfoLog(handle, log_length, NULL, (GLchar*)buf.begin()); 130 | #ifdef WIN32 131 | OutputDebugStringA(buf.begin()); 132 | #else 133 | fprintf(stderr, "%s", buf.begin()); 134 | #endif 135 | warningsAndErrors = buf.begin(); 136 | } 137 | return (GLboolean)status == GL_TRUE; 138 | } 139 | 140 | void recompileShaders(const char* inCode, std::string& warningsAndErrors) { 141 | assert(inCode); 142 | 143 | GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); 144 | 145 | const char* ptr = inCode; 146 | glShaderSource(fragment_shader, 1, &ptr, NULL); 147 | 148 | glCompileShader(fragment_shader); 149 | 150 | g_program = glCreateProgram(); 151 | 152 | glAttachShader(g_program, fragment_shader); 153 | 154 | if (vertex_shader != -1) { 155 | glAttachShader(g_program, vertex_shader); 156 | glLinkProgram(g_program); 157 | 158 | uniform0 = glGetUniformLocation(g_program, "uniform0"); 159 | assert(uniform0 >= 0); 160 | 161 | checkProgram(g_program, GL_LINK_STATUS, "program", warningsAndErrors); 162 | } 163 | } 164 | 165 | static void init() { 166 | vertex_shader = glCreateShader(GL_VERTEX_SHADER); 167 | 168 | glShaderSource(vertex_shader, 1, &vertex_shader_text, NULL); 169 | glCompileShader(vertex_shader); 170 | 171 | std::string warningsAndErrors; 172 | std::string shaderCode; 173 | shaderCode += fragment_shader_text0; 174 | shaderCode += fragment_shader_text1; 175 | recompileShaders(shaderCode.c_str(), warningsAndErrors); 176 | 177 | const float r = 1.0f; 178 | 179 | // x, y, z 180 | GLfloat vertices[] = { 181 | -r, r, 0.5f, // 0, left top 182 | r, r, 0.5f, // 1, right, top 183 | -r, -r, 0.5f, // 2, left bottom 184 | r, -r, 0.5f, // 3, right bottom 185 | }; 186 | 187 | glGenBuffers(1, &g_vbo); 188 | glBindBuffer(GL_ARRAY_BUFFER, g_vbo); 189 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 190 | 191 | unsigned int indices[] = { 192 | 0, 1, 2, 193 | 1, 3, 2 194 | }; 195 | 196 | glGenBuffers(1, &g_idx); 197 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_idx); 198 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); 199 | } 200 | 201 | void deinit() { 202 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 203 | glDeleteBuffers(1, &g_idx); 204 | 205 | glBindBuffer(GL_ARRAY_BUFFER, 0); 206 | glDeleteBuffers(1, &g_vbo); 207 | } 208 | 209 | void drawDemo(int width, int height) { 210 | static bool first = true; 211 | 212 | if (first) { 213 | init(); 214 | first = false; 215 | } 216 | 217 | // ImDrawData* draw_data = ImGui::GetDrawData(); 218 | // MyImGuiRenderFunction(draw_data); 219 | 220 | // glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 221 | // glClear(GL_COLOR_BUFFER_BIT); 222 | // glViewport(0, 0, 100, 100); 223 | glScissor(0, 0, 16 * 1024, 16 * 1024); 224 | glUseProgram(g_program); 225 | glBindBuffer(GL_ARRAY_BUFFER, g_vbo); 226 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, g_idx); 227 | glVertexAttribPointer( 228 | 0, // attribute pos 0 229 | 3, GL_FLOAT, // 3 floats 230 | GL_FALSE, // sRGB ? 231 | 3 * sizeof(float), // vertex buffer stride in bytes 232 | (void*)0 // byte offset in buffer 233 | ); 234 | glEnableVertexAttribArray(0); 235 | 236 | float mat[16] = { 0 }; 237 | // [0][0] = random 0..1 238 | mat[0] = rand() / (float)RAND_MAX; 239 | // [0][1] = time in seconds, precision loss when getting larger, best to also expose frac(time) 240 | mat[1] = (float)ImGui::GetTime(); 241 | // [1][0] = (screenSize.x,screenSize.y, 1/screenSize.x, 1/screenSize.y) 242 | mat[4 * 1 + 0] = (float)width; 243 | mat[4 * 1 + 1] = (float)height; 244 | mat[4 * 1 + 2] = 1.0f / width; 245 | mat[4 * 1 + 3] = 1.0f / height; 246 | 247 | glUniformMatrix4fv(uniform0, 1, GL_FALSE, mat); 248 | 249 | // glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_INT, (void*)0); 250 | glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, (void*)0); 251 | glUseProgram(0); 252 | } 253 | 254 | #else // SHADER_SUPPORT == 1 255 | void drawDemo(int width, int height) {} 256 | void recompileShaders(const char* /*inCode*/, std::string& /*warningsAndErrors*/) {} 257 | void deinit() {} 258 | #endif // SHADER_SUPPORT == 1 259 | -------------------------------------------------------------------------------- /ShaderBox.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern const char* fragment_shader_text0; 4 | extern const char* fragment_shader_text1; 5 | 6 | // 0:for testing, 1: default 7 | #define SHADER_SUPPORT 1 8 | 9 | // @param inCode must not be 0 10 | void recompileShaders(const char* inCode, std::string &warningsAndErrors); 11 | 12 | // todo:refactor 13 | void deinit(); 14 | -------------------------------------------------------------------------------- /StackerDemo.cpp: -------------------------------------------------------------------------------- 1 | #include "CppStackerBox.h" 2 | 3 | static StackerUI g_stackerUI; 4 | 5 | void init() { 6 | 7 | { 8 | StackerBoxRect rect; 9 | rect.x = (int32)(rand() % 10); 10 | rect.y = (int32)(rand() % 10); 11 | rect.width = (int32)((rand() % 10) + 2); 12 | rect.height = (int32)((rand() % 3) + 1); 13 | CppStackerBox* el = new CppStackerBox; 14 | el->validate(); 15 | el->rect = rect; 16 | el->nodeType = NT_RGBOutput; 17 | g_stackerUI.stackerBoxes.push_back(el); 18 | } 19 | /* 20 | { 21 | for (int32 i = 0; i < 1; ++i) { 22 | StackerBoxRect rect; 23 | rect.x = (int32)(rand() % 10); 24 | rect.y = (int32)(rand() % 10); 25 | rect.width = (int32)((rand() % 10) + 2); 26 | rect.height = (int32)((rand() % 3) + 1); 27 | bool isVariable = i < 2; 28 | if (isVariable) { 29 | CppStackerBoxFloat* el = new CppStackerBoxFloat; 30 | el->rect = rect; 31 | g_stackerUI.stackerBoxes.push_back(el); 32 | } 33 | else { 34 | CppStackerBox* el = new CppStackerBox; 35 | el->validate(); 36 | el->rect = rect; 37 | el->nodeType = NT_Add; 38 | el->name = "Node"; 39 | g_stackerUI.stackerBoxes.push_back(el); 40 | } 41 | } 42 | } 43 | */ 44 | 45 | static CppAppConnection cppAppConnection; 46 | g_stackerUI.setAppConnection(&cppAppConnection); 47 | } 48 | 49 | void stacker_demo() { 50 | static bool first = true; 51 | 52 | if (first) { 53 | init(); 54 | first = false; 55 | } 56 | 57 | g_stackerUI.draw(); 58 | 59 | 60 | static bool show_demo_window = false; 61 | 62 | if (ImGui::BeginMainMenuBar()) 63 | { 64 | if (ImGui::BeginMenu("Windows")) 65 | { 66 | ImGui::MenuItem("Stacker Panel", 0, &g_stackerUI.showStackerPanelWindow); 67 | ImGui::MenuItem("Stacker Code", 0, &g_stackerUI.showStackerCodeWindow); 68 | ImGui::MenuItem("Stacker Properties", 0, &g_stackerUI.showStackerPropertiesWindow); 69 | ImGui::Separator(); 70 | ImGui::MenuItem("Im Demo Window", 0, &show_demo_window); 71 | ImGui::EndMenu(); 72 | } 73 | ImGui::EndMainMenuBar(); 74 | } 75 | 76 | // ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate); 77 | 78 | 79 | // 1. Show the big demo window (Most of the sample code is in ImGui::ShowDemoWindow()! You can browse its code to learn more about Dear ImGui!). 80 | if (show_demo_window) 81 | ImGui::ShowDemoWindow(&show_demo_window); 82 | 83 | } -------------------------------------------------------------------------------- /StackerUI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include "imgui.h" 5 | #include "rapidjson/document.h" // for load and save 6 | #include "rapidjson/writer.h" 7 | 8 | typedef unsigned int uint32; 9 | typedef signed int int32; 10 | 11 | class StackerBox; 12 | class StackerUI; 13 | 14 | struct StackerBoxRect { 15 | int32 x = 0; 16 | int32 y = 0; 17 | int32 width = 0; 18 | int32 height = 0; 19 | }; 20 | 21 | struct GenerateCodeContext { 22 | const char* indentationStr = " "; 23 | // 0 if not in fullMode 24 | std::string* code = nullptr; 25 | // 26 | int32 nextFreeVIndex = 0; 27 | // 28 | std::vector params; 29 | }; 30 | 31 | // base class for all elements in StackerUI 32 | class StackerBox { 33 | public: 34 | // 35 | StackerBoxRect rect; 36 | 37 | // transient ------ 38 | 39 | // -1 if none, otherwise index in StackerUI::stackerBoxes[], set by buildGraph() 40 | int32 treeParentId = -1; 41 | // to generate variable names in generateCode() 42 | int32 vIndex = 0; 43 | // set by buildGraph() 44 | bool isUsedAsInput = false; 45 | bool compileError = false; 46 | 47 | // used by createNode() 48 | StackerBox(); 49 | 50 | // constructor 51 | StackerBox(const StackerBoxRect& inRect); 52 | 53 | // destructor 54 | virtual ~StackerBox(); 55 | 56 | // interface the derived classes can custiomize their behavior 57 | 58 | // needed for serialization, @return class name, must not be 0 59 | virtual const char* getType() const = 0; 60 | // 61 | virtual bool isVariable() const = 0; 62 | // imGui properties 63 | // @return something changed, set dirty / recompile 64 | virtual bool imGui() { return false; } 65 | // @return success 66 | virtual bool generateCode(GenerateCodeContext& context) = 0; 67 | // 68 | virtual void save(rapidjson::Document& d, rapidjson::Value& objValue) const; 69 | // 70 | virtual bool load(const rapidjson::Document::ValueType& doc); 71 | // 72 | virtual void drawBox(const StackerUI& stackerUI, const ImVec2 minR, const ImVec2 maxR) { (void)stackerUI; (void)minR; (void)maxR; } 73 | // todo: refine interface e.g. how many, what type 74 | virtual bool canHaveInput() const { return true; } 75 | 76 | // for debugging 77 | virtual void validate() const {} 78 | }; 79 | 80 | // -------------------------------------------------------------------------------- 81 | 82 | class StackerUI { 83 | public: 84 | // all mthods need to be implemented as thi class is also used as nUll implementation 85 | struct IAppConnection { 86 | virtual ~IAppConnection() {} 87 | virtual void openContextMenu(StackerUI& /*stackerUI*/, const StackerBoxRect& /*rect*/) {} 88 | // @param className must not be 0 89 | // @return 0 if failed 90 | virtual StackerBox* createNode(const char* /*className*/) { return nullptr; } 91 | virtual void startCompile() {} 92 | virtual std::string* code() { return nullptr; } 93 | virtual void endCompile() {}; 94 | virtual void reCompile() {}; 95 | // @return 0 if there are no warnings and errors 96 | virtual const char* getWarningsAndErrors() { return nullptr; } 97 | }; 98 | 99 | int32 scrollingX = 0; 100 | int32 scrollingY = 0; 101 | 102 | ImVec2 mouseDelta = {}; 103 | 104 | // object currently being resized (handles) 105 | // -1:not used, otherwise index into stackerBoxes 106 | int32 resizeObjectId = -1; 107 | // bit0:top, bit1:right, bit2:bottom, bit3:left 108 | uint32 resizeHandleMask = 0; 109 | // values are Id into stackerBoxes[], never <0 or >=stackerBoxes.size() 110 | std::vector selectedObjects; 111 | 112 | // only used if drag is active and selectedObject == -1 113 | int32 selectStartX = 0, selectStartY = 0; 114 | 115 | // 116 | bool dragActive = false; 117 | bool scrollingActive = false; 118 | // in pixels, sum of all movements in manhattan distance 119 | float scrollingAmount = 0.0f; 120 | bool contextMenuIsOpen = false; 121 | bool autoGenerateCode = true; 122 | 123 | bool showStackerPanelWindow = true; 124 | bool showStackerCodeWindow = true; 125 | bool showStackerPropertiesWindow = true; 126 | 127 | // if true it will trigger a recompile 128 | bool dirty = true; 129 | 130 | // [Id] = data 131 | std::vector stackerBoxes; 132 | // for code generation and drawing 133 | // once setup same size as stackerBoxes, values are id into stackerBoxes[] 134 | std::vector order; 135 | 136 | // UI customizations 137 | const int32 scale = 32; 138 | // must be smaller or same as scale, affects text clipping 139 | const uint32 clipBorderSize = 6; 140 | // must be smaller or same as scale 141 | const uint32 handleSizeX = scale; 142 | // must be smaller or same as scale 143 | const uint32 handleSizeY = scale; 144 | // must be smaller or same as scale 145 | const uint32 crossSize = scale / 2; 146 | // must be smaller or same as scale 147 | const uint32 connectorSize = scale / 2; 148 | 149 | // in grid cells, 0, 1, 2, .. 150 | const int32 newHalfSize = 2; 151 | 152 | // destructor 153 | ~StackerUI(); 154 | 155 | // @param appConnection may be 0, pointer is stored, not released 156 | void setAppConnection(IAppConnection* inAppConnection); 157 | 158 | // adds to stackerBoxes, selects / shows properties 159 | void addFromUI(StackerBox& in); 160 | // 161 | void draw(); 162 | // 163 | void panelUI(); 164 | // @param fileName must not be 0 165 | bool load(const char* fileName); 166 | // @param fileName must not be 0 167 | void save(const char* fileName); 168 | // 169 | void freeData(); 170 | 171 | // 172 | void clipboardCut(); 173 | // 174 | void clipboardCopy(); 175 | // 176 | // @param mousePosX in grid cells 177 | // @param mousePosY in grid cells 178 | void clipboardPaste(const int32 mousePosX, const int32 mousePosY); 179 | // 180 | // @param mousePosX in grid cells 181 | // @param mousePosY in grid cells 182 | void cutCopyPasteMenu(const int32 mousePosX, const int32 mousePosY); 183 | 184 | private: 185 | IAppConnection nullAppConnection; 186 | // never 0 so error handling is simpler 187 | IAppConnection* appConnection = &nullAppConnection; 188 | 189 | // [x + y * width], used by buildGraph(), -1:no used, -2:inside box after first line, otherwise index into stackerBoxes[] 190 | std::vector tempBitmap; 191 | // left, top, right, bottom 192 | int32 bitmapBounds[4] = { 0, 0, 0, 0 }; 193 | 194 | // 195 | void propertiesUI(); 196 | // @param fullMode false:verify only, true: generate code 197 | void generateCode(const bool fullMode); 198 | // 199 | void reCompile(); 200 | // 201 | void generatedCodeUI(); 202 | // 203 | void drawBoxes(const ImVec2 offset, const int32 hoverObjectId, const uint32 hoverHandle); 204 | // 205 | void drawConnectors(const ImVec2 offset); 206 | // 207 | void buildGraph(); 208 | // 209 | void contextMenu(const int32 mousePosX, const int32 mousePosY); 210 | // 211 | void buildOrder(); 212 | // 213 | void bitmapReset(); 214 | // 215 | uint32 getBitmapWidth() const { return bitmapBounds[2] - bitmapBounds[0]; } 216 | // 217 | uint32 getBitmapHeight() const { return bitmapBounds[3] - bitmapBounds[1]; } 218 | // @param id index into stackerBoxes[] 219 | void findChildren(const int32 id, std::vector& children); 220 | // @param id index into stackerBoxes[] 221 | void selectObject(const int32 id, const bool shift); 222 | // 223 | void clearSelection(); 224 | // @param id index into stackerBoxes[] 225 | bool isSelected(const int32 id) const; 226 | // @return true if there is any selection 227 | bool anySelection(); 228 | // 229 | void deleteSelection(); 230 | // @param id index into stackerBoxes[] 231 | void addToSelection(const int32 id); 232 | // 233 | void reset(); 234 | // @param what indices into stackerBoxes[] 235 | void saveToBuffer(rapidjson::StringBuffer& strbuf, const std::vector& what); 236 | // 237 | bool loadFromBuffer(const std::vector& fileBlob, bool select); 238 | }; 239 | -------------------------------------------------------------------------------- /WindowsImgui/.gitignore: -------------------------------------------------------------------------------- 1 | WindowsImgui/imgui.ini 2 | x64/** 3 | .vs/** 4 | 5 | -------------------------------------------------------------------------------- /WindowsImgui/Icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kosmokleaner/ImStacker/6866c520443e425b715ff8235f6d05e151cc1950/WindowsImgui/Icon.ico -------------------------------------------------------------------------------- /WindowsImgui/ImStacker.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ImStacker", "ImStacker.vcxproj", "{783A1B6F-05E9-40E1-BAC3-1DC232797557}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Release|x64 = Release|x64 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {783A1B6F-05E9-40E1-BAC3-1DC232797557}.Debug|x64.ActiveCfg = Debug|x64 15 | {783A1B6F-05E9-40E1-BAC3-1DC232797557}.Debug|x64.Build.0 = Debug|x64 16 | {783A1B6F-05E9-40E1-BAC3-1DC232797557}.Release|x64.ActiveCfg = Release|x64 17 | {783A1B6F-05E9-40E1-BAC3-1DC232797557}.Release|x64.Build.0 = Release|x64 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {5349D3EC-6C21-41E3-B1CF-8051E83AFAE7} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /WindowsImgui/ImStacker.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 16.0 23 | Win32Proj 24 | {783a1b6f-05e9-40e1-bac3-1dc232797557} 25 | ImStacker 26 | 10.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v142 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v142 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v142 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v142 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | ..\SDL;$(LibraryPath) 76 | 77 | 78 | false 79 | ..\SDL;$(LibraryPath) 80 | 81 | 82 | true 83 | $(LibraryPath) 84 | 85 | 86 | false 87 | $(LibraryPath) 88 | 89 | 90 | 91 | Level3 92 | true 93 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 94 | true 95 | .. 96 | 97 | 98 | Console 99 | true 100 | 101 | 102 | 103 | 104 | Level3 105 | true 106 | true 107 | true 108 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 109 | true 110 | .. 111 | 112 | 113 | Console 114 | true 115 | true 116 | true 117 | 118 | 119 | 120 | 121 | Level4 122 | true 123 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 124 | true 125 | ..\external\glfw\include;..\external\imgui;..\external 126 | 127 | 128 | Console 129 | true 130 | 131 | 132 | 133 | 134 | Level4 135 | true 136 | true 137 | true 138 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 139 | true 140 | ..\external\glfw\include;..\external\imgui;..\external 141 | 142 | 143 | Console 144 | true 145 | true 146 | true 147 | 148 | 149 | 150 | 151 | 152 | true 153 | true 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | -------------------------------------------------------------------------------- /WindowsImgui/ImStacker.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | imgui 6 | 7 | 8 | imgui 9 | 10 | 11 | imgui 12 | 13 | 14 | imgui 15 | 16 | 17 | imgui 18 | 19 | 20 | imgui 21 | 22 | 23 | imgui 24 | 25 | 26 | imstacker 27 | 28 | 29 | imstacker 30 | 31 | 32 | imstacker 33 | 34 | 35 | imstacker 36 | 37 | 38 | 39 | 40 | imgui 41 | 42 | 43 | 44 | 45 | {3d472d36-c090-4743-8026-d856a0ba93c5} 46 | 47 | 48 | {834a64f9-8e31-4f17-a82a-82e309de46f6} 49 | 50 | 51 | {69c52001-39e3-4fdf-8364-0f0c50b0a053} 52 | 53 | 54 | 55 | 56 | imgui 57 | 58 | 59 | imgui 60 | 61 | 62 | imgui 63 | 64 | 65 | imgui 66 | 67 | 68 | imgui 69 | 70 | 71 | imgui 72 | 73 | 74 | imgui 75 | 76 | 77 | imgui 78 | 79 | 80 | imgui 81 | 82 | 83 | imstacker 84 | 85 | 86 | imstacker 87 | 88 | 89 | imstacker 90 | 91 | 92 | imgui 93 | 94 | 95 | 96 | 97 | glfw 98 | 99 | 100 | glfw 101 | 102 | 103 | glfw 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | -------------------------------------------------------------------------------- /WindowsImgui/ImStacker.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /WindowsImgui/todo.txt: -------------------------------------------------------------------------------- 1 | 2 | * drag if height = 1 should also scale up if new pos is smaller y 3 | * web version is scaled and doesn't fill full window (stacker4 shows grid) 4 | 5 | * tooltip when hovering over box 6 | * show yellow (warning) X if a node output is needs to be connected 7 | * make function 8 | * screen/window size 9 | * utility functions e.g. sphereMask, length 10 | * separate visuals from coding e.g. make it a roadmap tool 11 | * see temporary values as color / image / number 12 | * comment box behind nodes, move nodes with it 13 | * if box height is 1, top should scale when moved up 14 | 15 | Code style (can be chnaged, this is just how it started): 16 | * tabs size 2 17 | * { in line with for, while, if, ... 18 | * spaces between operators e.g. *, _, -, / 19 | * space after , 20 | 21 | todo: 22 | * properties in line ? 23 | e.g. double click to rename 24 | right mouse to edit properties 25 | left mouse to edit properties in popup 26 | * load / save filename 27 | * 2 demo windows 28 | 29 | polish / later 30 | * undo/redo ? 31 | * min box width should be at least 2 or 3 grid cells 32 | * zoom in/out io.MouseWheel 33 | * set variable can have only one input but it can have 2 triangles 34 | * ctrl-A to select all, menu item 35 | * right mouse with minor mouse movement should still show context menu 36 | * each cross should have tooltip with error 37 | -------------------------------------------------------------------------------- /WindowsImgui/winMain.cpp: -------------------------------------------------------------------------------- 1 | // Dear ImGui: standalone example application for GLFW + OpenGL 3, using programmable pipeline 2 | // (GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.) 3 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 4 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 5 | 6 | #include "imgui.h" 7 | #include "imgui_impl_glfw.h" 8 | #include "imgui_impl_opengl3.h" 9 | #include 10 | #include 11 | #include // HICON 12 | #if defined(IMGUI_IMPL_OPENGL_ES2) 13 | #include 14 | #endif 15 | #include // Will drag system OpenGL headers 16 | 17 | #pragma comment(lib, "opengl32.lib") 18 | 19 | // [Win32] Our example includes a copy of glfw3.lib pre-compiled with VS2010 to maximize ease of testing and compatibility with old VS compilers. 20 | // To link with VS2010-era libraries, VS2015+ requires linking with legacy_stdio_definitions.lib, which we do using this pragma. 21 | // Your own project should not be affected, as you are likely to link with a newer binary of GLFW that is adequate for your version of Visual Studio. 22 | #if defined(_MSC_VER) && (_MSC_VER >= 1900) && !defined(IMGUI_DISABLE_WIN32_FUNCTIONS) 23 | #pragma comment(lib, "legacy_stdio_definitions") 24 | #endif 25 | 26 | static void glfw_error_callback(int error, const char* description) 27 | { 28 | fprintf(stderr, "Glfw Error %d: %s\n", error, description); 29 | } 30 | 31 | unsigned int RGBSwizzle(unsigned int c) { 32 | return (c >> 16) | (c & 0xff00) | ((c & 0xff) << 16); 33 | } 34 | 35 | int main(int, char**) 36 | { 37 | printf("winMain\n"); 38 | 39 | // Setup window 40 | glfwSetErrorCallback(glfw_error_callback); 41 | if (!glfwInit()) 42 | return 1; 43 | 44 | // Decide GL+GLSL versions 45 | #if defined(IMGUI_IMPL_OPENGL_ES2) 46 | // GL ES 2.0 + GLSL 100 47 | const char* glsl_version = "#version 100"; 48 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2); 49 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 50 | glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API); 51 | #elif defined(__APPLE__) 52 | // GL 3.2 + GLSL 150 53 | const char* glsl_version = "#version 150"; 54 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 55 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); 56 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 57 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // Required on Mac 58 | #else 59 | // GL 3.0 + GLSL 130 60 | const char* glsl_version = "#version 130"; 61 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); 62 | glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0); 63 | //glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // 3.2+ only 64 | //glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // 3.0+ only 65 | #endif 66 | 67 | // Create window with graphics context 68 | GLFWwindow* window = glfwCreateWindow(1600, 1200, "ImStacker example", NULL, NULL); 69 | if (window == NULL) 70 | return 1; 71 | 72 | // https://stackoverflow.com/questions/7375003/how-to-convert-hicon-to-hbitmap-in-vc 73 | #if _WIN32 74 | { 75 | HICON hIcon = (HICON)LoadImage(GetModuleHandle(0), L"icon.ico", IMAGE_ICON, 0,0, LR_LOADFROMFILE); 76 | 77 | HBITMAP hBITMAPcopy; 78 | ICONINFOEX IconInfo; 79 | BITMAP BM_32_bit_color; 80 | 81 | memset((void*)&IconInfo, 0, sizeof(ICONINFOEX)); 82 | IconInfo.cbSize = sizeof(ICONINFOEX); 83 | GetIconInfoEx(hIcon, &IconInfo); 84 | 85 | hBITMAPcopy = (HBITMAP)CopyImage(IconInfo.hbmColor, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); 86 | GetObject(hBITMAPcopy, sizeof(BITMAP), &BM_32_bit_color); 87 | //Now: BM_32_bit_color.bmBits pointing to BGRA data.(.bmWidth * .bmHeight * (.bmBitsPixel/8)) 88 | 89 | // BITMAP BM_1_bit_mask; 90 | //HBITMAP IconInfo.hbmMask is 1bit per pxl 91 | // From HBITMAP to BITMAP for mask 92 | // hBITMAPcopy = (HBITMAP)CopyImage(IconInfo.hbmMask, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION); 93 | // GetObject(hBITMAPcopy, sizeof(BITMAP), &BM_1_bit_mask); 94 | //Now: BM_1_bit_mask.bmBits pointing to mask data (.bmWidth * .bmHeight Bits!) 95 | 96 | assert(BM_32_bit_color.bmBitsPixel == 32); 97 | 98 | GLFWimage images[1]; 99 | images[0].width = BM_32_bit_color.bmWidth; 100 | images[0].height = BM_32_bit_color.bmHeight; 101 | 102 | std::vector mem; 103 | mem.resize(images[0].width * images[0].height); 104 | int* src = (int*)BM_32_bit_color.bmBits; 105 | for(int y = images[0].height - 1; y >= 0; --y) { 106 | for (int x = 0; x < images[0].width; ++x) { 107 | // seems glfwSetWindowIcon() doesn't support alpha 108 | mem[y * images[0].width + x] = RGBSwizzle(*src++); 109 | } 110 | } 111 | images[0].pixels = (unsigned char*)mem.data(); 112 | glfwSetWindowIcon(window, 1, images); 113 | } 114 | #endif 115 | 116 | glfwMakeContextCurrent(window); 117 | glfwSwapInterval(1); // Enable vsync 118 | 119 | // Setup Dear ImGui context 120 | IMGUI_CHECKVERSION(); 121 | ImGui::CreateContext(); 122 | ImGuiIO& io = ImGui::GetIO(); (void)io; 123 | //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls 124 | //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls 125 | 126 | // Setup Dear ImGui style 127 | ImGui::StyleColorsDark(); 128 | //ImGui::StyleColorsClassic(); 129 | 130 | // Setup Platform/Renderer backends 131 | ImGui_ImplGlfw_InitForOpenGL(window, true); 132 | ImGui_ImplOpenGL3_Init(glsl_version); 133 | 134 | // Load Fonts 135 | // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them. 136 | // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple. 137 | // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit). 138 | // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call. 139 | // - Read 'docs/FONTS.md' for more instructions and details. 140 | // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ ! 141 | //io.Fonts->AddFontDefault(); 142 | //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f); 143 | //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f); 144 | //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f); 145 | //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f); 146 | //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese()); 147 | //IM_ASSERT(font != NULL); 148 | 149 | // Our state 150 | ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); 151 | 152 | // Main loop 153 | while (!glfwWindowShouldClose(window)) 154 | { 155 | // Poll and handle events (inputs, window resize, etc.) 156 | // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs. 157 | // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy of the mouse data. 158 | // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your copy of the keyboard data. 159 | // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags. 160 | glfwPollEvents(); 161 | 162 | // Start the Dear ImGui frame 163 | ImGui_ImplOpenGL3_NewFrame(); 164 | ImGui_ImplGlfw_NewFrame(); 165 | ImGui::NewFrame(); 166 | 167 | void stacker_demo(); 168 | stacker_demo(); 169 | 170 | // Rendering 171 | ImGui::Render(); 172 | 173 | 174 | int display_w, display_h; 175 | glfwGetFramebufferSize(window, &display_w, &display_h); 176 | glViewport(0, 0, display_w, display_h); 177 | glClearColor(clear_color.x * clear_color.w, clear_color.y * clear_color.w, clear_color.z * clear_color.w, clear_color.w); 178 | glClear(GL_COLOR_BUFFER_BIT); 179 | 180 | void drawDemo(int, int); 181 | drawDemo(display_w, display_h); 182 | 183 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); 184 | 185 | glfwSwapBuffers(window); 186 | } 187 | 188 | // Cleanup 189 | ImGui_ImplOpenGL3_Shutdown(); 190 | ImGui_ImplGlfw_Shutdown(); 191 | ImGui::DestroyContext(); 192 | 193 | glfwDestroyWindow(window); 194 | glfwTerminate(); 195 | 196 | // todo: refactor 197 | void deinit(); 198 | deinit(); 199 | 200 | return 0; 201 | } 202 | -------------------------------------------------------------------------------- /external/glfw/LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2002-2006 Marcus Geelnard 2 | 3 | Copyright (c) 2006-2019 Camilla Löwy 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would 16 | be appreciated but is not required. 17 | 18 | 2. Altered source versions must be plainly marked as such, and must not 19 | be misrepresented as being the original software. 20 | 21 | 3. This notice may not be removed or altered from any source 22 | distribution. 23 | 24 | -------------------------------------------------------------------------------- /external/glfw/README.md: -------------------------------------------------------------------------------- 1 | # GLFW binaries for 64-bit Windows 2 | 3 | This archive contains documentation, headers, pre-compiled static libraries, 4 | import libraries and DLLs for GLFW 3.3.4. 5 | 6 | Binaries for the following compilers are included 7 | 8 | - Visual C++ 2019 (version 16.8.6) 9 | - Visual C++ 2017 (version 15.9.33) 10 | - Visual C++ 2015 (version 14.0.25431.01) 11 | - Visual C++ 2013 (version 12.0.40629.00) 12 | - Visual C++ 2012 (version 11.0.61219.00) 13 | - MinGW-w64 (GCC 10.2.0) 14 | 15 | 16 | ## Binaries for Visual C++ 17 | 18 | All binaries for Visual C++ 2017 and earlier are compatible with Windows XP, but 19 | this is not supported by Visual C++ 2019. 20 | 21 | ### GLFW as a DLL 22 | 23 | To use GLFW as a DLL, link against the `glfw3dll.lib` file for your 24 | environment. This will add a load time dependency on `glfw3.dll`. The 25 | remaining files in the same directory are not needed. 26 | 27 | This DLL is built in release mode for the Multithreaded DLL runtime library. 28 | 29 | There is also a GLFW DLL and import library pair in the `lib-static-ucrt` 30 | directory. These are built with Visual C++ 2019 and the static Multithreaded 31 | runtime library. 32 | 33 | ### GLFW as a static library 34 | 35 | To use GLFW as a static library, link against `glfw3.lib` if your application 36 | is using the Multithreaded DLL runtime library, or `glfw3_mt.lib` if it is 37 | using the static Multithreaded runtime library. The remaining files in the same 38 | directory are not needed. 39 | 40 | The static libraries are built in release mode and do not contain debug 41 | information but can still be linked with the debug versions of the runtime 42 | library. 43 | 44 | 45 | ## Binaries for MinGW-w64 46 | 47 | ### GLFW as a DLL 48 | 49 | To use GLFW as a DLL, link against the `libglfw3dll.a` file for your 50 | environment. This will add a load time dependency on `glfw3.dll`. The 51 | remaining files in the same directory are not needed. 52 | 53 | The DLLs are built in release mode. 54 | 55 | The DLLs depend on the `msvcrt.dll` C runtime library. There is also a GLFW 56 | DLL and import library in the `lib-static-ucrt` directory that is built with 57 | Visual C++ 2019 and statically linked against the UCRT. 58 | 59 | All DLLs in this archive provide the same ABI and can be used as drop-in 60 | replacements for one another, as long as the C runtime library they depend on is 61 | available. 62 | 63 | ### GLFW as a static library 64 | 65 | To use GLFW as a static library, link against the `libglfw3.a` file for your 66 | environment. The other files in the same directory are not needed. 67 | 68 | The library is built in release mode and do not contain debug information. 69 | -------------------------------------------------------------------------------- /external/glfw/lib-vc2019/glfw3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kosmokleaner/ImStacker/6866c520443e425b715ff8235f6d05e151cc1950/external/glfw/lib-vc2019/glfw3.dll -------------------------------------------------------------------------------- /external/glfw/lib-vc2019/glfw3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kosmokleaner/ImStacker/6866c520443e425b715ff8235f6d05e151cc1950/external/glfw/lib-vc2019/glfw3.lib -------------------------------------------------------------------------------- /external/glfw/lib-vc2019/glfw3_mt.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kosmokleaner/ImStacker/6866c520443e425b715ff8235f6d05e151cc1950/external/glfw/lib-vc2019/glfw3_mt.lib -------------------------------------------------------------------------------- /external/glfw/lib-vc2019/glfw3dll.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kosmokleaner/ImStacker/6866c520443e425b715ff8235f6d05e151cc1950/external/glfw/lib-vc2019/glfw3dll.lib -------------------------------------------------------------------------------- /external/imgui/imconfig.h: -------------------------------------------------------------------------------- 1 | //----------------------------------------------------------------------------- 2 | // COMPILE-TIME OPTIONS FOR DEAR IMGUI 3 | // Runtime options (clipboard callbacks, enabling various features, etc.) can generally be set via the ImGuiIO structure. 4 | // You can use ImGui::SetAllocatorFunctions() before calling ImGui::CreateContext() to rewire memory allocation functions. 5 | //----------------------------------------------------------------------------- 6 | // A) You may edit imconfig.h (and not overwrite it when updating Dear ImGui, or maintain a patch/rebased branch with your modifications to it) 7 | // B) or '#define IMGUI_USER_CONFIG "my_imgui_config.h"' in your project and then add directives in your own file without touching this template. 8 | //----------------------------------------------------------------------------- 9 | // You need to make sure that configuration settings are defined consistently _everywhere_ Dear ImGui is used, which include the imgui*.cpp 10 | // files but also _any_ of your code that uses Dear ImGui. This is because some compile-time options have an affect on data structures. 11 | // Defining those options in imconfig.h will ensure every compilation unit gets to see the same data structure layouts. 12 | // Call IMGUI_CHECKVERSION() from your .cpp files to verify that the data structures your files are using are matching the ones imgui.cpp is using. 13 | //----------------------------------------------------------------------------- 14 | 15 | #pragma once 16 | 17 | //---- Define assertion handler. Defaults to calling assert(). 18 | // If your macro uses multiple statements, make sure is enclosed in a 'do { .. } while (0)' block so it can be used as a single statement. 19 | //#define IM_ASSERT(_EXPR) MyAssert(_EXPR) 20 | //#define IM_ASSERT(_EXPR) ((void)(_EXPR)) // Disable asserts 21 | 22 | //---- Define attributes of all API symbols declarations, e.g. for DLL under Windows 23 | // Using Dear ImGui via a shared library is not recommended, because of function call overhead and because we don't guarantee backward nor forward ABI compatibility. 24 | // DLL users: heaps and globals are not shared across DLL boundaries! You will need to call SetCurrentContext() + SetAllocatorFunctions() 25 | // for each static/DLL boundary you are calling from. Read "Context and Memory Allocators" section of imgui.cpp for more details. 26 | //#define IMGUI_API __declspec( dllexport ) 27 | //#define IMGUI_API __declspec( dllimport ) 28 | 29 | //---- Don't define obsolete functions/enums/behaviors. Consider enabling from time to time after updating to avoid using soon-to-be obsolete function/names. 30 | //#define IMGUI_DISABLE_OBSOLETE_FUNCTIONS 31 | //#define IMGUI_DISABLE_OBSOLETE_KEYIO // 1.87: disable legacy io.KeyMap[]+io.KeysDown[] in favor io.AddKeyEvent(). This will be folded into IMGUI_DISABLE_OBSOLETE_FUNCTIONS in a few versions. 32 | 33 | //---- Disable all of Dear ImGui or don't implement standard windows/tools. 34 | // It is very strongly recommended to NOT disable the demo windows and debug tool during development. They are extremely useful in day to day work. Please read comments in imgui_demo.cpp. 35 | //#define IMGUI_DISABLE // Disable everything: all headers and source files will be empty. 36 | //#define IMGUI_DISABLE_DEMO_WINDOWS // Disable demo windows: ShowDemoWindow()/ShowStyleEditor() will be empty. 37 | //#define IMGUI_DISABLE_DEBUG_TOOLS // Disable metrics/debugger and other debug tools: ShowMetricsWindow(), ShowDebugLogWindow() and ShowStackToolWindow() will be empty (this was called IMGUI_DISABLE_METRICS_WINDOW before 1.88). 38 | 39 | //---- Don't implement some functions to reduce linkage requirements. 40 | //#define IMGUI_DISABLE_WIN32_DEFAULT_CLIPBOARD_FUNCTIONS // [Win32] Don't implement default clipboard handler. Won't use and link with OpenClipboard/GetClipboardData/CloseClipboard etc. (user32.lib/.a, kernel32.lib/.a) 41 | //#define IMGUI_ENABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with Visual Studio] Implement default IME handler (require imm32.lib/.a, auto-link for Visual Studio, -limm32 on command-line for MinGW) 42 | //#define IMGUI_DISABLE_WIN32_DEFAULT_IME_FUNCTIONS // [Win32] [Default with non-Visual Studio compilers] Don't implement default IME handler (won't require imm32.lib/.a) 43 | //#define IMGUI_DISABLE_WIN32_FUNCTIONS // [Win32] Won't use and link with any Win32 function (clipboard, ime). 44 | //#define IMGUI_ENABLE_OSX_DEFAULT_CLIPBOARD_FUNCTIONS // [OSX] Implement default OSX clipboard handler (need to link with '-framework ApplicationServices', this is why this is not the default). 45 | //#define IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS // Don't implement ImFormatString/ImFormatStringV so you can implement them yourself (e.g. if you don't want to link with vsnprintf) 46 | //#define IMGUI_DISABLE_DEFAULT_MATH_FUNCTIONS // Don't implement ImFabs/ImSqrt/ImPow/ImFmod/ImCos/ImSin/ImAcos/ImAtan2 so you can implement them yourself. 47 | //#define IMGUI_DISABLE_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle at all (replace them with dummies) 48 | //#define IMGUI_DISABLE_DEFAULT_FILE_FUNCTIONS // Don't implement ImFileOpen/ImFileClose/ImFileRead/ImFileWrite and ImFileHandle so you can implement them yourself if you don't want to link with fopen/fclose/fread/fwrite. This will also disable the LogToTTY() function. 49 | //#define IMGUI_DISABLE_DEFAULT_ALLOCATORS // Don't implement default allocators calling malloc()/free() to avoid linking with them. You will need to call ImGui::SetAllocatorFunctions(). 50 | //#define IMGUI_DISABLE_SSE // Disable use of SSE intrinsics even if available 51 | 52 | //---- Include imgui_user.h at the end of imgui.h as a convenience 53 | //#define IMGUI_INCLUDE_IMGUI_USER_H 54 | 55 | //---- Pack colors to BGRA8 instead of RGBA8 (to avoid converting from one to another) 56 | //#define IMGUI_USE_BGRA_PACKED_COLOR 57 | 58 | //---- Use 32-bit for ImWchar (default is 16-bit) to support unicode planes 1-16. (e.g. point beyond 0xFFFF like emoticons, dingbats, symbols, shapes, ancient languages, etc...) 59 | //#define IMGUI_USE_WCHAR32 60 | 61 | //---- Avoid multiple STB libraries implementations, or redefine path/filenames to prioritize another version 62 | // By default the embedded implementations are declared static and not available outside of Dear ImGui sources files. 63 | //#define IMGUI_STB_TRUETYPE_FILENAME "my_folder/stb_truetype.h" 64 | //#define IMGUI_STB_RECT_PACK_FILENAME "my_folder/stb_rect_pack.h" 65 | //#define IMGUI_STB_SPRINTF_FILENAME "my_folder/stb_sprintf.h" // only used if enabled 66 | //#define IMGUI_DISABLE_STB_TRUETYPE_IMPLEMENTATION 67 | //#define IMGUI_DISABLE_STB_RECT_PACK_IMPLEMENTATION 68 | 69 | //---- Use stb_sprintf.h for a faster implementation of vsnprintf instead of the one from libc (unless IMGUI_DISABLE_DEFAULT_FORMAT_FUNCTIONS is defined) 70 | // Compatibility checks of arguments and formats done by clang and GCC will be disabled in order to support the extra formats provided by stb_sprintf.h. 71 | //#define IMGUI_USE_STB_SPRINTF 72 | 73 | //---- Use FreeType to build and rasterize the font atlas (instead of stb_truetype which is embedded by default in Dear ImGui) 74 | // Requires FreeType headers to be available in the include path. Requires program to be compiled with 'misc/freetype/imgui_freetype.cpp' (in this repository) + the FreeType library (not provided). 75 | // On Windows you may use vcpkg with 'vcpkg install freetype --triplet=x64-windows' + 'vcpkg integrate install'. 76 | //#define IMGUI_ENABLE_FREETYPE 77 | 78 | //---- Use stb_truetype to build and rasterize the font atlas (default) 79 | // The only purpose of this define is if you want force compilation of the stb_truetype backend ALONG with the FreeType backend. 80 | //#define IMGUI_ENABLE_STB_TRUETYPE 81 | 82 | //---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4. 83 | // This will be inlined as part of ImVec2 and ImVec4 class declarations. 84 | /* 85 | #define IM_VEC2_CLASS_EXTRA \ 86 | constexpr ImVec2(const MyVec2& f) : x(f.x), y(f.y) {} \ 87 | operator MyVec2() const { return MyVec2(x,y); } 88 | 89 | #define IM_VEC4_CLASS_EXTRA \ 90 | constexpr ImVec4(const MyVec4& f) : x(f.x), y(f.y), z(f.z), w(f.w) {} \ 91 | operator MyVec4() const { return MyVec4(x,y,z,w); } 92 | */ 93 | 94 | //---- Use 32-bit vertex indices (default is 16-bit) is one way to allow large meshes with more than 64K vertices. 95 | // Your renderer backend will need to support it (most example renderer backends support both 16/32-bit indices). 96 | // Another way to allow large meshes while keeping 16-bit indices is to handle ImDrawCmd::VtxOffset in your renderer. 97 | // Read about ImGuiBackendFlags_RendererHasVtxOffset for details. 98 | //#define ImDrawIdx unsigned int 99 | 100 | //---- Override ImDrawCallback signature (will need to modify renderer backends accordingly) 101 | //struct ImDrawList; 102 | //struct ImDrawCmd; 103 | //typedef void (*MyImDrawCallback)(const ImDrawList* draw_list, const ImDrawCmd* cmd, void* my_renderer_user_data); 104 | //#define ImDrawCallback MyImDrawCallback 105 | 106 | //---- Debug Tools: Macro to break in Debugger 107 | // (use 'Metrics->Tools->Item Picker' to pick widgets with the mouse and break into them for easy debugging.) 108 | //#define IM_DEBUG_BREAK IM_ASSERT(0) 109 | //#define IM_DEBUG_BREAK __debugbreak() 110 | 111 | //---- Debug Tools: Have the Item Picker break in the ItemAdd() function instead of ItemHoverable(), 112 | // (which comes earlier in the code, will catch a few extra items, allow picking items other than Hovered one.) 113 | // This adds a small runtime cost which is why it is not enabled by default. 114 | //#define IMGUI_DEBUG_TOOL_ITEM_PICKER_EX 115 | 116 | //---- Debug Tools: Enable slower asserts 117 | //#define IMGUI_DEBUG_PARANOID 118 | 119 | //---- Tip: You can add extra functions within the ImGui:: namespace, here or in your own headers files. 120 | /* 121 | namespace ImGui 122 | { 123 | void MyFunction(const char* name, const MyMatrix44& v); 124 | } 125 | */ 126 | -------------------------------------------------------------------------------- /external/imgui/imgui_impl_glfw.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for GLFW 2 | // This needs to be used along with a Renderer (e.g. OpenGL3, Vulkan, WebGPU..) 3 | // (Info: GLFW is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan graphics context creation, etc.) 4 | // (Requires: GLFW 3.1+. Prefer GLFW 3.3+ for full feature support.) 5 | 6 | // Implemented features: 7 | // [X] Platform: Clipboard support. 8 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy GLFW_KEY_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 9 | // [X] Platform: Gamepad support. Enable with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 10 | // [x] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange' (note: the resizing cursors requires GLFW 3.4+). 11 | // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 12 | 13 | // Issues: 14 | // [ ] Platform: Multi-viewport support: ParentViewportID not honored, and so io.ConfigViewportsNoDefaultParent has no effect (minor). 15 | 16 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 17 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 18 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 19 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 20 | 21 | // About GLSL version: 22 | // The 'glsl_version' initialization parameter defaults to "#version 150" if NULL. 23 | // Only override if your GL version doesn't handle this GLSL version. Keep NULL if unsure! 24 | 25 | #pragma once 26 | #include "imgui.h" // IMGUI_IMPL_API 27 | 28 | struct GLFWwindow; 29 | struct GLFWmonitor; 30 | 31 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOpenGL(GLFWwindow* window, bool install_callbacks); 32 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForVulkan(GLFWwindow* window, bool install_callbacks); 33 | IMGUI_IMPL_API bool ImGui_ImplGlfw_InitForOther(GLFWwindow* window, bool install_callbacks); 34 | IMGUI_IMPL_API void ImGui_ImplGlfw_Shutdown(); 35 | IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame(); 36 | 37 | // GLFW callbacks (installer) 38 | // - When calling Init with 'install_callbacks=true': ImGui_ImplGlfw_InstallCallbacks() is called. GLFW callbacks will be installed for you. They will chain-call user's previously installed callbacks, if any. 39 | // - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call individual function yourself from your own GLFW callbacks. 40 | IMGUI_IMPL_API void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window); 41 | IMGUI_IMPL_API void ImGui_ImplGlfw_RestoreCallbacks(GLFWwindow* window); 42 | 43 | // GLFW callbacks (individual callbacks to call if you didn't install callbacks) 44 | IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84 45 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84 46 | IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87 47 | IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods); 48 | IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset); 49 | IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods); 50 | IMGUI_IMPL_API void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c); 51 | IMGUI_IMPL_API void ImGui_ImplGlfw_MonitorCallback(GLFWmonitor* monitor, int event); 52 | -------------------------------------------------------------------------------- /external/imgui/imgui_impl_opengl3.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Renderer Backend for modern OpenGL with shaders / programmatic pipeline 2 | // - Desktop GL: 2.x 3.x 4.x 3 | // - Embedded GL: ES 2.0 (WebGL 1.0), ES 3.0 (WebGL 2.0) 4 | // This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..) 5 | 6 | // Implemented features: 7 | // [X] Renderer: User texture binding. Use 'GLuint' OpenGL texture identifier as void*/ImTextureID. Read the FAQ about ImTextureID! 8 | // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 9 | // [x] Renderer: Large meshes support (64k+ vertices) with 16-bit indices (Desktop OpenGL only). 10 | 11 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 12 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 13 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 14 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 15 | 16 | // About GLSL version: 17 | // The 'glsl_version' initialization parameter should be NULL (default) or a "#version XXX" string. 18 | // On computer platform the GLSL version default to "#version 130". On OpenGL ES 3 platform it defaults to "#version 300 es" 19 | // Only override if your GL version doesn't handle this GLSL version. See GLSL version table at the top of imgui_impl_opengl3.cpp. 20 | 21 | #pragma once 22 | #include "imgui.h" // IMGUI_IMPL_API 23 | 24 | // Backend API 25 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_Init(const char* glsl_version = NULL); 26 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_Shutdown(); 27 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_NewFrame(); 28 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_RenderDrawData(ImDrawData* draw_data); 29 | 30 | // (Optional) Called by Init/NewFrame/Shutdown 31 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateFontsTexture(); 32 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyFontsTexture(); 33 | IMGUI_IMPL_API bool ImGui_ImplOpenGL3_CreateDeviceObjects(); 34 | IMGUI_IMPL_API void ImGui_ImplOpenGL3_DestroyDeviceObjects(); 35 | 36 | // Specific OpenGL ES versions 37 | //#define IMGUI_IMPL_OPENGL_ES2 // Auto-detected on Emscripten 38 | //#define IMGUI_IMPL_OPENGL_ES3 // Auto-detected on iOS/Android 39 | 40 | // You can explicitly select GLES2 or GLES3 API by using one of the '#define IMGUI_IMPL_OPENGL_LOADER_XXX' in imconfig.h or compiler command-line. 41 | #if !defined(IMGUI_IMPL_OPENGL_ES2) \ 42 | && !defined(IMGUI_IMPL_OPENGL_ES3) 43 | 44 | // Try to detect GLES on matching platforms 45 | #if defined(__APPLE__) 46 | #include 47 | #endif 48 | #if (defined(__APPLE__) && (TARGET_OS_IOS || TARGET_OS_TV)) || (defined(__ANDROID__)) 49 | #define IMGUI_IMPL_OPENGL_ES3 // iOS, Android -> GL ES 3, "#version 300 es" 50 | #elif defined(__EMSCRIPTEN__) || defined(__amigaos4__) 51 | #define IMGUI_IMPL_OPENGL_ES2 // Emscripten -> GL ES 2, "#version 100" 52 | #else 53 | // Otherwise imgui_impl_opengl3_loader.h will be used. 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /external/imgui/imgui_impl_sdl.h: -------------------------------------------------------------------------------- 1 | // dear imgui: Platform Backend for SDL2 2 | // This needs to be used along with a Renderer (e.g. DirectX11, OpenGL3, Vulkan..) 3 | // (Info: SDL2 is a cross-platform general purpose library for handling windows, inputs, graphics context creation, etc.) 4 | 5 | // Implemented features: 6 | // [X] Platform: Clipboard support. 7 | // [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy SDL_SCANCODE_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set] 8 | // [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'. 9 | // [X] Platform: Mouse cursor shape and visibility. Disable with 'io.ConfigFlags |= ImGuiConfigFlags_NoMouseCursorChange'. 10 | // [X] Platform: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'. 11 | // Missing features: 12 | // [ ] Platform: SDL2 handling of IME under Windows appears to be broken and it explicitly disable the regular Windows IME. You can restore Windows IME by compiling SDL with SDL_DISABLE_WINDOWS_IME. 13 | // [ ] Platform: Multi-viewport + Minimized windows seems to break mouse wheel events (at least under Windows). 14 | 15 | // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this. 16 | // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need. 17 | // If you are new to Dear ImGui, read documentation from the docs/ folder + read the top of imgui.cpp. 18 | // Read online: https://github.com/ocornut/imgui/tree/master/docs 19 | 20 | #pragma once 21 | #include "imgui.h" // IMGUI_IMPL_API 22 | 23 | struct SDL_Window; 24 | struct SDL_Renderer; 25 | typedef union SDL_Event SDL_Event; 26 | 27 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForOpenGL(SDL_Window* window, void* sdl_gl_context); 28 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForVulkan(SDL_Window* window); 29 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForD3D(SDL_Window* window); 30 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForMetal(SDL_Window* window); 31 | IMGUI_IMPL_API bool ImGui_ImplSDL2_InitForSDLRenderer(SDL_Window* window, SDL_Renderer* renderer); 32 | IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown(); 33 | IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(); 34 | IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event); 35 | 36 | #ifndef IMGUI_DISABLE_OBSOLETE_FUNCTIONS 37 | static inline void ImGui_ImplSDL2_NewFrame(SDL_Window*) { ImGui_ImplSDL2_NewFrame(); } // 1.84: removed unnecessary parameter 38 | #endif 39 | -------------------------------------------------------------------------------- /external/imgui/imgui_stdlib.cpp: -------------------------------------------------------------------------------- 1 | // dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.) 2 | // This is also an example of how you may wrap your own similar types. 3 | 4 | // Changelog: 5 | // - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string 6 | 7 | #include "imgui.h" 8 | #include "imgui_stdlib.h" 9 | 10 | struct InputTextCallback_UserData 11 | { 12 | std::string* Str; 13 | ImGuiInputTextCallback ChainCallback; 14 | void* ChainCallbackUserData; 15 | }; 16 | 17 | static int InputTextCallback(ImGuiInputTextCallbackData* data) 18 | { 19 | InputTextCallback_UserData* user_data = (InputTextCallback_UserData*)data->UserData; 20 | if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) 21 | { 22 | // Resize string callback 23 | // If for some reason we refuse the new length (BufTextLen) and/or capacity (BufSize) we need to set them back to what we want. 24 | std::string* str = user_data->Str; 25 | IM_ASSERT(data->Buf == str->c_str()); 26 | str->resize(data->BufTextLen); 27 | data->Buf = (char*)str->c_str(); 28 | } 29 | else if (user_data->ChainCallback) 30 | { 31 | // Forward to user callback, if any 32 | data->UserData = user_data->ChainCallbackUserData; 33 | return user_data->ChainCallback(data); 34 | } 35 | return 0; 36 | } 37 | 38 | bool ImGui::InputText(const char* label, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) 39 | { 40 | IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0); 41 | flags |= ImGuiInputTextFlags_CallbackResize; 42 | 43 | InputTextCallback_UserData cb_user_data; 44 | cb_user_data.Str = str; 45 | cb_user_data.ChainCallback = callback; 46 | cb_user_data.ChainCallbackUserData = user_data; 47 | return InputText(label, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data); 48 | } 49 | 50 | bool ImGui::InputTextMultiline(const char* label, std::string* str, const ImVec2& size, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) 51 | { 52 | IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0); 53 | flags |= ImGuiInputTextFlags_CallbackResize; 54 | 55 | InputTextCallback_UserData cb_user_data; 56 | cb_user_data.Str = str; 57 | cb_user_data.ChainCallback = callback; 58 | cb_user_data.ChainCallbackUserData = user_data; 59 | return InputTextMultiline(label, (char*)str->c_str(), str->capacity() + 1, size, flags, InputTextCallback, &cb_user_data); 60 | } 61 | 62 | bool ImGui::InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags, ImGuiInputTextCallback callback, void* user_data) 63 | { 64 | IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0); 65 | flags |= ImGuiInputTextFlags_CallbackResize; 66 | 67 | InputTextCallback_UserData cb_user_data; 68 | cb_user_data.Str = str; 69 | cb_user_data.ChainCallback = callback; 70 | cb_user_data.ChainCallbackUserData = user_data; 71 | return InputTextWithHint(label, hint, (char*)str->c_str(), str->capacity() + 1, flags, InputTextCallback, &cb_user_data); 72 | } 73 | -------------------------------------------------------------------------------- /external/imgui/imgui_stdlib.h: -------------------------------------------------------------------------------- 1 | // dear imgui: wrappers for C++ standard library (STL) types (std::string, etc.) 2 | // This is also an example of how you may wrap your own similar types. 3 | 4 | // Changelog: 5 | // - v0.10: Initial version. Added InputText() / InputTextMultiline() calls with std::string 6 | 7 | #pragma once 8 | 9 | #include 10 | 11 | namespace ImGui 12 | { 13 | // ImGui::InputText() with std::string 14 | // Because text input needs dynamic resizing, we need to setup a callback to grow the capacity 15 | IMGUI_API bool InputText(const char* label, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); 16 | IMGUI_API bool InputTextMultiline(const char* label, std::string* str, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); 17 | IMGUI_API bool InputTextWithHint(const char* label, const char* hint, std::string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL); 18 | } 19 | -------------------------------------------------------------------------------- /external/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. 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/error/en.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. 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_ERROR_EN_H_ 16 | #define RAPIDJSON_ERROR_EN_H_ 17 | 18 | #include "error.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(switch-enum) 23 | RAPIDJSON_DIAG_OFF(covered-switch-default) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Maps error code of parsing into error message. 29 | /*! 30 | \ingroup RAPIDJSON_ERRORS 31 | \param parseErrorCode Error code obtained in parsing. 32 | \return the error message. 33 | \note User can make a copy of this function for localization. 34 | Using switch-case is safer for future modification of error codes. 35 | */ 36 | inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) { 37 | switch (parseErrorCode) { 38 | case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error."); 39 | 40 | case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty."); 41 | case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values."); 42 | 43 | case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value."); 44 | 45 | case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member."); 46 | case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member."); 47 | case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member."); 48 | 49 | case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element."); 50 | 51 | case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string."); 52 | case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid."); 53 | case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string."); 54 | case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string."); 55 | case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string."); 56 | 57 | case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double."); 58 | case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number."); 59 | case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number."); 60 | 61 | case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error."); 62 | case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error."); 63 | 64 | default: return RAPIDJSON_ERROR_STRING("Unknown error."); 65 | } 66 | } 67 | 68 | //! Maps error code of validation into error message. 69 | /*! 70 | \ingroup RAPIDJSON_ERRORS 71 | \param validateErrorCode Error code obtained from validator. 72 | \return the error message. 73 | \note User can make a copy of this function for localization. 74 | Using switch-case is safer for future modification of error codes. 75 | */ 76 | inline const RAPIDJSON_ERROR_CHARTYPE* GetValidateError_En(ValidateErrorCode validateErrorCode) { 77 | switch (validateErrorCode) { 78 | case kValidateErrors: return RAPIDJSON_ERROR_STRING("One or more validation errors have occurred"); 79 | case kValidateErrorNone: return RAPIDJSON_ERROR_STRING("No error."); 80 | 81 | case kValidateErrorMultipleOf: return RAPIDJSON_ERROR_STRING("Number '%actual' is not a multiple of the 'multipleOf' value '%expected'."); 82 | case kValidateErrorMaximum: return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than the 'maximum' value '%expected'."); 83 | case kValidateErrorExclusiveMaximum: return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than or equal to the 'exclusiveMaximum' value '%expected'."); 84 | case kValidateErrorMinimum: return RAPIDJSON_ERROR_STRING("Number '%actual' is less than the 'minimum' value '%expected'."); 85 | case kValidateErrorExclusiveMinimum: return RAPIDJSON_ERROR_STRING("Number '%actual' is less than or equal to the 'exclusiveMinimum' value '%expected'."); 86 | 87 | case kValidateErrorMaxLength: return RAPIDJSON_ERROR_STRING("String '%actual' is longer than the 'maxLength' value '%expected'."); 88 | case kValidateErrorMinLength: return RAPIDJSON_ERROR_STRING("String '%actual' is shorter than the 'minLength' value '%expected'."); 89 | case kValidateErrorPattern: return RAPIDJSON_ERROR_STRING("String '%actual' does not match the 'pattern' regular expression."); 90 | 91 | case kValidateErrorMaxItems: return RAPIDJSON_ERROR_STRING("Array of length '%actual' is longer than the 'maxItems' value '%expected'."); 92 | case kValidateErrorMinItems: return RAPIDJSON_ERROR_STRING("Array of length '%actual' is shorter than the 'minItems' value '%expected'."); 93 | case kValidateErrorUniqueItems: return RAPIDJSON_ERROR_STRING("Array has duplicate items at indices '%duplicates' but 'uniqueItems' is true."); 94 | case kValidateErrorAdditionalItems: return RAPIDJSON_ERROR_STRING("Array has an additional item at index '%disallowed' that is not allowed by the schema."); 95 | 96 | case kValidateErrorMaxProperties: return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is more than 'maxProperties' value '%expected'."); 97 | case kValidateErrorMinProperties: return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is less than 'minProperties' value '%expected'."); 98 | case kValidateErrorRequired: return RAPIDJSON_ERROR_STRING("Object is missing the following members required by the schema: '%missing'."); 99 | case kValidateErrorAdditionalProperties: return RAPIDJSON_ERROR_STRING("Object has an additional member '%disallowed' that is not allowed by the schema."); 100 | case kValidateErrorPatternProperties: return RAPIDJSON_ERROR_STRING("Object has 'patternProperties' that are not allowed by the schema."); 101 | case kValidateErrorDependencies: return RAPIDJSON_ERROR_STRING("Object has missing property or schema dependencies, refer to following errors."); 102 | 103 | case kValidateErrorEnum: return RAPIDJSON_ERROR_STRING("Property has a value that is not one of its allowed enumerated values."); 104 | case kValidateErrorType: return RAPIDJSON_ERROR_STRING("Property has a type '%actual' that is not in the following list: '%expected'."); 105 | 106 | case kValidateErrorOneOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'oneOf', refer to following errors."); 107 | case kValidateErrorOneOfMatch: return RAPIDJSON_ERROR_STRING("Property matched more than one of the sub-schemas specified by 'oneOf'."); 108 | case kValidateErrorAllOf: return RAPIDJSON_ERROR_STRING("Property did not match all of the sub-schemas specified by 'allOf', refer to following errors."); 109 | case kValidateErrorAnyOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'anyOf', refer to following errors."); 110 | case kValidateErrorNot: return RAPIDJSON_ERROR_STRING("Property matched the sub-schema specified by 'not'."); 111 | 112 | default: return RAPIDJSON_ERROR_STRING("Unknown error."); 113 | } 114 | } 115 | 116 | RAPIDJSON_NAMESPACE_END 117 | 118 | #ifdef __clang__ 119 | RAPIDJSON_DIAG_POP 120 | #endif 121 | 122 | #endif // RAPIDJSON_ERROR_EN_H_ 123 | -------------------------------------------------------------------------------- /external/rapidjson/error/error.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. 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_ERROR_ERROR_H_ 16 | #define RAPIDJSON_ERROR_ERROR_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #ifdef __clang__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(padded) 23 | #endif 24 | 25 | /*! \file error.h */ 26 | 27 | /*! \defgroup RAPIDJSON_ERRORS RapidJSON error handling */ 28 | 29 | /////////////////////////////////////////////////////////////////////////////// 30 | // RAPIDJSON_ERROR_CHARTYPE 31 | 32 | //! Character type of error messages. 33 | /*! \ingroup RAPIDJSON_ERRORS 34 | The default character type is \c char. 35 | On Windows, user can define this macro as \c TCHAR for supporting both 36 | unicode/non-unicode settings. 37 | */ 38 | #ifndef RAPIDJSON_ERROR_CHARTYPE 39 | #define RAPIDJSON_ERROR_CHARTYPE char 40 | #endif 41 | 42 | /////////////////////////////////////////////////////////////////////////////// 43 | // RAPIDJSON_ERROR_STRING 44 | 45 | //! Macro for converting string literial to \ref RAPIDJSON_ERROR_CHARTYPE[]. 46 | /*! \ingroup RAPIDJSON_ERRORS 47 | By default this conversion macro does nothing. 48 | On Windows, user can define this macro as \c _T(x) for supporting both 49 | unicode/non-unicode settings. 50 | */ 51 | #ifndef RAPIDJSON_ERROR_STRING 52 | #define RAPIDJSON_ERROR_STRING(x) x 53 | #endif 54 | 55 | RAPIDJSON_NAMESPACE_BEGIN 56 | 57 | /////////////////////////////////////////////////////////////////////////////// 58 | // ParseErrorCode 59 | 60 | //! Error code of parsing. 61 | /*! \ingroup RAPIDJSON_ERRORS 62 | \see GenericReader::Parse, GenericReader::GetParseErrorCode 63 | */ 64 | enum ParseErrorCode { 65 | kParseErrorNone = 0, //!< No error. 66 | 67 | kParseErrorDocumentEmpty, //!< The document is empty. 68 | kParseErrorDocumentRootNotSingular, //!< The document root must not follow by other values. 69 | 70 | kParseErrorValueInvalid, //!< Invalid value. 71 | 72 | kParseErrorObjectMissName, //!< Missing a name for object member. 73 | kParseErrorObjectMissColon, //!< Missing a colon after a name of object member. 74 | kParseErrorObjectMissCommaOrCurlyBracket, //!< Missing a comma or '}' after an object member. 75 | 76 | kParseErrorArrayMissCommaOrSquareBracket, //!< Missing a comma or ']' after an array element. 77 | 78 | kParseErrorStringUnicodeEscapeInvalidHex, //!< Incorrect hex digit after \\u escape in string. 79 | kParseErrorStringUnicodeSurrogateInvalid, //!< The surrogate pair in string is invalid. 80 | kParseErrorStringEscapeInvalid, //!< Invalid escape character in string. 81 | kParseErrorStringMissQuotationMark, //!< Missing a closing quotation mark in string. 82 | kParseErrorStringInvalidEncoding, //!< Invalid encoding in string. 83 | 84 | kParseErrorNumberTooBig, //!< Number too big to be stored in double. 85 | kParseErrorNumberMissFraction, //!< Miss fraction part in number. 86 | kParseErrorNumberMissExponent, //!< Miss exponent in number. 87 | 88 | kParseErrorTermination, //!< Parsing was terminated. 89 | kParseErrorUnspecificSyntaxError //!< Unspecific syntax error. 90 | }; 91 | 92 | //! Result of parsing (wraps ParseErrorCode) 93 | /*! 94 | \ingroup RAPIDJSON_ERRORS 95 | \code 96 | Document doc; 97 | ParseResult ok = doc.Parse("[42]"); 98 | if (!ok) { 99 | fprintf(stderr, "JSON parse error: %s (%u)", 100 | GetParseError_En(ok.Code()), ok.Offset()); 101 | exit(EXIT_FAILURE); 102 | } 103 | \endcode 104 | \see GenericReader::Parse, GenericDocument::Parse 105 | */ 106 | struct ParseResult { 107 | //!! Unspecified boolean type 108 | typedef bool (ParseResult::*BooleanType)() const; 109 | public: 110 | //! Default constructor, no error. 111 | ParseResult() : code_(kParseErrorNone), offset_(0) {} 112 | //! Constructor to set an error. 113 | ParseResult(ParseErrorCode code, size_t offset) : code_(code), offset_(offset) {} 114 | 115 | //! Get the error code. 116 | ParseErrorCode Code() const { return code_; } 117 | //! Get the error offset, if \ref IsError(), 0 otherwise. 118 | size_t Offset() const { return offset_; } 119 | 120 | //! Explicit conversion to \c bool, returns \c true, iff !\ref IsError(). 121 | operator BooleanType() const { return !IsError() ? &ParseResult::IsError : NULL; } 122 | //! Whether the result is an error. 123 | bool IsError() const { return code_ != kParseErrorNone; } 124 | 125 | bool operator==(const ParseResult& that) const { return code_ == that.code_; } 126 | bool operator==(ParseErrorCode code) const { return code_ == code; } 127 | friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; } 128 | 129 | bool operator!=(const ParseResult& that) const { return !(*this == that); } 130 | bool operator!=(ParseErrorCode code) const { return !(*this == code); } 131 | friend bool operator!=(ParseErrorCode code, const ParseResult & err) { return err != code; } 132 | 133 | //! Reset error code. 134 | void Clear() { Set(kParseErrorNone); } 135 | //! Update error code and offset. 136 | void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; } 137 | 138 | private: 139 | ParseErrorCode code_; 140 | size_t offset_; 141 | }; 142 | 143 | //! Function pointer type of GetParseError(). 144 | /*! \ingroup RAPIDJSON_ERRORS 145 | 146 | This is the prototype for \c GetParseError_X(), where \c X is a locale. 147 | User can dynamically change locale in runtime, e.g.: 148 | \code 149 | GetParseErrorFunc GetParseError = GetParseError_En; // or whatever 150 | const RAPIDJSON_ERROR_CHARTYPE* s = GetParseError(document.GetParseErrorCode()); 151 | \endcode 152 | */ 153 | typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetParseErrorFunc)(ParseErrorCode); 154 | 155 | /////////////////////////////////////////////////////////////////////////////// 156 | // ValidateErrorCode 157 | 158 | //! Error codes when validating. 159 | /*! \ingroup RAPIDJSON_ERRORS 160 | \see GenericSchemaValidator 161 | */ 162 | enum ValidateErrorCode { 163 | kValidateErrors = -1, //!< Top level error code when kValidateContinueOnErrorsFlag set. 164 | kValidateErrorNone = 0, //!< No error. 165 | 166 | kValidateErrorMultipleOf, //!< Number is not a multiple of the 'multipleOf' value. 167 | kValidateErrorMaximum, //!< Number is greater than the 'maximum' value. 168 | kValidateErrorExclusiveMaximum, //!< Number is greater than or equal to the 'maximum' value. 169 | kValidateErrorMinimum, //!< Number is less than the 'minimum' value. 170 | kValidateErrorExclusiveMinimum, //!< Number is less than or equal to the 'minimum' value. 171 | 172 | kValidateErrorMaxLength, //!< String is longer than the 'maxLength' value. 173 | kValidateErrorMinLength, //!< String is longer than the 'maxLength' value. 174 | kValidateErrorPattern, //!< String does not match the 'pattern' regular expression. 175 | 176 | kValidateErrorMaxItems, //!< Array is longer than the 'maxItems' value. 177 | kValidateErrorMinItems, //!< Array is shorter than the 'minItems' value. 178 | kValidateErrorUniqueItems, //!< Array has duplicate items but 'uniqueItems' is true. 179 | kValidateErrorAdditionalItems, //!< Array has additional items that are not allowed by the schema. 180 | 181 | kValidateErrorMaxProperties, //!< Object has more members than 'maxProperties' value. 182 | kValidateErrorMinProperties, //!< Object has less members than 'minProperties' value. 183 | kValidateErrorRequired, //!< Object is missing one or more members required by the schema. 184 | kValidateErrorAdditionalProperties, //!< Object has additional members that are not allowed by the schema. 185 | kValidateErrorPatternProperties, //!< See other errors. 186 | kValidateErrorDependencies, //!< Object has missing property or schema dependencies. 187 | 188 | kValidateErrorEnum, //!< Property has a value that is not one of its allowed enumerated values 189 | kValidateErrorType, //!< Property has a type that is not allowed by the schema.. 190 | 191 | kValidateErrorOneOf, //!< Property did not match any of the sub-schemas specified by 'oneOf'. 192 | kValidateErrorOneOfMatch, //!< Property matched more than one of the sub-schemas specified by 'oneOf'. 193 | kValidateErrorAllOf, //!< Property did not match all of the sub-schemas specified by 'allOf'. 194 | kValidateErrorAnyOf, //!< Property did not match any of the sub-schemas specified by 'anyOf'. 195 | kValidateErrorNot //!< Property matched the sub-schema specified by 'not'. 196 | }; 197 | 198 | //! Function pointer type of GetValidateError(). 199 | /*! \ingroup RAPIDJSON_ERRORS 200 | 201 | This is the prototype for \c GetValidateError_X(), where \c X is a locale. 202 | User can dynamically change locale in runtime, e.g.: 203 | \code 204 | GetValidateErrorFunc GetValidateError = GetValidateError_En; // or whatever 205 | const RAPIDJSON_ERROR_CHARTYPE* s = GetValidateError(validator.GetInvalidSchemaCode()); 206 | \endcode 207 | */ 208 | typedef const RAPIDJSON_ERROR_CHARTYPE* (*GetValidateErrorFunc)(ValidateErrorCode); 209 | 210 | RAPIDJSON_NAMESPACE_END 211 | 212 | #ifdef __clang__ 213 | RAPIDJSON_DIAG_POP 214 | #endif 215 | 216 | #endif // RAPIDJSON_ERROR_ERROR_H_ 217 | -------------------------------------------------------------------------------- /external/rapidjson/filereadstream.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. 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_FILEREADSTREAM_H_ 16 | #define RAPIDJSON_FILEREADSTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(padded) 24 | RAPIDJSON_DIAG_OFF(unreachable-code) 25 | RAPIDJSON_DIAG_OFF(missing-noreturn) 26 | #endif 27 | 28 | RAPIDJSON_NAMESPACE_BEGIN 29 | 30 | //! File byte stream for input using fread(). 31 | /*! 32 | \note implements Stream concept 33 | */ 34 | class FileReadStream { 35 | public: 36 | typedef char Ch; //!< Character type (byte). 37 | 38 | //! Constructor. 39 | /*! 40 | \param fp File pointer opened for read. 41 | \param buffer user-supplied buffer. 42 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 43 | */ 44 | FileReadStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 45 | RAPIDJSON_ASSERT(fp_ != 0); 46 | RAPIDJSON_ASSERT(bufferSize >= 4); 47 | Read(); 48 | } 49 | 50 | Ch Peek() const { return *current_; } 51 | Ch Take() { Ch c = *current_; Read(); return c; } 52 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 53 | 54 | // Not implemented 55 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 56 | void Flush() { RAPIDJSON_ASSERT(false); } 57 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 58 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 59 | 60 | // For encoding detection only. 61 | const Ch* Peek4() const { 62 | return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0; 63 | } 64 | 65 | private: 66 | void Read() { 67 | if (current_ < bufferLast_) 68 | ++current_; 69 | else if (!eof_) { 70 | count_ += readCount_; 71 | readCount_ = std::fread(buffer_, 1, bufferSize_, fp_); 72 | bufferLast_ = buffer_ + readCount_ - 1; 73 | current_ = buffer_; 74 | 75 | if (readCount_ < bufferSize_) { 76 | buffer_[readCount_] = '\0'; 77 | ++bufferLast_; 78 | eof_ = true; 79 | } 80 | } 81 | } 82 | 83 | std::FILE* fp_; 84 | Ch *buffer_; 85 | size_t bufferSize_; 86 | Ch *bufferLast_; 87 | Ch *current_; 88 | size_t readCount_; 89 | size_t count_; //!< Number of characters read 90 | bool eof_; 91 | }; 92 | 93 | RAPIDJSON_NAMESPACE_END 94 | 95 | #ifdef __clang__ 96 | RAPIDJSON_DIAG_POP 97 | #endif 98 | 99 | #endif // RAPIDJSON_FILESTREAM_H_ 100 | -------------------------------------------------------------------------------- /external/rapidjson/filewritestream.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. 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_FILEWRITESTREAM_H_ 16 | #define RAPIDJSON_FILEWRITESTREAM_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | 21 | #ifdef __clang__ 22 | RAPIDJSON_DIAG_PUSH 23 | RAPIDJSON_DIAG_OFF(unreachable-code) 24 | #endif 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | 28 | //! Wrapper of C file stream for output using fwrite(). 29 | /*! 30 | \note implements Stream concept 31 | */ 32 | class FileWriteStream { 33 | public: 34 | typedef char Ch; //!< Character type. Only support char. 35 | 36 | FileWriteStream(std::FILE* fp, char* buffer, size_t bufferSize) : fp_(fp), buffer_(buffer), bufferEnd_(buffer + bufferSize), current_(buffer_) { 37 | RAPIDJSON_ASSERT(fp_ != 0); 38 | } 39 | 40 | void Put(char c) { 41 | if (current_ >= bufferEnd_) 42 | Flush(); 43 | 44 | *current_++ = c; 45 | } 46 | 47 | void PutN(char c, size_t n) { 48 | size_t avail = static_cast(bufferEnd_ - current_); 49 | while (n > avail) { 50 | std::memset(current_, c, avail); 51 | current_ += avail; 52 | Flush(); 53 | n -= avail; 54 | avail = static_cast(bufferEnd_ - current_); 55 | } 56 | 57 | if (n > 0) { 58 | std::memset(current_, c, n); 59 | current_ += n; 60 | } 61 | } 62 | 63 | void Flush() { 64 | if (current_ != buffer_) { 65 | size_t result = std::fwrite(buffer_, 1, static_cast(current_ - buffer_), fp_); 66 | if (result < static_cast(current_ - buffer_)) { 67 | // failure deliberately ignored at this time 68 | // added to avoid warn_unused_result build errors 69 | } 70 | current_ = buffer_; 71 | } 72 | } 73 | 74 | // Not implemented 75 | char Peek() const { RAPIDJSON_ASSERT(false); return 0; } 76 | char Take() { RAPIDJSON_ASSERT(false); return 0; } 77 | size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; } 78 | char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 79 | size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; } 80 | 81 | private: 82 | // Prohibit copy constructor & assignment operator. 83 | FileWriteStream(const FileWriteStream&); 84 | FileWriteStream& operator=(const FileWriteStream&); 85 | 86 | std::FILE* fp_; 87 | char *buffer_; 88 | char *bufferEnd_; 89 | char *current_; 90 | }; 91 | 92 | //! Implement specialized version of PutN() with memset() for better performance. 93 | template<> 94 | inline void PutN(FileWriteStream& stream, char c, size_t n) { 95 | stream.PutN(c, n); 96 | } 97 | 98 | RAPIDJSON_NAMESPACE_END 99 | 100 | #ifdef __clang__ 101 | RAPIDJSON_DIAG_POP 102 | #endif 103 | 104 | #endif // RAPIDJSON_FILESTREAM_H_ 105 | -------------------------------------------------------------------------------- /external/rapidjson/fwd.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. 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_FWD_H_ 16 | #define RAPIDJSON_FWD_H_ 17 | 18 | #include "rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | 22 | // encodings.h 23 | 24 | template struct UTF8; 25 | template struct UTF16; 26 | template struct UTF16BE; 27 | template struct UTF16LE; 28 | template struct UTF32; 29 | template struct UTF32BE; 30 | template struct UTF32LE; 31 | template struct ASCII; 32 | template struct AutoUTF; 33 | 34 | template 35 | struct Transcoder; 36 | 37 | // allocators.h 38 | 39 | class CrtAllocator; 40 | 41 | template 42 | class MemoryPoolAllocator; 43 | 44 | // stream.h 45 | 46 | template 47 | struct GenericStringStream; 48 | 49 | typedef GenericStringStream > StringStream; 50 | 51 | template 52 | struct GenericInsituStringStream; 53 | 54 | typedef GenericInsituStringStream > InsituStringStream; 55 | 56 | // stringbuffer.h 57 | 58 | template 59 | class GenericStringBuffer; 60 | 61 | typedef GenericStringBuffer, CrtAllocator> StringBuffer; 62 | 63 | // filereadstream.h 64 | 65 | class FileReadStream; 66 | 67 | // filewritestream.h 68 | 69 | class FileWriteStream; 70 | 71 | // memorybuffer.h 72 | 73 | template 74 | struct GenericMemoryBuffer; 75 | 76 | typedef GenericMemoryBuffer MemoryBuffer; 77 | 78 | // memorystream.h 79 | 80 | struct MemoryStream; 81 | 82 | // reader.h 83 | 84 | template 85 | struct BaseReaderHandler; 86 | 87 | template 88 | class GenericReader; 89 | 90 | typedef GenericReader, UTF8, CrtAllocator> Reader; 91 | 92 | // writer.h 93 | 94 | template 95 | class Writer; 96 | 97 | // prettywriter.h 98 | 99 | template 100 | class PrettyWriter; 101 | 102 | // document.h 103 | 104 | template 105 | class GenericMember; 106 | 107 | template 108 | class GenericMemberIterator; 109 | 110 | template 111 | struct GenericStringRef; 112 | 113 | template 114 | class GenericValue; 115 | 116 | typedef GenericValue, MemoryPoolAllocator > Value; 117 | 118 | template 119 | class GenericDocument; 120 | 121 | typedef GenericDocument, MemoryPoolAllocator, CrtAllocator> Document; 122 | 123 | // pointer.h 124 | 125 | template 126 | class GenericPointer; 127 | 128 | typedef GenericPointer Pointer; 129 | 130 | // schema.h 131 | 132 | template 133 | class IGenericRemoteSchemaDocumentProvider; 134 | 135 | template 136 | class GenericSchemaDocument; 137 | 138 | typedef GenericSchemaDocument SchemaDocument; 139 | typedef IGenericRemoteSchemaDocumentProvider IRemoteSchemaDocumentProvider; 140 | 141 | template < 142 | typename SchemaDocumentType, 143 | typename OutputHandler, 144 | typename StateAllocator> 145 | class GenericSchemaValidator; 146 | 147 | typedef GenericSchemaValidator, void>, CrtAllocator> SchemaValidator; 148 | 149 | RAPIDJSON_NAMESPACE_END 150 | 151 | #endif // RAPIDJSON_RAPIDJSONFWD_H_ 152 | -------------------------------------------------------------------------------- /external/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. 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/internal/dtoa.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. 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 | // This is a C++ header-only implementation of Grisu2 algorithm from the publication: 16 | // Loitsch, Florian. "Printing floating-point numbers quickly and accurately with 17 | // integers." ACM Sigplan Notices 45.6 (2010): 233-243. 18 | 19 | #ifndef RAPIDJSON_DTOA_ 20 | #define RAPIDJSON_DTOA_ 21 | 22 | #include "itoa.h" // GetDigitsLut() 23 | #include "diyfp.h" 24 | #include "ieee754.h" 25 | 26 | RAPIDJSON_NAMESPACE_BEGIN 27 | namespace internal { 28 | 29 | #ifdef __GNUC__ 30 | RAPIDJSON_DIAG_PUSH 31 | RAPIDJSON_DIAG_OFF(effc++) 32 | RAPIDJSON_DIAG_OFF(array-bounds) // some gcc versions generate wrong warnings https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124 33 | #endif 34 | 35 | inline void GrisuRound(char* buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) { 36 | while (rest < wp_w && delta - rest >= ten_kappa && 37 | (rest + ten_kappa < wp_w || /// closer 38 | wp_w - rest > rest + ten_kappa - wp_w)) { 39 | buffer[len - 1]--; 40 | rest += ten_kappa; 41 | } 42 | } 43 | 44 | inline int CountDecimalDigit32(uint32_t n) { 45 | // Simple pure C++ implementation was faster than __builtin_clz version in this situation. 46 | if (n < 10) return 1; 47 | if (n < 100) return 2; 48 | if (n < 1000) return 3; 49 | if (n < 10000) return 4; 50 | if (n < 100000) return 5; 51 | if (n < 1000000) return 6; 52 | if (n < 10000000) return 7; 53 | if (n < 100000000) return 8; 54 | // Will not reach 10 digits in DigitGen() 55 | //if (n < 1000000000) return 9; 56 | //return 10; 57 | return 9; 58 | } 59 | 60 | inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) { 61 | static const uint64_t kPow10[] = { 1U, 10U, 100U, 1000U, 10000U, 100000U, 1000000U, 10000000U, 100000000U, 62 | 1000000000U, 10000000000U, 100000000000U, 1000000000000U, 63 | 10000000000000U, 100000000000000U, 1000000000000000U, 64 | 10000000000000000U, 100000000000000000U, 1000000000000000000U, 65 | 10000000000000000000U }; 66 | const DiyFp one(uint64_t(1) << -Mp.e, Mp.e); 67 | const DiyFp wp_w = Mp - W; 68 | uint32_t p1 = static_cast(Mp.f >> -one.e); 69 | uint64_t p2 = Mp.f & (one.f - 1); 70 | int kappa = CountDecimalDigit32(p1); // kappa in [0, 9] 71 | *len = 0; 72 | 73 | while (kappa > 0) { 74 | uint32_t d = 0; 75 | switch (kappa) { 76 | case 9: d = p1 / 100000000; p1 %= 100000000; break; 77 | case 8: d = p1 / 10000000; p1 %= 10000000; break; 78 | case 7: d = p1 / 1000000; p1 %= 1000000; break; 79 | case 6: d = p1 / 100000; p1 %= 100000; break; 80 | case 5: d = p1 / 10000; p1 %= 10000; break; 81 | case 4: d = p1 / 1000; p1 %= 1000; break; 82 | case 3: d = p1 / 100; p1 %= 100; break; 83 | case 2: d = p1 / 10; p1 %= 10; break; 84 | case 1: d = p1; p1 = 0; break; 85 | default:; 86 | } 87 | if (d || *len) 88 | buffer[(*len)++] = static_cast('0' + static_cast(d)); 89 | kappa--; 90 | uint64_t tmp = (static_cast(p1) << -one.e) + p2; 91 | if (tmp <= delta) { 92 | *K += kappa; 93 | GrisuRound(buffer, *len, delta, tmp, kPow10[kappa] << -one.e, wp_w.f); 94 | return; 95 | } 96 | } 97 | 98 | // kappa = 0 99 | for (;;) { 100 | p2 *= 10; 101 | delta *= 10; 102 | char d = static_cast(p2 >> -one.e); 103 | if (d || *len) 104 | buffer[(*len)++] = static_cast('0' + d); 105 | p2 &= one.f - 1; 106 | kappa--; 107 | if (p2 < delta) { 108 | *K += kappa; 109 | int index = -kappa; 110 | GrisuRound(buffer, *len, delta, p2, one.f, wp_w.f * (index < 20 ? kPow10[index] : 0)); 111 | return; 112 | } 113 | } 114 | } 115 | 116 | inline void Grisu2(double value, char* buffer, int* length, int* K) { 117 | const DiyFp v(value); 118 | DiyFp w_m, w_p; 119 | v.NormalizedBoundaries(&w_m, &w_p); 120 | 121 | const DiyFp c_mk = GetCachedPower(w_p.e, K); 122 | const DiyFp W = v.Normalize() * c_mk; 123 | DiyFp Wp = w_p * c_mk; 124 | DiyFp Wm = w_m * c_mk; 125 | Wm.f++; 126 | Wp.f--; 127 | DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K); 128 | } 129 | 130 | inline char* WriteExponent(int K, char* buffer) { 131 | if (K < 0) { 132 | *buffer++ = '-'; 133 | K = -K; 134 | } 135 | 136 | if (K >= 100) { 137 | *buffer++ = static_cast('0' + static_cast(K / 100)); 138 | K %= 100; 139 | const char* d = GetDigitsLut() + K * 2; 140 | *buffer++ = d[0]; 141 | *buffer++ = d[1]; 142 | } 143 | else if (K >= 10) { 144 | const char* d = GetDigitsLut() + K * 2; 145 | *buffer++ = d[0]; 146 | *buffer++ = d[1]; 147 | } 148 | else 149 | *buffer++ = static_cast('0' + static_cast(K)); 150 | 151 | return buffer; 152 | } 153 | 154 | inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) { 155 | const int kk = length + k; // 10^(kk-1) <= v < 10^kk 156 | 157 | if (0 <= k && kk <= 21) { 158 | // 1234e7 -> 12340000000 159 | for (int i = length; i < kk; i++) 160 | buffer[i] = '0'; 161 | buffer[kk] = '.'; 162 | buffer[kk + 1] = '0'; 163 | return &buffer[kk + 2]; 164 | } 165 | else if (0 < kk && kk <= 21) { 166 | // 1234e-2 -> 12.34 167 | std::memmove(&buffer[kk + 1], &buffer[kk], static_cast(length - kk)); 168 | buffer[kk] = '.'; 169 | if (0 > k + maxDecimalPlaces) { 170 | // When maxDecimalPlaces = 2, 1.2345 -> 1.23, 1.102 -> 1.1 171 | // Remove extra trailing zeros (at least one) after truncation. 172 | for (int i = kk + maxDecimalPlaces; i > kk + 1; i--) 173 | if (buffer[i] != '0') 174 | return &buffer[i + 1]; 175 | return &buffer[kk + 2]; // Reserve one zero 176 | } 177 | else 178 | return &buffer[length + 1]; 179 | } 180 | else if (-6 < kk && kk <= 0) { 181 | // 1234e-6 -> 0.001234 182 | const int offset = 2 - kk; 183 | std::memmove(&buffer[offset], &buffer[0], static_cast(length)); 184 | buffer[0] = '0'; 185 | buffer[1] = '.'; 186 | for (int i = 2; i < offset; i++) 187 | buffer[i] = '0'; 188 | if (length - kk > maxDecimalPlaces) { 189 | // When maxDecimalPlaces = 2, 0.123 -> 0.12, 0.102 -> 0.1 190 | // Remove extra trailing zeros (at least one) after truncation. 191 | for (int i = maxDecimalPlaces + 1; i > 2; i--) 192 | if (buffer[i] != '0') 193 | return &buffer[i + 1]; 194 | return &buffer[3]; // Reserve one zero 195 | } 196 | else 197 | return &buffer[length + offset]; 198 | } 199 | else if (kk < -maxDecimalPlaces) { 200 | // Truncate to zero 201 | buffer[0] = '0'; 202 | buffer[1] = '.'; 203 | buffer[2] = '0'; 204 | return &buffer[3]; 205 | } 206 | else if (length == 1) { 207 | // 1e30 208 | buffer[1] = 'e'; 209 | return WriteExponent(kk - 1, &buffer[2]); 210 | } 211 | else { 212 | // 1234e30 -> 1.234e33 213 | std::memmove(&buffer[2], &buffer[1], static_cast(length - 1)); 214 | buffer[1] = '.'; 215 | buffer[length + 1] = 'e'; 216 | return WriteExponent(kk - 1, &buffer[0 + length + 2]); 217 | } 218 | } 219 | 220 | inline char* dtoa(double value, char* buffer, int maxDecimalPlaces = 324) { 221 | RAPIDJSON_ASSERT(maxDecimalPlaces >= 1); 222 | Double d(value); 223 | if (d.IsZero()) { 224 | if (d.Sign()) 225 | *buffer++ = '-'; // -0.0, Issue #289 226 | buffer[0] = '0'; 227 | buffer[1] = '.'; 228 | buffer[2] = '0'; 229 | return &buffer[3]; 230 | } 231 | else { 232 | if (value < 0) { 233 | *buffer++ = '-'; 234 | value = -value; 235 | } 236 | int length, K; 237 | Grisu2(value, buffer, &length, &K); 238 | return Prettify(buffer, length, K, maxDecimalPlaces); 239 | } 240 | } 241 | 242 | #ifdef __GNUC__ 243 | RAPIDJSON_DIAG_POP 244 | #endif 245 | 246 | } // namespace internal 247 | RAPIDJSON_NAMESPACE_END 248 | 249 | #endif // RAPIDJSON_DTOA_ 250 | -------------------------------------------------------------------------------- /external/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. 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/internal/meta.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. 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_META_H_ 16 | #define RAPIDJSON_INTERNAL_META_H_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | #ifdef __GNUC__ 21 | RAPIDJSON_DIAG_PUSH 22 | RAPIDJSON_DIAG_OFF(effc++) 23 | #endif 24 | 25 | #if defined(_MSC_VER) && !defined(__clang__) 26 | RAPIDJSON_DIAG_PUSH 27 | RAPIDJSON_DIAG_OFF(6334) 28 | #endif 29 | 30 | #if RAPIDJSON_HAS_CXX11_TYPETRAITS 31 | #include 32 | #endif 33 | 34 | //@cond RAPIDJSON_INTERNAL 35 | RAPIDJSON_NAMESPACE_BEGIN 36 | namespace internal { 37 | 38 | // Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching 39 | template struct Void { typedef void Type; }; 40 | 41 | /////////////////////////////////////////////////////////////////////////////// 42 | // BoolType, TrueType, FalseType 43 | // 44 | template struct BoolType { 45 | static const bool Value = Cond; 46 | typedef BoolType Type; 47 | }; 48 | typedef BoolType TrueType; 49 | typedef BoolType FalseType; 50 | 51 | 52 | /////////////////////////////////////////////////////////////////////////////// 53 | // SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr 54 | // 55 | 56 | template struct SelectIfImpl { template struct Apply { typedef T1 Type; }; }; 57 | template <> struct SelectIfImpl { template struct Apply { typedef T2 Type; }; }; 58 | template struct SelectIfCond : SelectIfImpl::template Apply {}; 59 | template struct SelectIf : SelectIfCond {}; 60 | 61 | template struct AndExprCond : FalseType {}; 62 | template <> struct AndExprCond : TrueType {}; 63 | template struct OrExprCond : TrueType {}; 64 | template <> struct OrExprCond : FalseType {}; 65 | 66 | template struct BoolExpr : SelectIf::Type {}; 67 | template struct NotExpr : SelectIf::Type {}; 68 | template struct AndExpr : AndExprCond::Type {}; 69 | template struct OrExpr : OrExprCond::Type {}; 70 | 71 | 72 | /////////////////////////////////////////////////////////////////////////////// 73 | // AddConst, MaybeAddConst, RemoveConst 74 | template struct AddConst { typedef const T Type; }; 75 | template struct MaybeAddConst : SelectIfCond {}; 76 | template struct RemoveConst { typedef T Type; }; 77 | template struct RemoveConst { typedef T Type; }; 78 | 79 | 80 | /////////////////////////////////////////////////////////////////////////////// 81 | // IsSame, IsConst, IsMoreConst, IsPointer 82 | // 83 | template struct IsSame : FalseType {}; 84 | template struct IsSame : TrueType {}; 85 | 86 | template struct IsConst : FalseType {}; 87 | template struct IsConst : TrueType {}; 88 | 89 | template 90 | struct IsMoreConst 91 | : AndExpr::Type, typename RemoveConst::Type>, 92 | BoolType::Value >= IsConst::Value> >::Type {}; 93 | 94 | template struct IsPointer : FalseType {}; 95 | template struct IsPointer : TrueType {}; 96 | 97 | /////////////////////////////////////////////////////////////////////////////// 98 | // IsBaseOf 99 | // 100 | #if RAPIDJSON_HAS_CXX11_TYPETRAITS 101 | 102 | template struct IsBaseOf 103 | : BoolType< ::std::is_base_of::value> {}; 104 | 105 | #else // simplified version adopted from Boost 106 | 107 | template struct IsBaseOfImpl { 108 | RAPIDJSON_STATIC_ASSERT(sizeof(B) != 0); 109 | RAPIDJSON_STATIC_ASSERT(sizeof(D) != 0); 110 | 111 | typedef char (&Yes)[1]; 112 | typedef char (&No) [2]; 113 | 114 | template 115 | static Yes Check(const D*, T); 116 | static No Check(const B*, int); 117 | 118 | struct Host { 119 | operator const B*() const; 120 | operator const D*(); 121 | }; 122 | 123 | enum { Value = (sizeof(Check(Host(), 0)) == sizeof(Yes)) }; 124 | }; 125 | 126 | template struct IsBaseOf 127 | : OrExpr, BoolExpr > >::Type {}; 128 | 129 | #endif // RAPIDJSON_HAS_CXX11_TYPETRAITS 130 | 131 | 132 | ////////////////////////////////////////////////////////////////////////// 133 | // EnableIf / DisableIf 134 | // 135 | template struct EnableIfCond { typedef T Type; }; 136 | template struct EnableIfCond { /* empty */ }; 137 | 138 | template struct DisableIfCond { typedef T Type; }; 139 | template struct DisableIfCond { /* empty */ }; 140 | 141 | template 142 | struct EnableIf : EnableIfCond {}; 143 | 144 | template 145 | struct DisableIf : DisableIfCond {}; 146 | 147 | // SFINAE helpers 148 | struct SfinaeTag {}; 149 | template struct RemoveSfinaeTag; 150 | template struct RemoveSfinaeTag { typedef T Type; }; 151 | 152 | #define RAPIDJSON_REMOVEFPTR_(type) \ 153 | typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \ 154 | < ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type 155 | 156 | #define RAPIDJSON_ENABLEIF(cond) \ 157 | typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ 158 | ::Type * = NULL 159 | 160 | #define RAPIDJSON_DISABLEIF(cond) \ 161 | typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ 162 | ::Type * = NULL 163 | 164 | #define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \ 165 | typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \ 166 | ::Type 168 | 169 | #define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \ 170 | typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \ 171 | ::Type 173 | 174 | } // namespace internal 175 | RAPIDJSON_NAMESPACE_END 176 | //@endcond 177 | 178 | #if defined(_MSC_VER) && !defined(__clang__) 179 | RAPIDJSON_DIAG_POP 180 | #endif 181 | 182 | #ifdef __GNUC__ 183 | RAPIDJSON_DIAG_POP 184 | #endif 185 | 186 | #endif // RAPIDJSON_INTERNAL_META_H_ 187 | -------------------------------------------------------------------------------- /external/rapidjson/internal/pow10.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. 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_POW10_ 16 | #define RAPIDJSON_POW10_ 17 | 18 | #include "../rapidjson.h" 19 | 20 | RAPIDJSON_NAMESPACE_BEGIN 21 | namespace internal { 22 | 23 | //! Computes integer powers of 10 in double (10.0^n). 24 | /*! This function uses lookup table for fast and accurate results. 25 | \param n non-negative exponent. Must <= 308. 26 | \return 10.0^n 27 | */ 28 | inline double Pow10(int n) { 29 | static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes 30 | 1e+0, 31 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20, 32 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40, 33 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60, 34 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80, 35 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100, 36 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120, 37 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140, 38 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160, 39 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180, 40 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200, 41 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220, 42 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240, 43 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260, 44 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280, 45 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300, 46 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308 47 | }; 48 | RAPIDJSON_ASSERT(n >= 0 && n <= 308); 49 | return e[n]; 50 | } 51 | 52 | } // namespace internal 53 | RAPIDJSON_NAMESPACE_END 54 | 55 | #endif // RAPIDJSON_POW10_ 56 | -------------------------------------------------------------------------------- /external/rapidjson/internal/stack.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. 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_STACK_H_ 16 | #define RAPIDJSON_INTERNAL_STACK_H_ 17 | 18 | #include "../allocators.h" 19 | #include "swap.h" 20 | #include 21 | 22 | #if defined(__clang__) 23 | RAPIDJSON_DIAG_PUSH 24 | RAPIDJSON_DIAG_OFF(c++98-compat) 25 | #endif 26 | 27 | RAPIDJSON_NAMESPACE_BEGIN 28 | namespace internal { 29 | 30 | /////////////////////////////////////////////////////////////////////////////// 31 | // Stack 32 | 33 | //! A type-unsafe stack for storing different types of data. 34 | /*! \tparam Allocator Allocator for allocating stack memory. 35 | */ 36 | template 37 | class Stack { 38 | public: 39 | // Optimization note: Do not allocate memory for stack_ in constructor. 40 | // Do it lazily when first Push() -> Expand() -> Resize(). 41 | Stack(Allocator* allocator, size_t stackCapacity) : allocator_(allocator), ownAllocator_(0), stack_(0), stackTop_(0), stackEnd_(0), initialCapacity_(stackCapacity) { 42 | } 43 | 44 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 45 | Stack(Stack&& rhs) 46 | : allocator_(rhs.allocator_), 47 | ownAllocator_(rhs.ownAllocator_), 48 | stack_(rhs.stack_), 49 | stackTop_(rhs.stackTop_), 50 | stackEnd_(rhs.stackEnd_), 51 | initialCapacity_(rhs.initialCapacity_) 52 | { 53 | rhs.allocator_ = 0; 54 | rhs.ownAllocator_ = 0; 55 | rhs.stack_ = 0; 56 | rhs.stackTop_ = 0; 57 | rhs.stackEnd_ = 0; 58 | rhs.initialCapacity_ = 0; 59 | } 60 | #endif 61 | 62 | ~Stack() { 63 | Destroy(); 64 | } 65 | 66 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 67 | Stack& operator=(Stack&& rhs) { 68 | if (&rhs != this) 69 | { 70 | Destroy(); 71 | 72 | allocator_ = rhs.allocator_; 73 | ownAllocator_ = rhs.ownAllocator_; 74 | stack_ = rhs.stack_; 75 | stackTop_ = rhs.stackTop_; 76 | stackEnd_ = rhs.stackEnd_; 77 | initialCapacity_ = rhs.initialCapacity_; 78 | 79 | rhs.allocator_ = 0; 80 | rhs.ownAllocator_ = 0; 81 | rhs.stack_ = 0; 82 | rhs.stackTop_ = 0; 83 | rhs.stackEnd_ = 0; 84 | rhs.initialCapacity_ = 0; 85 | } 86 | return *this; 87 | } 88 | #endif 89 | 90 | void Swap(Stack& rhs) RAPIDJSON_NOEXCEPT { 91 | internal::Swap(allocator_, rhs.allocator_); 92 | internal::Swap(ownAllocator_, rhs.ownAllocator_); 93 | internal::Swap(stack_, rhs.stack_); 94 | internal::Swap(stackTop_, rhs.stackTop_); 95 | internal::Swap(stackEnd_, rhs.stackEnd_); 96 | internal::Swap(initialCapacity_, rhs.initialCapacity_); 97 | } 98 | 99 | void Clear() { stackTop_ = stack_; } 100 | 101 | void ShrinkToFit() { 102 | if (Empty()) { 103 | // If the stack is empty, completely deallocate the memory. 104 | Allocator::Free(stack_); // NOLINT (+clang-analyzer-unix.Malloc) 105 | stack_ = 0; 106 | stackTop_ = 0; 107 | stackEnd_ = 0; 108 | } 109 | else 110 | Resize(GetSize()); 111 | } 112 | 113 | // Optimization note: try to minimize the size of this function for force inline. 114 | // Expansion is run very infrequently, so it is moved to another (probably non-inline) function. 115 | template 116 | RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) { 117 | // Expand the stack if needed 118 | if (RAPIDJSON_UNLIKELY(static_cast(sizeof(T) * count) > (stackEnd_ - stackTop_))) 119 | Expand(count); 120 | } 121 | 122 | template 123 | RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) { 124 | Reserve(count); 125 | return PushUnsafe(count); 126 | } 127 | 128 | template 129 | RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) { 130 | RAPIDJSON_ASSERT(stackTop_); 131 | RAPIDJSON_ASSERT(static_cast(sizeof(T) * count) <= (stackEnd_ - stackTop_)); 132 | T* ret = reinterpret_cast(stackTop_); 133 | stackTop_ += sizeof(T) * count; 134 | return ret; 135 | } 136 | 137 | template 138 | T* Pop(size_t count) { 139 | RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T)); 140 | stackTop_ -= count * sizeof(T); 141 | return reinterpret_cast(stackTop_); 142 | } 143 | 144 | template 145 | T* Top() { 146 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 147 | return reinterpret_cast(stackTop_ - sizeof(T)); 148 | } 149 | 150 | template 151 | const T* Top() const { 152 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T)); 153 | return reinterpret_cast(stackTop_ - sizeof(T)); 154 | } 155 | 156 | template 157 | T* End() { return reinterpret_cast(stackTop_); } 158 | 159 | template 160 | const T* End() const { return reinterpret_cast(stackTop_); } 161 | 162 | template 163 | T* Bottom() { return reinterpret_cast(stack_); } 164 | 165 | template 166 | const T* Bottom() const { return reinterpret_cast(stack_); } 167 | 168 | bool HasAllocator() const { 169 | return allocator_ != 0; 170 | } 171 | 172 | Allocator& GetAllocator() { 173 | RAPIDJSON_ASSERT(allocator_); 174 | return *allocator_; 175 | } 176 | 177 | bool Empty() const { return stackTop_ == stack_; } 178 | size_t GetSize() const { return static_cast(stackTop_ - stack_); } 179 | size_t GetCapacity() const { return static_cast(stackEnd_ - stack_); } 180 | 181 | private: 182 | template 183 | void Expand(size_t count) { 184 | // Only expand the capacity if the current stack exists. Otherwise just create a stack with initial capacity. 185 | size_t newCapacity; 186 | if (stack_ == 0) { 187 | if (!allocator_) 188 | ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)(); 189 | newCapacity = initialCapacity_; 190 | } else { 191 | newCapacity = GetCapacity(); 192 | newCapacity += (newCapacity + 1) / 2; 193 | } 194 | size_t newSize = GetSize() + sizeof(T) * count; 195 | if (newCapacity < newSize) 196 | newCapacity = newSize; 197 | 198 | Resize(newCapacity); 199 | } 200 | 201 | void Resize(size_t newCapacity) { 202 | const size_t size = GetSize(); // Backup the current size 203 | stack_ = static_cast(allocator_->Realloc(stack_, GetCapacity(), newCapacity)); 204 | stackTop_ = stack_ + size; 205 | stackEnd_ = stack_ + newCapacity; 206 | } 207 | 208 | void Destroy() { 209 | Allocator::Free(stack_); 210 | RAPIDJSON_DELETE(ownAllocator_); // Only delete if it is owned by the stack 211 | } 212 | 213 | // Prohibit copy constructor & assignment operator. 214 | Stack(const Stack&); 215 | Stack& operator=(const Stack&); 216 | 217 | Allocator* allocator_; 218 | Allocator* ownAllocator_; 219 | char *stack_; 220 | char *stackTop_; 221 | char *stackEnd_; 222 | size_t initialCapacity_; 223 | }; 224 | 225 | } // namespace internal 226 | RAPIDJSON_NAMESPACE_END 227 | 228 | #if defined(__clang__) 229 | RAPIDJSON_DIAG_POP 230 | #endif 231 | 232 | #endif // RAPIDJSON_STACK_H_ 233 | -------------------------------------------------------------------------------- /external/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. 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 | //! Custom strcmpn() which works on different character types. 49 | /*! \tparam Ch Character type (e.g. char, wchar_t, short) 50 | \param s1 Null-terminated input string. 51 | \param s2 Null-terminated input string. 52 | \return 0 if equal 53 | */ 54 | template 55 | inline int StrCmp(const Ch* s1, const Ch* s2) { 56 | RAPIDJSON_ASSERT(s1 != 0); 57 | RAPIDJSON_ASSERT(s2 != 0); 58 | while(*s1 && (*s1 == *s2)) { s1++; s2++; } 59 | return static_cast(*s1) < static_cast(*s2) ? -1 : static_cast(*s1) > static_cast(*s2); 60 | } 61 | 62 | //! Returns number of code points in a encoded string. 63 | template 64 | bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) { 65 | RAPIDJSON_ASSERT(s != 0); 66 | RAPIDJSON_ASSERT(outCount != 0); 67 | GenericStringStream is(s); 68 | const typename Encoding::Ch* end = s + length; 69 | SizeType count = 0; 70 | while (is.src_ < end) { 71 | unsigned codepoint; 72 | if (!Encoding::Decode(is, &codepoint)) 73 | return false; 74 | count++; 75 | } 76 | *outCount = count; 77 | return true; 78 | } 79 | 80 | } // namespace internal 81 | RAPIDJSON_NAMESPACE_END 82 | 83 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_ 84 | -------------------------------------------------------------------------------- /external/rapidjson/internal/strtod.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. 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_STRTOD_ 16 | #define RAPIDJSON_STRTOD_ 17 | 18 | #include "ieee754.h" 19 | #include "biginteger.h" 20 | #include "diyfp.h" 21 | #include "pow10.h" 22 | #include 23 | #include 24 | 25 | RAPIDJSON_NAMESPACE_BEGIN 26 | namespace internal { 27 | 28 | inline double FastPath(double significand, int exp) { 29 | if (exp < -308) 30 | return 0.0; 31 | else if (exp >= 0) 32 | return significand * internal::Pow10(exp); 33 | else 34 | return significand / internal::Pow10(-exp); 35 | } 36 | 37 | inline double StrtodNormalPrecision(double d, int p) { 38 | if (p < -308) { 39 | // Prevent expSum < -308, making Pow10(p) = 0 40 | d = FastPath(d, -308); 41 | d = FastPath(d, p + 308); 42 | } 43 | else 44 | d = FastPath(d, p); 45 | return d; 46 | } 47 | 48 | template 49 | inline T Min3(T a, T b, T c) { 50 | T m = a; 51 | if (m > b) m = b; 52 | if (m > c) m = c; 53 | return m; 54 | } 55 | 56 | inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) { 57 | const Double db(b); 58 | const uint64_t bInt = db.IntegerSignificand(); 59 | const int bExp = db.IntegerExponent(); 60 | const int hExp = bExp - 1; 61 | 62 | int dS_Exp2 = 0, dS_Exp5 = 0, bS_Exp2 = 0, bS_Exp5 = 0, hS_Exp2 = 0, hS_Exp5 = 0; 63 | 64 | // Adjust for decimal exponent 65 | if (dExp >= 0) { 66 | dS_Exp2 += dExp; 67 | dS_Exp5 += dExp; 68 | } 69 | else { 70 | bS_Exp2 -= dExp; 71 | bS_Exp5 -= dExp; 72 | hS_Exp2 -= dExp; 73 | hS_Exp5 -= dExp; 74 | } 75 | 76 | // Adjust for binary exponent 77 | if (bExp >= 0) 78 | bS_Exp2 += bExp; 79 | else { 80 | dS_Exp2 -= bExp; 81 | hS_Exp2 -= bExp; 82 | } 83 | 84 | // Adjust for half ulp exponent 85 | if (hExp >= 0) 86 | hS_Exp2 += hExp; 87 | else { 88 | dS_Exp2 -= hExp; 89 | bS_Exp2 -= hExp; 90 | } 91 | 92 | // Remove common power of two factor from all three scaled values 93 | int common_Exp2 = Min3(dS_Exp2, bS_Exp2, hS_Exp2); 94 | dS_Exp2 -= common_Exp2; 95 | bS_Exp2 -= common_Exp2; 96 | hS_Exp2 -= common_Exp2; 97 | 98 | BigInteger dS = d; 99 | dS.MultiplyPow5(static_cast(dS_Exp5)) <<= static_cast(dS_Exp2); 100 | 101 | BigInteger bS(bInt); 102 | bS.MultiplyPow5(static_cast(bS_Exp5)) <<= static_cast(bS_Exp2); 103 | 104 | BigInteger hS(1); 105 | hS.MultiplyPow5(static_cast(hS_Exp5)) <<= static_cast(hS_Exp2); 106 | 107 | BigInteger delta(0); 108 | dS.Difference(bS, &delta); 109 | 110 | return delta.Compare(hS); 111 | } 112 | 113 | inline bool StrtodFast(double d, int p, double* result) { 114 | // Use fast path for string-to-double conversion if possible 115 | // see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/ 116 | if (p > 22 && p < 22 + 16) { 117 | // Fast Path Cases In Disguise 118 | d *= internal::Pow10(p - 22); 119 | p = 22; 120 | } 121 | 122 | if (p >= -22 && p <= 22 && d <= 9007199254740991.0) { // 2^53 - 1 123 | *result = FastPath(d, p); 124 | return true; 125 | } 126 | else 127 | return false; 128 | } 129 | 130 | // Compute an approximation and see if it is within 1/2 ULP 131 | template 132 | inline bool StrtodDiyFp(const Ch* decimals, int dLen, int dExp, double* result) { 133 | uint64_t significand = 0; 134 | int i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999 135 | for (; i < dLen; i++) { 136 | if (significand > RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) || 137 | (significand == RAPIDJSON_UINT64_C2(0x19999999, 0x99999999) && decimals[i] > Ch('5'))) 138 | break; 139 | significand = significand * 10u + static_cast(decimals[i] - Ch('0')); 140 | } 141 | 142 | if (i < dLen && decimals[i] >= Ch('5')) // Rounding 143 | significand++; 144 | 145 | int remaining = dLen - i; 146 | const int kUlpShift = 3; 147 | const int kUlp = 1 << kUlpShift; 148 | int64_t error = (remaining == 0) ? 0 : kUlp / 2; 149 | 150 | DiyFp v(significand, 0); 151 | v = v.Normalize(); 152 | error <<= -v.e; 153 | 154 | dExp += remaining; 155 | 156 | int actualExp; 157 | DiyFp cachedPower = GetCachedPower10(dExp, &actualExp); 158 | if (actualExp != dExp) { 159 | static const DiyFp kPow10[] = { 160 | DiyFp(RAPIDJSON_UINT64_C2(0xa0000000, 0x00000000), -60), // 10^1 161 | DiyFp(RAPIDJSON_UINT64_C2(0xc8000000, 0x00000000), -57), // 10^2 162 | DiyFp(RAPIDJSON_UINT64_C2(0xfa000000, 0x00000000), -54), // 10^3 163 | DiyFp(RAPIDJSON_UINT64_C2(0x9c400000, 0x00000000), -50), // 10^4 164 | DiyFp(RAPIDJSON_UINT64_C2(0xc3500000, 0x00000000), -47), // 10^5 165 | DiyFp(RAPIDJSON_UINT64_C2(0xf4240000, 0x00000000), -44), // 10^6 166 | DiyFp(RAPIDJSON_UINT64_C2(0x98968000, 0x00000000), -40) // 10^7 167 | }; 168 | int adjustment = dExp - actualExp; 169 | RAPIDJSON_ASSERT(adjustment >= 1 && adjustment < 8); 170 | v = v * kPow10[adjustment - 1]; 171 | if (dLen + adjustment > 19) // has more digits than decimal digits in 64-bit 172 | error += kUlp / 2; 173 | } 174 | 175 | v = v * cachedPower; 176 | 177 | error += kUlp + (error == 0 ? 0 : 1); 178 | 179 | const int oldExp = v.e; 180 | v = v.Normalize(); 181 | error <<= oldExp - v.e; 182 | 183 | const int effectiveSignificandSize = Double::EffectiveSignificandSize(64 + v.e); 184 | int precisionSize = 64 - effectiveSignificandSize; 185 | if (precisionSize + kUlpShift >= 64) { 186 | int scaleExp = (precisionSize + kUlpShift) - 63; 187 | v.f >>= scaleExp; 188 | v.e += scaleExp; 189 | error = (error >> scaleExp) + 1 + kUlp; 190 | precisionSize -= scaleExp; 191 | } 192 | 193 | DiyFp rounded(v.f >> precisionSize, v.e + precisionSize); 194 | const uint64_t precisionBits = (v.f & ((uint64_t(1) << precisionSize) - 1)) * kUlp; 195 | const uint64_t halfWay = (uint64_t(1) << (precisionSize - 1)) * kUlp; 196 | if (precisionBits >= halfWay + static_cast(error)) { 197 | rounded.f++; 198 | if (rounded.f & (DiyFp::kDpHiddenBit << 1)) { // rounding overflows mantissa (issue #340) 199 | rounded.f >>= 1; 200 | rounded.e++; 201 | } 202 | } 203 | 204 | *result = rounded.ToDouble(); 205 | 206 | return halfWay - static_cast(error) >= precisionBits || precisionBits >= halfWay + static_cast(error); 207 | } 208 | 209 | template 210 | inline double StrtodBigInteger(double approx, const Ch* decimals, int dLen, int dExp) { 211 | RAPIDJSON_ASSERT(dLen >= 0); 212 | const BigInteger dInt(decimals, static_cast(dLen)); 213 | Double a(approx); 214 | int cmp = CheckWithinHalfULP(a.Value(), dInt, dExp); 215 | if (cmp < 0) 216 | return a.Value(); // within half ULP 217 | else if (cmp == 0) { 218 | // Round towards even 219 | if (a.Significand() & 1) 220 | return a.NextPositiveDouble(); 221 | else 222 | return a.Value(); 223 | } 224 | else // adjustment 225 | return a.NextPositiveDouble(); 226 | } 227 | 228 | template 229 | inline double StrtodFullPrecision(double d, int p, const Ch* decimals, size_t length, size_t decimalPosition, int exp) { 230 | RAPIDJSON_ASSERT(d >= 0.0); 231 | RAPIDJSON_ASSERT(length >= 1); 232 | 233 | double result = 0.0; 234 | if (StrtodFast(d, p, &result)) 235 | return result; 236 | 237 | RAPIDJSON_ASSERT(length <= INT_MAX); 238 | int dLen = static_cast(length); 239 | 240 | RAPIDJSON_ASSERT(length >= decimalPosition); 241 | RAPIDJSON_ASSERT(length - decimalPosition <= INT_MAX); 242 | int dExpAdjust = static_cast(length - decimalPosition); 243 | 244 | RAPIDJSON_ASSERT(exp >= INT_MIN + dExpAdjust); 245 | int dExp = exp - dExpAdjust; 246 | 247 | // Make sure length+dExp does not overflow 248 | RAPIDJSON_ASSERT(dExp <= INT_MAX - dLen); 249 | 250 | // Trim leading zeros 251 | while (dLen > 0 && *decimals == '0') { 252 | dLen--; 253 | decimals++; 254 | } 255 | 256 | // Trim trailing zeros 257 | while (dLen > 0 && decimals[dLen - 1] == '0') { 258 | dLen--; 259 | dExp++; 260 | } 261 | 262 | if (dLen == 0) { // Buffer only contains zeros. 263 | return 0.0; 264 | } 265 | 266 | // Trim right-most digits 267 | const int kMaxDecimalDigit = 767 + 1; 268 | if (dLen > kMaxDecimalDigit) { 269 | dExp += dLen - kMaxDecimalDigit; 270 | dLen = kMaxDecimalDigit; 271 | } 272 | 273 | // If too small, underflow to zero. 274 | // Any x <= 10^-324 is interpreted as zero. 275 | if (dLen + dExp <= -324) 276 | return 0.0; 277 | 278 | // If too large, overflow to infinity. 279 | // Any x >= 10^309 is interpreted as +infinity. 280 | if (dLen + dExp > 309) 281 | return std::numeric_limits::infinity(); 282 | 283 | if (StrtodDiyFp(decimals, dLen, dExp, &result)) 284 | return result; 285 | 286 | // Use approximation from StrtodDiyFp and make adjustment with BigInteger comparison 287 | return StrtodBigInteger(result, decimals, dLen, dExp); 288 | } 289 | 290 | } // namespace internal 291 | RAPIDJSON_NAMESPACE_END 292 | 293 | #endif // RAPIDJSON_STRTOD_ 294 | -------------------------------------------------------------------------------- /external/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. 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/istreamwrapper.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. 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_ISTREAMWRAPPER_H_ 16 | #define RAPIDJSON_ISTREAMWRAPPER_H_ 17 | 18 | #include "stream.h" 19 | #include 20 | #include 21 | 22 | #ifdef __clang__ 23 | RAPIDJSON_DIAG_PUSH 24 | RAPIDJSON_DIAG_OFF(padded) 25 | #elif defined(_MSC_VER) 26 | RAPIDJSON_DIAG_PUSH 27 | RAPIDJSON_DIAG_OFF(4351) // new behavior: elements of array 'array' will be default initialized 28 | #endif 29 | 30 | RAPIDJSON_NAMESPACE_BEGIN 31 | 32 | //! Wrapper of \c std::basic_istream into RapidJSON's Stream concept. 33 | /*! 34 | The classes can be wrapped including but not limited to: 35 | 36 | - \c std::istringstream 37 | - \c std::stringstream 38 | - \c std::wistringstream 39 | - \c std::wstringstream 40 | - \c std::ifstream 41 | - \c std::fstream 42 | - \c std::wifstream 43 | - \c std::wfstream 44 | 45 | \tparam StreamType Class derived from \c std::basic_istream. 46 | */ 47 | 48 | template 49 | class BasicIStreamWrapper { 50 | public: 51 | typedef typename StreamType::char_type Ch; 52 | 53 | //! Constructor. 54 | /*! 55 | \param stream stream opened for read. 56 | */ 57 | BasicIStreamWrapper(StreamType &stream) : stream_(stream), buffer_(peekBuffer_), bufferSize_(4), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 58 | Read(); 59 | } 60 | 61 | //! Constructor. 62 | /*! 63 | \param stream stream opened for read. 64 | \param buffer user-supplied buffer. 65 | \param bufferSize size of buffer in bytes. Must >=4 bytes. 66 | */ 67 | BasicIStreamWrapper(StreamType &stream, char* buffer, size_t bufferSize) : stream_(stream), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) { 68 | RAPIDJSON_ASSERT(bufferSize >= 4); 69 | Read(); 70 | } 71 | 72 | Ch Peek() const { return *current_; } 73 | Ch Take() { Ch c = *current_; Read(); return c; } 74 | size_t Tell() const { return count_ + static_cast(current_ - buffer_); } 75 | 76 | // Not implemented 77 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 78 | void Flush() { RAPIDJSON_ASSERT(false); } 79 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 80 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 81 | 82 | // For encoding detection only. 83 | const Ch* Peek4() const { 84 | return (current_ + 4 - !eof_ <= bufferLast_) ? current_ : 0; 85 | } 86 | 87 | private: 88 | BasicIStreamWrapper(); 89 | BasicIStreamWrapper(const BasicIStreamWrapper&); 90 | BasicIStreamWrapper& operator=(const BasicIStreamWrapper&); 91 | 92 | void Read() { 93 | if (current_ < bufferLast_) 94 | ++current_; 95 | else if (!eof_) { 96 | count_ += readCount_; 97 | readCount_ = bufferSize_; 98 | bufferLast_ = buffer_ + readCount_ - 1; 99 | current_ = buffer_; 100 | 101 | if (!stream_.read(buffer_, static_cast(bufferSize_))) { 102 | readCount_ = static_cast(stream_.gcount()); 103 | *(bufferLast_ = buffer_ + readCount_) = '\0'; 104 | eof_ = true; 105 | } 106 | } 107 | } 108 | 109 | StreamType &stream_; 110 | Ch peekBuffer_[4], *buffer_; 111 | size_t bufferSize_; 112 | Ch *bufferLast_; 113 | Ch *current_; 114 | size_t readCount_; 115 | size_t count_; //!< Number of characters read 116 | bool eof_; 117 | }; 118 | 119 | typedef BasicIStreamWrapper IStreamWrapper; 120 | typedef BasicIStreamWrapper WIStreamWrapper; 121 | 122 | #if defined(__clang__) || defined(_MSC_VER) 123 | RAPIDJSON_DIAG_POP 124 | #endif 125 | 126 | RAPIDJSON_NAMESPACE_END 127 | 128 | #endif // RAPIDJSON_ISTREAMWRAPPER_H_ 129 | -------------------------------------------------------------------------------- /external/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. 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/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. 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/msinttypes/inttypes.h: -------------------------------------------------------------------------------- 1 | // ISO C9x compliant inttypes.h for Microsoft Visual Studio 2 | // Based on ISO/IEC 9899:TC2 Committee draft (May 6, 2005) WG14/N1124 3 | // 4 | // Copyright (c) 2006-2013 Alexander Chemeris 5 | // 6 | // Redistribution and use in source and binary forms, with or without 7 | // modification, are permitted provided that the following conditions are met: 8 | // 9 | // 1. Redistributions of source code must retain the above copyright notice, 10 | // this list of conditions and the following disclaimer. 11 | // 12 | // 2. Redistributions in binary form must reproduce the above copyright 13 | // notice, this list of conditions and the following disclaimer in the 14 | // documentation and/or other materials provided with the distribution. 15 | // 16 | // 3. Neither the name of the product nor the names of its contributors may 17 | // be used to endorse or promote products derived from this software 18 | // without specific prior written permission. 19 | // 20 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 21 | // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 22 | // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 23 | // EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 26 | // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 28 | // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 29 | // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | // 31 | /////////////////////////////////////////////////////////////////////////////// 32 | 33 | // The above software in this distribution may have been modified by 34 | // THL A29 Limited ("Tencent Modifications"). 35 | // All Tencent Modifications are Copyright (C) 2015 THL A29 Limited. 36 | 37 | #ifndef _MSC_VER // [ 38 | #error "Use this header only with Microsoft Visual C++ compilers!" 39 | #endif // _MSC_VER ] 40 | 41 | #ifndef _MSC_INTTYPES_H_ // [ 42 | #define _MSC_INTTYPES_H_ 43 | 44 | #if _MSC_VER > 1000 45 | #pragma once 46 | #endif 47 | 48 | #include "stdint.h" 49 | 50 | // miloyip: VC supports inttypes.h since VC2013 51 | #if _MSC_VER >= 1800 52 | #include 53 | #else 54 | 55 | // 7.8 Format conversion of integer types 56 | 57 | typedef struct { 58 | intmax_t quot; 59 | intmax_t rem; 60 | } imaxdiv_t; 61 | 62 | // 7.8.1 Macros for format specifiers 63 | 64 | #if !defined(__cplusplus) || defined(__STDC_FORMAT_MACROS) // [ See footnote 185 at page 198 65 | 66 | // The fprintf macros for signed integers are: 67 | #define PRId8 "d" 68 | #define PRIi8 "i" 69 | #define PRIdLEAST8 "d" 70 | #define PRIiLEAST8 "i" 71 | #define PRIdFAST8 "d" 72 | #define PRIiFAST8 "i" 73 | 74 | #define PRId16 "hd" 75 | #define PRIi16 "hi" 76 | #define PRIdLEAST16 "hd" 77 | #define PRIiLEAST16 "hi" 78 | #define PRIdFAST16 "hd" 79 | #define PRIiFAST16 "hi" 80 | 81 | #define PRId32 "I32d" 82 | #define PRIi32 "I32i" 83 | #define PRIdLEAST32 "I32d" 84 | #define PRIiLEAST32 "I32i" 85 | #define PRIdFAST32 "I32d" 86 | #define PRIiFAST32 "I32i" 87 | 88 | #define PRId64 "I64d" 89 | #define PRIi64 "I64i" 90 | #define PRIdLEAST64 "I64d" 91 | #define PRIiLEAST64 "I64i" 92 | #define PRIdFAST64 "I64d" 93 | #define PRIiFAST64 "I64i" 94 | 95 | #define PRIdMAX "I64d" 96 | #define PRIiMAX "I64i" 97 | 98 | #define PRIdPTR "Id" 99 | #define PRIiPTR "Ii" 100 | 101 | // The fprintf macros for unsigned integers are: 102 | #define PRIo8 "o" 103 | #define PRIu8 "u" 104 | #define PRIx8 "x" 105 | #define PRIX8 "X" 106 | #define PRIoLEAST8 "o" 107 | #define PRIuLEAST8 "u" 108 | #define PRIxLEAST8 "x" 109 | #define PRIXLEAST8 "X" 110 | #define PRIoFAST8 "o" 111 | #define PRIuFAST8 "u" 112 | #define PRIxFAST8 "x" 113 | #define PRIXFAST8 "X" 114 | 115 | #define PRIo16 "ho" 116 | #define PRIu16 "hu" 117 | #define PRIx16 "hx" 118 | #define PRIX16 "hX" 119 | #define PRIoLEAST16 "ho" 120 | #define PRIuLEAST16 "hu" 121 | #define PRIxLEAST16 "hx" 122 | #define PRIXLEAST16 "hX" 123 | #define PRIoFAST16 "ho" 124 | #define PRIuFAST16 "hu" 125 | #define PRIxFAST16 "hx" 126 | #define PRIXFAST16 "hX" 127 | 128 | #define PRIo32 "I32o" 129 | #define PRIu32 "I32u" 130 | #define PRIx32 "I32x" 131 | #define PRIX32 "I32X" 132 | #define PRIoLEAST32 "I32o" 133 | #define PRIuLEAST32 "I32u" 134 | #define PRIxLEAST32 "I32x" 135 | #define PRIXLEAST32 "I32X" 136 | #define PRIoFAST32 "I32o" 137 | #define PRIuFAST32 "I32u" 138 | #define PRIxFAST32 "I32x" 139 | #define PRIXFAST32 "I32X" 140 | 141 | #define PRIo64 "I64o" 142 | #define PRIu64 "I64u" 143 | #define PRIx64 "I64x" 144 | #define PRIX64 "I64X" 145 | #define PRIoLEAST64 "I64o" 146 | #define PRIuLEAST64 "I64u" 147 | #define PRIxLEAST64 "I64x" 148 | #define PRIXLEAST64 "I64X" 149 | #define PRIoFAST64 "I64o" 150 | #define PRIuFAST64 "I64u" 151 | #define PRIxFAST64 "I64x" 152 | #define PRIXFAST64 "I64X" 153 | 154 | #define PRIoMAX "I64o" 155 | #define PRIuMAX "I64u" 156 | #define PRIxMAX "I64x" 157 | #define PRIXMAX "I64X" 158 | 159 | #define PRIoPTR "Io" 160 | #define PRIuPTR "Iu" 161 | #define PRIxPTR "Ix" 162 | #define PRIXPTR "IX" 163 | 164 | // The fscanf macros for signed integers are: 165 | #define SCNd8 "d" 166 | #define SCNi8 "i" 167 | #define SCNdLEAST8 "d" 168 | #define SCNiLEAST8 "i" 169 | #define SCNdFAST8 "d" 170 | #define SCNiFAST8 "i" 171 | 172 | #define SCNd16 "hd" 173 | #define SCNi16 "hi" 174 | #define SCNdLEAST16 "hd" 175 | #define SCNiLEAST16 "hi" 176 | #define SCNdFAST16 "hd" 177 | #define SCNiFAST16 "hi" 178 | 179 | #define SCNd32 "ld" 180 | #define SCNi32 "li" 181 | #define SCNdLEAST32 "ld" 182 | #define SCNiLEAST32 "li" 183 | #define SCNdFAST32 "ld" 184 | #define SCNiFAST32 "li" 185 | 186 | #define SCNd64 "I64d" 187 | #define SCNi64 "I64i" 188 | #define SCNdLEAST64 "I64d" 189 | #define SCNiLEAST64 "I64i" 190 | #define SCNdFAST64 "I64d" 191 | #define SCNiFAST64 "I64i" 192 | 193 | #define SCNdMAX "I64d" 194 | #define SCNiMAX "I64i" 195 | 196 | #ifdef _WIN64 // [ 197 | # define SCNdPTR "I64d" 198 | # define SCNiPTR "I64i" 199 | #else // _WIN64 ][ 200 | # define SCNdPTR "ld" 201 | # define SCNiPTR "li" 202 | #endif // _WIN64 ] 203 | 204 | // The fscanf macros for unsigned integers are: 205 | #define SCNo8 "o" 206 | #define SCNu8 "u" 207 | #define SCNx8 "x" 208 | #define SCNX8 "X" 209 | #define SCNoLEAST8 "o" 210 | #define SCNuLEAST8 "u" 211 | #define SCNxLEAST8 "x" 212 | #define SCNXLEAST8 "X" 213 | #define SCNoFAST8 "o" 214 | #define SCNuFAST8 "u" 215 | #define SCNxFAST8 "x" 216 | #define SCNXFAST8 "X" 217 | 218 | #define SCNo16 "ho" 219 | #define SCNu16 "hu" 220 | #define SCNx16 "hx" 221 | #define SCNX16 "hX" 222 | #define SCNoLEAST16 "ho" 223 | #define SCNuLEAST16 "hu" 224 | #define SCNxLEAST16 "hx" 225 | #define SCNXLEAST16 "hX" 226 | #define SCNoFAST16 "ho" 227 | #define SCNuFAST16 "hu" 228 | #define SCNxFAST16 "hx" 229 | #define SCNXFAST16 "hX" 230 | 231 | #define SCNo32 "lo" 232 | #define SCNu32 "lu" 233 | #define SCNx32 "lx" 234 | #define SCNX32 "lX" 235 | #define SCNoLEAST32 "lo" 236 | #define SCNuLEAST32 "lu" 237 | #define SCNxLEAST32 "lx" 238 | #define SCNXLEAST32 "lX" 239 | #define SCNoFAST32 "lo" 240 | #define SCNuFAST32 "lu" 241 | #define SCNxFAST32 "lx" 242 | #define SCNXFAST32 "lX" 243 | 244 | #define SCNo64 "I64o" 245 | #define SCNu64 "I64u" 246 | #define SCNx64 "I64x" 247 | #define SCNX64 "I64X" 248 | #define SCNoLEAST64 "I64o" 249 | #define SCNuLEAST64 "I64u" 250 | #define SCNxLEAST64 "I64x" 251 | #define SCNXLEAST64 "I64X" 252 | #define SCNoFAST64 "I64o" 253 | #define SCNuFAST64 "I64u" 254 | #define SCNxFAST64 "I64x" 255 | #define SCNXFAST64 "I64X" 256 | 257 | #define SCNoMAX "I64o" 258 | #define SCNuMAX "I64u" 259 | #define SCNxMAX "I64x" 260 | #define SCNXMAX "I64X" 261 | 262 | #ifdef _WIN64 // [ 263 | # define SCNoPTR "I64o" 264 | # define SCNuPTR "I64u" 265 | # define SCNxPTR "I64x" 266 | # define SCNXPTR "I64X" 267 | #else // _WIN64 ][ 268 | # define SCNoPTR "lo" 269 | # define SCNuPTR "lu" 270 | # define SCNxPTR "lx" 271 | # define SCNXPTR "lX" 272 | #endif // _WIN64 ] 273 | 274 | #endif // __STDC_FORMAT_MACROS ] 275 | 276 | // 7.8.2 Functions for greatest-width integer types 277 | 278 | // 7.8.2.1 The imaxabs function 279 | #define imaxabs _abs64 280 | 281 | // 7.8.2.2 The imaxdiv function 282 | 283 | // This is modified version of div() function from Microsoft's div.c found 284 | // in %MSVC.NET%\crt\src\div.c 285 | #ifdef STATIC_IMAXDIV // [ 286 | static 287 | #else // STATIC_IMAXDIV ][ 288 | _inline 289 | #endif // STATIC_IMAXDIV ] 290 | imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) 291 | { 292 | imaxdiv_t result; 293 | 294 | result.quot = numer / denom; 295 | result.rem = numer % denom; 296 | 297 | if (numer < 0 && result.rem > 0) { 298 | // did division wrong; must fix up 299 | ++result.quot; 300 | result.rem -= denom; 301 | } 302 | 303 | return result; 304 | } 305 | 306 | // 7.8.2.3 The strtoimax and strtoumax functions 307 | #define strtoimax _strtoi64 308 | #define strtoumax _strtoui64 309 | 310 | // 7.8.2.4 The wcstoimax and wcstoumax functions 311 | #define wcstoimax _wcstoi64 312 | #define wcstoumax _wcstoui64 313 | 314 | #endif // _MSC_VER >= 1800 315 | 316 | #endif // _MSC_INTTYPES_H_ ] 317 | -------------------------------------------------------------------------------- /external/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. 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/stream.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. 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 "rapidjson.h" 16 | 17 | #ifndef RAPIDJSON_STREAM_H_ 18 | #define RAPIDJSON_STREAM_H_ 19 | 20 | #include "encodings.h" 21 | 22 | RAPIDJSON_NAMESPACE_BEGIN 23 | 24 | /////////////////////////////////////////////////////////////////////////////// 25 | // Stream 26 | 27 | /*! \class rapidjson::Stream 28 | \brief Concept for reading and writing characters. 29 | 30 | For read-only stream, no need to implement PutBegin(), Put(), Flush() and PutEnd(). 31 | 32 | For write-only stream, only need to implement Put() and Flush(). 33 | 34 | \code 35 | concept Stream { 36 | typename Ch; //!< Character type of the stream. 37 | 38 | //! Read the current character from stream without moving the read cursor. 39 | Ch Peek() const; 40 | 41 | //! Read the current character from stream and moving the read cursor to next character. 42 | Ch Take(); 43 | 44 | //! Get the current read cursor. 45 | //! \return Number of characters read from start. 46 | size_t Tell(); 47 | 48 | //! Begin writing operation at the current read pointer. 49 | //! \return The begin writer pointer. 50 | Ch* PutBegin(); 51 | 52 | //! Write a character. 53 | void Put(Ch c); 54 | 55 | //! Flush the buffer. 56 | void Flush(); 57 | 58 | //! End the writing operation. 59 | //! \param begin The begin write pointer returned by PutBegin(). 60 | //! \return Number of characters written. 61 | size_t PutEnd(Ch* begin); 62 | } 63 | \endcode 64 | */ 65 | 66 | //! Provides additional information for stream. 67 | /*! 68 | By using traits pattern, this type provides a default configuration for stream. 69 | For custom stream, this type can be specialized for other configuration. 70 | See TEST(Reader, CustomStringStream) in readertest.cpp for example. 71 | */ 72 | template 73 | struct StreamTraits { 74 | //! Whether to make local copy of stream for optimization during parsing. 75 | /*! 76 | By default, for safety, streams do not use local copy optimization. 77 | Stream that can be copied fast should specialize this, like StreamTraits. 78 | */ 79 | enum { copyOptimization = 0 }; 80 | }; 81 | 82 | //! Reserve n characters for writing to a stream. 83 | template 84 | inline void PutReserve(Stream& stream, size_t count) { 85 | (void)stream; 86 | (void)count; 87 | } 88 | 89 | //! Write character to a stream, presuming buffer is reserved. 90 | template 91 | inline void PutUnsafe(Stream& stream, typename Stream::Ch c) { 92 | stream.Put(c); 93 | } 94 | 95 | //! Put N copies of a character to a stream. 96 | template 97 | inline void PutN(Stream& stream, Ch c, size_t n) { 98 | PutReserve(stream, n); 99 | for (size_t i = 0; i < n; i++) 100 | PutUnsafe(stream, c); 101 | } 102 | 103 | /////////////////////////////////////////////////////////////////////////////// 104 | // GenericStreamWrapper 105 | 106 | //! A Stream Wrapper 107 | /*! \tThis string stream is a wrapper for any stream by just forwarding any 108 | \treceived message to the origin stream. 109 | \note implements Stream concept 110 | */ 111 | 112 | #if defined(_MSC_VER) && _MSC_VER <= 1800 113 | RAPIDJSON_DIAG_PUSH 114 | RAPIDJSON_DIAG_OFF(4702) // unreachable code 115 | RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated 116 | #endif 117 | 118 | template > 119 | class GenericStreamWrapper { 120 | public: 121 | typedef typename Encoding::Ch Ch; 122 | GenericStreamWrapper(InputStream& is): is_(is) {} 123 | 124 | Ch Peek() const { return is_.Peek(); } 125 | Ch Take() { return is_.Take(); } 126 | size_t Tell() { return is_.Tell(); } 127 | Ch* PutBegin() { return is_.PutBegin(); } 128 | void Put(Ch ch) { is_.Put(ch); } 129 | void Flush() { is_.Flush(); } 130 | size_t PutEnd(Ch* ch) { return is_.PutEnd(ch); } 131 | 132 | // wrapper for MemoryStream 133 | const Ch* Peek4() const { return is_.Peek4(); } 134 | 135 | // wrapper for AutoUTFInputStream 136 | UTFType GetType() const { return is_.GetType(); } 137 | bool HasBOM() const { return is_.HasBOM(); } 138 | 139 | protected: 140 | InputStream& is_; 141 | }; 142 | 143 | #if defined(_MSC_VER) && _MSC_VER <= 1800 144 | RAPIDJSON_DIAG_POP 145 | #endif 146 | 147 | /////////////////////////////////////////////////////////////////////////////// 148 | // StringStream 149 | 150 | //! Read-only string stream. 151 | /*! \note implements Stream concept 152 | */ 153 | template 154 | struct GenericStringStream { 155 | typedef typename Encoding::Ch Ch; 156 | 157 | GenericStringStream(const Ch *src) : src_(src), head_(src) {} 158 | 159 | Ch Peek() const { return *src_; } 160 | Ch Take() { return *src_++; } 161 | size_t Tell() const { return static_cast(src_ - head_); } 162 | 163 | Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; } 164 | void Put(Ch) { RAPIDJSON_ASSERT(false); } 165 | void Flush() { RAPIDJSON_ASSERT(false); } 166 | size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; } 167 | 168 | const Ch* src_; //!< Current read position. 169 | const Ch* head_; //!< Original head of the string. 170 | }; 171 | 172 | template 173 | struct StreamTraits > { 174 | enum { copyOptimization = 1 }; 175 | }; 176 | 177 | //! String stream with UTF8 encoding. 178 | typedef GenericStringStream > StringStream; 179 | 180 | /////////////////////////////////////////////////////////////////////////////// 181 | // InsituStringStream 182 | 183 | //! A read-write string stream. 184 | /*! This string stream is particularly designed for in-situ parsing. 185 | \note implements Stream concept 186 | */ 187 | template 188 | struct GenericInsituStringStream { 189 | typedef typename Encoding::Ch Ch; 190 | 191 | GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {} 192 | 193 | // Read 194 | Ch Peek() { return *src_; } 195 | Ch Take() { return *src_++; } 196 | size_t Tell() { return static_cast(src_ - head_); } 197 | 198 | // Write 199 | void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; } 200 | 201 | Ch* PutBegin() { return dst_ = src_; } 202 | size_t PutEnd(Ch* begin) { return static_cast(dst_ - begin); } 203 | void Flush() {} 204 | 205 | Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; } 206 | void Pop(size_t count) { dst_ -= count; } 207 | 208 | Ch* src_; 209 | Ch* dst_; 210 | Ch* head_; 211 | }; 212 | 213 | template 214 | struct StreamTraits > { 215 | enum { copyOptimization = 1 }; 216 | }; 217 | 218 | //! Insitu string stream with UTF8 encoding. 219 | typedef GenericInsituStringStream > InsituStringStream; 220 | 221 | RAPIDJSON_NAMESPACE_END 222 | 223 | #endif // RAPIDJSON_STREAM_H_ 224 | -------------------------------------------------------------------------------- /external/rapidjson/stringbuffer.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. 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_STRINGBUFFER_H_ 16 | #define RAPIDJSON_STRINGBUFFER_H_ 17 | 18 | #include "stream.h" 19 | #include "internal/stack.h" 20 | 21 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 22 | #include // std::move 23 | #endif 24 | 25 | #include "internal/stack.h" 26 | 27 | #if defined(__clang__) 28 | RAPIDJSON_DIAG_PUSH 29 | RAPIDJSON_DIAG_OFF(c++98-compat) 30 | #endif 31 | 32 | RAPIDJSON_NAMESPACE_BEGIN 33 | 34 | //! Represents an in-memory output stream. 35 | /*! 36 | \tparam Encoding Encoding of the stream. 37 | \tparam Allocator type for allocating memory buffer. 38 | \note implements Stream concept 39 | */ 40 | template 41 | class GenericStringBuffer { 42 | public: 43 | typedef typename Encoding::Ch Ch; 44 | 45 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {} 46 | 47 | #if RAPIDJSON_HAS_CXX11_RVALUE_REFS 48 | GenericStringBuffer(GenericStringBuffer&& rhs) : stack_(std::move(rhs.stack_)) {} 49 | GenericStringBuffer& operator=(GenericStringBuffer&& rhs) { 50 | if (&rhs != this) 51 | stack_ = std::move(rhs.stack_); 52 | return *this; 53 | } 54 | #endif 55 | 56 | void Put(Ch c) { *stack_.template Push() = c; } 57 | void PutUnsafe(Ch c) { *stack_.template PushUnsafe() = c; } 58 | void Flush() {} 59 | 60 | void Clear() { stack_.Clear(); } 61 | void ShrinkToFit() { 62 | // Push and pop a null terminator. This is safe. 63 | *stack_.template Push() = '\0'; 64 | stack_.ShrinkToFit(); 65 | stack_.template Pop(1); 66 | } 67 | 68 | void Reserve(size_t count) { stack_.template Reserve(count); } 69 | Ch* Push(size_t count) { return stack_.template Push(count); } 70 | Ch* PushUnsafe(size_t count) { return stack_.template PushUnsafe(count); } 71 | void Pop(size_t count) { stack_.template Pop(count); } 72 | 73 | const Ch* GetString() const { 74 | // Push and pop a null terminator. This is safe. 75 | *stack_.template Push() = '\0'; 76 | stack_.template Pop(1); 77 | 78 | return stack_.template Bottom(); 79 | } 80 | 81 | //! Get the size of string in bytes in the string buffer. 82 | size_t GetSize() const { return stack_.GetSize(); } 83 | 84 | //! Get the length of string in Ch in the string buffer. 85 | size_t GetLength() const { return stack_.GetSize() / sizeof(Ch); } 86 | 87 | static const size_t kDefaultCapacity = 256; 88 | mutable internal::Stack stack_; 89 | 90 | private: 91 | // Prohibit copy constructor & assignment operator. 92 | GenericStringBuffer(const GenericStringBuffer&); 93 | GenericStringBuffer& operator=(const GenericStringBuffer&); 94 | }; 95 | 96 | //! String buffer with UTF8 encoding 97 | typedef GenericStringBuffer > StringBuffer; 98 | 99 | template 100 | inline void PutReserve(GenericStringBuffer& stream, size_t count) { 101 | stream.Reserve(count); 102 | } 103 | 104 | template 105 | inline void PutUnsafe(GenericStringBuffer& stream, typename Encoding::Ch c) { 106 | stream.PutUnsafe(c); 107 | } 108 | 109 | //! Implement specialized version of PutN() with memset() for better performance. 110 | template<> 111 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) { 112 | std::memset(stream.stack_.Push(n), c, n * sizeof(c)); 113 | } 114 | 115 | RAPIDJSON_NAMESPACE_END 116 | 117 | #if defined(__clang__) 118 | RAPIDJSON_DIAG_POP 119 | #endif 120 | 121 | #endif // RAPIDJSON_STRINGBUFFER_H_ 122 | --------------------------------------------------------------------------------