Skip to content

Commit 3dc6d22

Browse files
-bundled nameof
-updated unit tests -added static reflection examples and functional tests
1 parent c95b65e commit 3dc6d22

Some content is hidden

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

44 files changed

+512
-50
lines changed

.github/workflows/build_and_test.yml

+18-6
Original file line numberDiff line numberDiff line change
@@ -29,30 +29,30 @@ jobs:
2929
cc: "gcc",
3030
cxx: "g++",
3131
flags: "-Wall -Werror -Wextra -Wpedantic -Wcast-align -Wnon-virtual-dtor -Woverloaded-virtual -Wunused",
32-
artifacts-path: "build/examples"
32+
artifacts-path: ""
3333
}
3434
- {
3535
name: "Ubuntu Latest clang",
3636
os: ubuntu-latest,
3737
cc: "clang",
3838
cxx: "clang++",
3939
flags: "-Wall -Werror -Wextra -Wpedantic -Wcast-align -Wnon-virtual-dtor -Woverloaded-virtual -Wunused",
40-
artifacts-path: "build/examples"
40+
artifacts-path: ""
4141
}
4242
- {
4343
name: "Windows Latest MSVC",
4444
os: windows-latest,
4545
cc: "cl",
4646
cxx: "cl",
4747
flags: "/EHsc /W4 /WX /wd4267",
48-
artifacts-path: "build/examples/Release"
48+
artifacts-path: "/Release"
4949
}
5050

5151
steps:
5252
- uses: actions/checkout@v3
5353

5454
- name: Configure CMake
55-
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON -DENABLE_EXAMPLES=ON -DFIGCONE_USE_NAMEOF=${{ matrix.use_nameof }} -DCMAKE_CXX_FLAGS="${{ matrix.config.flags }}"
55+
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON -DENABLE_TESTS_CPP20=ON -DENABLE_TESTS_STATIC_REFL=ON -DENABLE_EXAMPLES=ON -DENABLE_EXAMPLES_STATIC_REFL=ON -DFIGCONE_USE_NAMEOF=${{ matrix.use_nameof }} -DCMAKE_CXX_FLAGS="${{ matrix.config.flags }}"
5656

5757
- name: Build
5858
run: cmake --build ${{github.workspace}}/build --config Release
@@ -65,7 +65,9 @@ jobs:
6565
uses: actions/upload-artifact@v3
6666
with:
6767
name: figcone-examples-${{ matrix.config.os }}-nameof-${{ matrix.use_nameof }}
68-
path: ${{ matrix.config.artifacts-path }}
68+
path: |
69+
${{github.workspace}}/build/examples${{ matrix.config.artifacts-path }}
70+
${{github.workspace}}/build/examples_static_refl${{ matrix.config.artifacts-path }}
6971
7072
functional_tests:
7173
name: Functional testing (${{ matrix.config.name }}, nameof = ${{ matrix.use_nameof }})
@@ -110,12 +112,22 @@ jobs:
110112
uses: actions/download-artifact@v3
111113
with:
112114
name: figcone-examples-${{ matrix.config.os }}-nameof-${{ matrix.use_nameof }}
113-
path: build/examples
115+
path: build/
116+
- name: Fix artifacts paths on Windows
117+
if: matrix.config.name == 'Windows'
118+
working-directory: ${{github.workspace}}/build/
119+
shell: sh
120+
run: mv examples_static_refl/Release/* examples_static_refl/ && mv examples/Release/* examples/ || true
114121
- name: Set artifacts execute permissions
115122
if: matrix.config.name == 'Linux'
116123
shell: sh
117124
working-directory: ${{github.workspace}}/build/examples
118125
run: chmod +x ex* && chmod +x demo_*
126+
- name: Set artifacts execute permissions
127+
if: matrix.config.name == 'Linux'
128+
shell: sh
129+
working-directory: ${{github.workspace}}/build/examples_static_refl
130+
run: chmod +x ex* && chmod +x demo_*
119131
- name: Launch tests
120132
id: launch_tests
121133
working-directory: ${{github.workspace}}

CMakeLists.txt

+18-14
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,25 @@ SealLake_Import(
1010
GIT_TAG v2.0.0
1111
)
1212

13-
option(FIGCONE_USE_NAMEOF "Enable automatic registration of struct field names using the nameof library" OFF)
13+
option(FIGCONE_USE_NAMEOF "Enable automatic registration of struct field names using the nameof library" ON)
1414
if (FIGCONE_USE_NAMEOF)
1515
SealLake_IsInstalled(NAMEOF_OPT_INSTALL)
1616
SealLake_Bundle(
17-
NAME nameof
17+
NAME figcone_nameof
18+
SKIP_LOAD
1819
GIT_REPOSITORY https://github.com/Neargye/nameof.git
1920
GIT_TAG master
21+
DESTINATION include/figcone/detail/external
22+
FILES include/nameof.hpp
23+
TEXT_REPLACEMENTS
24+
"namespace nameof" "namespace figcone::nameof"
25+
"NAMEOF_" "FIGCONE_NAMEOF_"
2026
)
2127
endif ()
2228

2329
SealLake_Bundle(
2430
NAME figcone_pfr
31+
SKIP_LOAD
2532
GIT_REPOSITORY https://github.com/apolukhin/pfr_non_boost.git
2633
GIT_TAG 2.2.0
2734
DESTINATION include/figcone/detail/external
@@ -80,7 +87,7 @@ if (FIGCONE_USE_NAMEOF AND CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
8087
set(CPP_STANDARD_FEATURE cxx_std_20)
8188
else()
8289
set(CPP_STANDARD_FEATURE cxx_std_17)
83-
endif()
90+
endif ()
8491

8592
SealLake_HeaderOnlyLibrary(
8693
COMPILE_FEATURES ${CPP_STANDARD_FEATURE}
@@ -90,22 +97,19 @@ SealLake_HeaderOnlyLibrary(
9097
figcone_tree 2.0.0
9198
)
9299

93-
if (FIGCONE_USE_NAMEOF)
94-
SealLake_Libraries(
95-
nameof::nameof
96-
)
97-
SealLake_Dependencies(
98-
nameof 0.10.2
99-
)
100-
endif()
101-
102100
if (FIGCONE_USE_ALL OR FIGCONE_USE_JSON OR FIGCONE_USE_YAML OR FIGCONE_USE_TOML OR FIGCONE_USE_INI OR FIGCONE_USE_XML OR FIGCONE_USE_SHOAL)
103101
SealLake_Libraries(
104102
figcone::figcone_formats
105103
)
106104
SealLake_Dependencies(
107105
figcone_formats 1.0.0
108106
)
109-
endif()
107+
endif ()
110108

111-
SealLake_OptionalBuildSteps(tests tests_cpp20 examples)
109+
SealLake_OptionalBuildSteps(
110+
tests
111+
tests_cpp20
112+
tests_static_refl
113+
examples
114+
examples_static_refl
115+
)

examples/demo.h

+41-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,47 @@
11
#pragma once
2-
#include <figcone/config.h>
2+
#include <figcone/figcone.h>
33
#include <figcone/shortmacros.h> //enables macros without FIGCONE_ prefix
44
#include <string>
55
#include <vector>
66
#include <map>
77

8+
#ifdef FIGCONE_EXAMPLE_STATIC_REFLECTION
9+
10+
struct ThumbnailCfg {
11+
bool enabled = true;
12+
int maxWidth;
13+
int maxHeight;
14+
15+
using traits = figcone::FieldTraits<
16+
figcone::OptionalField<&ThumbnailCfg::enabled>>;
17+
};
18+
struct HostCfg {
19+
std::string ip;
20+
int port;
21+
};
22+
struct SharedAlbumCfg {
23+
std::filesystem::path dir;
24+
std::string name;
25+
std::vector<HostCfg> hosts;
26+
27+
using traits = figcone::FieldTraits<
28+
figcone::OptionalField<&SharedAlbumCfg::hosts>>;
29+
};
30+
struct PhotoViewerCfg {
31+
std::filesystem::path rootDir;
32+
std::vector<std::string> supportedFiles;
33+
ThumbnailCfg thumbnails;
34+
std::vector<SharedAlbumCfg> sharedAlbums;
35+
std::map<std::string, std::string> envVars;
36+
37+
using traits = figcone::FieldTraits<
38+
figcone::OptionalField<&PhotoViewerCfg::envVars>,
39+
figcone::OptionalField<&PhotoViewerCfg::sharedAlbums>,
40+
figcone::CopyNodeListField<&PhotoViewerCfg::sharedAlbums>>;
41+
};
42+
43+
#else
44+
845
struct ThumbnailCfg : public figcone::Config
946
{
1047
PARAM(enabled, bool)(true);
@@ -27,4 +64,6 @@ struct PhotoViewerCfg : public figcone::Config{
2764
COPY_NODELIST(sharedAlbums, std::vector<SharedAlbumCfg>)();
2865
using StringMap = std::map<std::string, std::string>;
2966
DICT(envVars, StringMap)();
30-
};
67+
};
68+
69+
#endif

examples/ex01.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#include <figcone/config.h>
2-
#include <figcone/configreader.h>
1+
#include <figcone/figcone.h>
32
#include <filesystem>
43
#include <iostream>
54
#include <vector>

examples/ex02.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#include <figcone/config.h>
2-
#include <figcone/configreader.h>
1+
#include <figcone/figcone.h>
32
#include <filesystem>
43
#include <iostream>
54
#include <vector>

examples/ex03.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#include <figcone/config.h>
2-
#include <figcone/configreader.h>
1+
#include <figcone/figcone.h>
32
#include <figcone/shortmacros.h> //enables macros without FIGCONE_ prefix
43
#include <filesystem>
54
#include <iostream>

examples/ex04.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#include <figcone/config.h>
2-
#include <figcone/configreader.h>
1+
#include <figcone/figcone.h>
32
#include <figcone/shortmacros.h>
43
#include <filesystem>
54
#include <iostream>

examples/ex05.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#include <figcone/config.h>
2-
#include <figcone/configreader.h>
1+
#include <figcone/figcone.h>
32
#include <algorithm>
43
#include <filesystem>
54
#include <iostream>

examples_static_refl/CMakeLists.txt

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
cmake_minimum_required(VERSION 3.18)
2+
project(figcone_examples_static_refl)
3+
4+
file(GLOB SRC_FILES "../examples/demo_*.cpp")
5+
foreach(SRC_FILE ${SRC_FILES})
6+
SealLake_StringAfterLast(${SRC_FILE} "/" TEST_NAME)
7+
SealLake_StringBeforeLast(${TEST_NAME} "." TEST_NAME)
8+
9+
SealLake_Executable(
10+
NAME ${TEST_NAME}_static_refl
11+
SOURCES ${SRC_FILE}
12+
COMPILE_FEATURES cxx_std_20
13+
PROPERTIES
14+
CXX_EXTENSIONS OFF
15+
LIBRARIES
16+
figcone::figcone
17+
)
18+
target_compile_definitions(${TEST_NAME}_static_refl PUBLIC "FIGCONE_EXAMPLE_STATIC_REFLECTION")
19+
endforeach()
20+
21+
set(EXAMPLE_SRC
22+
ex01_static_refl.cpp
23+
ex02_static_refl.cpp
24+
ex03_static_refl.cpp
25+
ex04_static_refl.cpp
26+
ex05_static_refl.cpp
27+
)
28+
foreach(SRC_FILE ${EXAMPLE_SRC})
29+
SealLake_StringAfterLast(${SRC_FILE} "/" TEST_NAME)
30+
SealLake_StringBeforeLast(${TEST_NAME} "." TEST_NAME)
31+
32+
SealLake_Executable(
33+
NAME ${TEST_NAME}
34+
SOURCES ${SRC_FILE}
35+
COMPILE_FEATURES cxx_std_20
36+
PROPERTIES
37+
CXX_EXTENSIONS OFF
38+
LIBRARIES
39+
figcone::figcone
40+
)
41+
endforeach()
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include "figcone/figcone.h"
2+
#include <filesystem>
3+
#include <iostream>
4+
#include <vector>
5+
6+
struct ThumbnailCfg {
7+
int maxWidth;
8+
int maxHeight;
9+
};
10+
11+
struct PhotoViewerCfg {
12+
std::filesystem::path rootDir;
13+
std::vector<std::string> supportedFiles;
14+
ThumbnailCfg thumbnailSettings;
15+
};
16+
17+
int main()
18+
{
19+
auto cfgReader = figcone::ConfigReader{};
20+
auto cfg = cfgReader.readToml<PhotoViewerCfg>(R"(
21+
rootDir = "~/Photos"
22+
supportedFiles = [".jpg", ".png"]
23+
[thumbnailSettings]
24+
maxWidth = 256
25+
maxHeight = 256
26+
)");
27+
//At this point your config is ready to use
28+
std::cout << "Launching PhotoViewer in directory " << cfg.rootDir << std::endl;
29+
30+
if (!cfg.supportedFiles.empty())
31+
std::cout << "Supported files:" << std::endl;
32+
for (const auto& file : cfg.supportedFiles)
33+
std::cout << " " << file << std::endl;
34+
35+
std::cout << "Thumbnail settings:" << std::endl;
36+
std::cout << " Max width:" << cfg.thumbnailSettings.maxWidth << std::endl;
37+
std::cout << " Max height:" << cfg.thumbnailSettings.maxHeight << std::endl;
38+
}
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <figcone/figcone.h>
2+
#include <filesystem>
3+
#include <iostream>
4+
#include <vector>
5+
6+
struct ThumbnailCfg {
7+
int maxWidth;
8+
int maxHeight;
9+
};
10+
11+
struct PhotoViewerCfg {
12+
std::filesystem::path rootDir;
13+
std::vector<std::string> supportedFiles;
14+
ThumbnailCfg thumbnailSettings;
15+
};
16+
17+
int main()
18+
{
19+
auto cfgReader = figcone::ConfigReader{figcone::NameFormat::SnakeCase};
20+
auto cfg = cfgReader.readToml<PhotoViewerCfg>(R"(
21+
root_dir = "/home/kamchatka-volcano/photos"
22+
supported_files = [".jpg", ".png"]
23+
[thumbnail_settings]
24+
max_width = 256
25+
max_height = 256
26+
)");
27+
//At this point your config is ready to use
28+
std::cout << "Launching PhotoViewer in directory " << cfg.rootDir << std::endl;
29+
30+
if (!cfg.supportedFiles.empty())
31+
std::cout << "Supported files:" << std::endl;
32+
for (const auto& file : cfg.supportedFiles)
33+
std::cout << " " << file << std::endl;
34+
35+
std::cout << "Thumbnail settings:" << std::endl;
36+
std::cout << " Max width:" << cfg.thumbnailSettings.maxWidth << std::endl;
37+
std::cout << " Max height:" << cfg.thumbnailSettings.maxHeight << std::endl;
38+
return 0;
39+
}

0 commit comments

Comments
 (0)