Index

DKAny

Purpose:

DKAny provides a mechanism to deal with dynamic data types, where the type of data is only known at run-time. DKAny has methods for setting and getting its type and value of the data.

DKAny knows the following types and manages the storage for them:

If the type is not included in this list, then the user is responsible for managing the storage.

For the following object reference types, for example, storage is not managed by DKAny:

Copying operations on DKAny containing the listed types will copy the pointer only, a shallow copy. These operations include assignment, copy and copy constructor. In addition, you will have to provide the destructors for these object reference types.

Class summary:

    class DKAny
    {
   public:
enum TypeCode { tc_null,  tc_ushort,    tc_short,
            tc_ulong,  tc_long,       tc_double,    tc_boolean,
            tc_char,   tc_string,     tc_decimal,   tc_nvpair,
            tc_date,   tc_time,       tc_timestamp,
            tc_objref, tc_collection, tc_dobase,
            tc_voidptr, tc_bytearray, tc_float,
            tc_typecode
                  };
     DKAny ();
     DKAny (const DKAny&);
     DKAny (const short);
     DKAny (const unsigned short);
     DKAny (const long);
     DKAny (const unsigned long);
     DKAny (const double);
     DKAny (const DKBoolean);
     DKAny (const char);
     DKAny (const DKString&);
     DKAny (const DKDate&);
     DKAny (const DKTime&);
     DKAny (const DKTimestamp&);
     DKAny (const DKByteArray&);
     DKAny (const DKDecimal&);  
     DKAny (const dkDataObjectBase*);
     DKAny (const void *);
     DKAny (const TypeCode);
     DKAny();
     // assignment to DKAny; for example, DKAny = typeX;
     DKAny& operator= (const DKAny&);
     DKAny& operator= (short);
     DKAny& operator= (unsigned short);
     DKAny& operator= (long);
     DKAny& operator= (unsigned long);
     DKAny& operator= (double);
     DKAny& operator= (DKBoolean);
     DKAny& operator= (char);
     DKAny& operator= (const DKString&);
     DKAny& operator= (const DKDate&);
     DKAny& operator= (const DKTime&);
     DKAny& operator= (const DKTimestamp&);
     DKAny& operator= (const dkDataObjectBase*);
     DKAny& operator= (const void *);
     DKAny& operator= (const TypeCode);
     DKAny& operator= (const DKByteArray&);
     DKAny& operator= (const DKDecimal&);
     // assignment from DKAny; for example, typeX = DKAny;
     operator short()            const;
     operator unsigned short()   const;
     operator long ()            const;
     operator unsigned long()    const;
     operator double()           const;
     operator DKBoolean()        const;
     operator DKString()         const;
     operator DKDate()           const;
     operator DKTime()           const;
     operator DKTimestamp()      const;
 
     operator DKByteArray()      const;
     operator DKDecimal()   const;   
     operator dkDataObjectBase() const;
     operator void* ()           const;
     operator TypeCode()         const;
     DKBoolean operator== (const DKAny&) const;
     DKBoolean operator!= (const DKAny&) const;
     friend ostream& operator << (ostream& outStream, 
                                  const DKAny& src);
     TypeCode typeCode() const;
     DKBoolean isNull() const;
     short getSubType();
     void  setSubType(short sub_type);
     void* value() const;
     void replace(TypeCode newTypeCode, void* newValue, 
                  short newSubType = 0);
     void     setNull();
    };

Data member:

TypeCode

    enum TypeCode { tc_null,    tc_short,   tc_ushort,    tc_long, tc_ulong,   tc_double,  tc_boolean, tc_char,                      tc_string,  tc_decimal, tc_date, tc_time,                      tc_timestamp, tc_objref,  tc_collection, tc_dobase,                     tc_voidptr, tc_bytearray, tc_typecode};

Enumerated type code of types known by DKAny.

Members:

Constructors and destructor
The first constructor is the default constructor. It creates DKAny with tc_null as the type-code. The second constructor is the copy constructor. It copies attributes of the given DKAny to create a new DKAny. The third constructor creates DKAny using the parameters: var of type <TYPE>. It will set the type-code to tc_<TYPE> and copy the var value.
DKAny();
     DKAny(const DKAny&);
     DKAny(const <TYPE> var);
     DKAny();

Member functions

operator==
Equality operator. Returns TRUE if both DKAny are equal.
DKBoolean operator== (const DKAny&);

operator!
Inequality operator. Returns FALSE if both DKAny objects are equal.
DKBoolean operator!= (const DKAny&);

operator=
The first method assigns a data of type TYPE to DKAny. TYPE can be any valid data type known to DKAny. The second method extracts data from DKAny and assigns it to a variable of type TYPE. TYPE must be the same as DKAny type.

Exceptions

  • DKUsageError
DKAny& operator= (const <TYPE> var);     <TYPE>  operator= (<TYPE>, const DKAny&);

typeCode
Returns the type-code of this DKAny. TypeCode is an enumerated constant of all type-code known by DKAny.
TypeCode typeCode() const;

isNull
Returns TRUE if this DKAny is null.
DKBoolean isNull() const;

setSubType
Set a type code extension defined by the end user. It is optional, and set to 0 by default. This is useful if you want to define an additional type to the types currently supported. Sub-types can be defined for each type-code, but it is usually used for describing subtypes of object-reference, void pointer, or collection.
void setSubType(short sub_type);

getSubType
Returns the user defined sub-type.
short getSubType() const;

Exceptions:

DKUsageError
The parameter supplied to DKAny has an incorrect type.

(c) Copyright International Business Machines Corporation 1996, 2003. IBM Corp. All rights reserved.