Mirror reflection library - Puddle compile-time layer 0.5.13

puddle/example/print_all.cpp

This example shows the usage of the Puddle compile-time layer.

Copyright 2008-2011 Matus Chochlik. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <mirror/mirror_base.hpp>
#include <mirror/pre_registered/full.hpp>
#include <puddle/puddle.hpp>

#include <iostream>

struct object_printer
{
    std::ostream& out;
    int indent_level;

    std::ostream& indented_output(void)
    {
        for(int i=0;i!=indent_level;++i)
            out << "  ";
        return out;
    }

    template <class MetaObject>
    void print_details(MetaObject obj, mirror::meta_object_tag)
    {
    }

    template <class MetaObject>
    void print_details(MetaObject obj, mirror::meta_scope_tag)
    {
        out << ": ";
        if(obj.members().empty())
        {
            out << "{ }";
        }
        else
        {
            out << "{" << std::endl;
            object_printer print_members = {out, indent_level+1};
            obj.members().for_each(print_members);
            indented_output() << "}";
        }
    }

    template <class MetaObject>
    void print(MetaObject obj, bool last)
    {
        indented_output()
            << obj.self().construct_name()
            << " "
            << obj.base_name();
        print_details(obj, obj.category());
        if(!last) out << ",";
        out << std::endl;
    }

    template <class MetaObject>
    void operator()(MetaObject obj, bool first, bool last)
    {
        print(obj, last);
    }

    template <class MetaObject>
    void operator()(MetaObject obj)
    {
        print(obj, true);
    }
};

int main(void)
{
    object_printer print = {std::cout, 0};
    print(puddle::adapt<MIRRORED_GLOBAL_SCOPE()>());
    return 0;
}

/* Example of output:
 | global scope : {
 |   namespace std: {
 |     class string: { },
 |     class wstring: { },
 |     template pair,
 |     template tuple,
 |     template initializer_list,
 |     template allocator,
 |     template equal_to,
 |     template not_equal_to,
 |     template less,
 |     template greater,
 |     template less_equal,
 |     template greater_equal,
 |     template deque,
 |     class tm: {
 |       member variable tm_sec,
 |       member variable tm_min,
 |       member variable tm_hour,
 |       member variable tm_mday,
 |       member variable tm_mon,
 |       member variable tm_year,
 |       member variable tm_wday,
 |       member variable tm_yday,
 |       member variable tm_isdst
 |     },
 |     template vector,
 |     template list,
 |     template set,
 |     template map
 |   },
 |   namespace boost: {
 |     template optional
 |   },
 |   namespace mirror: { },
 |   type void,
 |   type bool,
 |   type char,
 |   type unsigned char,
 |   type wchar_t,
 |   type short int,
 |   type int,
 |   type long int,
 |   type unsigned short int,
 |   type unsigned int,
 |   type unsigned long int,
 |   type float,
 |   type double,
 |   type long double
 | }
 */

Copyright © 2006-2011 Matus Chochlik, University of Zilina, Zilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Fri Dec 16 2011 by Doxygen (version 1.7.3).
Important note: Although the 'boostified' version of Mirror uses the Boost C++ libraries Coding Guidelines and is implemented inside of the boost namespace, it IS NOT an officially reviewed and accepted Boost library. Mirror is being developed with the intention to be submitted for review for inclusion to the Boost C++ libraries.