Skip to content

Commit e051202

Browse files
committed
refactor
1 parent 4f96527 commit e051202

14 files changed

Lines changed: 1110 additions & 1055 deletions

File tree

.gitignore

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,50 @@
1-
# Prerequisites
2-
*.d
3-
4-
# Compiled Object files
5-
*.slo
6-
*.lo
1+
build/
2+
build-*/
73
*.o
84
*.obj
9-
10-
# Precompiled Headers
11-
*.gch
12-
*.pch
13-
14-
# Linker files
15-
*.ilk
16-
17-
# Debugger Files
18-
*.pdb
19-
20-
# Compiled Dynamic libraries
21-
*.so
22-
*.dylib
23-
*.dll
24-
25-
# Fortran module files
26-
*.mod
27-
*.smod
28-
29-
# Compiled Static libraries
5+
*.lo
6+
*.slo
307
*.lai
318
*.la
329
*.a
3310
*.lib
34-
35-
# Executables
11+
*.so
12+
*.dylib
13+
*.dll
3614
*.exe
3715
*.out
3816
*.app
39-
40-
# debug information files
17+
*.gch
18+
*.pch
4119
*.dwo
42-
build/
20+
*.d
4321
.vscode/
44-
cmd.md
22+
.idea/
23+
*.swp
24+
*.swo
25+
*.bak
26+
*.tmp
27+
compile_commands.json
28+
CMakeCache.txt
29+
CMakeFiles/
30+
cmake_install.cmake
31+
*.log
32+
vix.log
33+
text.md
34+
cmd.md
35+
text.txt
36+
cmd.txt
37+
scripts/changelog-release.sh
38+
scripts/update_changelog.sh
39+
build-ref/
40+
build-rel/
41+
hello_server
42+
/hello_world/
43+
*.bak
44+
db.sql
45+
revoir.md
46+
main.cpp
47+
.vix-scripts
48+
out.json
49+
50+

CMakeLists.txt

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
cmake_minimum_required(VERSION 3.20)
21

2+
# @file CMakeLists.cpp
3+
# @author Gaspard Kirira
4+
#
5+
# Copyright 2025, Gaspard Kirira. All rights reserved.
6+
# https://github.com/vixcpp/vix
7+
# Use of this source code is governed by a MIT license
8+
# that can be found in the License file.
9+
#
310
# ====================================================================
411
# Vix.cpp — JSON Module (Header-only, Umbrella-integrated)
512
# ====================================================================
@@ -21,23 +28,23 @@ cmake_minimum_required(VERSION 3.20)
2128
# target_link_libraries(app PRIVATE vix::json)
2229
# ====================================================================
2330

31+
cmake_minimum_required(VERSION 3.20)
32+
2433
project(vix_json VERSION 1.4.1 LANGUAGES CXX)
2534

2635
include(GNUInstallDirs)
2736
include(FetchContent)
2837

29-
# ---------------- Target (header-only) ----------------
38+
# Target (header-only)
3039
add_library(vix_json INTERFACE)
3140
add_library(vix::json ALIAS vix_json)
3241
target_compile_features(vix_json INTERFACE cxx_std_20)
3342

34-
# Public include layout to allow: #include <vix/json/...>
3543
target_include_directories(vix_json INTERFACE
3644
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
3745
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
3846
)
3947

40-
# ---------------- Dependency: nlohmann_json ----------------
4148
set(_VIX_JSON_PROVIDER "none")
4249

4350
find_package(nlohmann_json QUIET CONFIG)
@@ -60,7 +67,6 @@ else()
6067
)
6168
FetchContent_MakeAvailable(nlohmann_json_fallback)
6269

63-
# Create imported target (so consumers can always link nlohmann_json::nlohmann_json)
6470
if (NOT TARGET nlohmann_json::nlohmann_json)
6571
add_library(nlohmann_json::nlohmann_json INTERFACE IMPORTED)
6672
target_include_directories(nlohmann_json::nlohmann_json INTERFACE
@@ -73,7 +79,7 @@ else()
7379
endif()
7480
endif()
7581

76-
# ---------------- Examples (opt-in) ----------------
82+
# Examples
7783
option(VIX_JSON_BUILD_EXAMPLES "Build json examples" OFF)
7884
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
7985

@@ -95,7 +101,7 @@ if (VIX_JSON_BUILD_EXAMPLES)
95101
)
96102
endif()
97103

98-
# ---------------- Install / Export (umbrella) ----------------
104+
# Install / Export (umbrella)
99105
install(DIRECTORY include/
100106
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
101107
FILES_MATCHING PATTERN "*.hpp" PATTERN "*.h"
@@ -105,7 +111,7 @@ install(TARGETS vix_json
105111
EXPORT VixTargets # <- join umbrella export-set
106112
)
107113

108-
# ---------------- Status ----------------
114+
# Status
109115
message(STATUS "------------------------------------------------------")
110116
message(STATUS "vix_json configured (version ${PROJECT_VERSION})")
111117
message(STATUS "Provider: ${_VIX_JSON_PROVIDER}")

examples/builders.cpp

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
/**
2-
* @file json_demo.cpp
2+
*
3+
* @file builders.cpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
312
* @brief Example usage of the Vix.cpp JSON module.
413
*
514
* This example demonstrates how to use the high-level JSON helpers
@@ -39,25 +48,25 @@
3948

4049
int main()
4150
{
42-
using namespace vix::json;
51+
using namespace vix::json;
4352

44-
// ---------------------------------------------------------------------
45-
// Build a JSON object using `o()` and an array using `a()`
46-
// ---------------------------------------------------------------------
47-
auto user = o(
48-
"id", 42,
49-
"name", "Ada",
50-
"tags", a("pro", "admin"));
53+
// ---------------------------------------------------------------------
54+
// Build a JSON object using `o()` and an array using `a()`
55+
// ---------------------------------------------------------------------
56+
auto user = o(
57+
"id", 42,
58+
"name", "Ada",
59+
"tags", a("pro", "admin"));
5160

52-
// ---------------------------------------------------------------------
53-
// Build another JSON object using `kv()` (initializer list syntax)
54-
// ---------------------------------------------------------------------
55-
auto conf = kv({{"host", "localhost"},
56-
{"port", 8080}});
61+
// ---------------------------------------------------------------------
62+
// Build another JSON object using `kv()` (initializer list syntax)
63+
// ---------------------------------------------------------------------
64+
auto conf = kv({{"host", "localhost"},
65+
{"port", 8080}});
5766

58-
// ---------------------------------------------------------------------
59-
// Pretty-print both JSON objects with indentation
60-
// ---------------------------------------------------------------------
61-
std::cout << dumps(user, 2) << "\n"
62-
<< dumps(conf, 2) << "\n";
67+
// ---------------------------------------------------------------------
68+
// Pretty-print both JSON objects with indentation
69+
// ---------------------------------------------------------------------
70+
std::cout << dumps(user, 2) << "\n"
71+
<< dumps(conf, 2) << "\n";
6372
}

examples/io.cpp

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
/**
2-
* @file json_loads_dumps_demo.cpp
2+
*
3+
* @file io.cpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
312
* @brief Demonstrates parsing, writing, and reloading JSON with Vix.cpp helpers.
413
*
514
* This example shows how to:
@@ -34,25 +43,25 @@
3443

3544
int main()
3645
{
37-
using namespace vix::json;
46+
using namespace vix::json;
3847

39-
// ---------------------------------------------------------------------
40-
// Parse a JSON string into a Json object
41-
// ---------------------------------------------------------------------
42-
auto j = loads(R"({"a":1,"b":[10,20]})");
48+
// ---------------------------------------------------------------------
49+
// Parse a JSON string into a Json object
50+
// ---------------------------------------------------------------------
51+
auto j = loads(R"({"a":1,"b":[10,20]})");
4352

44-
// ---------------------------------------------------------------------
45-
// Write JSON to disk safely (atomic write using .tmp)
46-
// ---------------------------------------------------------------------
47-
dump_file("out.json", j, 2);
53+
// ---------------------------------------------------------------------
54+
// Write JSON to disk safely (atomic write using .tmp)
55+
// ---------------------------------------------------------------------
56+
dump_file("out.json", j, 2);
4857

49-
// ---------------------------------------------------------------------
50-
// Read the same file back into a new Json object
51-
// ---------------------------------------------------------------------
52-
auto j2 = load_file("out.json");
58+
// ---------------------------------------------------------------------
59+
// Read the same file back into a new Json object
60+
// ---------------------------------------------------------------------
61+
auto j2 = load_file("out.json");
5362

54-
// ---------------------------------------------------------------------
55-
// Pretty-print the reloaded JSON to stdout
56-
// ---------------------------------------------------------------------
57-
std::cout << dumps(j2, 2) << "\n";
63+
// ---------------------------------------------------------------------
64+
// Pretty-print the reloaded JSON to stdout
65+
// ---------------------------------------------------------------------
66+
std::cout << dumps(j2, 2) << "\n";
5867
}

examples/jpath.cpp

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
/**
2-
* @file json_jpath_demo.cpp
2+
*
3+
* @file jpath.cpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
312
* @brief Demonstrates JSON navigation and mutation with JPath helpers.
413
*
514
* This example showcases how to use `jset()` and `jget()` to manipulate
@@ -42,31 +51,31 @@
4251

4352
int main()
4453
{
45-
using namespace vix::json;
54+
using namespace vix::json;
4655

47-
// ---------------------------------------------------------------------
48-
// Start with an empty JSON object
49-
// ---------------------------------------------------------------------
50-
Json j = obj();
56+
// ---------------------------------------------------------------------
57+
// Start with an empty JSON object
58+
// ---------------------------------------------------------------------
59+
Json j = obj();
5160

52-
// ---------------------------------------------------------------------
53-
// Use jset() to assign values via JPath
54-
// Automatically creates missing objects/arrays
55-
// ---------------------------------------------------------------------
56-
jset(j, "user.langs[2]", "cpp"); // -> [null, null, "cpp"]
57-
jset(j, "user.profile.name", "Gaspard"); // creates nested object
58-
jset(j, R"(user["display.name"])", "Ada L."); // handles quoted keys
61+
// ---------------------------------------------------------------------
62+
// Use jset() to assign values via JPath
63+
// Automatically creates missing objects/arrays
64+
// ---------------------------------------------------------------------
65+
jset(j, "user.langs[2]", "cpp"); // -> [null, null, "cpp"]
66+
jset(j, "user.profile.name", "Gaspard"); // creates nested object
67+
jset(j, R"(user["display.name"])", "Ada L."); // handles quoted keys
5968

60-
// ---------------------------------------------------------------------
61-
// Access nested values via jget()
62-
// ---------------------------------------------------------------------
63-
if (auto v = jget(j, "user.langs[2]"))
64-
{
65-
std::cout << v->get<std::string>() << "\n"; // cpp
66-
}
69+
// ---------------------------------------------------------------------
70+
// Access nested values via jget()
71+
// ---------------------------------------------------------------------
72+
if (auto v = jget(j, "user.langs[2]"))
73+
{
74+
std::cout << v->get<std::string>() << "\n"; // cpp
75+
}
6776

68-
// ---------------------------------------------------------------------
69-
// Pretty-print the resulting JSON
70-
// ---------------------------------------------------------------------
71-
std::cout << dumps(j, 2) << "\n";
77+
// ---------------------------------------------------------------------
78+
// Pretty-print the resulting JSON
79+
// ---------------------------------------------------------------------
80+
std::cout << dumps(j, 2) << "\n";
7281
}

examples/quick_start.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
/**
2-
* @file json_build_demo.cpp
2+
*
3+
* @file quick_start.cpp
4+
* @author Gaspard Kirira
5+
*
6+
* Copyright 2025, Gaspard Kirira. All rights reserved.
7+
* https://github.com/vixcpp/vix
8+
* Use of this source code is governed by a MIT license
9+
* that can be found in the License file.
10+
*
11+
* Vix.cpp
312
* @brief Demonstrates JSON object and array creation with Vix.cpp JSON builders.
413
*
514
* This example shows how to use the high-level helper functions:
@@ -33,18 +42,18 @@
3342

3443
int main()
3544
{
36-
using namespace vix::json;
45+
using namespace vix::json;
3746

38-
// ---------------------------------------------------------------------
39-
// Build a JSON object and array using concise builder syntax
40-
// ---------------------------------------------------------------------
41-
auto j = o(
42-
"message", "Hello",
43-
"count", 3,
44-
"arr", a(1, 2, 3));
47+
// ---------------------------------------------------------------------
48+
// Build a JSON object and array using concise builder syntax
49+
// ---------------------------------------------------------------------
50+
auto j = o(
51+
"message", "Hello",
52+
"count", 3,
53+
"arr", a(1, 2, 3));
4554

46-
// ---------------------------------------------------------------------
47-
// Pretty-print the JSON result
48-
// ---------------------------------------------------------------------
49-
std::cout << dumps(j, 2) << "\n";
55+
// ---------------------------------------------------------------------
56+
// Pretty-print the JSON result
57+
// ---------------------------------------------------------------------
58+
std::cout << dumps(j, 2) << "\n";
5059
}

0 commit comments

Comments
 (0)