### JSON Configuration Management Example (C++) Source: https://context7.com/bouncmpe/cpp-project-template/llms.txt An integration example in C++ demonstrating a `ConfigManager` class that uses the `bouncmpe::jsonmerge` function to apply multiple updates to a base JSON configuration. It shows dynamic configuration loading and merging for application settings. Dependencies include Boost.JSON and the library's `jsonmerge` functionality. ```cpp #include "bouncmpe/jsonmerge.hpp" #include #include #include class ConfigManager { public: ConfigManager(const boost::json::value& base_config) : config(base_config) {} void applyUpdate(const boost::json::value& update) { config = bouncmpe::jsonmerge(config, update); } boost::json::value getConfig() const { return config; } private: boost::json::value config; }; int main() { // Base configuration boost::json::value base_config = { {"database", { {"host", "localhost"}, {"port", 5432}, {"timeout", 30} }}, {"logging", { {"level", "info"}, {"format", "json"} }} }; ConfigManager manager(base_config); // Apply production overrides boost::json::value prod_override = { {"database", { {"host", "prod-db.example.com"}, {"port", 5433} }}, {"logging", { {"level", "warn"} }} }; manager.applyUpdate(prod_override); // Apply environment-specific settings boost::json::value env_settings = { {"database", { {"pool_size", 20} }}, {"cache", { {"enabled", true}, {"ttl", 3600} }} }; manager.applyUpdate(env_settings); std::cout << "Final config: " << manager.getConfig() << std::endl; return 0; } ``` -------------------------------- ### add_two_integer - Integer Addition Utility Source: https://context7.com/bouncmpe/cpp-project-template/llms.txt A simple utility function that adds two integers and returns their sum. This function serves as a basic example of the library's interface pattern and can be used for testing the build system integration. ```APIDOC ## Integer Addition Utility ### Description A simple utility function that adds two integers and returns their sum. ### Method Internal Library Function (not a direct API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp #include "bouncmpe/jsonmerge.hpp" int main() { int a = 10; int b = 12; int result = bouncmpe::add_two_integer(a, b); // Expected result: 22 return 0; } ``` ### Response #### Success Response - **result** (int) - The sum of the two input integers. ``` -------------------------------- ### Add Two Integers Utility Function (C++) Source: https://context7.com/bouncmpe/cpp-project-template/llms.txt A simple C++ utility function that performs addition on two integers. It serves as a basic example of the library's interface and is useful for verifying build system integration. It takes two integers as input and returns their sum. No external dependencies are required beyond standard C++ libraries. ```cpp #include "bouncmpe/jsonmerge.hpp" int main() { int a = 10; int b = 12; // Add two integers int result = bouncmpe::add_two_integer(a, b); // Expected result: 22 std::cout << "Result: " << result << std::endl; return 0; } ``` -------------------------------- ### Build and Test C++ Project with CMake and Make (Bash) Source: https://context7.com/bouncmpe/cpp-project-template/llms.txt Shell commands for building and testing the C++ project using CMake and Make. The `make all` command configures, builds, and tests the project. Individual steps include CMake configuration, building, and running tests via CTest. Requires CMake, Make, and a C++ compiler. ```bash # Configure, build, and test in one command make all # Or run steps individually: # Configure CMake project cmake -S . -B /tmp/build -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON # Build the library cmake --build /tmp/build # Run test suite ctest --test-dir /tmp/build --output-on-failure ``` -------------------------------- ### CMake Configuration for C++ Project with Boost.JSON Source: https://github.com/bouncmpe/cpp-project-template/blob/main/CMakeLists.txt This CMakeLists.txt file configures a C++ project named 'LIBBOUNCMPE'. It sets the C++ standard to 17, finds and links the Boost.JSON library (version 1.81), and defines include directories. It also conditionally includes subdirectories for tests and applications based on build flags. ```cmake cmake_minimum_required(VERSION 3.20) project("LIBBOUNCMPE" CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) add_library(bouncmpe) find_package(Boost 1.81 COMPONENTS json REQUIRED) target_include_directories( bouncmpe PUBLIC $ $/include ) target_sources( bouncmpe PRIVATE "src/jsonmerge.cpp" ) target_link_libraries( bouncmpe PUBLIC Boost::json ) if (ENABLE_TESTS) add_subdirectory(tests) enable_testing() endif() if (BOUNCMPE_BUILD_APPS) add_subdirectory(apps) endif() ``` -------------------------------- ### Merge JSON Objects with Boost.JSON (C++) Source: https://context7.com/bouncmpe/cpp-project-template/llms.txt Core C++ function for merging two JSON objects using Boost.JSON. It takes a target JSON object and a patch object, applying the patch's values to the target. This function is essential for updating configurations or combining API responses. It requires Boost.JSON and standard C++ exception handling. ```cpp #include "bouncmpe/jsonmerge.hpp" #include #include int main() { // Create target JSON object boost::json::value target = { {"key1", "v1"}, {"key2", "a"}, {"nested", { {"field1", 100}, {"field2", "original"} }} }; // Create patch JSON object boost::json::value patch = { {"key1", "v2"}, // Override existing key {"key3", "new"} // Add new key }; try { // Perform merge operation boost::json::value result = bouncmpe::jsonmerge(target, patch); // Expected result: {"key1":"v2", "key2":"a", "key3":"new", "nested":{...}} std::cout << "Merged JSON: " << result << std::endl; } catch (const std::exception& e) { std::cerr << "Error during merge: " << e.what() << std::endl; return 1; } return 0; } ``` -------------------------------- ### jsonmerge - JSON Object Merging Source: https://context7.com/bouncmpe/cpp-project-template/llms.txt Merges two JSON values by applying patch values to a target JSON object. The function takes two Boost.JSON value objects and returns a merged result. This is the core functionality of the library, enabling dynamic JSON manipulation. ```APIDOC ## JSON Object Merging ### Description Merges two JSON values by applying patch values to a target JSON object. This function is the core functionality of the library. ### Method Internal Library Function (not a direct API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```cpp #include "bouncmpe/jsonmerge.hpp" #include #include int main() { boost::json::value target = { {"key1", "v1"}, {"key2", "a"}, {"nested", { {"field1", 100}, {"field2", "original"} }} }; boost::json::value patch = { {"key1", "v2"}, {"key3", "new"} }; try { boost::json::value result = bouncmpe::jsonmerge(target, patch); // Expected result: {"key1":"v2", "key2":"a", "key3":"new", "nested":{...}} std::cout << "Merged JSON: " << result << std::endl; } catch (const std::exception& e) { std::cerr << "Error during merge: " << e.what() << std::endl; return 1; } return 0; } ``` ### Response #### Success Response - **result** (boost::json::value) - The merged JSON object. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.