Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
78dd283
Ensure disabled MacOS build
Twon Oct 25, 2022
2020f15
Functional wrappers for serilisation
Twon Oct 25, 2022
624f6c3
Directive log to track serialisation
Twon Oct 25, 2022
4740f42
Merge branch 'main' into further_serialisation
Twon Nov 1, 2022
2c95e74
Minor fixes
Twon Nov 4, 2022
393984e
Support Date across compilers
Twon Nov 8, 2022
a718410
Merge branch 'main' into further_serialisation
Twon Nov 9, 2022
65f2293
Move to coroutine generator support to deserialisation of sequences
Twon Nov 24, 2022
d67ca23
Merged github action
Twon Nov 24, 2022
8628a5c
Merge branch 'main' into further_serialisation
Twon Nov 26, 2022
d6b72cf
Serialisation mocking update
Twon Nov 26, 2022
f7b475d
Merge branch 'main' into further_serialisation
Twon Jan 15, 2023
976f439
Merge branch 'main' into further_serialisation
Twon Apr 1, 2023
a9cf72e
Formatting
Twon Apr 1, 2023
3460dc9
Formatting
Twon Apr 29, 2023
8a5ab76
Merge branch 'main' into further_serialisation
Twon May 1, 2023
1f25c5e
Merge branch 'main' into further_serialisation
Twon May 13, 2023
0ae7b0b
Merge branch 'further_serialisation' of github.com:Twon/Morpheus into…
Twon May 13, 2023
f0dde1d
Merge branch 'main' into further_serialisation
Twon May 14, 2023
22f44cc
Directives picked up by mocking
Twon May 14, 2023
f97044b
Ranges merge fixes
Twon May 14, 2023
714ea29
Merge branch 'main' into further_serialisation
Twon May 14, 2023
888b459
Merge branch 'main' into further_serialisation
Twon May 15, 2023
9027104
Merge branch 'main' into further_serialisation
Twon Jul 14, 2023
952636f
Deserialise for ranges
Twon Jul 15, 2023
dfb3544
Test clean up
Twon Jul 15, 2023
b8dce1a
Ensure tests are run for builds
Twon Jul 16, 2023
0f9e9f6
Remove inner lambda and simply with repeat current
Twon Jul 16, 2023
8d83efd
Enable debugging on the CI
Twon Jul 16, 2023
c13ad27
Merge branch 'main' into further_serialisation
Twon Aug 8, 2023
97a3401
Merge branch 'main' into further_serialisation
Twon Aug 11, 2023
57ae2da
Merge branch 'further_serialisation' of github.com:Twon/Morpheus into…
Twon Aug 11, 2023
39e8203
Merge fix
Twon Aug 11, 2023
93e4541
work in progress changes for range deserialisation tests
Twon Aug 21, 2023
b5bdc43
Reader need sequence support
Twon Aug 21, 2023
8cf5479
Merge branch 'main' into further_serialisation
Twon Aug 26, 2023
e35db94
Merge branch 'main' into further_serialisation
Twon Sep 6, 2023
a021b54
Merge branch 'main' into further_serialisation
Twon Sep 12, 2023
027a623
Merge branch 'further_serialisation' of github.com:Twon/Morpheus into…
Twon Sep 12, 2023
8e9e829
Merge branch 'main' into further_serialisation
Twon Sep 13, 2023
075b4c7
Span of bytes is also a native type
Twon Sep 13, 2023
e7f7c45
Merge branch 'main' into further_serialisation
Twon Sep 16, 2023
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
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ include(CTest)
include(FetchContent)
include(GNUInstallDirs)
include(CMakeDependentOption)

include(CMakePackageConfigHelpers)

option(MORPHEUS_ENABLE_TESTS "Build Morpheus tests" OFF)
option(MORPHEUS_ENABLE_EXAMPLES "Build Morpheus examples" OFF)
cmake_dependent_option(MORPHEUS_CODE_COVERAGE "Enable code coverage" ON "\"${CMAKE_CXX_COMPILER_ID}\" STREQUAL \"Clang\" OR \"${CMAKE_CXX_COMPILER_ID}\" STREQUAL \"GNU\"" OFF)
cmake_dependent_option(MORPHEUS_INCLUDE_NATVIS "Enable inclusion of a natvis files for debugging" ON "\"${CMAKE_CXX_COMPILER_ID}\" STREQUAL \"MSVC\"" OFF)

Expand Down
29 changes: 22 additions & 7 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from conan import ConanFile
from conan.errors import ConanException, ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import cmake_layout, CMake, CMakeDeps
from conan.tools.cmake import cmake_layout, CMake, CMakeDeps, CMakeToolchain
from conan.tools.files import copy
from conan.tools.scm import Version
from conan.tools.files import load
Expand Down Expand Up @@ -56,23 +56,24 @@ class Morpheus(ConanFile):
"shared": [True, False],
"fPIC": [True, False],
"tools": [True, False],
"build_docs": [True, False]
"build_docs": [True, False],
"build_tests": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"tools": True,
"build_docs": False
"build_docs": False,
"build_tests": True
}
exports_sources = ["CMakeLists.txt", "LICENSE", "version.txt", "cmake/*", "examples/*" "libraries/*"]
generators = "CMakeDeps", "CMakeToolchain"
#generators = "CMakeDeps", "CMakeToolchain"
requires = (
"boost/1.82.0",
"ctre/3.8",
"fmt/[^10]",
"glbinding/3.1.0",
"glew/2.2.0",
"gtest/1.13.0",
"magic_enum/0.8.2",
"ms-gsl/4.0.0",
"rapidjson/cci.20220822",
Expand All @@ -93,7 +94,12 @@ def set_version(self):

def build_requirements(self):
self.tool_requires("ninja/1.11.1")
self.test_requires("catch2/3.4.0")

if self.options.build_tests:
self.test_requires("gtest/1.13.0")
#self.test_requires("rapidcheck/cci.20220514", options={'enable_catch':'True'})
#self.requires("catch2/3.3.2", override=True, test=True) # Should be 'test_requires' but that does not allow override which we need for catch2.
self.test_requires("catch2/3.4.0")

if get_cmake_version() < Version("3.27.0"):
self.tool_requires("cmake/3.27.0")
Expand Down Expand Up @@ -129,7 +135,7 @@ def _minimum_compilers_version(self):
"apple-clang": "13"
}

def configure(self):
def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, self._minimum_cpp_standard)
min_version = self._minimum_compilers_version.get(
Expand All @@ -146,6 +152,15 @@ def configure(self):
self.name, self._minimum_cpp_standard,
self.settings.compiler,
self.settings.compiler.version))

def generate(self):
tc = CMakeToolchain(self)
tc.variables["MORPHEUS_ENABLE_TESTS"] = self.options.build_tests
tc.variables["MORPHEUS_BUILD_DOCUMENTATION"] = self.options.build_docs
tc.generate()

tc = CMakeDeps(self)
tc.generate()

# def generate(self):
# tc = CMakeToolchain(self, generator=os.getenv("CONAN_CMAKE_GENERATOR"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ class Reader
{
return read(T{});
}

/* template <typename T>
T readSequence()
requires requires(Reader r) { r.read(T{}); }
{
return read(T{});
}
*/
};

} // namespace morpheus::serialisation::mock
25 changes: 18 additions & 7 deletions libraries/core/src/morpheus/core/concurrency/generator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ struct Generator
using reference = std::conditional_t<std::is_reference_v<T>, T, const value_type&>;
using pointer = std::add_pointer_t<reference>;

Generator(handle_type h) : coro(h) {}
Generator(handle_type h)
: coro(h)
{}

/// Destroys the generator.
~Generator()
Expand All @@ -38,7 +40,9 @@ struct Generator
Generator(const Generator&) = delete;
Generator& operator=(const Generator&) = delete;

Generator(Generator&& rhs) noexcept : coro(std::exchange(rhs.coro, {})) {}
Generator(Generator&& rhs) noexcept
: coro(std::exchange(rhs.coro, {}))
{}

Generator& operator=(Generator&& rhs) noexcept
{
Expand All @@ -54,7 +58,10 @@ struct Generator

auto get_return_object() { return Generator{handle_type::from_promise(*this)}; }

auto return_void() { return coro_ns::suspend_never{}; }
// auto return_void() {
// return coro_ns::suspend_never{};
// }
void return_void() noexcept {}

auto yield_value(const T value)
{
Expand All @@ -73,16 +80,18 @@ struct Generator
{
public:
using value_type = Generator::value_type; ///< Value type pointed to by the iterator.
using reference = Generator::reference; ///< Reference to the underlying value type pointed to by the iterator.
using pointer = Generator::pointer; ///< Pointer to the underlying value type pointed to by the iterator.
using reference = Generator::reference; ///< Reference to the underlying value type pointed to by the iterator.
using pointer = Generator::pointer; ///< Pointer to the underlying value type pointed to by the iterator.
using difference_type = std::ptrdiff_t;
using iterator_category = std::input_iterator_tag;

iterator() = default;
iterator(iterator const& rhs) noexcept = default;
iterator& operator=(iterator const& other) noexcept = default;

iterator(iterator&& rhs) noexcept : handle(std::exchange(rhs.handle, {})) {}
iterator(iterator&& rhs) noexcept
: handle(std::exchange(rhs.handle, {}))
{}

iterator& operator=(iterator&& other) noexcept
{
Expand Down Expand Up @@ -112,7 +121,9 @@ struct Generator
private:
friend Generator;

explicit iterator(coro_ns::coroutine_handle<promise_type> h) noexcept : handle(h) {}
explicit iterator(coro_ns::coroutine_handle<promise_type> h) noexcept
: handle(h)
{}

coro_ns::coroutine_handle<promise_type> handle;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
target_sources(MorpheusCore
PUBLIC
array.hpp
chrono.hpp
deque.hpp
expected.hpp
forward_list.hpp
Expand All @@ -9,8 +10,10 @@ target_sources(MorpheusCore
monostate.hpp
optional.hpp
pair.hpp
ranges.hpp
set.hpp
source_location.hpp
span.hpp
tuple.hpp
unique_ptr.hpp
unordered_set.hpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ T deserialise(Serialiser& serialiser)
exp_ns::unexpected(serialiser.template deserialise<typename T::error_type>("error")));
}

} // namespace morpheus::serialisation::detail
} // namespace morpheus::serialisation::detail
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ concept IsStdPair = meta::IsSpecialisationOf<std::pair, T>;
template<concepts::WriteSerialiser Serialiser, concepts::WriteSerialisable T1, concepts::WriteSerialisable T2>
void serialise(Serialiser& serialiser, std::pair<T1, T2> const& value)
{
serialiser.writer().beginSequence(std::tuple_size<std::pair<T1, T2>>::value);
serialiser.serialise(value.first);
serialiser.serialise(value.second);
serialiser.writer().endSequence();
serialiser.serialise(std::tuple_size<std::pair<T1, T2>>::value, [&]()
{
serialiser.serialise(value.first);
serialiser.serialise(value.second);
});
}

template<concepts::ReadSerialiser Serialiser, IsStdPair T>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once

#include "morpheus/core/conformance/ranges.hpp"
#include "morpheus/core/meta/concepts/string.hpp"
#include "morpheus/core/serialisation/concepts/read_serialisable.hpp"
#include "morpheus/core/serialisation/concepts/read_serialiser.hpp"
#include "morpheus/core/serialisation/concepts/write_serialisable.hpp"
Expand Down Expand Up @@ -31,4 +30,18 @@ void serialise(Serialiser& serialiser, IsRange auto const& range)
serialiser.writer().endSequence();
}

} // namespace morpheus::serialisation::detail
template<concepts::ReadSerialiser Serialiser, IsRange T>
T deserialise(Serialiser& serialiser)
{
auto const scope = makeScopedSequence(serialiser.reader());
auto sequenceGenerator = serialiser.reader().template readSequence<int>();
// We should be using the for_range_t constructor create the container but there is no support for this in Gcc 12 and Clang 15.
// T sequence(std::from_range_t, sequenceGenerator);
T sequence;
for (auto& entry : sequenceGenerator) {
sequence.push_back(entry);
}
return sequence;
}

} // namespace morpheus::serialisation::detail
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "morpheus/core/serialisation/adapters/std/ranges.hpp"

#include <vector>

namespace morpheus::serialisation::detail
{

template <typename T>
inline constexpr bool isEnabledForRangeSerialisation<std::span<T>> = true;

/// std::span<std::byte> is handled by the native interface.
template <>
inline constexpr bool isEnabledForRangeSerialisation<std::span<std::byte>> = false;

} // namespace morpheus::serialisation::detail
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ template<concepts::WriteSerialiser Serialiser, concepts::WriteSerialisable... T>
void serialise(Serialiser& serialiser, std::tuple<T...> const& value)
{
constexpr auto size = std::tuple_size<std::tuple<T...>>::value;
serialiser.writer().beginSequence(size);
[&] <std::size_t... Indexes>(std::index_sequence<Indexes...>)
{
(serialiser.serialise(std::get<Indexes>(value)), ...);
}(std::make_index_sequence<size>());
serialiser.writer().endSequence();
serialiser.serialise(size,
[&] <std::size_t... Indexes>(std::index_sequence<Indexes...>)
{
return [&] { (serialiser.serialise(std::get<Indexes>(value)), ...); };
}(std::make_index_sequence<size>())
);
}

template<concepts::ReadSerialiser Serialiser, IsStdTuple T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,25 @@ template<concepts::WriteSerialiser Serialiser, concepts::WriteSerialisable... T>
void serialise(Serialiser& serialiser, std::variant<T...> const& value)
{
serialiser.writer().beginComposite();
if (value.valueless_by_exception()) [[unlikely]]
// serialiser.serialise([&]()
{
serialiser.serialise("index", static_cast<std::uint64_t>(std::variant_npos));
}
else
{
if (serialiser.writer().isTextual())
if (value.valueless_by_exception()) [[unlikely]]
{
serialiser.serialise("type", TypeListNames<std::variant<T...>>::name(value.index()));
serialiser.serialise("index", static_cast<std::uint64_t>(std::variant_npos));
}
else
serialiser.serialise("index", static_cast<std::uint64_t>(value.index()));
{
if (serialiser.writer().isTextual())
{
serialiser.serialise("type", TypeListNames<std::variant<T...>>::name(value.index()));
}
else
serialiser.serialise("index", static_cast<std::uint64_t>(value.index()));

std::visit([&serialiser](auto const& value) { serialiser.serialise("value", value); }, value);
std::visit([&serialiser](auto const& value) { return serialiser.serialise("value", value); }, value);
}
}
//);
serialiser.writer().endComposite();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ namespace morpheus::serialisation::detail
template <typename T, typename A>
inline constexpr bool isEnabledForRangeSerialisation<std::vector<T, A>> = true;

/// std::vector<std::byte>> is handled by the native interface.
template <>
inline constexpr bool isEnabledForRangeSerialisation<std::vector<std::byte>> = false;

} // namespace morpheus::serialisation::detail
11 changes: 10 additions & 1 deletion libraries/core/src/morpheus/core/serialisation/json_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,19 @@ struct JsonExtracter : rapidjson::BaseReaderHandler<rapidjson::UTF8<>, JsonExtra
JsonReader::EventValue mCurrent; ///< Current json event.
};


void JsonReader::repeatCurrent()
{
MORPHEUS_ASSERT(!mRepeat);
mRepeat = true;
}

JsonReader::EventValue JsonReader::getNext()
{
if (mRepeat) {
mRepeat = false;
return mExtractor->mCurrent;
}

using namespace rapidjson;
mJsonReader.IterativeParseNext<kParseCommentsFlag | kParseNanAndInfFlag | kParseValidateEncodingFlag>(mStream, *mExtractor);
if (mJsonReader.HasParseError()) {
Expand Down
Loading