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


typelib
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Thu Jan 2 2014 11:38:41