Skip to content

Commit

Permalink
+ add some convinient funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualGMQ committed Nov 21, 2023
1 parent 49342a9 commit 95e3ae6
Show file tree
Hide file tree
Showing 19 changed files with 257 additions and 70 deletions.
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ project(mirrow

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

add_subdirectory(serd_backend/tomlplusplus)

aux_source_directory(src/drefl mirrow_src)
aux_source_directory(src/serd/dynamic/backends mirrow_src)
add_library(mirrow STATIC ${mirrow_src})

file(GLOB_RECURSE mirrow_header_files "./include/*.hpp")

add_library(mirrow STATIC ${mirrow_src} ${mirrow_header_files})
target_include_directories(mirrow PUBLIC ./include)
target_link_libraries(mirrow PUBLIC tomlplusplus::tomlplusplus)
target_compile_features(mirrow PUBLIC cxx_std_17)

option(MIRROW_BUILD_TEST "build test" OFF)
option(MIRROW_TEST_ENABLE_TOML++ "enable test serialization with toml++" OFF)

if (PROJECT_IS_TOP_LEVEL)
set(MIRROW_BUILD_TEST ON CACHE BOOL "build test" FORCE)
set(MIRROW_TEST_ENABLE_TOML++ ON CACHE BOOL "enable test serialization with toml++" FORCE)
endif()

if (MIRROW_BUILD_TEST)
enable_testing()
if (MIRROW_TEST_ENABLE_TOML++)
add_subdirectory(serd_backend/tomlplusplus)
target_link_libraries(mirrow PRIVATE tomlplusplus::tomlplusplus)
endif()
add_subdirectory(test)
endif()
16 changes: 16 additions & 0 deletions include/mirrow/drefl/any.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,22 @@ class any final {
return {access_type::Copy, elem, operations_, type_};
}

void copy_assign(any& o) {
if (o.type_info() == type_info()) {
operations_->copy_assignment(payload_, o.payload_);
} else {
MIRROW_LOG("can't copy assign between two different types");
}
}

void steal_assign(any&& o) {
if (o.type_info() == type_info()) {
operations_->steal_assignment(payload_, o.payload_);
} else {
MIRROW_LOG("can't copy assign between two different types");
}
}

any steal() {
auto access = access_;
auto payload = operations_->steal_construct(payload_);
Expand Down
20 changes: 16 additions & 4 deletions include/mirrow/drefl/class.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once

#include "mirrow/drefl/type.hpp"
#include "mirrow/drefl/qualifier.hpp"
#include "mirrow/drefl/type.hpp"
#include "mirrow/util/misc.hpp"
#include <memory>
#include <type_traits>
#include <vector>


namespace mirrow::drefl {

#define SET_QUALIFIER_BIT(qualif, newBit) \
Expand Down Expand Up @@ -40,16 +41,27 @@ class clazz final : public type {
template <typename T>
friend class class_factory;

explicit clazz(const std::string& name): type(value_kind::Class, name) {}
clazz(): type(value_kind::Class) {}
using default_construct_fn = any(void);

explicit clazz(const std::string& name, default_construct_fn dc)
: type(value_kind::Class, name), default_construct_(dc) {}

clazz() : type(value_kind::Class) {}

auto& properties() const noexcept { return properties_; }

void set_value(any& from, any& to);
void steal_value(any& from, any& to);

bool is_default_constructbile() const noexcept {
return default_construct_ != nullptr;
}

any default_construct() const;

private:
std::vector<std::shared_ptr<property>> properties_;
default_construct_fn* default_construct_ = nullptr;
};

}
} // namespace mirrow::drefl
42 changes: 0 additions & 42 deletions include/mirrow/drefl/class_factory.hpp

This file was deleted.

6 changes: 6 additions & 0 deletions include/mirrow/drefl/drefl.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#pragma once

#include "mirrow/drefl/any.hpp"
#include "mirrow/drefl/factory.hpp"
#include "mirrow/drefl/cast_any.hpp"
#include "mirrow/drefl/make_any.hpp"
Loading

0 comments on commit 95e3ae6

Please sign in to comment.