home *** CD-ROM | disk | FTP | other *** search
/ PC Media 7 / PC MEDIA CD07.iso / share / prog / cm / cmreserv.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-09-06  |  4.7 KB  |  109 lines

  1. // CmReserv.h
  2. // -----------------------------------------------------------------
  3. // Compendium - C++ Container Class Library
  4. // Copyright (C) 1992-1994, Glenn M. Poorman, All rights reserved
  5. // -----------------------------------------------------------------
  6. // In-memory data base definition.
  7. // -----------------------------------------------------------------
  8.  
  9. #ifndef _CMRESERV_H
  10. #define _CMRESERV_H
  11.  
  12. #include <cm/include/cmbdict.h>
  13. #include <cm/include/cmlist.h>
  14. #include <cm/include/cmbtree.h>
  15. #include <cm/include/cmstring.h>
  16.  
  17. class CmReserve {                               // Reserve definition.
  18. public:
  19.   CmReserve(const char*);                       // Reserve constructor.
  20.   CmReserve(const CmReserve&);                  // Reserve copy constructor.
  21.  ~CmReserve();                                  // Reserve destructor.
  22.  
  23.   CmReserve& operator=(const CmReserve&);       // Assignment operator.
  24.  
  25.   Bool exists() const;                          // Check file status.
  26.  
  27.   void        name(const char*);                // Set new reserve name.
  28.   const char* name() const;                     // Get reserve name.
  29.  
  30.   void        identifier(const char*);          // Set reserve identifier.
  31.   const char* identifier() const;               // Get reserve identifier.
  32.  
  33.   Bool         addRoot     (const char*, CmContainer*); // Add root to reserve.
  34.   CmContainer* createRoot  (const char*);       // Create a new root.
  35.   int          totalRoots  () const;            // Get number of roots.
  36.   Bool         containsRoot(const char*) const; // See if root is in reserve.
  37.   CmContainer* getRoot     (const char*) const; // Get a root by index.
  38.   Bool         removeRoot  (const char*);       // Remove root by index.
  39.   void         removeAll   ();                  // Remove all roots.
  40.  
  41.   CmContainer* operator[](const char*) const;   // Get a root by name.
  42.  
  43.   virtual Bool write() const;                       // Write reserve to file.
  44.   virtual Bool read ();                             // Read reserve from file.
  45.  
  46.   // Call the specified function for every object in the reserve
  47.   // until the end is reached or the function returns FALSE.
  48.   void forEach(CmQueryFunc,    void* = NULL);
  49.   void forEach(CmQueryMemFunc, void* = NULL);
  50.  
  51.   // Return the first object to satisfy the conditional test performed
  52.   // in the specified function.
  53.   CmObject* firstThat(CmQueryFunc,    void* = NULL);
  54.   CmObject* firstThat(CmQueryMemFunc, void* = NULL);
  55.  
  56.   // Call the specified function for every object in the reserve
  57.   // adding all objects for which the function returns TRUE to an
  58.   // output container.
  59.   CmContainer* query(CmQueryFunc,    void* = NULL); // Create subset.
  60.   CmContainer* query(CmQueryMemFunc, void* = NULL); // Create subset.
  61.  
  62.   static void      initialize      ();              // Register Cm classes.
  63.   static char*     fileIdentifier  (const char*);   // Get an identifier.
  64.   static Bool      registerClass   (CmObject*);     // Register a class.
  65.   static CmObject* getClassRegister(const char*);   // Get class register.
  66.   static void      resetTable      ();              // Reset reference table.
  67.  
  68.   static void maintainReferences(Bool);             // Set reference flag.
  69.   static Bool maintainReferences();                 // Get reference flag.
  70.  
  71.   enum ref_flag { OBJECT=0, REFERENCE=1 };          // Reference flag.
  72.  
  73. private:
  74.   static Bool      addToTable  (CmObject*,int); // Add object to table.
  75.   static CmObject* getFromTable(int);           // Get object at index.
  76.   static int       getFromTable(CmObject*);     // Get object at index.
  77.  
  78.   CmString                   _name;             // Reserve name.
  79.   CmString                   _identifier;       // Reserve identifier.
  80.   CmBTreeDictionary         *_roots;            // Root list.
  81.   static CmLinkedList       *_classes;          // Registered class list.
  82.   static Bool                _references;       // References allowed flag.
  83.   friend                     CmObject;          // Object can access.
  84.  
  85.   static CmBTree *_referenceTable;              // I/O reference table.
  86. };
  87.  
  88. // "name" sets a new reserve name.
  89. inline void CmReserve::name(const char* name)
  90. { _name = name; }
  91.  
  92. // "name" returns the current reserve name.
  93. inline const char* CmReserve::name() const
  94. { return _name; }
  95.  
  96. // "identifier" sets a new reserve identifier.
  97. inline void CmReserve::identifier(const char* ident)
  98. { _identifier = ident; }
  99.  
  100. // "identifier" returns the current reserve identifier.
  101. inline const char* CmReserve::identifier() const
  102. { return _identifier; }
  103.  
  104. // "[]" indexing operator returns a pointer to the root by name.
  105. inline CmContainer* CmReserve::operator[](const char* name) const
  106. { return getRoot(name); }
  107.  
  108. #endif
  109.