Skip to content
Snippets Groups Projects
Commit 6646e4cf authored by Jan Trávníček's avatar Jan Trávníček
Browse files

abstraction: make sure an object made unique does not participate in denormalization

parent aace6a7c
No related branches found
No related tags found
1 merge request!221New normalization
......@@ -33,6 +33,10 @@ bool type_details::compatible_with ( const type_details & other ) const {
return m_type_details->compatible_with ( * other.m_type_details );
}
 
bool type_details::compatible_with ( const type_details_base & other ) const {
return m_type_details->compatible_with ( other );
}
std::ostream & operator << ( std::ostream & os, const type_details & arg ) {
return os << ( * arg.m_type_details );
}
......
......@@ -45,6 +45,8 @@ public:
 
bool compatible_with ( const type_details & other ) const;
 
bool compatible_with ( const type_details_base & other ) const;
friend std::ostream & operator << ( std::ostream & os, const type_details & arg );
 
std::strong_ordering operator <=> ( const type_details & other ) const;
......
......@@ -119,6 +119,8 @@ object::Object type_util < object::Object >::normalize ( object::Object && arg )
}
 
std::unique_ptr < type_details_base > type_util < object::Object >::type ( const object::Object & arg ) {
if ( arg.getId ( ) > 0 ) // Denormalization of an object that is incremented to its actual type would drop the id
return std::make_unique < type_details_type > ( "object::Object" );
return arg.getType ( );
}
 
......
......@@ -80,8 +80,8 @@ bool stringApi < object::Object >::first ( ext::istream & input ) {
}
 
void stringApi < object::Object >::compose ( ext::ostream & output, const object::Object & data ) {
core::type_details type = core::type_details::get ( data );
auto callback = std::find_if ( composeFunctions ( ).begin ( ), composeFunctions ( ).end ( ), [ & ] ( const std::pair < const core::type_details, std::unique_ptr < GroupWriter > > & entry ) { return entry.first.compatible_with ( type ); } );
std::unique_ptr < core::type_details_base > type = data.getType ( );
auto callback = std::find_if ( composeFunctions ( ).begin ( ), composeFunctions ( ).end ( ), [ & ] ( const std::pair < const core::type_details, std::unique_ptr < GroupWriter > > & entry ) { return entry.first.compatible_with ( * type ); } );
 
if ( callback == composeFunctions ( ).end ( ) ) throw exception::CommonException ( "Compose callback for " + ext::to_string ( type ) + " tag not registered." );
 
......
......@@ -150,8 +150,8 @@ void xmlApi < object::Object >::composeUnique ( xmlApiOutputContext & output, co
}
 
void xmlApi < object::Object >::composeObject ( xmlApiOutputContext & output, const object::Object & data ) {
core::type_details type = core::type_details::get ( data );
auto callback = std::find_if ( composeFunctions ( ).begin ( ), composeFunctions ( ).end ( ), [ & ] ( const std::pair < const core::type_details, std::unique_ptr < GroupComposer > > & entry ) { return entry.first.compatible_with ( type ); } );
std::unique_ptr < core::type_details_base > type = data.getType ( );
auto callback = std::find_if ( composeFunctions ( ).begin ( ), composeFunctions ( ).end ( ), [ & ] ( const std::pair < const core::type_details, std::unique_ptr < GroupComposer > > & entry ) { return entry.first.compatible_with ( * type ); } );
 
if ( callback == composeFunctions ( ).end ( ) )
throw exception::CommonException ( "Compose callback for " + ext::to_string ( type ) + " tag not registered." );
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment