Member metaobjects provide the ability of introspection and
source-code translation of
the members. They can be obtained by calling NthMember()
or LookupMember()
on a class metaobject. The following
is the list of the member functions provided by the member metaobjects.
ArgumentList()
Arguments()
FunctionBody()
GetUserAccessSpecifier()
GetUserArgumentModifiers(PtreeArray& modifiers)
GetUserMemberModifier()
IsConstructor()
IsDestructor()
IsFunction()
IsInline()
IsMutable()
IsPrivate()
IsProtected()
IsPublic()
IsPureVirtual()
IsStatic()
IsVirtual()
Member(Member&)
MemberInitializers()
Name()
NewArgumentList()
NewFunctionBody()
NewMemberInitializers()
NewName()
Nth()
SetArgumentList(Ptree* arglist)
SetFunctionBody(Ptree* body)
SetMemberInitializers(Ptree* init)
SetName(Ptree* name)
SetQualifiedName(Ptree* name)
Signature(TypeInfo& t)
Supplier()
First, we show the member functions for introspection.
Member(Member&)
This is a constructor to make a copy of a member metaobject.
Ptree* Name()
This returns the member name.
Ptree* ArgumentList()
This returns the formal argument list of the member.
For example, if the member is int f(int, char*)
,
then this function returns [[[int] [nil]] , [[char] [*]]]
.
If the member is a data member, this function returns nil
.
Ptree* Arguments()
This returns the argument list of the member.
Unlike ArgumentList()
, the returned list does not include
the types. It is a list of the argument names. If the member is int f(int p, char* q)
, then this function returns [p , q]
. Even if the argument name is not given in the argument
list, it is automatically filled by this function. In this case,
the formal argument list of the member is also changed to include that
argument name.
If the member is a data member, this function returns nil
.
Ptree* MemberInitializers()
This returns the member initializers if the member is a constructor.
Otherwise, it returns nil
. For example, if the member is:
X::X() : p(3), q(1) {
... }
Then this function returns [: [p ( [3] )] , [q ( [1] )]]
.
Ptree* FunctionBody()
This returns the function body if the member is a function. The
returned text includes braces {}
.
int Nth()
If the member is the i
-th member, this returns i
. Otherwise, if the member is not declared,
it returns -1.
void Signature(TypeInfo& t)
This returns the type of the member in t
. If the
member is a member function, the returned type is the function type.
Class* Supplier()
This returns the class supplying this member. If the member is inherited from the base class, then the returned class is that base class.
bool IsConstructor()
This returns true
if the member is a constructor.
bool IsDestructor()
This returns true
if the member is a destructor.
bool IsFunction()
This returns true
if the member is a member function.
bool IsPublic()
This returns true
if the member is a public
member.
bool IsProtected()
This returns true
if the member is a protected
member.
bool IsPrivate()
This returns true
if the member is a private
member.
bool IsStatic()
This returns true
if the member is a static
member.
bool IsMutable()
This returns true
if the member is a mutable
member.
bool IsInline()
This returns true
if the member is a inline
member function.
bool IsVirtual()
This returns true
if the member is a virtual
member function.
bool IsPureVirtual()
This returns true
if the member is a pure virtual
member function.
OpenC++ allows syntax extensions for access specifiers and argument lists. The following members are used for dealing with such syntax extensions.
Ptree* GetUserAccessSpecifier()
This returns an user-defined access specifier for the member.
For example, suppose that sync
is a user-defined keyword:
class Window {
public:
void Move();
sync:
void Resize();
};
Then GetUserAccessSpecifier()
called on Resize()
returns [sync :]
. The user-defined
access specifier is effective until another access specifier
appears. For example:
class X {
public:
void f1(); // public
sync:
void f2(); // public, sync
private:
void g1(); // private
sync:
void g2(); // private, sync
};
The user-defined access specifiers are automatically eliminated. The programmer does not have to be concerned about it.
Ptree* GetUserMemberModifier()
This returns the member modifier for the member.
If no member modifier is specified, this returns nil
.
The member modifier is automatically eliminated.
The programmer does not have to be concerned about it.
bool GetUserArgumentModifiers(PtreeArray& modifiers)
This computes user-defined type modifiers
attached to the argument types. If successful, it returns true
and stores the result in modifiers
. The result is
a PtreeArray
of user-defined type modifiers. The i
-the element is one for the i
-th argument. If no modifier
is specified, the element is nil
. For example, if ref
is a user-defined type modifier,
class C {
public:
void f(ref int p1, int p2);
};
Then GetUserArgumentModifiers()
called on f
returns
an array { [ref], nil }
.
All the user-defined type modifiers are automatically eliminated. The programmer does not have to be concerned about it.
The member metaobjects also provide functions for customizing the
member. The changes are not actually reflected on the source-code translation
until ChangeMember()
or AppendMember()
is called on
the class metaobject.
void SetName(Ptree* name)
This changes the member name to name
.
void SetQualifiedName(Ptree* name)
This changes the member name to name
.
Unlike SetName()
, this function substitutes name
for
the member name including the qualified class name. It is
useful in Class::TranslateMemberFunction()
.
For example, if the member is:
void Rect::Enlarge(int rx, int ry) { ... }
Then, SetQualifiedName(Ptree::Make("Point::Move"))
changes
this member to:
void Point::Move(int rx, int ry) { ... }
void SetArgumentList(Ptree* arglist)
This changes the formal argument list of the member function
to arglist
.
void SetMemberInitializers(Ptree* init)
This changes the member initializers of the constructor
to init
.
void SetFunctionBody(Ptree* body)
This changes the function body of the member to body
.
The member functions for introspection such as Name()
does
not reflect the customization in the results.
For example, Name()
returns the original member name
even if SetName()
specifies a new name. To get the new value
specified by the above functions such as SetName()
,
the following functions are used:
void NewName()
This returns the new member name substituted for the original one.
void NewArgumentList()
This returns the new argument list substituted for the original one.
void NewMemberInitializers()
This returns the new member initializers substituted for the original one.
void NewFunctionBody()
This returns the new function body substituted for the original one.