home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13035 < prev    next >
Encoding:
Internet Message Format  |  1992-08-29  |  2.9 KB

  1. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!jvnc.net!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!ut-emx!emx.utexas.edu!plyon
  2. From: plyon@emx.cc.utexas.edu (Paul Lyon)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: File I/O using C++ (write/read objects...)
  5. Message-ID: <PLYON.92Aug28193142@emx.cc.utexas.edu>
  6. Date: 29 Aug 92 00:31:42 GMT
  7. References: <1992Aug26.023255.10785@gucis.cit.gu.edu.au>
  8.     <DAVIDM.92Aug26132938@consilium.com>
  9. Sender: news@ut-emx.uucp
  10. Organization: The University of Texas at Austin
  11. Lines: 50
  12. In-reply-to: davidm@consilium.com's message of 26 Aug 92 20:29:38 GMT
  13.  
  14.  
  15. In article <DAVIDM.92Aug26132938@consilium.com> davidm@consilium.co
  16. (David S. Masterson) writes:
  17.  
  18.    As far as I've seen, there is no automatic, reliable approach to
  19.    writing a C++
  20.    object to a file (or sending it in a message).  It requires knowing what the
  21.    format of the object internally looks like and, possibly, converting this
  22.    internal format into a format that is persistent.
  23.  
  24.    The only generic, portable approach to doing this that I've seen is
  25.    what I'll call "linearization" of an object.  That is, when object
  26.    wants to write itself onto a stream (as defined by operator>>), it
  27.    converts itself into a stream of bytes that will be recognizable on
  28.    the other end of the stream (so that operator<< will understand it).
  29.     With these operators defined on every object, newly derived objects
  30.    simply worry about their internal structure and call the appropriate
  31.    superclass method to handle the rest.  The drawback with this is that
  32.    it suggests a Smalltalk approach to creating objects (everything
  33.    derives from the central controlling Object).  Naturally, there are a
  34.    lot of little "gotchas" in this that must be worked out (like peeking
  35.    into a stream and making a guess about what the next object is that's
  36.    coming out of the stream so that the appropriate object may be
  37.    constructed).
  38.  
  39.    Comments?
  40.    --
  41.  
  42. These remarks seem sensible enough to me, but I think it worth noting
  43. that a model of how to do this may be found in the NIH class library.
  44. See, in particular, the "OIO" files in the distribution thereof and
  45. the documentation for same. Both may be ftp'd from
  46. wuarchive.wustl.edu, in the directory ~ftp/mirrors2/gnu. What they do
  47. here is both to have a single derivation tree and also to keep a table
  48. of class information that allows each store-to-stream and
  49. read-from-stream method to keep track of contained class objects and
  50. class derivation so that each object of a class in the system can
  51. reliably be written out and recovered in such a way that each class in
  52. the system only needs to worry about the data peculiar to itself in
  53. the process, leaving its base classe object(s) and contained class
  54. object(s) to take care of their own, and so on.  I do not know how
  55. adaptable their approach would be to other contexts, but pondering the
  56. approach taken should at least be informative about what needs to be
  57. done to make this sort of scheme work.
  58.  
  59. Hope this helps...
  60.  
  61. Paul Lyon
  62.  
  63.  
  64.