C++ Generic Data Class
Original Publication Date: 1994-Apr-01
Included in the Prior Art Database: 2005-Mar-26
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.
C++ Generic Data Class
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.
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.
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.
classes require that all stored objects are of the same
o It is necessary
for the retriever of an object in a container to
know the type of the object.
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.
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, 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).
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
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...