typedisplay.cc
Go to the documentation of this file.
00001 #include "typedisplay.hh"
00002 #include <string>
00003 #include <iostream>
00004 
00005 using namespace Typelib;
00006 using namespace std;
00007 
00008 namespace
00009 {
00010     struct Indent
00011     {
00012         std::string& m_indent;
00013         std::string  m_save;
00014         Indent(std::string& current)
00015             : m_indent(current), m_save(current)
00016         { m_indent += "  "; }
00017         ~Indent() { m_indent = m_save; }
00018     };
00019 }
00020 
00021 TypeDisplayVisitor::TypeDisplayVisitor(std::ostream& stream, std::string const& base_indent)
00022     : m_stream(stream), m_indent(base_indent) {}
00023             
00024 bool TypeDisplayVisitor::visit_(NullType const& type)
00025 {
00026     m_stream << "null\n";
00027     return true;
00028 }
00029 
00030 bool TypeDisplayVisitor::visit_(OpaqueType const& type)
00031 {
00032     m_stream << "opaque " << type.getName() << "\n";
00033     return true;
00034 }
00035 
00036 bool TypeDisplayVisitor::visit_(Compound const& type)
00037 { 
00038     m_stream << "compound " << type.getName() << " [" << type.getSize() << "] {\n";
00039     
00040     { Indent indenter(m_indent);
00041         TypeVisitor::visit_(type);
00042     }
00043 
00044     m_stream << m_indent
00045         << "};";
00046     return true;
00047 }
00048 bool TypeDisplayVisitor::visit_(Compound const& type, Field const& field)
00049 { 
00050     m_stream << m_indent << "(+" << field.getOffset() << ") ";
00051     TypeVisitor::visit_(type, field);
00052     m_stream << "\n";
00053     return true;
00054 }
00055 
00056 bool TypeDisplayVisitor::visit_(Numeric const& type)
00057 {
00058     char const* name = "";
00059     switch (type.getNumericCategory())
00060     {
00061     case Numeric::SInt:
00062         name = "sint";
00063         break;
00064     case Numeric::UInt:
00065         name = "uint";
00066         break;
00067     case Numeric::Float:
00068         name = "float";
00069         break;
00070     };
00071 
00072     m_stream
00073         << name << "(" << type.getSize() << ")";
00074     return true;
00075 }
00076 
00077 bool TypeDisplayVisitor::visit_(Enum const& type)
00078 {
00079     m_stream << "enum " << type.getName();
00080     return true;
00081 }
00082 
00083 bool TypeDisplayVisitor::visit_(Pointer const& type)
00084 {
00085     m_stream << "pointer on " << type.getIndirection().getName() << "\n";
00086     return true;
00087 }
00088 
00089 bool TypeDisplayVisitor::visit_(Array const& type)
00090 {
00091     m_stream << "array[" << type.getDimension() << "] of\n";
00092     { Indent indenter(m_indent);
00093         m_stream << m_indent;
00094         TypeVisitor::visit_(type);
00095     }
00096     return true;
00097 }
00098 
00099 


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