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

add cast to SetOfObjectPairs

parent 9e8185f5
No related branches found
No related tags found
No related merge requests found
...@@ -27,6 +27,35 @@ class PrimitiveRegistrator { ...@@ -27,6 +27,35 @@ class PrimitiveRegistrator {
throw std::invalid_argument ( "Casted object does not contain data of type " + ext::to_string < ext::set < object::Object > > ( ) + "." ); throw std::invalid_argument ( "Casted object does not contain data of type " + ext::to_string < ext::set < object::Object > > ( ) + "." );
} }
   
static ext::set < ext::pair < object::Object, object::Object > > denormalizeSetObjectPair ( const object::Object & o ) {
const object::AnyObjectBase & data = o.getData ( );
const object::AnyObject < ext::set < ext::pair < object::Object, object::Object > > > * innerData = dynamic_cast < const object::AnyObject < ext::set < ext::pair < object::Object, object::Object > > > * > ( & data );
if ( innerData )
return innerData->getData ( );
const object::AnyObject < ext::set < object::Object > > * innerData2 = dynamic_cast < const object::AnyObject < ext::set < object::Object > > * > ( & data );
if ( innerData2 ) {
ext::set < ext::pair < object::Object, object::Object > > res;
for ( const object::Object & inner : innerData2->getData ( ) ) {
const object::AnyObjectBase & dataTmp = inner.getData ( );
const object::AnyObject < ext::pair < object::Object, object::Object > > * innerDataTmp = dynamic_cast < const object::AnyObject < ext::pair < object::Object, object::Object > > * > ( & dataTmp );
if ( innerDataTmp ) {
res.insert ( innerDataTmp->getData ( ) );
continue;
}
const object::AnyObject < ext::pair < unsigned, unsigned > > * innerDataTmp2 = dynamic_cast < const object::AnyObject < ext::pair < unsigned, unsigned > > * > ( & dataTmp );
if ( innerDataTmp2 ) {
res.insert ( ext::make_pair ( object::Object ( innerDataTmp2->getData ( ).first ), object::Object ( innerDataTmp2->getData ( ).second ) ) );
continue;
}
throw std::invalid_argument ( "Casted object does not contain data of type " + ext::to_string < ext::set < ext::pair < object::Object, object::Object > > > ( ) + "." );
}
return res;
}
throw std::invalid_argument ( "Casted object does not contain data of type " + ext::to_string < ext::set < ext::pair < object::Object, object::Object > > > ( ) + "." );
}
public: public:
PrimitiveRegistrator ( ) { PrimitiveRegistrator ( ) {
alib::ExceptionHandler::addHandler < 3 > ( [] ( std::ostream & out, const exception::CommonException & exception ) { alib::ExceptionHandler::addHandler < 3 > ( [] ( std::ostream & out, const exception::CommonException & exception ) {
...@@ -52,6 +81,7 @@ public: ...@@ -52,6 +81,7 @@ public:
abstraction::CastRegistry::registerCast < long, int > ( "long", ext::to_string < int > ( ) ); abstraction::CastRegistry::registerCast < long, int > ( "long", ext::to_string < int > ( ) );
   
abstraction::CastRegistry::registerCastAlgorithm < const ext::set < object::Object > &, const object::Object & > ( "SetOfObjects", ext::to_string < object::Object > ( ), denormalizeSetObject, true ); abstraction::CastRegistry::registerCastAlgorithm < const ext::set < object::Object > &, const object::Object & > ( "SetOfObjects", ext::to_string < object::Object > ( ), denormalizeSetObject, true );
abstraction::CastRegistry::registerCastAlgorithm < ext::set < ext::pair < object::Object, object::Object > >, const object::Object & > ( "SetOfObjectPairs", ext::to_string < object::Object > ( ), denormalizeSetObjectPair, true );
abstraction::CastRegistry::registerCast < object::Object, const ext::set < object::Object > & > ( "DefaultStateType", ext::to_string < const ext::set < object::Object > & > ( ), true ); abstraction::CastRegistry::registerCast < object::Object, const ext::set < object::Object > & > ( "DefaultStateType", ext::to_string < const ext::set < object::Object > & > ( ), true );
   
abstraction::ContainerRegistry::registerSet < int > ( ); abstraction::ContainerRegistry::registerSet < int > ( );
...@@ -111,6 +141,9 @@ public: ...@@ -111,6 +141,9 @@ public:
abstraction::CastRegistry::unregisterCast < unsigned, int > ( ); abstraction::CastRegistry::unregisterCast < unsigned, int > ( );
   
abstraction::CastRegistry::unregisterCast ( "long", ext::to_string < int > ( ) ); abstraction::CastRegistry::unregisterCast ( "long", ext::to_string < int > ( ) );
abstraction::CastRegistry::unregisterCast ( "SetOfObjects", ext::to_string < object::Object > ( ) );
abstraction::CastRegistry::unregisterCast ( "SetOfObjectPairs", ext::to_string < object::Object > ( ) );
abstraction::CastRegistry::unregisterCast ( "DefaultStateType", ext::to_string < const ext::set < object::Object > & > ( ) );
   
abstraction::ContainerRegistry::unregisterSet < int > ( ); abstraction::ContainerRegistry::unregisterSet < int > ( );
   
......
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