typevisitor.cc
Go to the documentation of this file.
00001 #include "typevisitor.hh"
00002 
00003 namespace Typelib
00004 {
00005     bool TypeVisitor::visit_ ( NullType const& type )
00006     { throw NullTypeFound(type); }
00007     bool TypeVisitor::visit_ (OpaqueType const& type)
00008     { return true; }
00009     bool TypeVisitor::visit_  (Numeric const& type)
00010     { return true; }
00011     bool TypeVisitor::visit_  (Enum const& type)
00012     { return true; }
00013 
00014     bool TypeVisitor::visit_  (Pointer const& type)
00015     { return dispatch(type.getIndirection()); }
00016     bool TypeVisitor::visit_  (Array const& type)
00017     { return dispatch(type.getIndirection()); }
00018     bool TypeVisitor::visit_  (Container const& type)
00019     { return dispatch(type.getIndirection()); }
00020 
00021     bool TypeVisitor::visit_  (Compound const& type)                 
00022     {  
00023         typedef Compound::FieldList Fields;
00024         Fields const& fields(type.getFields());
00025         Fields::const_iterator const end = fields.end();
00026         
00027         for (Fields::const_iterator it = fields.begin(); it != end; ++it)
00028         {
00029             if (! visit_(type, *it))
00030                 return false;
00031         }
00032         return true;
00033     }
00034     bool TypeVisitor::visit_  (Compound const& type, Field const& field)   
00035     { return dispatch(field.getType()); }
00036 
00037     bool TypeVisitor::dispatch(Type const& type)
00038     {
00039         switch(type.getCategory())
00040         {
00041             case Type::NullType:
00042                 return visit_ ( dynamic_cast<NullType const&>(type) );
00043             case Type::Numeric:
00044                 return visit_( dynamic_cast<Numeric const&>(type) );
00045             case Type::Enum:
00046                 return visit_( dynamic_cast<Enum const&>(type) );
00047             case Type::Array:
00048                 return visit_( dynamic_cast<Array const&>(type) );
00049             case Type::Pointer:
00050                 return visit_( dynamic_cast<Pointer const&>(type) );
00051             case Type::Opaque:
00052                 return visit_( dynamic_cast<OpaqueType const&>(type) );
00053             case Type::Compound:
00054                 return visit_( dynamic_cast<Compound const&>(type) );
00055             case Type::Container:
00056                 return visit_( dynamic_cast<Container const&>(type) );
00057             default:
00058                 throw UnsupportedType(type, "unsupported type category");
00059         }
00060     }
00061 
00062     void TypeVisitor::apply(Type const& type)
00063     { dispatch(type); }
00064 }
00065 


typelib
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Sat Jun 8 2019 18:49:22