├── img └── logo.png ├── envyConfig.cmake.in ├── envy.pc.in ├── utils └── amalgamate │ ├── config.json │ ├── CHANGES.md │ ├── LICENSE.md │ ├── README.md │ └── amalgamate.py ├── single_include.json ├── LICENSE ├── LICENSE.json ├── LICENSE.visit_struct ├── CMakeLists.txt ├── include └── envy │ ├── envy.hpp │ └── visit_struct │ └── visit_struct.hpp ├── README.md └── .gitignore /img/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/p-ranav/envy/HEAD/img/logo.png -------------------------------------------------------------------------------- /envyConfig.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include(CMakeFindDependencyMacro) 4 | 5 | if (NOT TARGET envy::envy) 6 | include(${CMAKE_CURRENT_LIST_DIR}/envyTargets.cmake) 7 | endif () 8 | -------------------------------------------------------------------------------- /envy.pc.in: -------------------------------------------------------------------------------- 1 | includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ 2 | 3 | Name: @PROJECT_NAME@ 4 | Description: @PROJECT_DESCRIPTION@ 5 | URL: @PROJECT_HOMEPAGE_URL@ 6 | Version: @PROJECT_VERSION@ 7 | Cflags: -I${includedir} 8 | -------------------------------------------------------------------------------- /utils/amalgamate/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": "cgame competitive programming for codingame", 3 | "target": "AllTrees.cpp", 4 | "sources": [ 5 | "test/gametheory/TreesTest.cpp" 6 | ], 7 | "include_paths": ["include"] 8 | } 9 | -------------------------------------------------------------------------------- /single_include.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": "Deserialize environment variables into type-safe structs", 3 | "target": "single_include/envy/envy.hpp", 4 | "sources": [ 5 | "include/envy/json/json.hpp", 6 | "include/envy/visit_struct/visit_struct.hpp", 7 | "include/envy/envy.hpp" 8 | ], 9 | "include_paths": ["include"] 10 | } 11 | -------------------------------------------------------------------------------- /utils/amalgamate/CHANGES.md: -------------------------------------------------------------------------------- 1 | The following changes have been made to the code with respect to : 2 | 3 | - Resolved inspection results from PyCharm: 4 | - replaced tabs with spaces 5 | - added encoding annotation 6 | - reindented file to remove trailing whitespaces 7 | - unused import `sys` 8 | - membership check 9 | - made function from `_is_within` 10 | - removed unused variable `actual_path` 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Pranav 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 | -------------------------------------------------------------------------------- /LICENSE.json: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2013-2020 Niels Lohmann 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 | -------------------------------------------------------------------------------- /LICENSE.visit_struct: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /utils/amalgamate/LICENSE.md: -------------------------------------------------------------------------------- 1 | amalgamate.py - Amalgamate C source and header files 2 | Copyright (c) 2012, Erik Edlund 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, 8 | this list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of Erik Edlund, nor the names of its contributors may 15 | be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /utils/amalgamate/README.md: -------------------------------------------------------------------------------- 1 | 2 | # amalgamate.py - Amalgamate C source and header files 3 | 4 | Origin: https://bitbucket.org/erikedlund/amalgamate 5 | 6 | Mirror: https://github.com/edlund/amalgamate 7 | 8 | `amalgamate.py` aims to make it easy to use SQLite-style C source and header 9 | amalgamation in projects. 10 | 11 | For more information, please refer to: http://sqlite.org/amalgamation.html 12 | 13 | ## Here be dragons 14 | 15 | `amalgamate.py` is quite dumb, it only knows the bare minimum about C code 16 | required in order to be able to handle trivial include directives. It can 17 | produce weird results for unexpected code. 18 | 19 | Things to be aware of: 20 | 21 | `amalgamate.py` will not handle complex include directives correctly: 22 | 23 | #define HEADER_PATH "path/to/header.h" 24 | #include HEADER_PATH 25 | 26 | In the above example, `path/to/header.h` will not be included in the 27 | amalgamation (HEADER_PATH is never expanded). 28 | 29 | `amalgamate.py` makes the assumption that each source and header file which 30 | is not empty will end in a new-line character, which is not immediately 31 | preceded by a backslash character (see 5.1.1.2p1.2 of ISO C99). 32 | 33 | `amalgamate.py` should be usable with C++ code, but raw string literals from 34 | C++11 will definitely cause problems: 35 | 36 | R"delimiter(Terrible raw \ data " #include )delimiter" 37 | R"delimiter(Terrible raw \ data " escaping)delimiter" 38 | 39 | In the examples above, `amalgamate.py` will stop parsing the raw string literal 40 | when it encounters the first quotation mark, which will produce unexpected 41 | results. 42 | 43 | ## Installing amalgamate.py 44 | 45 | Python v.2.7.0 or higher is required. 46 | 47 | `amalgamate.py` can be tested and installed using the following commands: 48 | 49 | ./test.sh && sudo -k cp ./amalgamate.py /usr/local/bin/ 50 | 51 | ## Using amalgamate.py 52 | 53 | amalgamate.py [-v] -c path/to/config.json -s path/to/source/dir \ 54 | [-p path/to/prologue.(c|h)] 55 | 56 | * The `-c, --config` option should specify the path to a JSON config file which 57 | lists the source files, include paths and where to write the resulting 58 | amalgamation. Have a look at `test/source.c.json` and `test/include.h.json` 59 | to see two examples. 60 | 61 | * The `-s, --source` option should specify the path to the source directory. 62 | This is useful for supporting separate source and build directories. 63 | 64 | * The `-p, --prologue` option should specify the path to a file which will be 65 | added to the beginning of the amalgamation. It is optional. 66 | 67 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | 3 | if(DEFINED PROJECT_NAME) 4 | set(ENVY_SUBPROJECT ON) 5 | endif() 6 | 7 | if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.12") 8 | project(envy VERSION 1.0.0 LANGUAGES CXX 9 | HOMEPAGE_URL "https://github.com/p-ranav/envy" 10 | DESCRIPTION "Deserialize environment variables into type-safe structs") 11 | elseif(CMAKE_VERSION VERSION_GREATER_EQUAL "3.9") 12 | project(envy VERSION 1.0.0 LANGUAGES CXX 13 | DESCRIPTION "Deserialize environment variables into type-safe structs") 14 | else() 15 | project(envy VERSION 1.9.0 LANGUAGES CXX) 16 | endif() 17 | 18 | if(EXISTS "${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") 19 | include("${CMAKE_BINARY_DIR}/conanbuildinfo.cmake") 20 | conan_basic_setup() 21 | endif() 22 | 23 | include(CMakePackageConfigHelpers) 24 | include(GNUInstallDirs) 25 | 26 | add_library(envy INTERFACE) 27 | add_library(envy::envy ALIAS envy) 28 | 29 | target_compile_features(envy INTERFACE cxx_std_11) 30 | target_include_directories(envy INTERFACE 31 | $ 32 | $) 33 | target_link_libraries(envy INTERFACE Threads::Threads) 34 | 35 | if(NOT ENVY_SUBPROJECT) 36 | configure_package_config_file(envyConfig.cmake.in 37 | ${CMAKE_CURRENT_BINARY_DIR}/envyConfig.cmake 38 | INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/envy) 39 | write_basic_package_version_file(envyConfigVersion.cmake 40 | COMPATIBILITY AnyNewerVersion) 41 | 42 | configure_file(envy.pc.in envy.pc @ONLY) 43 | 44 | install(TARGETS envy EXPORT envyTargets) 45 | install(EXPORT envyTargets 46 | FILE envyTargets.cmake 47 | NAMESPACE envy:: 48 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/envy) 49 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/envyConfig.cmake 50 | ${CMAKE_CURRENT_BINARY_DIR}/envyConfigVersion.cmake 51 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/envy) 52 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/envy.pc 53 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) 54 | install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/include/envy 55 | DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} 56 | USE_SOURCE_PERMISSIONS 57 | PATTERN "*.hpp") 58 | install(FILES LICENSE LICENSE.json LICENSE.visit_struct 59 | DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/licenses/envy) 60 | 61 | if(EXISTS "${PROJECT_SOURCE_DIR}/.gitignore") 62 | # Simple glob to regex conversion (.gitignore => CPACK_SOURCE_IGNORE_FILES) 63 | file(READ ".gitignore" DOT_GITIGNORE) 64 | string(REPLACE ";" "RANDOMSEQUENCE" DOT_GITIGNORE "${DOT_GITIGNORE}") 65 | string(REPLACE "\n" ";" DOT_GITIGNORE "${DOT_GITIGNORE}") 66 | string(REPLACE "RANDOMSEQUENCE" "\\;" DOT_GITIGNORE "${DOT_GITIGNORE}") 67 | foreach(IGNORE_LINE ${DOT_GITIGNORE}) 68 | if(NOT IGNORE_LINE OR IGNORE_LINE MATCHES "^#") 69 | continue() 70 | endif() 71 | string(REPLACE "\\" "\\\\" IGNORE_LINE "${IGNORE_LINE}") 72 | string(REPLACE "." "\\\\." IGNORE_LINE "${IGNORE_LINE}") 73 | string(REPLACE "*" ".*" IGNORE_LINE "${IGNORE_LINE}") 74 | string(REPLACE "+" "\\\\+" IGNORE_LINE "${IGNORE_LINE}") 75 | list(APPEND CPACK_SOURCE_IGNORE_FILES "${IGNORE_LINE}") 76 | endforeach() 77 | endif() 78 | 79 | # extra ignored files 80 | list(APPEND CPACK_SOURCE_IGNORE_FILES 81 | .editorconfig 82 | .git 83 | .gitignore 84 | .travis.yml 85 | .appveyor.yml 86 | ) 87 | set(CPACK_SOURCE_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}") 88 | set(CPACK_GENERATOR "TGZ;TXZ") 89 | set(CPACK_SOURCE_GENERATOR "TGZ;TXZ") 90 | include(CPack) 91 | endif() 92 | -------------------------------------------------------------------------------- /include/envy/envy.hpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | ____ _______ _____.__. 4 | _/ __ \ / \ \/ < | | Deserialize Environment Variables 5 | \ ___/| | \ / \___ | into type-safe structs 6 | \___ >___| /\_/ / ____| https://github.com/p-ranav/envy 7 | \/ \/ \/ 8 | Licensed under the MIT License . 9 | SPDX-License-Identifier: MIT 10 | Copyright (c) 2020 Pranav Srinivas Kumar . 11 | Permission is hereby granted, free of charge, to any person obtaining a copy 12 | of this software and associated documentation files (the "Software"), to deal 13 | in the Software without restriction, including without limitation the rights 14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 | copies of the Software, and to permit persons to whom the Software is 16 | furnished to do so, subject to the following conditions: 17 | The above copyright notice and this permission notice shall be included in all 18 | copies or substantial portions of the Software. 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 25 | SOFTWARE. 26 | */ 27 | #pragma once 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #define ENVY_STRUCT VISITABLE_STRUCT 39 | 40 | namespace envy { 41 | 42 | namespace details { // namespace for helper methods 43 | 44 | template class Ref> 45 | struct is_specialization : std::false_type {}; 46 | 47 | template