home *** CD-ROM | disk | FTP | other *** search
- /* --------------------------------------------------------------------------
- * Copyright 1992 by Forschungszentrum Informatik (FZI)
- *
- * You can use and distribute this software under the terms of the licence
- * you should have received along with this program.
- * If not or if you want additional information, write to
- * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
- * D-7500 Karlsruhe 1, Germany.
- * --------------------------------------------------------------------------
- */
- /* persistent storage manager: header */
-
- #ifndef PSMH
- #define PSMH 1
-
- // enumeration of sos_Access_mode and sos_container_status must be in a
- // fixed order (i.e. the same order), because two functions (entercontainer, access)
- // use this fact in a cast construction
-
- enum sos_Sync_mode {WAITING, TESTING};
- enum sos_Open_result {OPENED, LOCKED, UNACCESSIBLE};
- enum sos_Access_mode {READING, CHECKOUT, WRITING};
- enum sos_Container_status {READABLE,CHECKEDOUT,WRITEABLE,UNAVAILABLE, DESTROYED};
- enum sos_Existing_status {NOT_EXISTING, PERHAPS_EXISTING};
-
- typedef unsigned sos_Offset;
-
- void psm_initialize(); //automatically called from C++
-
- class sos_Object;
- class sos_Container_set;
- class sos_Container_cursor;
- class sos_Container;
-
- #ifndef NO_TT
- extern const sos_Container _psm_checked_cnt;
- #endif NO_TT
-
- // *******************************************************************************
-
- class sos_Container
- {
- int id; // 0<=id<2^24-1
-
- public:
- static sos_Container make (int i) {sos_Container ct; ct.id=i; return ct;}
- static sos_Container create();
-
- operator int() const {return id;}
- int operator==(sos_Container c) const {return id==c.id;}
-
- sos_Container_status status() const;
- int modified() const;
- int exists() const;
- int deleted() const;
- unsigned occupied() const;
- sos_Existing_status object_exists(sos_Offset, unsigned) const;
-
- sos_Open_result open(sos_Access_mode, sos_Sync_mode) const;
- sos_Open_result access(sos_Access_mode, sos_Sync_mode) const;
- sos_Open_result checkout(sos_Access_mode, sos_Sync_mode) const;
- void close() const;
- void destroy() const;
-
- void commit() const;
- void reset() const;
- void squeeze() const;
- void clear() const;
-
- sos_Offset allocate(unsigned size) const; // allocates rounded(size) bytes
- void deallocate(sos_Offset o, unsigned size) const; //deallocates rounded(size) bytes
- unsigned rounded(unsigned size) const; // rounded(size) >= size
-
- void read(sos_Offset o, unsigned size, void* data) const;
- void write(sos_Offset o, unsigned size, void* data) const;
- void copy(sos_Offset o1, unsigned size, sos_Container c2, sos_Offset o2) const;
- int equal(sos_Offset o1, unsigned size, sos_Container c2, sos_Offset o2) const;
- int hash_value(sos_Offset o1, unsigned size) const;
-
- sos_Object root_object () const;
- };
-
- // ******************************************************************************
-
- extern const sos_Container TEMP_CONTAINER;
- extern const sos_Container ROOT_CONTAINER;
- extern const sos_Container UNUSED_CONTAINER;
-
- extern const sos_Offset ROOT_OFFSET;
-
- // ******************************************************************************
-
- class sos_Container_set {
-
- //friend sos_Open_result op(int, const sos_Container_set& ,const sos_Container_set&, sos_Sync_mode);
- //friend void cl(int, const sos_Container_set&, const sos_Container_set&);
-
- public:
- unsigned card() const { return n; }
- // sos_Container_set(const sos_Container_set&);
- // copy constructor do not work correectly for the gnu compiler
- sos_Container_set();
- ~sos_Container_set();
- //sos_Container_set& operator=(const sos_Container_set&);
- sos_Container_set& operator+=(sos_Container c);
-
- static sos_Container_set& open_containers(sos_Container_status);
- static sos_Open_result open(const sos_Container_set& rd, const sos_Container_set& wr, sos_Sync_mode);
- sos_Open_result open(sos_Access_mode, sos_Sync_mode) const;
- void close() const;
-
- static sos_Open_result op(int, const sos_Container_set& ,const sos_Container_set&, sos_Sync_mode);
- static void cl(int, const sos_Container_set&, const sos_Container_set&);
-
- void commit() const;
- void reset() const;
-
- sos_Container_cursor open_cursor() const;
- void close_cursor (sos_Container_cursor&) const;
- int to_succ (sos_Container_cursor&) const;
- int is_valid(sos_Container_cursor) const;
- sos_Container get (sos_Container_cursor) const;
-
- private:
- int* s;
- unsigned n,size;
- };
-
- // ****************************** sos_Container_cursor ******************************
- class sos_Container_cursor {
- friend class sos_Container_set;
-
- public:
- int is_valid() const { return (idx >= 0); }
- private:
- int idx;
- };
-
- // ****************************** cnt_iterate ******************************
-
- #define cnt_iterate(s, e) \
- {sos_Container_cursor _cnt_cursor = s.open_cursor(); \
- for (int _cnt_valid = s.is_valid (_cnt_cursor); \
- _cnt_valid; \
- _cnt_valid = s.to_succ (_cnt_cursor)) \
- { e = s.get(_cnt_cursor);
-
- #define cnt_iterate_end(s, e) } s.close_cursor (_cnt_cursor);}
-
- #endif PSMH
-