Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 27 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,50 +40,46 @@ project(reflectcpp LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)

if(REFLECTCPP_USE_BUNDLED_DEPENDENCIES)
if (REFLECTCPP_BUILD_SHARED)
add_library(reflectcpp SHARED)
else()
add_library(reflectcpp STATIC)
endif()
if (REFLECTCPP_BUILD_SHARED)
add_library(reflectcpp SHARED)
else()
add_library(reflectcpp STATIC)
endif()

target_sources(reflectcpp PRIVATE src/reflectcpp.cpp src/yyjson.c)
set_source_files_properties(src/yyjson.c PROPERTIES LANGUAGE CXX)
if (MSVC)
target_compile_options(reflectcpp PRIVATE $<$<CONFIG:Debug>:-Wall>)
else()
target_compile_options(reflectcpp PRIVATE $<$<CONFIG:Debug>:-Wall -Wextra>)
endif()

target_compile_features(reflectcpp PUBLIC cxx_std_20)
target_compile_features(reflectcpp PUBLIC cxx_std_20)

if (MSVC)
target_compile_options(reflectcpp PRIVATE $<$<CONFIG:Debug>:-Wall>)
else()
target_compile_options(reflectcpp PRIVATE $<$<CONFIG:Debug>:-Wall -Wextra>)
endif()
set(REFLECT_CPP_SOURCES
src/reflectcpp.cpp
)

target_include_directories(
reflectcpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/rfl/thirdparty>)
else()
if (REFLECTCPP_BUILD_SHARED)
add_library(reflectcpp SHARED)
else()
add_library(reflectcpp STATIC)
endif()
target_include_directories(
reflectcpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

target_sources(reflectcpp PRIVATE src/reflectcpp.cpp)
if(REFLECTCPP_USE_BUNDLED_DEPENDENCIES)
list(APPEND REFLECT_CPP_SOURCES
src/yyjson.c
)
set_source_files_properties(src/yyjson.c PROPERTIES LANGUAGE CXX)

target_include_directories(
reflectcpp PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)

target_compile_features(reflectcpp PUBLIC cxx_std_20)

$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/rfl/thirdparty>)
else()
find_package(ctre CONFIG REQUIRED)
find_package(yyjson CONFIG REQUIRED)
target_link_libraries(reflectcpp INTERFACE ctre::ctre yyjson::yyjson)
endif()

target_sources(reflectcpp PRIVATE ${REFLECT_CPP_SOURCES})

set_target_properties(reflectcpp PROPERTIES LINKER_LANGUAGE CXX)

if (REFLECTCPP_BSON)
Expand Down
114 changes: 114 additions & 0 deletions src/Generic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*

MIT License

Copyright (c) 2023-2024 Code17 GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

#include "rfl/Generic.hpp"

namespace rfl {

Generic::Generic() : value_(false) {}

Generic::Generic(Generic&& _other) noexcept = default;

Generic::Generic(const Generic& _other) = default;

Generic::Generic(const ReflectionType& _value) : value_(_value) {}

Generic::Generic(ReflectionType&& _value) noexcept
: value_(std::move(_value)) {}

Generic::~Generic() = default;

Generic& Generic::operator=(const ReflectionType& _value) {
value_ = _value;
return *this;
}

Generic& Generic::operator=(ReflectionType&& _value) noexcept {
value_ = std::move(_value);
return *this;
}

Generic& Generic::operator=(const Generic& _other) = default;

Generic& Generic::operator=(Generic&& _other) = default;

Result<Generic::Array> Generic::to_array() const noexcept {
if (const auto* ptr = std::get_if<Array>(&value_)) {
return *ptr;
} else {
return Error(
"rfl::Generic: Could not cast the underlying value to an "
"rfl::Generic::Array.");
}
}

Result<bool> Generic::to_bool() const noexcept {
if (const auto* ptr = std::get_if<bool>(&value_)) {
return *ptr;
} else {
return Error(
"rfl::Generic: Could not cast the underlying value to a boolean.");
}
}

Result<double> Generic::to_double() const noexcept {
if (const auto* ptr = std::get_if<double>(&value_)) {
return *ptr;
} else {
return Error(
"rfl::Generic: Could not cast the underlying value to a double.");
}
}

Result<int> Generic::to_int() const noexcept {
if (const auto* ptr = std::get_if<int>(&value_)) {
return *ptr;
} else {
return Error(
"rfl::Generic: Could not cast the underlying value to an integer.");
}
}

Result<Generic::Object> Generic::to_object() const noexcept {
if (const auto* ptr = std::get_if<Object>(&value_)) {
return *ptr;
} else {
return Error(
"rfl::Generic: Could not cast the underlying value to an "
"rfl::Generic::Object.");
}
}

Result<std::string> Generic::to_string() const noexcept {
if (const auto* ptr = std::get_if<std::string>(&value_)) {
return *ptr;
} else {
return Error(
"rfl::Generic: Could not cast the underlying value to a string.");
}
}

} // namespace rfl
40 changes: 40 additions & 0 deletions src/Type.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*

MIT License

Copyright (c) 2023-2024 Code17 GmbH

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

#include "rfl/parsing/schema/Type.hpp"

namespace rfl::parsing::schema {

/// Requires a lot of template instantiation, so we do not want this to be
/// inlined.

Type::Type() : variant_() {}

Type::Type(const VariantType& _variant) : variant_(_variant) {}

Type::~Type() = default;

} // namespace rfl::parsing::schema
Loading