C12Adapter Opensource C++ Interface
MClass Class Reference

Notion of a class that serves as the base for the reflection API. More...

Public Types

enum  {
  MAXIMUM_NUMBER_OF_SERVICE_PARAMETERS = 6,
  MAXIMUM_CLASS_NAME_LENGTH = 40
}
 

Public Member Functions

const MClassGetParent () const
 Get parent of a class, or NULL if the class has no parent. More...
 
bool IsKindOf (const MClass *) const
 Tell about the relationship between this class and a given class. More...
 
MConstChars GetName () const
 Access the name of the MClass. More...
 
MConstChars GetTypeName () const
 Access the type name of the class. More...
 
const MClassGetParentClass (const MStdString &name) const
 Get parent class by the name specified. More...
 
const MServiceDefinitionGetServiceDefinitionOrNull (const MStdString &name, int expectedNumberOfParameters=-1) const
 Get the constant definition of service (method) with the given name, or return NULL if such service does not exist. More...
 
const MServiceDefinitionGetServiceDefinition (const MStdString &name, int expectedNumberOfParameters=-1) const
 Get the constant definition of service (method) with the given name, or return NULL if such service does not exist. More...
 
bool IsServicePresent (const MStdString &name) const
 Tell if the service (method) with the given name exists in the class. More...
 
MStdStringVector GetAllServiceNames () const
 The collection of all publicly available reflection enabled services. More...
 
MStdStringVector GetOwnServiceNames () const
 The collection of publicly available reflection enabled services owned by the class. More...
 
const MServiceDefinitionGetOwnServiceDefinitions () const
 Return the pointer to the array of objects that represent publicly available services. More...
 
MVariant Call (const MStdString &name, const MVariant &params) const
 Call the static service of the class with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name) const
 Call the static service of the object with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1) const
 Call the static service of the object with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2) const
 Call the static service of the object with two parameter. More...
 
MVariant CallV (const MStdString &name, const MVariant::VariantVector &params) const
 Call the static service of the object with vector of parameter. More...
 
const MPropertyDefinitionGetPropertyDefinition (const MStdString &name) const
 Get the existing constant definition of the property with the name specified. More...
 
const MPropertyDefinitionGetPropertyDefinitionOrNull (const MStdString &name) const
 Get the constant definition of the property with the name specified, or NULL if such property does not exist. More...
 
bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists. More...
 
MVariant GetProperty (const MStdString &name) const
 Get the static class property value using name of the property. More...
 
void SetProperty (const MStdString &name, const MVariant &value) const
 Set the static class property value using name of the property. More...
 
MStdStringVector GetAllPropertyNames () const
 Return the whole list of publicly available properties of this class and parents. More...
 
MStdStringVector GetOwnPropertyNames () const
 Return the list of publicly available properties owned by this class. More...
 
MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of publicly available persistent properties of this class and all parents of this class. More...
 
MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
bool MatchesClassOrTypeName (const MStdString &name) const
 Whether the given string is either class name or type name. More...
 

Static Public Member Functions

static const MClassGetClass (const MStdString &name)
 Find an MClass of a class with the name given. More...
 
static const MClassGetExistingClass (const MStdString &name)
 Find an existing MClass of a class with the name given. More...
 
static MStdStringVector GetAllClassNames ()
 Return the list of all publicly available classes. More...
 
static bool StaticIsKindOf (const MObject *obj, const MClass *cls)
 
static bool StaticIsKindOf (const MObject &ref, const MClass *cls)
 

Friends

class M_CLASS MObject
 

Detailed Description

Notion of a class that serves as the base for the reflection API.

Every class derived from MObject and exposed through Reflection has an associated class object. Class gives the way for an object to dynamically present the information about itself:

  • Parent class
  • Properties
  • Services (methods) and their parameters Current implementation supports only single inheritance.

Somewhat more popular name for what is called "service" is "method."

Properties can be read-only, in which case their values cannot be set by direct assignment to property. Read-write properties can be persistent, which means there is a default value available for such property, and that the value of such property is suitable for persisting in configuration.

See also
MObject

Member Enumeration Documentation

anonymous enum
Enumerator
MAXIMUM_NUMBER_OF_SERVICE_PARAMETERS 

Maximum number of parameters supported in a service.

MAXIMUM_CLASS_NAME_LENGTH 

Maximum size of class name in characters including trailing zero (divisible by 4)

Member Function Documentation

MVariant MClass::Call ( const MStdString name,
const MVariant params 
) const

Call the static service of the class with parameters, given as variant.

Service of the class is the same as static method in C++.

Precondition
The service with such name should exist, shall be static (service of class), and the number of parameters should be equal to one supported by the call, otherwise an exception is thrown. The preconditions of the particular service that gets called also apply.
Parameters
nameName of the static service (method) to call.
paramsParameters to pass to the static service.
  • To pass no parameters, supply an empty MVariant as parameter, or more conveniently, use Call0.
  • To pass a single non-empty non-collection MVariant using Call, give it directly as param, or use Call1.
  • To pass a single empty MVariant as parameter, enclose it into a collection, or use Call1.
  • To pass a couple of parameters, supply them in a collection of MVariant values.
  • To pass a single parameter, which is a collection of MVariant value, enclose it into another collection.
Returns
Returns whatever the reflected service/method with the given name returns. If the called service has no return value, the returned MVariant is empty.
See also
Call0 - calling service without parameters
Call1 - calling service with one parameter
Call2 - calling service with two parameters
CallV - calling service with a vector of parameters
MObject::Call - calling non-static service of an object
MVariant MClass::Call0 ( const MStdString name) const

Call the static service of the object with no parameters.

Service of the class is the same as static method in C++.

Precondition
The service with such name should exist, shall be static (service of class), and should have no parameters, otherwise an exception is thrown. The preconditions of the particular service that gets called also apply.
Parameters
nameName of the static service (method) to call.
Returns
Returns whatever the reflected service/method with the given name returns. If the called service has no return value, the returned MVariant is empty.
See also
Call - generic call of the service with parameters given as generic MVariant
Call1 - calling service with one parameter
Call2 - calling service with two parameters
CallV - calling service with a vector of parameters
MObject::Call0 - calling non-static service of an object with no parameters
MVariant MClass::Call1 ( const MStdString name,
const MVariant p1 
) const

Call the static service of the object with one parameter.

Service of the class is the same as static method in C++.

Precondition
The service with such name should exist, shall be static (service of class), and should have one parameter, otherwise an exception is thrown. The preconditions of the particular service that gets called also apply.
Parameters
nameName of the static service (method) to call.
p1The parameter to pass to static service.
Returns
Returns whatever the reflected service/method with the given name returns. If the called service has no return value, the returned MVariant is empty.
See also
Call - generic call of the service with parameters given as generic MVariant
Call0 - calling service with no parameters
Call2 - calling service with two parameters
CallV - calling service with a vector of parameters
MObject::Call1 - calling non-static service of an object with one parameter
MVariant MClass::Call2 ( const MStdString name,
const MVariant p1,
const MVariant p2 
) const

Call the static service of the object with two parameter.

Service of the class is the same as static method in C++.

Precondition
The service with such name should exist, shall be static (service of class), and should have two parameters, otherwise an exception is thrown. The preconditions of the particular service that gets called also apply.
Parameters
nameName of the service (method) to call.
p1The first parameter to pass to service.
p2The second parameter to pass to service.
Returns
Returns whatever the reflected service/method with the given name returns. If the called service has no return value, the returned MVariant is empty.
See also
Call - generic call of the service with parameters given as generic MVariant
Call0 - calling service with no parameters
Call1 - calling service with two parameters
CallV - calling service with a vector of parameters
MObject::Call2 - calling non-static service of an object with two parameters
MVariant MClass::CallV ( const MStdString name,
const MVariant::VariantVector params 
) const

Call the static service of the object with vector of parameter.

Service of the class is the same as static method in C++.

Precondition
The service with such name should exist, shall be static (service of class), and should have the same number of parameters as the vector count given, otherwise an exception is thrown. The preconditions of the particular service that gets called also apply.
Parameters
nameName of the service (method) to call.
paramsThe vector of parameters to pass to service.
Returns
Returns whatever the reflected service/method with the given name returns. If the called service has no return value, the returned MVariant is empty.
See also
Call - generic call of the service with parameters given as generic MVariant
Call0 - calling service with no parameters
Call1 - calling service with one parameter
Call2 - calling service with two parameters
MObject::CallV - calling non-static service of an object with vector of parameters
static MStdStringVector MClass::GetAllClassNames ( )
static

Return the list of all publicly available classes.

While this property is declared in MClass, it really belongs to global environment of the application. The list composes all classes from all shared libraries or executables available at the time of the call. If a library is loaded dynamically at run time, and it has reflected classes, this list will grow.

MStdStringVector MClass::GetAllPersistentPropertyNames ( ) const

Return the list of publicly available persistent properties of this class and all parents of this class.

Persistent properties of this class and all parents of this class are returned.

See also
GetAllPropertyNames - fetch properties of this class and all parents of this class
GetOwnPropertyNames - fetch properties of this class, excluding parents
MStdStringVector MClass::GetAllPropertyNames ( ) const

Return the whole list of publicly available properties of this class and parents.

Persistent and not persistent properties of this class and all parents of this class are returned.

See also
GetOwnPropertyNames - fetch only this class properties, excluding properties of parents
GetAllPersistentPropertyNames - fetch only persistent properties.
MStdStringVector MClass::GetAllServiceNames ( ) const

The collection of all publicly available reflection enabled services.

The list of services includes services of parent class. If the service has copies with different number of parameters, still only one copy of the service name will be present.

See also
GetOwnServiceNames - return class own service names, excluding parents
static const MClass* MClass::GetClass ( const MStdString name)
static

Find an MClass of a class with the name given.

All reflected classes existing in the application are enumerated to find a class.

Parameters
nameClass name to search for
Returns
MClass object to represent the existing reflected class, or null, if parent with such name does not exist.
See also
GetExistingClass - throws an exception if class is not present
static const MClass* MClass::GetExistingClass ( const MStdString name)
static

Find an existing MClass of a class with the name given.

All reflected classes existing in the application are enumerated to find a class.

Parameters
nameClass name to search for. Such class should exist, or an exception is thrown.
Returns
MClass object to represent the existing reflected class.
See also
GetClass - returns null if class is not present
MConstChars MClass::GetName ( ) const
inline

Access the name of the MClass.

This will be a string representation of a particular class, like "Table" would be the one to represent class MTable.

MStdStringVector MClass::GetOwnPropertyNames ( ) const

Return the list of publicly available properties owned by this class.

Persistent and not persistent properties of this class are returned.

See also
GetAllPropertyNames - fetch properties of this class and all parents of this class
GetAllPersistentPropertyNames - fetch only persistent properties.
const MServiceDefinition* MClass::GetOwnServiceDefinitions ( ) const
inline

Return the pointer to the array of objects that represent publicly available services.

This is a C++ only call.

MStdStringVector MClass::GetOwnServiceNames ( ) const

The collection of publicly available reflection enabled services owned by the class.

The list of services does not include services of parent class. If the service has copies with different number of parameters, still only one copy of the service name will be present.

See also
GetAllServiceNames - return all service names available, including those in parents
const MClass* MClass::GetParent ( ) const
inline

Get parent of a class, or NULL if the class has no parent.

The only class that has no parent is MObject.

const MClass* MClass::GetParentClass ( const MStdString name) const

Get parent class by the name specified.

Parameters
nameClass name, parent name.
Returns
MClass object to represent the parent class, or null, if parent with such name does not exist.
MVariant MClass::GetPersistentPropertyDefaultValue ( const MStdString name) const

Get the default value of persistent property with the name given.

Parameters
nameName of the persistent property to fetch default value from. The object should have the property with such name, and this property should have a default value (be persistent). Otherwise an exception is thrown.
Returns
Default value of property of a given name is returned.
MVariant MClass::GetProperty ( const MStdString name) const

Get the static class property value using name of the property.

Precondition
Particular property's preconditions apply to this call.
Parameters
nameName of the property of interest. The property with such name should exist, and it should be the property of the class. Otherwise an exception will be thrown.
Returns
Value of property is returned.
See also
SetProperty - Set class property value.
GetPropertyDefinition - returns the constant pointer to the definition of the property with a name given.
MObject::GetProperty - Get property of an object. In case the static class property is accessed, the call MObject::GetProperty translates into this call, MClass::GetProperty
const MPropertyDefinition* MClass::GetPropertyDefinition ( const MStdString name) const
inline

Get the existing constant definition of the property with the name specified.

Parameters
nameThe name of the property. The property with the name given should exist, otherwise the service throws an exception.
Returns
Property definition to represent the property of a given name will be returned.
See also
GetPropertyDefinitionOrNull - will return NULL if the property with the given name does not exist.
const MPropertyDefinition* MClass::GetPropertyDefinitionOrNull ( const MStdString name) const

Get the constant definition of the property with the name specified, or NULL if such property does not exist.

Parameters
nameThe name of the property.
Returns
Property definition to represent the property of a given name will be returned, or NULL, if there is no such property.
See also
GetPropertyDefinition - will never return NULL but rather throw an exception if the property does not exist.
const MServiceDefinition* MClass::GetServiceDefinition ( const MStdString name,
int  expectedNumberOfParameters = -1 
) const

Get the constant definition of service (method) with the given name, or return NULL if such service does not exist.

This is C++ only. Service, as used in the identifier, is another name for method.

Parameters
nameService name to get definition for. If service does not exist, an exception is thrown.
expectedNumberOfParametersExpected number of parameters. If specified, and not -1, shall denote the valid expected number of parameters. This parameter will need to be specified only for services that allow overloading.
Returns
Service definition is returned, never a null.
See also
GetServiceDefinitionOrNull - throws an exception
const MServiceDefinition* MClass::GetServiceDefinitionOrNull ( const MStdString name,
int  expectedNumberOfParameters = -1 
) const

Get the constant definition of service (method) with the given name, or return NULL if such service does not exist.

This is C++ only. Service, as used in the identifier, is another name for method.

Parameters
nameService name to get definition for. If service does not exist, NULL will be returned.
expectedNumberOfParametersExpected number of parameters. If specified, and not -1, shall denote the valid expected number of parameters. This parameter will need to be specified only for services that allow overloading.
Returns
Service definition, if such service exists in the class, or NULL, if the specified service does not exist.
See also
GetServiceDefinition - throws an exception
MConstChars MClass::GetTypeName ( ) const
inline

Access the type name of the class.

Type of the class is in majority of cases the same as the class name. The differences exist only in MCOM classes, those derived from MCOMObject, such as MProtocol and MChannel.

bool MClass::IsKindOf ( const MClass ) const

Tell about the relationship between this class and a given class.

Returns
True will mean the current object is kind of a given class.
See also
StaticIsKindOf - static version that also checks if the object is not null
bool MClass::IsPropertyPresent ( const MStdString name) const
inline

Tell if the property with the given name exists.

Parameters
nameThe property name for which to check the existence
Returns
True returned if such property is present in either this class, or its parent
See also
MObject::IsPropertyPresent - essentially the same call, but it works on objects, not classes
bool MClass::IsServicePresent ( const MStdString name) const
inline

Tell if the service (method) with the given name exists in the class.

Parameters
nameName of the service to check.
Returns
True returned if such service/method is present in either this class, or its parent
See also
MObject::IsServicePresent - essentially the same call, but it works on objects, not classes
bool MClass::MatchesClassOrTypeName ( const MStdString name) const

Whether the given string is either class name or type name.

This method is a convenience when a string has to match either class or type of this Class.

Parameters
nameName of the presumed class or type.
Returns
True will be returned if the parameter matches either class name or type name.
void MClass::SetProperty ( const MStdString name,
const MVariant value 
) const

Set the static class property value using name of the property.

Precondition
Particular property's preconditions apply to this call.
Parameters
nameName of the property of interest. The property with such name should exist, it should not be read-only, and it should be the property of the class. Otherwise an exception will be thrown.
valueValue to assign to the property.
See also
GetProperty - Get class property value.
MObject::SetProperty - Set property of an object. In case the static class property is accessed, the call MObject::SetProperty translates into this call, MClass::SetProperty
static bool MClass::StaticIsKindOf ( const MObject obj,
const MClass cls 
)
static

Static version that tells if a given object is of a given class, or it is its child.

Different from IsKindOf, this version checks of the given object is null.

Returns
True will mean the given object is not null, and is kind of a given class.
static bool MClass::StaticIsKindOf ( const MObject ref,
const MClass cls 
)
inlinestatic

Static version that tells if a given object is of a given class, or it is its child.

Different from IsKindOf, this version checks of the given object is null.

Returns
True will mean the given object is not null, and is kind of a given class.