|
@@ -5,8 +5,10 @@
|
|
|
|
|
|
|
|
#include <jvalidate/adapter.h>
|
|
#include <jvalidate/adapter.h>
|
|
|
#include <jvalidate/detail/array_iterator.h>
|
|
#include <jvalidate/detail/array_iterator.h>
|
|
|
|
|
+#include <jvalidate/detail/expect.h>
|
|
|
#include <jvalidate/detail/object_iterator.h>
|
|
#include <jvalidate/detail/object_iterator.h>
|
|
|
#include <jvalidate/forward.h>
|
|
#include <jvalidate/forward.h>
|
|
|
|
|
+#include <jvalidate/status.h>
|
|
|
|
|
|
|
|
namespace jvalidate::adapter::detail {
|
|
namespace jvalidate::adapter::detail {
|
|
|
template <typename JSON, typename Adapter = AdapterFor<JSON>> class SimpleObjectAdapter {
|
|
template <typename JSON, typename Adapter = AdapterFor<JSON>> class SimpleObjectAdapter {
|
|
@@ -87,6 +89,8 @@ private:
|
|
|
|
|
|
|
|
template <typename JSON, typename CRTP = AdapterFor<JSON>> class SimpleAdapter : public Adapter {
|
|
template <typename JSON, typename CRTP = AdapterFor<JSON>> class SimpleAdapter : public Adapter {
|
|
|
public:
|
|
public:
|
|
|
|
|
+ static constexpr bool is_mutable =
|
|
|
|
|
+ not std::is_const_v<JSON> && MutableObject<decltype(std::declval<CRTP>().as_object())>;
|
|
|
using value_type = std::remove_const_t<JSON>;
|
|
using value_type = std::remove_const_t<JSON>;
|
|
|
|
|
|
|
|
public:
|
|
public:
|
|
@@ -127,6 +131,19 @@ public:
|
|
|
return std::make_unique<GenericConst<value_type>>(const_value());
|
|
return std::make_unique<GenericConst<value_type>>(const_value());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ void assign(Const const & frozen) const requires(is_mutable) {
|
|
|
|
|
+ EXPECT_M(value_ != nullptr, "Failed to create a new element in parent object");
|
|
|
|
|
+ if (auto * this_frozen = dynamic_cast<GenericConst<value_type> const *>(&frozen)) {
|
|
|
|
|
+ *value_ = this_frozen->value();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ frozen.apply([this](Adapter const & adapter) {
|
|
|
|
|
+ static_cast<CRTP const *>(this)->assign(adapter);
|
|
|
|
|
+ return Status::Accept;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
auto operator<=>(SimpleAdapter const & rhs) const requires std::totally_ordered<JSON> {
|
|
auto operator<=>(SimpleAdapter const & rhs) const requires std::totally_ordered<JSON> {
|
|
|
using ord = std::strong_ordering;
|
|
using ord = std::strong_ordering;
|
|
|
if (value_ == rhs.value_) {
|
|
if (value_ == rhs.value_) {
|