home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16807 < prev    next >
Encoding:
Text File  |  1992-11-24  |  3.4 KB  |  106 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!rpi!nelsonc
  3. From: nelsonc@colossus.cs.rpi.edu (Chris Nelson)
  4. Subject: Class design problem
  5. Message-ID: <sa41r=c@rpi.edu>
  6. Nntp-Posting-Host: colossus.cs.rpi.edu
  7. Organization: Rensselaer Polytechnic Institute, Troy, NY
  8. References: <722544958snx@trmphrst.demon.co.uk>
  9. Date: Mon, 23 Nov 1992 22:42:43 GMT
  10. Lines: 94
  11.  
  12.  
  13. I've built a class hierarchy for dealing with the data files from several
  14. different pieces of laboratory equipment and now I'm running into problems
  15. adding a new feature to the system.  I'm looking for advice.
  16.  
  17. All of the classes have in common a set of evenly spaced Y values for a
  18. range of X values.  In other works, X = 1,2,3,4 or 2,4,6,8 or 6,9,12,15,18
  19. and I have Y=[Y1, Y2, Y3, Y4 ...] corresponding to these X values.  My basic
  20. class definition is (abbreviated):
  21.  
  22.    class SampleDataSet {
  23.       protected:
  24.          double* Data;
  25.          unsigned Samples; // sizeof(Data)/sizeof(double)
  26.          float StartX;
  27.          float EndX;
  28.          float DeltaX; // 1 + (EndX - StartX)/Samples
  29.       public:
  30.          SimpleDataSet();
  31.          ~SimpleDataSet();
  32.          virtual int LoadData(FILE* F);
  33.          virtual int SaveData(FILE* F);
  34.    };
  35.  
  36.  
  37. I've also got another class which adds some functionality (not related to
  38. the apparatus) to make a DataSet:
  39.  
  40.     class DataSet : public SimpleDataSet, public Other {
  41.     };
  42.  
  43. And then I derive several apparatus-specific classes from DataSet:
  44.  
  45.     +----------+   +----------+
  46.     |  Simple  |   |  Other   |
  47.     +----------+   +----------+
  48.              |       |
  49.             +---------+
  50.             | DataSet |
  51.             +---------+
  52.              |   |   |
  53.    +----------+  |  +----------+
  54.    | SetType1 |  |  | SetType3 |
  55.    +----------+  |  +----------+
  56.                  |
  57.            +----------+
  58.            | SetType2 |
  59.            +----------+
  60.  
  61. Now I've got to add a method to splice two data sets to make a new one.  For
  62. example, if Sa and Sb are SetType1 with Sa having values from X=1 to X=4 and
  63. Sb having values from X=3 to X=10, I need to do something like
  64.  
  65.    Sc = Sa.SpliceIn(Sb)
  66.  
  67. and have Sc be a SetType1 with values from X=1 to X=10.
  68. I tried adding
  69.  
  70.     DataSet* DataSet::Splice(DataSet* P);
  71.  
  72. but Sc ended up being of type DataSet (of course).  This meant that the
  73. wrong LoadData() and SaveData() methods were called for Sc.
  74.  
  75. Then I tried making Splice abstract:
  76.  
  77.     virtual DataSet* DataSet::Splice(DataSet* P) = 0;
  78.  
  79.     virtual SetType1* SetType1::Splice(DataSet* P);
  80.  
  81. but I got a conflict.  (Note that the argument to Splice can be a basic
  82. DataSet because no SetType_-specific behaviour is used in Splice.
  83.  
  84. I think what I need is to "xerox" one of the source data sets and then
  85. splice into it.  Something like:
  86.  
  87.       Sc = Sa.Xerox();
  88.       Sc.SpliceIn(Sb);
  89.  
  90. But I haven't figured out how to write Xerox().  In Borland Pascal
  91. (with Objects), the equivalent of new will take a variable identifier
  92. and figure out it's type so I'd could do something like:
  93.  
  94.       Sc = new Sa;
  95.  
  96. but as far as I can tell, that doesn't work in C++.  I'll take any advice
  97. (other than scrapping my hierarchy) that I can get.  Thanks in advance.
  98.  
  99.                                   Chris       
  100.  
  101. -- 
  102. ------------------------------+------------------------------------------
  103. Chris Nelson                  |  Rens-se-LEER is a county.
  104. Internet: nelsonc@cs.rpi.edu  |  RENS-se-ler is a city. 
  105. CompuServe: 70441,3321        |  R-P-I is a school in Troy!
  106.