Skip to content

Commit c5347ee

Browse files
Added XML support; #21
1 parent 2281849 commit c5347ee

File tree

124 files changed

+4653
-1438
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+4653
-1438
lines changed

.github/workflows/test.yaml

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ jobs:
1818
- name: Run test
1919
run: |
2020
g++ --version
21-
cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_FLEXBUFFERS=ON -DCMAKE_BUILD_TYPE=Release
21+
cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_FLEXBUFFERS=ON -DREFLECTCPP_XML=ON -DCMAKE_BUILD_TYPE=Release
2222
cmake --build build -j 4
2323
./build/tests/flexbuffers/reflect-cpp-flexbuffers-tests
2424
./build/tests/json/reflect-cpp-json-tests
25+
./build/tests/xml/reflect-cpp-xml-tests
2526
2627
linux-clang:
2728
runs-on: ubuntu-latest
@@ -45,10 +46,11 @@ jobs:
4546
CXX: clang++
4647
run: |
4748
clang --version
48-
cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_FLEXBUFFERS=ON -DCMAKE_BUILD_TYPE=Release
49+
cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_FLEXBUFFERS=ON -DREFLECTCPP_XML=ON -DCMAKE_BUILD_TYPE=Release
4950
cmake --build build -j 4
5051
./build/tests/flexbuffers/reflect-cpp-flexbuffers-tests
5152
./build/tests/json/reflect-cpp-json-tests
53+
./build/tests/xml/reflect-cpp-xml-tests
5254
5355
5456
# The latest MSVC version on GitHub Actions has a bug, and it's difficult to switch to another version.
@@ -67,4 +69,4 @@ jobs:
6769
# cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_FLEXBUFFERS=ON
6870
# cmake --build build -j 4
6971
# .\build\tests\flexbuffers\Release\reflect-cpp-flexbuffers-tests.exe
70-
# .\build\tests\json\Release\reflect-cpp-json-tests.exe
72+
# .\build\tests\json\Release\reflect-cpp-json-tests.exe

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@
4343
# Output files
4444
*.json
4545
*.fb
46-
!vcpkg.json
46+
*.xml
47+
48+
!vcpkg.json

CMakeLists.txt

+10-5
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ cmake_minimum_required(VERSION 3.15)
22

33
option(REFLECTCPP_BUILD_SHARED "Build shared library" OFF)
44
option(REFLECTCPP_FLEXBUFFERS "Enable flexbuffers support" OFF)
5+
option(REFLECTCPP_XML "Enable XML support" OFF)
56

67
option(REFLECTCPP_BUILD_TESTS "Build tests" OFF)
78

8-
99
# enable vcpkg if require features other than JSON
10-
if (REFLECTCPP_FLEXBUFFERS)
11-
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")
10+
if (REFLECTCPP_FLEXBUFFERS OR REFLECTCPP_XML)
11+
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake CACHE STRING "Vcpkg toolchain file")
1212
endif ()
1313

1414
project(reflectcpp)
@@ -20,16 +20,21 @@ if (REFLECTCPP_BUILD_SHARED)
2020
else ()
2121
add_library(reflectcpp STATIC src/yyjson.c)
2222
endif ()
23-
target_include_directories(reflectcpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
2423

24+
target_include_directories(reflectcpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
2525

2626
if (REFLECTCPP_FLEXBUFFERS)
2727
find_package(flatbuffers CONFIG REQUIRED)
2828
target_link_libraries(reflectcpp INTERFACE flatbuffers::flatbuffers)
2929
endif ()
3030

31+
if (REFLECTCPP_XML)
32+
find_package(pugixml CONFIG REQUIRED)
33+
target_link_libraries(reflectcpp INTERFACE pugixml::pugixml)
34+
endif ()
35+
3136
target_compile_options(reflectcpp PRIVATE -Wall)
3237

3338
if (REFLECTCPP_BUILD_TESTS)
3439
add_subdirectory(tests)
35-
endif ()
40+
endif ()

README.md

+28-11
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,17 @@ Finally, it is very easy to extend full support to your own classes, refer to th
341341

342342
## Serialization formats
343343

344-
reflect-cpp currently supports the following serialization formats:
344+
reflect-cpp is deliberately designed in a very modular way, using [concepts](https://en.cppreference.com/w/cpp/language/constraints), to make it as easy as possible to interface C or C++ libraries for various serialization formats. Refer to the [documentation](https://github.com/getml/reflect-cpp/tree/main/docs) for details. PRs related to serialization formats are welcome.
345345

346-
- **JSON**: Out-of-the-box support, no additional dependencies required.
347-
- **flexbuffers**: Requires [flatbuffers](https://github.com/google/flatbuffers).
346+
The following table lists the serialization formats currently supported by reflect-cpp and the underlying libraries used:
348347

349-
reflect-cpp is deliberately designed in a very modular format, using [concepts](https://en.cppreference.com/w/cpp/language/constraints), to make it as easy as possible to support additional serialization formats. Refer to the [documentation](https://github.com/getml/reflect-cpp/tree/main/docs) for details. PRs related to serialization formats are welcome.
348+
| Format | Library | Version | License | Remarks |
349+
|--------------|------------------------------------------------------|--------------|------------| -----------------------------------------------------|
350+
| JSON | [YYJSON](https://github.com/ibireme/yyjson) | >= 0.8.0 | MIT | out-of-the-box support, included in this repository |
351+
| flexbuffers | [flatbuffers](https://github.com/google/flatbuffers) | >= 23.5.26#1 | Apache 2.0 | |
352+
| XML | [pugixml](https://github.com/zeux/pugixml) | >= 1.14 | MIT | |
353+
354+
Please also refer to the *vcpkg.json* in this repository.
350355

351356
## Documentation
352357

@@ -367,7 +372,7 @@ If you **do not** need JSON support or you want to link YYJSON yourself, then re
367372

368373
Simply copy the contents of the folder `include` into your source repository or add it to your include path and also add `src/yyjson.c` to your source files for compilation.
369374

370-
If you need support for other serialization formats like flexbuffers, you should also include and link the respective libraries, as listed in the previous section.
375+
If you need support for other serialization formats like flexbuffers or XML, you should also include and link the respective libraries, as listed in the section on serialization formats.
371376

372377
### Option 3: Compilation using cmake
373378

@@ -399,6 +404,7 @@ To use reflect-cpp in your project:
399404
add_subdirectory(reflect-cpp) # Add this project as a subdirectory
400405
401406
set(REFLECTCPP_FLEXBUFFERS ON) # Optional
407+
set(REFLECTCPP_XML ON) # Optional
402408
403409
target_link_libraries(your_project PRIVATE reflectcpp) # Link against the library
404410
```
@@ -413,17 +419,26 @@ vcpkg is a great, but very ambitious and complex project (just like C++ is a gre
413419

414420
3. On some occasions you might be asked to specify a compiler. You can do so by simply adding it to the cmake command as follows: `cmake -S . -B build ... -DCMAKE_C_COMPILER=gcc -DCMAKE_C_COMPILER=g++` or `cmake -S . -B build ... -DCMAKE_C_COMPILER=clang-17 -DCMAKE_C_COMPILER=clang++-17` (or whatever supported compiler you would like to use).
415421

416-
## Compiling the tests
422+
## Compiling and running the tests
423+
424+
### JSON only
417425

418426
To compile the tests, do the following:
419427

420428
```bash
421429
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DREFLECTCPP_BUILD_TESTS=ON
422430
cmake --build build -j 4 # gcc, clang
423431
cmake --build build --config Release -j 4 # MSVC
432+
```
433+
434+
To run the tests, do the following:
435+
436+
```
424437
./build/tests/json/reflect-cpp-json-tests
425438
```
426439

440+
### All serialization formats
441+
427442
To compile the tests with serialization formats other than JSON, do the following:
428443

429444
```bash
@@ -433,11 +448,17 @@ git submodule update --init
433448
./vcpkg/bootstrap-vcpkg.bat # Windows
434449
# You may be prompted to install additional dependencies.
435450

436-
cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_FLEXBUFFERS=ON -DCMAKE_BUILD_TYPE=Release
451+
cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_FLEXBUFFERS=ON -DREFLECTCPP_XML=ON -DCMAKE_BUILD_TYPE=Release
437452
cmake --build build -j 4 # gcc, clang
438453
cmake --build build --config Release -j 4 # MSVC
454+
```
455+
456+
To run the tests, do the following:
457+
458+
```
439459
./build/tests/flexbuffers/reflect-cpp-flexbuffers-tests
440460
./build/tests/json/reflect-cpp-json-tests
461+
./build/tests/xml/reflect-cpp-xml-tests
441462
```
442463

443464
## Related projects
@@ -453,7 +474,3 @@ reflect-cpp has been developed by [scaleML](https://www.scaleml.de), a company s
453474
reflect-cpp is released under the MIT License. Refer to the LICENSE file for details.
454475

455476
reflect-cpp includes [YYJSON](https://github.com/ibireme/yyjson), the fastest JSON library currently in existence. YYJSON is written by YaoYuan and also released under the MIT License.
456-
457-
458-
459-

0 commit comments

Comments
 (0)