home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / OOFILE / Buildable, limited OOFILE / OOFILE headers / oof0.hpp next >
Encoding:
C/C++ Source or Header  |  1995-09-25  |  3.7 KB  |  175 lines  |  [TEXT/CWIE]

  1. #ifndef H_OOF0
  2. #define H_OOF0
  3.  
  4. // COPYRIGHT 1994 A.D. Software, All rights reserved
  5.  
  6. // minimal root public layer of OOFILE database
  7.  
  8. #ifndef _Windows
  9.     #ifdef _WINDOWS
  10.         #define _Windows
  11. // the difference between Borland and Visual C++, sigh!
  12.     #endif
  13.     #ifndef _Macintosh
  14.         #ifdef __MWERKS__
  15.             #define _Macintosh
  16.         #else
  17.             #ifdef macintosh
  18.                 #define _Macintosh
  19.             #endif
  20.         #endif
  21.     #endif
  22. #endif
  23.  
  24. #include <assert.h>
  25. #include <limits.h>
  26. #include <string.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29.  
  30. // different libs have fstream including iostream & vice-versa so need both
  31. #include <iostream.h>
  32. #include <fstream.h>
  33. #ifdef _Windows
  34.     #include <strstrea.h>
  35. // yes this is really necessary - the long name fails under NT as the file is 
  36. // really called strstrea.h
  37. #else
  38.     #include <strstream.h>
  39. #endif
  40.  
  41. #ifdef OOF_SmartHeap
  42.     #include <smrtheap.hpp>
  43. #endif
  44.  
  45. #ifndef __MWERKS__
  46.     #ifndef OOF_GCC
  47.         #include <io.h>
  48.     #endif
  49.     #ifdef macintosh
  50.         #include <unix.h>
  51.     #endif
  52.     #include <fcntl.h>
  53. #endif
  54. #ifdef _Windows
  55.     #include <windows.h>
  56. #endif
  57.  
  58. #ifndef EXIT_SUCCESS
  59.   #define EXIT_SUCCESS 1
  60. #endif
  61.  
  62.  
  63. #include "oofbool.hpp"
  64.  
  65. class dbClass {
  66. public:
  67.     bool hidden() const { return mHidden; };
  68.     void hide(bool hideIt) { mHidden = hideIt; };
  69.     virtual void describe(ostream&) {};
  70. protected:
  71.     dbClass() : mHidden(false) {};
  72.     virtual ~dbClass() {};
  73.     
  74.     bool mHidden;
  75. };
  76.  
  77.  
  78. typedef dbClass    * OOF_bitPointer;
  79.  
  80. class OOF_mixRefCount {
  81. protected:
  82.     OOF_mixRefCount() :
  83.         mReferences(1) {};
  84.     unsigned int mReferences;
  85. };
  86.  
  87.  
  88. class OOF_DictRep : public OOF_mixRefCount {
  89. private:
  90.     OOF_DictRep(unsigned int numSlots, unsigned int expandBySlots);
  91.     OOF_DictRep(const OOF_DictRep*);
  92.     ~OOF_DictRep();
  93.     void operator=(const OOF_DictRep&) {assert(0);};
  94.  
  95. // access protocol
  96.     void Append(OOF_bitPointer);
  97.     OOF_bitPointer& operator[](unsigned int index); 
  98.     OOF_bitPointer& operator[](const char *name);
  99.     OOF_bitPointer& item(unsigned int index);
  100.     OOF_bitPointer value(unsigned int index) const;
  101.     void Reset();
  102.     void ExpandToInclude(unsigned int indexToCover);
  103.  
  104. // data storage
  105.     enum {kSlotSize=sizeof(OOF_bitPointer)};
  106.     OOF_bitPointer *mBits;    // owned
  107.     unsigned int mExpansionChunk, mNextFreeEntry, mNumSlots;
  108.  
  109.     friend class OOF_Dictionary;
  110.     friend class dbView;
  111.     friend class dbRelChain;
  112. };
  113.  
  114.  
  115. class OOF_Dictionary {  
  116. // a Handle or Envelope class for OOF_DictRep
  117. // but independently acting as an iterator
  118. // contains list of dbClass
  119.  
  120. // default constructor, or passing in zero items  skips allocating storage
  121. public:
  122.     enum {kDefExpansionChunk=10};
  123.     
  124.     OOF_Dictionary() ;
  125.     OOF_Dictionary(const OOF_DictRep* rep);
  126.     OOF_Dictionary(unsigned int numSlots);
  127.     OOF_Dictionary(unsigned int numSlots, unsigned int expansionChunk);
  128.     OOF_Dictionary(const OOF_Dictionary&);  
  129.     OOF_Dictionary clone() const;
  130.     virtual ~OOF_Dictionary();
  131.     OOF_Dictionary& operator=(const OOF_Dictionary&);    
  132.  
  133. // access operators
  134.     OOF_bitPointer& operator[](unsigned int); 
  135.     OOF_bitPointer& operator[](const char*);
  136.     OOF_bitPointer& operator[](int);
  137.     OOF_bitPointer& item(unsigned int index);
  138.     OOF_bitPointer value(unsigned int index) const;
  139.     OOF_bitPointer& operator()();
  140.     void append(OOF_bitPointer);
  141.     void reset();
  142.     
  143.     // iterator protocol
  144.     void start();
  145.     bool more();
  146.     void next();
  147.     unsigned int count() const;
  148.  
  149.     void startVisible(bool);
  150.     bool moreVisible(bool);
  151.     void nextVisible(bool);
  152.     unsigned int countVisible(bool);
  153.  
  154. // other protocol
  155.     bool allObjectsMatch(OOF_Dictionary&);
  156.     void deleteAll();
  157.     virtual void describe(ostream&);
  158.     virtual void describeVisible(ostream&, bool wantVisible);
  159.     void ownsContents(bool ownsFlag=true);
  160.  
  161. protected:
  162.     bool EntryMatchesVisibility(const dbClass*, bool) const;
  163.  
  164. // data storage
  165.     OOF_DictRep *mRep;    // owned
  166.     unsigned int mInternalIter;
  167.     bool mOwnsContents;
  168. };
  169.  
  170.  
  171.  
  172. // include inline definitions
  173. #include "oof0.inl"
  174. #endif
  175.