add new tool to generate default data of root.nf7
This commit is contained in:
parent
ab6c7f7507
commit
59735f3ab7
@ -7,6 +7,7 @@ project(nf7 CXX)
|
||||
option(NF7_STATIC "link all libs statically" ON)
|
||||
|
||||
set(NF7_GENERATED_INCLUDE_DIR "${PROJECT_BINARY_DIR}/include/generated")
|
||||
file(MAKE_DIRECTORY "${NF7_GENERATED_INCLUDE_DIR}")
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
@ -20,6 +21,7 @@ set(NF7_CXX_FLAGS
|
||||
)
|
||||
|
||||
add_subdirectory(thirdparty EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(tool)
|
||||
|
||||
|
||||
# ---- application ----
|
||||
@ -59,3 +61,14 @@ target_link_libraries(nf7
|
||||
source_location
|
||||
yas
|
||||
)
|
||||
|
||||
# ---- resource compile ----
|
||||
set(NF7_DEFAULT_ROOT_INC "${NF7_GENERATED_INCLUDE_DIR}/root.nf7.inc")
|
||||
add_custom_command(
|
||||
OUTPUT ${NF7_DEFAULT_ROOT_INC}
|
||||
DEPENDS nf7-init
|
||||
COMMAND $<TARGET_FILE:nf7-init> > ${NF7_DEFAULT_ROOT_INC}
|
||||
COMMENT "generating root.nf7..."
|
||||
VERBATIM
|
||||
)
|
||||
target_sources(nf7 PRIVATE ${NF7_DEFAULT_ROOT_INC})
|
||||
|
3
tool/CMakeLists.txt
Normal file
3
tool/CMakeLists.txt
Normal file
@ -0,0 +1,3 @@
|
||||
add_executable(nf7-init)
|
||||
target_link_libraries(nf7-init PRIVATE yas)
|
||||
target_sources(nf7-init PRIVATE init.cc)
|
56
tool/init.cc
Normal file
56
tool/init.cc
Normal file
@ -0,0 +1,56 @@
|
||||
#include <cassert>
|
||||
#include <functional>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <yas/serialize.hpp>
|
||||
#include <yas/types/std/map.hpp>
|
||||
#include <yas/types/std/string.hpp>
|
||||
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
|
||||
using Ar = yas::binary_oarchive<yas::mem_ostream>;
|
||||
using L = std::function<void(void)>;
|
||||
|
||||
namespace yas::detail {
|
||||
template <size_t F>
|
||||
struct serializer<
|
||||
type_prop::not_a_fundamental,
|
||||
ser_case::use_internal_serializer,
|
||||
F,
|
||||
L> {
|
||||
public:
|
||||
static Ar& save(Ar& ar, const L& f) {
|
||||
f();
|
||||
return ar;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
L Write(Ar& ar, Args&&... args) {
|
||||
return [...args = std::forward<Args>(args), &ar]() mutable {
|
||||
ar(std::forward<Args>(args)...);
|
||||
};
|
||||
}
|
||||
int main(void) {
|
||||
yas::mem_ostream os;
|
||||
Ar ar(os);
|
||||
|
||||
ar("Dir"s);
|
||||
ar(std::map<std::string, L> {
|
||||
{ "home"s, Write(ar, "Dir"s, std::map<std::string, L> {}, false) },
|
||||
}, false);
|
||||
|
||||
const auto buf = os.get_shared_buffer();
|
||||
for (size_t i = 0; i < buf.size;) {
|
||||
for (size_t j = 0; j < 32 && i < buf.size; ++j, ++i) {
|
||||
std::cout << static_cast<int>(buf.data.get()[i]) << ',';
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user