From 4109f4acbc02b7a5ef975d0ad8f97f0786a564d1 Mon Sep 17 00:00:00 2001 From: Pierre Anquez Date: Fri, 7 Mar 2025 10:55:12 +0100 Subject: [PATCH 1/3] fix(Identifier): set default name as uuid --- src/geode/basic/identifier.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/geode/basic/identifier.cpp b/src/geode/basic/identifier.cpp index b9f42b22c..804b330b7 100644 --- a/src/geode/basic/identifier.cpp +++ b/src/geode/basic/identifier.cpp @@ -34,7 +34,13 @@ namespace geode class Identifier::Impl { public: - Impl() = default; + Impl() + { + if( name_ == DEFAULT_NAME ) + { + name_ = id_.string(); + } + } const uuid& id() const { From bfa804422af1ae6ee79505e0ceebfd2d21a65c7f Mon Sep 17 00:00:00 2001 From: Pierre Anquez Date: Mon, 10 Mar 2025 15:44:07 +0100 Subject: [PATCH 2/3] PR review --- src/geode/basic/identifier.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/geode/basic/identifier.cpp b/src/geode/basic/identifier.cpp index 804b330b7..d7c029116 100644 --- a/src/geode/basic/identifier.cpp +++ b/src/geode/basic/identifier.cpp @@ -34,13 +34,7 @@ namespace geode class Identifier::Impl { public: - Impl() - { - if( name_ == DEFAULT_NAME ) - { - name_ = id_.string(); - } - } + Impl() = default; const uuid& id() const { @@ -49,7 +43,11 @@ namespace geode std::string_view name() const { - return name_; + if( name_ ) + { + return name_.value(); + } + return id_.string(); } void set_id( const uuid& unique_id ) @@ -110,7 +108,7 @@ namespace geode private: uuid id_; - std::string name_ = std::string{ DEFAULT_NAME }; + std::optional< std::string > name_ = std::nullopt; }; Identifier::Identifier() = default; From b3469139a5724d1dab139c389e8175f6ca773c0b Mon Sep 17 00:00:00 2001 From: Arnaud Botella Date: Mon, 10 Mar 2025 16:40:06 +0100 Subject: [PATCH 3/3] update bitsery --- src/geode/basic/identifier.cpp | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/geode/basic/identifier.cpp b/src/geode/basic/identifier.cpp index d7c029116..4b6034a8f 100644 --- a/src/geode/basic/identifier.cpp +++ b/src/geode/basic/identifier.cpp @@ -25,6 +25,8 @@ #include +#include + #include #include #include @@ -34,8 +36,6 @@ namespace geode class Identifier::Impl { public: - Impl() = default; - const uuid& id() const { return id_; @@ -95,20 +95,34 @@ namespace geode "[Identifier::load] Error while reading file: ", filename ); } + private: + friend class bitsery::Access; template < typename Archive > void serialize( Archive& archive ) { - archive.ext( *this, Growable< Archive, Impl >{ - { []( Archive& local_archive, Impl& impl ) { - local_archive.object( impl.id_ ); - local_archive.text1b( - impl.name_, impl.name_.max_size() ); - } } } ); + archive.ext( *this, + Growable< Archive, Impl >{ + { []( Archive& local_archive, Impl& impl ) { + local_archive.object( impl.id_ ); + std::string old_name; + local_archive.text1b( old_name, old_name.max_size() ); + impl.name_.emplace( std::move( old_name ) ); + }, + []( Archive& local_archive, Impl& impl ) { + local_archive.object( impl.id_ ); + local_archive.ext( impl.name_, + bitsery::ext::StdOptional{}, + []( Archive& local_archive2, + std::string& name ) { + local_archive2.text1b( + name, name.max_size() ); + } ); + } } } ); } private: uuid id_; - std::optional< std::string > name_ = std::nullopt; + std::optional< std::string > name_; }; Identifier::Identifier() = default;