Mirror reflection library 0.5.13
Defines

Mirror - Utility macros

Defines

#define MIRROR_TYPEDEF(NAMESPACE, TYPEDEF)
 Returns a special type representing a nested typedef to Mirror.
#define MIRROR_GLOBAL_SCOPE_TYPEDEF(TYPEDEF)
 Returns a special type representing a typedef from the global scope.
#define MIRROR_USING_NESTED_NAMESPACE(ID, NAMESPACE)
 Macro which tells Mirror to remove this nested namespace's name from local names.
#define MIRROR_USING_NAMESPACE(NAMESPACE)   MIRROR_USING_NESTED_NAMESPACE(NAMESPACE, NAMESPACE)
 Macro which tells Mirror to remove this namespace's name from local names.
#define MIRROR_USING_NAMESPACE_(NAMESPACE)   MIRROR_USING_NESTED_NAMESPACE(_, NAMESPACE)
 Macro which tells Mirror to remove this namespace's name from local names.

Detailed Description

Other macros


Define Documentation

#define MIRROR_GLOBAL_SCOPE_TYPEDEF (   TYPEDEF)

Returns a special type representing a typedef from the global scope.

This macro expands into a special type that represents a typedef registered with Mirror. This special type can be used for example in registering class member variables having typedefined types.

Parameters:
TYPEDEFthe base typedef-ined name
See also:
MIRROR_TYPEDEF
MIRROR_REG_GLOBAL_SCOPE_TYPEDEF
MIRRORED_TYPEDEF_GLOBAL_SCOPE
MIRROR_REG_CLASS_MEM_VAR
#define MIRROR_TYPEDEF (   NAMESPACE,
  TYPEDEF 
)

Returns a special type representing a nested typedef to Mirror.

This macro expands into a special type that represents a typedef registered with Mirror. This special type can be used for example in registering class member variables having typedefined types.

Parameters:
NAMESPACEthe full namespace name NOT containing the leading double colon
TYPEDEFthe base typedef-ined name
See also:
MIRROR_GLOBAL_SCOPE_TYPEDEF
MIRROR_REG_TYPEDEF
MIRRORED_TYPEDEF
MIRROR_REG_CLASS_MEM_VAR
#include <mirror/mirror.hpp>
#include <mirror/using_directive.hpp>
#include <iostream>

namespace test {

// use typedef to define some types
typedef double kilogram;
typedef size_t centimeter;
typedef size_t year;

// a test class using typedefs for member variable types
struct person
{
    std::string first_name;
    std::string middle_name;
    std::string family_name;

    kilogram weight;
    centimeter height;
    year age;
};

} // namespace test

MIRROR_REG_BEGIN

// register the test namespace
MIRROR_QREG_GLOBAL_SCOPE_NAMESPACE(test)

// register the typedefs with Mirror
MIRROR_REG_TYPEDEF(test, kilogram)
MIRROR_REG_TYPEDEF(test, centimeter)
MIRROR_REG_TYPEDEF(test, year)

// get the typedefs
typedef MIRROR_TYPEDEF(test, kilogram) _typedef_kilogram;
typedef MIRROR_TYPEDEF(test, centimeter) _typedef_centimeter;
typedef MIRROR_TYPEDEF(test, year) _typedef_year;

// register the person class
MIRROR_REG_CLASS_BEGIN(struct, test, person)
MIRROR_REG_CLASS_MEM_VARS_BEGIN
    MIRROR_REG_CLASS_MEM_VAR( _, _, _, first_name)
    MIRROR_REG_CLASS_MEM_VAR( _, _, _, middle_name)
    MIRROR_REG_CLASS_MEM_VAR( _, _, _, family_name)
    MIRROR_REG_CLASS_MEM_VAR( _, _, _typedef_kilogram, weight)
    MIRROR_REG_CLASS_MEM_VAR( _, _, _typedef_centimeter, height)
    MIRROR_REG_CLASS_MEM_VAR( _, _, _typedef_year, age)
MIRROR_REG_CLASS_MEM_VARS_END
MIRROR_REG_CLASS_END


MIRROR_REG_END

struct info_printer
{
    template <class IterInfo>
    void operator()(IterInfo)
    {
        using namespace mirror;
        if(IterInfo::is_first::value)
            std::cout << "(" << std::endl;
        std::cout << "\t"
            << IterInfo::type::type::local_name()
            << " "
            << IterInfo::type::base_name();
        if(IterInfo::is_last::value)
            std::cout << std::endl << ")" << std::endl;
        else std::cout << ", " << std::endl;
    }
};

template <class Class>
void print_info(void)
{
    using namespace mirror;
    typedef MIRRORED_CLASS(Class) meta_X;
    std::cout << "Members of "
        << meta_X::local_name()
        << ": ";
    mp::for_each_ii< all_member_variables<meta_X> >(info_printer());
}

int main(void)
{
    using namespace mirror;
    //
    // print with the full names
    print_info<test::person>();
    //
    // print with the test:: name specifier stripped
    {
        MIRROR_USING_NAMESPACE(test);
        print_info<test::person>();
    }
    //
    // print with the test:: and the std::
    // name specifiers stripped
    {
        MIRROR_USING_NAMESPACE(test);
        MIRROR_USING_NAMESPACE(std);
        print_info<test::person>();
    }
    //
    return 0;
}

/* Example of output:
 |  Members of test::person: (
 |          std::string first_name,
 |          std::string middle_name,
 |          std::string family_name,
 |          test::kilogram weight,
 |          test::centimeter height,
 |          test::year age
 |  )
 |  Members of person: (
 |          std::string first_name,
 |          std::string middle_name,
 |          std::string family_name,
 |          kilogram weight,
 |          centimeter height,
 |          year age
 |  )
 |  Members of person: (
 |          std::string first_name,
 |          std::string middle_name,
 |          std::string family_name,
 |          kilogram weight,
 |          centimeter height,
 |          year age
 |  )
 */
Examples:
mirror/example/typedefd_members.cpp.
#define MIRROR_USING_NAMESPACE (   NAMESPACE)    MIRROR_USING_NESTED_NAMESPACE(NAMESPACE, NAMESPACE)

Macro which tells Mirror to remove this namespace's name from local names.

This macro acts in a similar way as the 'using namespace' directive and causes the local_name member function of MetaNamedScopedObject(s) to remove the namespace name from the full names of members of this namespace. It can be used only with top-level namespaces. For nested namespaces see the MIRROR_USING_NESTED_NAMESPACE() or the MIRROR_USING_NAMESPACE_() macro.

Parameters:
NAMESPACEthe name of the namespace to be used. If it is a nested namespace (i.e. its name contains ::) then the MIRROR_USING_NESTED_NAMESPACE() macro must be used instead.
See also:
MetaNamedScopedObject
MIRROR_USING_NESTED_NAMESPACE
MIRROR_USING_NAMESPACE_
Examples:
mirror/example/factories/person_boostfs.cpp, mirror/example/factories/person_mijson.cpp, mirror/example/factories/person_script.cpp, mirror/example/factories/random_tetrahedron.cpp, mirror/example/factories/script_parsers.cpp, mirror/example/factories/tetrahedron_rapidxml.cpp, mirror/example/factories/tetrahedron_script.cpp, mirror/example/factories/tetrahedron_wxxml.cpp, mirror/example/factories/tetrahedrons_script.cpp, mirror/example/factories/tetrahedrons_wxxml.cpp, mirror/example/typedefd_members.cpp, and mirror/example/typenames_03.cpp.
#define MIRROR_USING_NAMESPACE_ (   NAMESPACE)    MIRROR_USING_NESTED_NAMESPACE(_, NAMESPACE)

Macro which tells Mirror to remove this namespace's name from local names.

This macro acts in a similar way as the 'using namespace' directive and causes the local_name member function of MetaNamedScopedObject(s) to remove the namespace name from the full names of members of this namespace. Unlike MIRROR_USING_NAMESPACE(), this macro can be also used for nested namespaces, but only one namespace can be 'used' on a particular scope.

Parameters:
NAMESPACEthe name of the namespace to be used.
See also:
MetaNamedScopedObject
MIRROR_USING_NESTED_NAMESPACE
MIRROR_USING_NAMESPACE
Examples:
mirror/example/typenames_03.cpp.
#define MIRROR_USING_NESTED_NAMESPACE (   ID,
  NAMESPACE 
)
Value:
const mirror::aux::_using< \
        MIRRORED_NAMESPACE(NAMESPACE) \
    > _boost_mirror_using_ ## ID(__COUNTER__)

Macro which tells Mirror to remove this nested namespace's name from local names.

This macro acts in a similar way as the 'using namespace' directive and causes the local_name member function of MetaNamedScopedObject(s) to remove the namespace name from the full names of members of this namespace. This version of the macro must be used for nested namespaces (i.e. namespaces whose name contains ::).

Parameters:
IDan identifier for the using directive, which distinguishes it from other using directives on the same scope. Generally the same rules as for the identifier names apply, except that it can start with a digit.
NAMESPACEthe name of the namespace to be used
See also:
MetaNamedScopedObject
MIRROR_USING_NAMESPACE
MIRROR_USING_NAMESPACE_
Examples:
mirror/example/typenames_03.cpp.

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.