iopc::Type Class Reference
[iopcmeta]

Instances of this class descendants - the Type Descriptions - represent reflection-capable classes and selected C++ or STL types. More...

#include <type.h>

Inheritance diagram for iopc::Type:

Inheritance graph
[legend]

List of all members.

Public Types

enum  DataTypeClassEnum { IOPC_TYPECLASS_SIMPLE = 0, IOPC_TYPECLASS_STRING, IOPC_TYPECLASS_COMPLEX, IOPC_TYPECLASS_ENHANCED }
 Types can be classified into one of the following categories. More...
enum  DataTypeEnum {
  IOPC_TYPE_INVALID = 0, IOPC_TYPE_BOOL, IOPC_TYPE_CHAR, IOPC_TYPE_UCHAR,
  IOPC_TYPE_SCHAR, IOPC_TYPE_SHORT, IOPC_TYPE_USHORT, IOPC_TYPE_INT,
  IOPC_TYPE_UINT, IOPC_TYPE_LONG, IOPC_TYPE_ULONG, IOPC_TYPE_FLOAT,
  IOPC_TYPE_DOUBLE, IOPC_TYPE_LONGDOUBLE, IOPC_TYPE_WCHART, IOPC_TYPE_STRING,
  IOPC_TYPE_WSTRING, IOPC_TYPE_REF, IOPC_TYPE_COMPLEX, IOPC_TYPE_EINT,
  IOPC_TYPE_EUINT, IOPC_TYPE_ECHAR, IOPC_TYPE_EUCHAR, IOPC_TYPE_ESCHAR,
  IOPC_TYPE_ESHORT, IOPC_TYPE_EUSHORT, IOPC_TYPE_ELONG, IOPC_TYPE_EULONG,
  IOPC_TYPE_EFLOAT, IOPC_TYPE_EDOUBLE, IOPC_TYPE_ELDOUBLE, IOPC_TYPE_EWCHART,
  IOPC_TYPE_EBOOL, IOPC_TYPE_ESTRING, IOPC_TYPE_EWSTRING
}
 Enumerates types defined in iopcmeta. More...
typedef std::map< std::string,
Attribute
AttributesMap
typedef std::map< std::string,
const Attribute * > 
InheritedAttributesMap

Public Member Functions

virtual const std::string getName () const =0
 Returns name of the type.
virtual const std::string getNamespace () const =0
 Returns name of the namespace in which this type is defined.
const std::string getQualifiedName () const
 Returns qualified name of the type.
virtual int getSizeOf (const void *object) const =0
 Returns memory size of object of this type.
virtual bool isBuiltIn () const =0
 Determines whether the type is C++ built-in or STL data type.
virtual void * newInstance () const =0
 Allocates a new instance of the data type this Type represents.
virtual ObjectnewObjectInstance () const =0
 Allocates a new instance of the reflection-capable class this Type represents.
virtual void deleteInstance (void *instance) const =0
 Frees the instance allocated by the newInstance method.
virtual DataTypeClassEnum getDataTypeClass () const =0
 Returns the data type class for the current type.
virtual DataTypeEnum getDataType () const =0
 Returns the DataTypeEnum value of the current type.
virtual void fillAttributeValues (const Object &o, std::map< std::string, AttributeValue > &out) const =0
 Used by Object.
const ParentsList & getParents () const
 Returns a list of direct ancestors of this type.
const ChildrenList & getChildren () const
 Returns a list of direct descendants of this type.
const AllChildrenList & getAllChildren () const
 Returns a list of direct and indirect descendants of this type.
const AllParentsList & getAllParents () const
 Returns a list of direct and indirect ancestors of this type.
const AttributesMapgetAttributes () const
 Returns a map of Attribute objects representing attributes defined in this type.
const InheritedAttributesMapgetInheritedAttributes () const
 Returns a map of Attribute objects representing attributes defined in this type and attributes inherited from its ancestors.
const AttributegetAttribute (const std::string &name) const
 Looks up an Attribute by its name. Uses the list of attributes defined in this type.
bool hasAttribute (const std::string &name) const
 Determines whether this type contains an Attribute of a specified name.
const AttributegetAttributeAll (const std::string &name) const
 Looks up an Attribute by its name. Uses the list of attributes defined in this type or in its ancestors.
bool hasAttributeAll (const std::string &name) const
 Determines whether this type or its ancestors contain an Attribute of a specified name.
const TypegetFirstParent () const
 Assumes that this type has only one parent and returns it.
bool isTypeOf (const Type &type) const
 Determines whether this type is descendant of or identitcal to a Type.
template<typename T>
bool isTypeOf () const
 Determines whether this type is descendant of or identitcal to a type.
template<typename T>
bool is () const
 Determines whether this type is identitcal to a specified type.
template<typename T>
bool isNot () const
 Determines whether this type differs from a specified type.


Detailed Description

Instances of this class descendants - the Type Descriptions - represent reflection-capable classes and selected C++ or STL types.

There is only one Type Description for a reflection-capable class or a basic type. This interface provides methods for the type structure inspection.

Implementations of this abstract class - specialisations of the TypeDesc<T> template class are either defined in the library or generated using iopcsp.

The following example illustrates the type inspection features this class provides.

 // Type Descriptions can be obtained either from the TypeManager:
 const Type& t = TypeManager::getType("::ClassX");
 // or statically:
 const Type& t = TypeDesc<Person>::getType();

 // The type parents can be iterated:
 const Type::ParentsList& parents = t.getParents();
 for(Type::ParentsIterator it = parents.begin();        it != parents.end(); it++) {
   cout << (*it)->getQualifiedName() << endl;
 }

 // Children:
 const Type::ChildrenList& children = t.getChildren();
 for(Type::ChildrenIterator it = children.begin(); it != children.end(); it++) {
   cout << (*it)->getQualifiedName() << endl;
 }

 // Attributes:
 const Type::AttributesMap& attributes = t.getAttributes();
 for(Type::AttributesIterator it = attributes.begin(); it != attributes.end(); it++) {
   const Attribute& attr = it->second;
         switch (attr.getVisibility()) {
                case Attribute::VISIBILITY_PUBLIC: cout << "public "; break;
                case Attribute::VISIBILITY_PRIVATE: cout << "private "; break;
                case Attribute::VISIBILITY_PROTECTED: cout << "protected ";break;
         }
         cout << it->second.getType().getQualifiedName()        << " " << it->first << endl;
 }

 // Type Descriptions can be compared:
 const Type& t1 = TypeDesc<Person>::getType();
 const Type& t2 = TypeDesc<Student>::getType();
 if (t1 == t2) { cout << "t1 is t2" << endl; }
 if (t1 != t2) { cout << "t1 is not t2" << endl; }
 if (t1.isTypeOf(t2)) { cout << "t1 is t2 or t1 is descendant of t2" << endl; }
 if (t2.isTypeOf(t1)) { cout << "t1 is t2 or t2 is descendant of t1" << endl; }
 if (t1.is<Student>()) { cout << "t1 is of type Student" << endl; }
 if (t2.is<Student>()) { cout << "t2 is of type Student" << endl; }
 if (t1.isTypeOf<Person>()) { cout << "t1 is of type Person or its descendant" << endl; }
 if (t2.isTypeOf<Person>()) { cout << "t2 is of type Person or its descendant" << endl; }

Member Typedef Documentation

typedef std::map<std::string, Attribute> iopc::Type::AttributesMap

Keys are names of the attributes stored as values

typedef std::map<std::string, const Attribute*> iopc::Type::InheritedAttributesMap

Keys are names of the attributes stored as values


Member Enumeration Documentation

Types can be classified into one of the following categories.

Enumerator:
IOPC_TYPECLASS_SIMPLE  Built-in numeric types
IOPC_TYPECLASS_STRING  String types - std::string and std::wstring
IOPC_TYPECLASS_COMPLEX  Classes or structures. Descendants of Object (except enhanced data types)
IOPC_TYPECLASS_ENHANCED  Enhanced data types. Descendants of EnhancedTypeBase

Enumerates types defined in iopcmeta.

Enumerator:
IOPC_TYPE_INVALID  not a valid type
IOPC_TYPE_BOOL  bool
IOPC_TYPE_CHAR  char (signed or unsigned - depends on platform and compiler settings)
IOPC_TYPE_UCHAR  unsigned char
IOPC_TYPE_SCHAR  signed char
IOPC_TYPE_SHORT  short (signed)
IOPC_TYPE_USHORT  unsigned short
IOPC_TYPE_INT  int (signed)
IOPC_TYPE_UINT  unsigned
IOPC_TYPE_LONG  long (signed)
IOPC_TYPE_ULONG  unsigned long
IOPC_TYPE_FLOAT  float
IOPC_TYPE_DOUBLE  double
IOPC_TYPE_LONGDOUBLE  long double
IOPC_TYPE_WCHART  wchar_t
IOPC_TYPE_STRING  char * (0-terminated)
IOPC_TYPE_WSTRING  wchar_t * (00-terminated)
IOPC_TYPE_REF  reference to some other persistent object
IOPC_TYPE_COMPLEX  Classes or structures. Descendants of Object (except enhanced data types).
IOPC_TYPE_EINT  Enhanced int.
IOPC_TYPE_EUINT  Enhanced unsigned int.
IOPC_TYPE_ECHAR  Enhanced char.
IOPC_TYPE_EUCHAR  Enhanced unsigned char.
IOPC_TYPE_ESCHAR  Enhanced signed char.
IOPC_TYPE_ESHORT  Enhanced short int.
IOPC_TYPE_EUSHORT  Enhanced unsigned short int.
IOPC_TYPE_ELONG  Enhanced long.
IOPC_TYPE_EULONG  Enhanced unsigned long.
IOPC_TYPE_EFLOAT  Enhanced float.
IOPC_TYPE_EDOUBLE  Enhanced double.
IOPC_TYPE_ELDOUBLE  Enhanced long double.
IOPC_TYPE_EWCHART  Enhanced wchar_t.
IOPC_TYPE_EBOOL  Enhanced bool.
IOPC_TYPE_ESTRING  Enhanced string.
IOPC_TYPE_EWSTRING  Enhanced wstring.


Member Function Documentation

virtual const std::string iopc::Type::getNamespace (  )  const [pure virtual]

Returns name of the namespace in which this type is defined.

Returns empty string if the type does not have any namespace.

Implemented in iopc::TypeDesc< T >, iopc::TypeDesc< iopc::EStr< wchar_t > >, iopc::TypeDesc< std::string >, iopc::TypeDesc< std::wstring >, iopc::TypeDesc< iopc::DbPtrBase >, and iopc::TypeDesc< iopc::EStr< char > >.

const std::string iopc::Type::getQualifiedName (  )  const [inline]

Returns qualified name of the type.

Returns:
getNamespace() + NAMESPACE_DELIMITER + getName()

virtual int iopc::Type::getSizeOf ( const void *  object  )  const [pure virtual]

Returns memory size of object of this type.

In some cases, the object parameter is ignored as it is not needed to determine the memory size. (Types of non-variable length such as numeric types). For some variable length types such as std::string or EString it doesn't return sizeof(std::string), sizeof(EString), but memory size needed to store the strings as standard, zero-terminated C-strings.

Returns:
Memory size needed to store the object this type represents.

Implemented in iopc::TypeDesc< T >, iopc::TypeDesc< iopc::EStr< wchar_t > >, iopc::TypeDesc< std::string >, iopc::TypeDesc< std::wstring >, iopc::TypeDesc< iopc::DbPtrBase >, and iopc::TypeDesc< iopc::EStr< char > >.

virtual void* iopc::Type::newInstance (  )  const [pure virtual]

Allocates a new instance of the data type this Type represents.

The instance is allocated using the new operator. To free the instance, use the corresponding deleteInstance(void* instance) method.

Implemented in iopc::TypeDesc< T >, iopc::TypeDesc< iopc::EStr< wchar_t > >, iopc::TypeDesc< std::string >, iopc::TypeDesc< std::wstring >, iopc::TypeDesc< iopc::DbPtrBase >, and iopc::TypeDesc< iopc::EStr< char > >.

virtual Object* iopc::Type::newObjectInstance (  )  const [pure virtual]

Allocates a new instance of the reflection-capable class this Type represents.

The instance is allocated using the new operator. To free the instance, you can use standard delete operator.

Returns:
Other types than Object descendants return NULL.

Implemented in iopc::TypeDesc< T >, iopc::TypeDesc< iopc::EStr< wchar_t > >, iopc::TypeDesc< std::string >, iopc::TypeDesc< std::wstring >, iopc::TypeDesc< iopc::DbPtrBase >, and iopc::TypeDesc< iopc::EStr< char > >.

virtual void iopc::Type::fillAttributeValues ( const Object o,
std::map< std::string, AttributeValue > &  out 
) const [pure virtual]

Used by Object.

Used to fill a map of AttributeValues by the type description

Parameters:
[in] o Object containing the attributes
[out] out Map into which the attribute values are inserted

Implemented in iopc::TypeDesc< T >, iopc::TypeDesc< iopc::EStr< wchar_t > >, iopc::TypeDesc< std::string >, iopc::TypeDesc< std::wstring >, iopc::TypeDesc< iopc::DbPtrBase >, and iopc::TypeDesc< iopc::EStr< char > >.

const Attribute& iopc::Type::getAttribute ( const std::string &  name  )  const

Looks up an Attribute by its name. Uses the list of attributes defined in this type.

Parameters:
name A name of attribute to look for
Exceptions:
IopcIncorrectUsageException If no attribute of the specified name is found

bool iopc::Type::hasAttribute ( const std::string &  name  )  const

Determines whether this type contains an Attribute of a specified name.

Parameters:
name A name of attribute to look for

const Attribute & iopc::Type::getAttributeAll ( const std::string &  name  )  const

Looks up an Attribute by its name. Uses the list of attributes defined in this type or in its ancestors.

Parameters:
name A name of attribute to look for
Exceptions:
IopcIncorrectUsageException If no attribute of the specified name is found

bool iopc::Type::hasAttributeAll ( const std::string &  name  )  const

Determines whether this type or its ancestors contain an Attribute of a specified name.

Parameters:
name A name of attribute to look for

const Type & iopc::Type::getFirstParent (  )  const

Assumes that this type has only one parent and returns it.

Exceptions:
IopcIncorrectUsageException If this type has no parent class

bool iopc::Type::isTypeOf ( const Type type  )  const

Determines whether this type is descendant of or identitcal to a Type.

Parameters:
type The type to test against

template<typename T>
bool iopc::Type::isTypeOf (  )  const [inline]

Determines whether this type is descendant of or identitcal to a type.

Template Parameters:
T The type to test against

template<typename T>
bool iopc::Type::is (  )  const [inline]

Determines whether this type is identitcal to a specified type.

Template Parameters:
T The type to test against

template<typename T>
bool iopc::Type::isNot (  )  const [inline]

Determines whether this type differs from a specified type.

Template Parameters:
T The type to test against


The documentation for this class was generated from the following files:

Generated on Tue Apr 14 16:46:37 2009 for IOPC 2 by  doxygen 1.5.6