ponder 3.2
C++ reflection library
ponder::ClassVisitor Class Reference

Base class for writing custom Class visitors. More...

#include <classvisitor.hpp>

Public Member Functions

virtual ~ClassVisitor ()
 Destructor.
 
virtual void visit (const Property &property)
 Visit any kind of property. More...
 
virtual void visit (const SimpleProperty &property)
 Visit a simple property. More...
 
virtual void visit (const ArrayProperty &property)
 Visit an array property. More...
 
virtual void visit (const EnumProperty &property)
 Visit an enum property. More...
 
virtual void visit (const UserProperty &property)
 Visit a user property. More...
 
virtual void visit (const Function &function)
 Visit a function. More...
 

Detailed Description

Base class for writing custom Class visitors.

A ClassVisitor, when applied to a Class, will be notified for each member property and function of the target class. To receive this notification for a specific type T of property or function, you have to override the visit(T) function.

The benefit of such visitation is that you directly get the actual type of the property or function, and can handle it safely without having to use dangerous downcasts.

Another benefit of this method is that you can easily filter the properties and functions according to their C++ type: if you don't want to handle a specific type of property or function, just don't override the corresponding visit function.

Here an example of a visitor which prints the contents of a class:

class MyClassVisitor : public ponder::ClassVisitor
{
void visit(const ponder::SimpleProperty& property)
{
std::cout << "Simple property: " << property.name() << std::endl;
}
void visit(const ponder::ArrayProperty& property)
{
std::cout << "Array property: " << property.name() << " - "
<< "dynamic:" << property.dynamic() << std::endl;
}
void visit(const ponder::EnumProperty& property)
{
std::cout << "Enum property: " << property.name() << " - "
<< "owner enum:" << property.getEnum().name() << std::endl;
}
void visit(const ponder::UserProperty& property)
{
std::cout << "User property: " << property.name() << " - "
<< "owner class:" << property.getClass().name() << std::endl;
}
void visit(const ponder::Function& function)
{
std::cout << "Function: " << function.name() << " - "
<< "number of parameters:" << function.paramCount() << std::endl;
}
};
const ponder::Class& metaclass = ponder::classByName("MyClass");
MyClassVisitor visitor;
metaclass.visit(visitor);

Member Function Documentation

◆ visit() [1/6]

virtual void ponder::ClassVisitor::visit ( const ArrayProperty property)
virtual

Visit an array property.

Parameters
propertyProperty which is being visited

◆ visit() [2/6]

virtual void ponder::ClassVisitor::visit ( const EnumProperty property)
virtual

Visit an enum property.

Parameters
propertyProperty which is being visited

◆ visit() [3/6]

virtual void ponder::ClassVisitor::visit ( const Function function)
virtual

Visit a function.

Parameters
functionFunction which is being visited

◆ visit() [4/6]

virtual void ponder::ClassVisitor::visit ( const Property property)
virtual

Visit any kind of property.

This function is a generic callback which can be used to receive all property types which are not handled with their derived type.

Parameters
propertyProperty which is being visited

◆ visit() [5/6]

virtual void ponder::ClassVisitor::visit ( const SimpleProperty property)
virtual

Visit a simple property.

Parameters
propertyProperty which is being visited

◆ visit() [6/6]

virtual void ponder::ClassVisitor::visit ( const UserProperty property)
virtual

Visit a user property.

Parameters
propertyProperty which is being visited

The documentation for this class was generated from the following file:
ponder::SimpleProperty
Base class for all simple types of properties.
Definition: simpleproperty.hpp:47
ponder::Class::visit
void visit(ClassVisitor &visitor) const
Start visitation of a class.
ponder::ClassVisitor::visit
virtual void visit(const Property &property)
Visit any kind of property.
ponder::EnumProperty
Specialized type of property for enums.
Definition: enumproperty.hpp:45
ponder::ClassVisitor
Base class for writing custom Class visitors.
Definition: classvisitor.hpp:99
ponder::Function
Abstract representation of a function.
Definition: function.hpp:55
ponder::UserProperty
Specialized type of property for user types.
Definition: userproperty.hpp:44
ponder::ArrayProperty
Specialized type of property for arrays.
Definition: arrayproperty.hpp:44
ponder::Class
ponder::Class represents a metaclass composed of properties and functions
Definition: class.hpp:84