Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

IopcTranslatingSupport Class Reference

Class used to generate methods which makes a class persistent capable. More...

#include <iopcTranslatingSupport.h>

Inheritance diagram for IopcTranslatingSupport:

Inheritance graph
[legend]
Collaboration diagram for IopcTranslatingSupport:

Collaboration graph
[legend]
List of all members.

Public Member Functions

PtreecreateAttributeDeclaration (const char *className, const char *attrName, TypeInfo &typeInfo)
void createGettersAndSetters (const char *className, CStdString &getters, CStdString &setters)
CStdString createInitObjectFnc (const char *className)
CStdString createExportAttributesFnc (const char *className)
CStdString createImportAttributesFnc (const char *className)
CStdString createCreateInstanceFnc (const char *className)
CStdString createCreateReferenceFnc (const char *className)
CStdString createClassNameFnc (const char *className)
CStdString createClassRegistrarInstance (const char *className, const char *qualifiedClassName)
PtreecreateGetterCall (const char *className, const char *attrName, const char *fullClassQualification, Ptree *object, Ptree *op)
PtreecreateSetterCall (const char *className, const char *attrName, const char *fullClassQualification, Ptree *translatedExpr, Ptree *object, Ptree *op)
void sendClassToMetadataWriter (const char *className)

Protected Member Functions

CStdString createGetter (const char *className, const char *attrName, IopcAttributeInfo *attrInfo, int attrNumber)
CStdString createSetter (const char *className, const char *attrName, IopcAttributeInfo *attrInfo, int attrNumber)

Static Protected Member Functions

const char * getImportExportStructField (IopcDataType dataType)

Detailed Description

Class used to generate methods which makes a class persistent capable.

This class is inherited from IopcPcClassStore - so it works as a store for information about persistent classes.

The new functionality in this class is ability to generate methods needed to make a class persistent capable. This functionality is used by IopcTranslator.


Member Function Documentation

Ptree * IopcTranslatingSupport::createAttributeDeclaration const char *  className,
const char *  attrName,
TypeInfo typeInfo
 

Generates declaration of attribute and its indicator variable.

Because in OpenC++ it is not possible to change access specifier of a variable, persistent atributes declared by user cannot be simply renamed but it is necessary to remove them and add the renamed attributes with access specifier "private".

Returns:
Declaration of the renamed attribute and declaration of its indicator variable, the access specifier is added by IopcTranslator itself. The returned tree contains something like this:
int m_attr;\n bool m_attr_isValid;
Parameters:
className Name of the class from which the attribute came from.
attrName The original attribute name.
typeInfo OpenC++ representation of the attribute type.
See also:
VARIABLE_NAME, INDICATOR_VARIABLE_NAME

void IopcTranslatingSupport::createGettersAndSetters const char *  className,
CStdString &  getters,
CStdString &  setters
 

Generates getters and setters for all potentially persistent attributes of class className.

Traverses class's attributes and calls for each of them createSetter() and createGetter().

Note:
Individual getters and setters cannot be created while walking through the class in IopcTranslator::TranslateClass() because createGetter() needs number of attributes in the class - so IopcTranslator processes all attributes and adds them to IopcPcClassStore. Then it calls this function.
Parameters:
className Name of the class.
getters Result - string containing the generated getters.
setters Result - string containing the generated setters.

CStdString IopcTranslatingSupport::createInitObjectFnc const char *  className  ) 
 

Generates method iopcInitObject(), that initializes indicator variables of attributes in the persistent capable class and sets pointer to class's IopcClassObject if necessary.

The generated method can look like this:

void iopcInitObject(bool loadingFromDB) { if (loadingFromDB) { m_refA3_isValid = false; m_xxx_isValid = false; m_yyy_isValid = false; } else { m_classObject = IopcClassObject::getClassObject(ClassName(), true); m_refA3_isValid = true; m_xxx_isValid = true; m_yyy_isValid = true; } }

The only parameter of the generated method specifies whether we are loading the object from the database or not. The indicator variables are set according to it.

Parameters:
className Name of the class.
Returns:
The generated method as string.

CStdString IopcTranslatingSupport::createExportAttributesFnc const char *  className  ) 
 

Generates method iopcExportAttributes(), that exports values of object's attributes to IOPC LIB's class attributes array (parameter data).

If type of an attribute is IOPC_COMPLEX_DATA_TYPE, iopcExportAttributes() calls method iopcExport() on it and puts the method's result into the array. Attribute dataLen is used for safety.

The generated method can look like this:

virtual int iopcExportAttributes(IopcImportExportStruct * data, int dataLen) { if (dataLen != 3) return 1; data[0].valid = m_refA3_isValid; if (m_refA3_isValid) data[0].ulongVal = m_refA3.iopcExport(this); data[1].valid = m_xxx_isValid; if (m_xxx_isValid) data[1].stringVal = m_xxx; data[2].valid = m_yyy_isValid; if (m_yyy_isValid) data[2].wstringVal = m_yyy; return 0; }

Note:
Array data contains entries also for non persistent attributes - IOPC LIB doesn't know which data types are non-persistent (cannot distinguish them from attributes said in metadata to be transient).
Parameters:
className Name of the class.
Returns:
The generated method as string.

CStdString IopcTranslatingSupport::createImportAttributesFnc const char *  className  ) 
 

Generates method iopcImportAttributes(), that imports values from IOPC LIB's class attributes array (parameter data) to object's attributes.

If type of an attribute is IOPC_COMPLEX_DATA_TYPE, iopcImportAttributes() calls method iopcImport() on it giving it the value from the array. String attributes are copyied in this method, old strings are freed. Attribute dataLen is used for safety.

The generated method can look like this:

virtual int iopcImportAttributes(IopcImportExportStruct * data, int dataLen) { if (dataLen != 3) return 1; if (data[0].valid) { m_refA3.iopcImport(data[0].ulongVal, this); m_refA3_isValid = true; } if (data[1].valid) { if ((m_xxx_isValid) && (m_xxx)) free(m_xxx); m_xxx = strdup(data[1].stringVal); m_xxx_isValid = true; } if (data[2].valid) { if ((m_yyy_isValid) && (m_yyy)) free(m_yyy); m_yyy = wcsdup(data[2].wstringVal); m_yyy_isValid = true; } return 0; }

Note:
Array data contains entries also for non persistent attributes - IOPC LIB doesn't know which data types are non-persistent (cannot distinguish them from attributes said in metadata to be transient).
Parameters:
className Name of the class.
Returns:
The generated method as string.

CStdString IopcTranslatingSupport::createCreateInstanceFnc const char *  className  ) 
 

Generates method iopcCreateInstance(), that creates new instance of processed class (className) and initializes it. See example below:

static IopcPersistentObject * iopcCreateInstance() { IopcPersistentObject * object = new A3; object->iopcInitObject(true); return object; }

The method is used by IOPC LIB's class IopcClassFactory and related stuff to provide query and reference polymorphism.

Parameters:
className Name of the class.
Returns:
The generated method as string.
See also:
createClassRegistrarInstance().

CStdString IopcTranslatingSupport::createCreateReferenceFnc const char *  className  ) 
 

Generates method iopcCreateReference(), that creates new reference (Ref<T>) to processed class (className). See example below:

static RefBase * iopcCreateReference() { return new Ref<A3>; }

The method is used by IOPC LIB's class IopcClassFactory and related stuff for example when traversing results of a query.

Parameters:
className Name of the class.
Returns:
The generated method as string.
See also:
Ref, createClassRegistrarInstance().

CStdString IopcTranslatingSupport::createClassNameFnc const char *  className  ) 
 

Creates simple function ClassName() which redefines the one defined in Object. This function cannot be implemented in IopcPersistentObject because it is static (and IopcPersistentObject::m_classObject cannot be static).

Example of the generated code:

static const char * ClassName() { return "A3"; }

Parameters:
className Name of the class.
Returns:
The generated method as string.

CStdString IopcTranslatingSupport::createClassRegistrarInstance const char *  className,
const char *  qualifiedClassName
 

Generates definition of template IopcClassRegistrar<T> instance. This instance is static variable and its purpose is to register class's iopcCreateInstance() and iopcCreateReference() methods in IOPC LIB's IopcClassFactory. This is needed to support polymorphic queries, polymorphic referencies and so on.

Example of the generated code:

static A3_IopcClassRegistrar("A3");

Parameters:
className Name of the class (f.e. "NestedClass").
qualifiedClassName Qualified name of the class (f.e. "Namespace::Class::NestedClass").
Returns:
The generated method as string.
See also:
createCreateInstanceFnc(), createCreateReferenceFnc().

Ptree * IopcTranslatingSupport::createGetterCall const char *  className,
const char *  attrName,
const char *  fullClassQualification,
Ptree object,
Ptree op
 

Simple function that returns source code which calls getter of the specified attribute.

Example of function's result:

object->get_xxx()

Parameters:
className Name of the class that owns the attribute.
attrName Name of the attribute.
fullClassQualification Fully qualified name of the class (may be NULL).
object Object on which the getter should be called (NULL if on "this" object).
op Operator to be used when calling the getter ("." or "->", NULL if object is NULL).
Returns:
The generated piece of code.
See also:
GETTER_PREFIX, createGetter().

Ptree * IopcTranslatingSupport::createSetterCall const char *  className,
const char *  attrName,
const char *  fullClassQualification,
Ptree translatedExpr,
Ptree object,
Ptree op
 

Simple function that returns source code which calls setter of the specified attribute.

Example of function's result:

object->set_xxx(translatedExpr)

Parameters:
className Name of the class that owns the attribute.
attrName Name of the attribute.
fullClassQualification Fully qualified name of the class (may be NULL).
translatedExpr Expression, to whose result the attribute should be set..
object Object on which the getter should be called (NULL if on "this" object).
op Operator to be used when calling the getter ("." or "->", NULL if object is NULL).
Returns:
The generated piece of code.
See also:
SETTER_PREFIX, createSetter().

void IopcTranslatingSupport::sendClassToMetadataWriter const char *  className  ) 
 

Sends information about class given by className to MetadataWriter.

Finds the class in its internal structures (getClass()) and sends data about it to MetadataWriter (MetadataWriter::addClass()).

Parameters:
className Name of the class.

CStdString IopcTranslatingSupport::createGetter const char *  className,
const char *  attrName,
IopcAttributeInfo attrInfo,
int  attrNumber
[protected]
 

Creates getter for specified attribute.

Getter is method that returns value of an attribute. If the attribute is persistent and its value is not in memory (appropriate indicator variable is "false"), loads the value from database (using IOPC LIB's IopcClassObjectImpl::loadAttribute()).

Example of the getter:

public: virtual char * get_xxx() { if (!m_isPersistent || m_xxx_isValid || !m_classObject->isAttributePersistent(1)) return m_xxx; m_classObject->loadAttribute(1, this); if (!m_xxx_isValid) throw IopcExceptionUnexpected(); return m_xxx; }

Parameters:
className Name of the class that owns the attribute.
attrName Name of the attribute.
attrInfo Information about the attribute.
attrNumber Attribute's number in this class (in lexicographic order). Used when calling IopcClassObjectImpl::loadAttribute().
Returns:
The generated method as string.
See also:
GETTER_PREFIX, INDICATOR_VARIABLE_NAME, createGetterCall().

CStdString IopcTranslatingSupport::createSetter const char *  className,
const char *  attrName,
IopcAttributeInfo attrInfo,
int  attrNumber
[protected]
 

Creates setter for specified attribute.

Setter is method that sets value of an attribute. Attribute's indicator variable is set to "true". If the object is persistent, dirty flag is set.

Example of the setter:

public: virtual char * set_xxx(char * _xxx) { m_xxx =_xxx; m_xxx_isValid = true; if (m_isPersistent) MarkAsDirty(); return _xxx; }

Note:
Setter must return a value to make translating of expressions like "x = y = 4;" possible.
Parameters:
className Name of the class that owns the attribute.
attrName Name of the attribute.
attrInfo Information about the attribute.
attrNumber Attribute's number in this class (in lexicographic order). Not used for now.
Returns:
The generated method as string.
See also:
SETTER_PREFIX, INDICATOR_VARIABLE_NAME, createSetterCall().

const char * IopcTranslatingSupport::getImportExportStructField IopcDataType  dataType  )  [inline, static, protected]
 

For given data type returns field of IopcImportExportStruct's union, which should be used when storing attributes of given type.

Parameters:
dataType Attribute data type.
Returns:
The field name as string.
See also:
IopcImportExportStruct


The documentation for this class was generated from the following files:
Generated on Wed Aug 11 22:35:40 2004 for IOPC by Doxygen 1.3.6