home *** CD-ROM | disk | FTP | other *** search
- NOTES ON THE LISTINGS FILES FOR "TYPING YOUR DATA":
-
- The download files for this article include two complete sets of
- files. The first are those discussed in the text: TYPES.H,
- TYPES.CPP, and TYPEDEMO.CPP. These files implement a simple
- database from three data types. A second set of files is
- provided that were too long to include in the text. These allow
- for strings plus the five major numeric types from int to long
- double. The code for typed values gets long fast as you add
- types -- it tends to increase by the square of the types. That's
- because each class has to support operations with each of the
- other classes. The code doesn't really get more complex, just a
- lot longer.
-
- When you do something like this, it's best to start with two or
- maybe three data types to get all the basics sorted out. Then
- you can take advantage of the strong symmetry in the code to add
- the additional types using your debugged code as a model. This
- is especially important since the floating point types add other
- problems that aren't really germane to the basic algorithm. For
- example, a double can be too small as well too large to convert
- into a float. That is, it can be a value too close to zero.
-
- That's moderately interesting, and you can see how to deal with
- it in TYPESALL.CPP, but it doesn't really have anything to do
- with the basic objective of creating typed data objects. It's
- best to defer such questions until you have your basic set of
- methods worked out. The files with all of the numeric types
- represented are TYPESALL.H and TYPESALL.CPP. This version of the
- value objects works with the original demo program just as well,
- since that's the point of encapsulation. But TYPEDEMO.CPP
- doesn't include functions to assert the extra types, so I wrote a
- second demo program, TYPEDEM2.CPP, to show off the expanded
- definition of types.
-
- To compile the examples, put TYPES.H and TYPESALL.H in your
- include directory. Create one project with TYPES.CPP and
- TYPEDEMO.CPP, and another project with TYPESALL.CPP and
- TYPEDEM2.CPP. To use typed data objects in your own projects,
- just add TYPESALL.CPP to your own project and include
- <TYPESALL.H> in your source code. For simplicity, delete the
- reduced version files used in the article, and then rename the
- full version files as TYPES.H and TYPES.CPP.
-
- --Gary W. Sims