Browse Prior Art Database

C++ Generic Data Class

IP.com Disclosure Number: IPCOM000111941D
Original Publication Date: 1994-Apr-01
Included in the Prior Art Database: 2005-Mar-26
Document File: 2 page(s) / 98K

Publishing Venue

IBM

Related People

Dischner, B: AUTHOR

Abstract

Historically, computer languages have taken several approaches that ranged from strong to weak data typing, in order to handle a variety of data types. Weak data typing places minimal requirements on a programmer but leaves a large margin for programmer error. Strong data typing places rigorous requirements on the programmer in order to minimize his potential for error.

This text was extracted from an ASCII text file.
This is the abbreviated version, containing approximately 52% of the total text.

C++ Generic Data Class

      Historically, computer languages have taken several approaches
that ranged from strong to weak data typing, in order to handle a
variety of data types.  Weak data typing places minimal requirements
on a programmer but leaves a large margin for programmer error.
Strong data typing places rigorous requirements on the programmer in
order to minimize his potential for error.

      Neither weak nor strong data typing offers an optimum solution
for handling data of differing types.  They present a choice that
hinges on a tradeoff between either flexibility and ease or error
prevention.  A C++ generic Data Class is a solution that changes that
decision from an either/or choice.

      Application requirements frequently specify the need to store,
retrieve and manipulate a complete range of data types, including
missing data.  An implementation using current state-of-the-art
container classes had several limitations.

o   Container classes require that all stored objects are of the same
    type.

o   It is necessary for the retriever of an object in a container to
    know the type of the object.

      The first limitation can be avoided by using a container class
of void pointers.  That solution does nothing to address the second
limitation and, in fact, actually serves to highlight the second
limitation.  In order to retrieve and use an object referenced by a
void pointer, the void pointer must be cast to a pointer of the
appropriate type.  The ultimate result is a proliferation of switch
statements that are extremely difficult to maintain.

      The development of a generic Data Class, based on the Letter
and Envelope Class Idiom espoused by Coplien, allows differences
between data types to be handled within the Data Class.  All data
that is used within the system is simply of type Data.  The only time
that the actual data type must be known is when a datum is exported
from the system into a system that doesn't use the generic Data
Class.

      The Data Class, which is the envelope class, is used as a
parent class from which letter classes are derived.  The letter
classes encompass all of the data types that are to be used as part
of the Data Class (e.g., TypeINT, TypeFLOAT, TypeMISSING).

      The Data Class has a data member that is a union which is
comprised of either a pointer to a generic Data Class object or an
integer reference count.  The letter classes, since they are derived
from the Data Class, have the same union but also have an additional
data member of the appropriate type.  The TypeINT Class contains an
integer, the TypeFLOAT contains a float, and the TypeMISSING contains
a char.

      The envelope and letter class idiom specifies that letter
classes can only exist within an envelope class object.  This means
that all data types are created and used as Data Class objects.

      When a Data Class object is crea...