C12Adapter Opensource C++ Interface
MObject Class Referenceabstract

Root object that establishes dynamic class information, dynamic property and method handling and marshaling. More...

Inheritance diagram for MObject:

Public Member Functions

virtual ~MObject ()
 Object destructor.
 
virtual const MClassGetClass () const =0
 Get the final class of the object. More...
 
virtual unsigned GetEmbeddedSizeof () const
 For embedded object types, return the size of the class. More...
 
bool IsEmbeddedObject () const
 Tell if the object is of embedded kind. More...
 
SHOW_INTERNAL MVariant Call (const MStdString &name, const MVariant &params)
 Call the object service with parameters, given as variant. More...
 
MVariant Call0 (const MStdString &name)
 Call the object service with no parameters. More...
 
MVariant Call1 (const MStdString &name, const MVariant &p1)
 Call the object service with one parameter. More...
 
MVariant Call2 (const MStdString &name, const MVariant &p1, const MVariant &p2)
 Call the object service with two parameter. More...
 
MVariant Call3 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3)
 Call the object service with three parameter. More...
 
MVariant Call4 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4)
 Call the object service with four parameter. More...
 
MVariant Call5 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5)
 Call the object service with five parameter. More...
 
MVariant Call6 (const MStdString &name, const MVariant &p1, const MVariant &p2, const MVariant &p3, const MVariant &p4, const MVariant &p5, const MVariant &p6)
 Call the object service with six parameter. More...
 
virtual MVariant CallV (const MStdString &name, const MVariant::VariantVector &params)
 Call the object service with parameters, given as variant vector. More...
 
virtual bool IsPropertyPresent (const MStdString &name) const
 Tell if the property with the given name exists.
 
virtual bool IsServicePresent (const MStdString &name) const
 Tell if the service with the given name exists.
 
virtual MVariant GetProperty (const MStdString &name) const
 Get the property value using name of the property. More...
 
virtual void SetProperty (const MStdString &name, const MVariant &value)
 Set the property using name of the property, and value. More...
 
virtual MStdStringVector GetAllPropertyNames () const
 Return the list of publicly available properties, persistent or not. More...
 
virtual MStdStringVector GetAllPersistentPropertyNames () const
 Return the list of persistent properties. More...
 
virtual void SetPersistentPropertiesToDefault ()
 Set the persistent properties of the object to their default values. More...
 
virtual MVariant GetPersistentPropertyDefaultValue (const MStdString &name) const
 Get the default value of persistent property with the name given. More...
 
virtual void SetPersistentPropertyToDefault (const MStdString &name)
 Set the persistent property with the name given to default value. More...
 
virtual const char * GetType () const
 Get the name of the type for the object (could be the same as class name).
 
virtual void SetType (const MStdString &)
 Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name. More...
 
virtual void Validate ()
 Validate internal structures of the object. More...
 

Static Public Member Functions

static const MClassGetStaticClass ()
 Get the declared class of this particular object. More...
 
static bool IsClassPresent (const MStdString &name)
 Tells if the given class name is available. More...
 

Static Public Attributes

static const MClass s_class
 Class of MObject.
 

Protected Member Functions

 MObject ()
 Object constructor, protected as the class is abstract.
 
void DoSetPersistentPropertiesToDefault (const MClass *staticClass)
 Set the persistent properties to their default values for one object provided the class for that object. More...
 

Detailed Description

Root object that establishes dynamic class information, dynamic property and method handling and marshaling.

The class is an abstract base.

The derived objects have type names available from the abstract service GetType.

This class allows for having a number of properties and methods to be publicly defined, and available through their names. This is done by implementation of the the dynamic dispatching mechanism alternative to the semi-static virtual C++ dispatching.

The children of this class should have a macro M_DECLARE_*_CLASS at the end of their declaration, and a set of M_PROPERTY_ macros in the implementation CPP file. They should define the properties publicly available.

Here is an example of some MObject abstract child:

// File SomeObject.h
class MSomeObject : public MObject
{
public:
MSomeObject();
virtual ~MSomeObject();
int GetSpeed() const; // Get integer property method
void SetSpeed(int); // Set integer property method
unsigned GetDeviceID() const; // Get device ID, Get-only
private:
M_DECLARE_CLASS(SomeObject)
};
// File SomeObject.cpp
#include "SomeObject.h"
....
M_START_PROPERTIES(SomeObject)
M_OBJECT_PROPERTY_PERSISTENT_INT(SomeObject, Speed, 9600)
M_OBJECT_PROPERTY_READONLY_UINT (SomeObject, DeviceId, 0) // Get-only property
M_START_METHODS(SomeObject)
M_END_CLASS(SomeObject, Object)

Here is an example of some MObject child:

// File MSomeProtocol.h
class MSomeProtocol : public MObject
{
public:
MSomeProtocol();
virtual ~MSomeProtocol();
int GetSpeed() const; // Get integer property method
void SetSpeed(int); // Set integer property method
unsigned GetDeviceID() const; // Get device ID, Get-only
private:
M_DECLARE_CLASS(SomeProtocol)
};
// File SomeProtocol.cpp
#include "SomeProtocol.h"
....
M_START_PROPERTIES(SomeProtocol)
M_OBJECT_PROPERTY_PERSISTENT_INT(SomeProtocol, Speed, 9600)
M_OBJECT_PROPERTY_READONLY_UINT (SomeProtocol, DeviceId) // Get-only property
M_START_METHODS(SomeProtocol)
M_END_CLASS(SomeProtocol, Object)

The _EXACT class declarations do not add M prefix to their names given. The _TYPED class declarations make type and class names different for the class definition.

There is one property defined for the class. This is TYPE, which gives the standard string, representation of the type (class).

Member Function Documentation

SHOW_INTERNAL MVariant MObject::Call ( const MStdString name,
const MVariant params 
)

Call the object service with parameters, given as variant.

Parameters can be Empty variant, which will mean no parameters; a variant vector, which will be the vector of parameters; or it can be one single parameter.

Precondition
The service with such name should exist, 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 apply.
See also
CallV which unconditionally takes the vector of parameters.
MVariant MObject::Call0 ( const MStdString name)

Call the object service with no parameters.

Precondition
The service with such name should exist, and shall have no parameters, otherwise an exception is thrown. The preconditions of the particular service apply.
See also
CallV which unconditionally takes the variant as parameters
Call that takes a variant
Call1 that takes a variant with 1 parameter
Call2 that takes a variant with 2 parameters
Call3 that takes a variant with 3 parameters
Call4 that takes a variant with 4 parameters
Call5 that takes a variant with 5 parameters
Call6 that takes a variant with 6 parameters
MVariant MObject::Call1 ( const MStdString name,
const MVariant p1 
)

Call the object service with one parameter.

The clients have to provide CallV as implementation.

Precondition
The service with such name should exist, and shall have no parameters, otherwise an exception is thrown. The preconditions of the particular service apply.
See also
CallV which unconditionally takes the variant as parameters
Call that takes a variant
Call0 that takes a variant with no parameters
Call2 that takes a variant with 2 parameters
Call3 that takes a variant with 3 parameters
Call4 that takes a variant with 4 parameters
Call5 that takes a variant with 5 parameters
Call6 that takes a variant with 6 parameters
MVariant MObject::Call2 ( const MStdString name,
const MVariant p1,
const MVariant p2 
)

Call the object service with two parameter.

The clients have to provide CallV as implementation.

Precondition
The service with such name should exist, and shall have no parameters, otherwise an exception is thrown. The preconditions of the particular service apply.
See also
CallV which unconditionally takes the variant as parameters
Call that takes a variant
Call0 that takes a variant with no parameters
Call1 that takes a variant with 1 parameter
Call3 that takes a variant with 3 parameters
Call4 that takes a variant with 4 parameters
Call5 that takes a variant with 5 parameters
Call6 that takes a variant with 6 parameters
MVariant MObject::Call3 ( const MStdString name,
const MVariant p1,
const MVariant p2,
const MVariant p3 
)

Call the object service with three parameter.

The clients have to provide CallV as implementation.

Precondition
The service with such name should exist, and shall have no parameters, otherwise an exception is thrown. The preconditions of the particular service apply.
See also
CallV which unconditionally takes the variant as parameters
Call that takes a variant
Call0 that takes a variant with no parameters
Call1 that takes a variant with 1 parameter
Call2 that takes a variant with 2 parameters
Call4 that takes a variant with 4 parameters
Call5 that takes a variant with 5 parameters
Call6 that takes a variant with 6 parameters
MVariant MObject::Call4 ( const MStdString name,
const MVariant p1,
const MVariant p2,
const MVariant p3,
const MVariant p4 
)

Call the object service with four parameter.

The clients have to provide CallV as implementation.

Precondition
The service with such name should exist, and shall have no parameters, otherwise an exception is thrown. The preconditions of the particular service apply.
See also
CallV which unconditionally takes the variant as parameters
Call that takes a variant
Call0 that takes a variant with no parameters
Call1 that takes a variant with 1 parameter
Call2 that takes a variant with 2 parameters
Call3 that takes a variant with 3 parameters
Call5 that takes a variant with 5 parameters
Call6 that takes a variant with 6 parameters
MVariant MObject::Call5 ( const MStdString name,
const MVariant p1,
const MVariant p2,
const MVariant p3,
const MVariant p4,
const MVariant p5 
)

Call the object service with five parameter.

The clients have to provide CallV as implementation.

Precondition
The service with such name should exist, and shall have no parameters, otherwise an exception is thrown. The preconditions of the particular service apply.
See also
CallV which unconditionally takes the variant as parameters
Call that takes a variant
Call0 that takes a variant with no parameters
Call1 that takes a variant with 1 parameter
Call2 that takes a variant with 2 parameters
Call3 that takes a variant with 3 parameters
Call4 that takes a variant with 4 parameters
Call6 that takes a variant with 6 parameters
MVariant MObject::Call6 ( const MStdString name,
const MVariant p1,
const MVariant p2,
const MVariant p3,
const MVariant p4,
const MVariant p5,
const MVariant p6 
)

Call the object service with six parameter.

The clients have to provide CallV as implementation.

Precondition
The service with such name should exist, and shall have no parameters, otherwise an exception is thrown. The preconditions of the particular service apply.
See also
CallV which unconditionally takes the variant as parameters
Call that takes a variant
Call0 that takes a variant with no parameters
Call1 that takes a variant with 1 parameter
Call2 that takes a variant with 2 parameters
Call3 that takes a variant with 3 parameters
Call4 that takes a variant with 4 parameters
Call5 that takes a variant with 5 parameters
virtual MVariant MObject::CallV ( const MStdString name,
const MVariant::VariantVector params 
)
virtual

Call the object service with parameters, given as variant vector.

Precondition
The service with such name should exist, 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 apply.
See also
Call that takes a variant
Call0 that takes a variant with no parameters
Call1 that takes a variant with 1 parameter
Call2 that takes a variant with 2 parameters
Call3 that takes a variant with 3 parameters
Call4 that takes a variant with 4 parameters
Call5 that takes a variant with 5 parameters
Call6 that takes a variant with 6 parameters

Reimplemented in MAutomation.

void MObject::DoSetPersistentPropertiesToDefault ( const MClass staticClass)
protected

Set the persistent properties to their default values for one object provided the class for that object.

This service is for calling it from constructors. A typical parameter is the static class of the object. The parameters for the parent properties are not touched. This is not a virtual service!

Parameters
staticClassPointer to a class of this object, typically m_class
See also
M_SET_PERSISTENT_PROPERTIES_TO_DEFAULT Easiest way to call this method
virtual MStdStringVector MObject::GetAllPersistentPropertyNames ( ) const
virtual

Return the list of persistent properties.

See also
GetAllPropertyNames for the list of all properties

Reimplemented in MCOMObject.

virtual MStdStringVector MObject::GetAllPropertyNames ( ) const
virtual

Return the list of publicly available properties, persistent or not.

See also
GetAllPersistentPropertyNames for persistent properties only

Reimplemented in MCOMObject.

virtual const MClass* MObject::GetClass ( ) const
pure virtual

Get the final class of the object.

Do not overload this service explicitly. It is done automatically within the appropriate implementation macros.

Precondition
This particular service is pure virtual, and should not be called explicitly.
virtual unsigned MObject::GetEmbeddedSizeof ( ) const
virtual

For embedded object types, return the size of the class.

For regular, not embedded types, this is zero, which is the default implementation.

Returns
size of embedded object in bytes, or zero if the object is not embedded

Reimplemented in MTime, MVersion, MTimeRecurrentYearly, MTimeSpan, MGuid, and MTimer.

virtual MVariant MObject::GetPersistentPropertyDefaultValue ( const MStdString name) const
virtual

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

Precondition
The object should have the property with such name, and this property should have a default value (be persistent). Otherwise an exception is thrown.
virtual MVariant MObject::GetProperty ( const MStdString name) const
virtual

Get the property value using name of the property.

The service allows extensions in children objects.

Precondition
The property with such name should exist, otherwise an exception will be thrown. The property value should be available at the time the service is called, or the value-related exception can be thrown.
See also
MClass::GetPropertyDefinition returns the constant pointer to the definition of the property with a name given.

Reimplemented in MAutomation.

static const MClass* MObject::GetStaticClass ( )
inlinestatic

Get the declared class of this particular object.

This service is defined explicitly with the reflection support macros.

static bool MObject::IsClassPresent ( const MStdString name)
inlinestatic

Tells if the given class name is available.

The call uses the reflection mechanism to tell if the class name exists

Parameters
nameClass name to test
Returns
True is returned if the given class is available, False otherwise
bool MObject::IsEmbeddedObject ( ) const
inline

Tell if the object is of embedded kind.

Embedded objects are value types, those that can be copied and compared by simple memory copy and comparison.

Returns
True means the object is of an embedded kind, and it can be manipulated by value
virtual void MObject::SetPersistentPropertiesToDefault ( )
virtual

Set the persistent properties of the object to their default values.

Also look at DoSetPersistentPropertiesToDefault that is typically used in constructors of MObject parents that have persistent properties.

Precondition
The object is built completely, will not work in constructor or destructor due to incomplete virtual table.
virtual void MObject::SetPersistentPropertyToDefault ( const MStdString name)
virtual

Set the persistent property with the name given to default value.

If the persistent property does exist, the error never results from setting the value to this property, as it is the duty of the application developer to ensure that the value is correct (the assertion is in place for debug version).

Precondition
The object should have the property with such name, and this property should have a default value (be persistent). Otherwise an exception is thrown.
virtual void MObject::SetProperty ( const MStdString name,
const MVariant value 
)
virtual

Set the property using name of the property, and value.

The service allows extensions in children objects.

Precondition
The property with such name should exist, otherwise an exception will be thrown. Any value-related or object-related exception can be thrown in case the given value has wrong type, or it is invalid, or the value cannot be set at this moment.

Reimplemented in MAutomation.

virtual void MObject::SetType ( const MStdString )
virtual

Intentionally, it will set the name of the type for the object, but the service will not allow setting the name to anything other than the current name.

Precondition
The name supplied should match exactly the one which is got by GetType, otherwise the exception takes place.
virtual void MObject::Validate ( )
virtual

Validate internal structures of the object.

Precondition
The object is properly initialized.