Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / Cache_Heap_T.h
blob89f46561acee0741bec0d9f51aec08247cbef0a2
1 /* -*- c++ -*- */
2 #ifndef JAWS_CACHE_HEAP_T_H
3 #define JAWS_CACHE_HEAP_T_H
5 #include "ace/Malloc.h"
6 #include "JAWS/Cache_Object.h"
8 // Forward declarations
9 template <class EXT_ID, class FACTORY, class HASH_FUNC, class EQ_FUNC>
10 class JAWS_Cache_Manager;
12 template <class EXT_ID, class FACTORY, class HASH_FUNC, class EQ_FUNC>
13 class JAWS_Cache_Heap_Item;
16 template <class EXT_ID, class FACT, class H_FN, class E_FN>
17 class JAWS_Cache_Heap
18 // Roll my own heap here. Eventually, a heap should be its own
19 // standalone data structure.
21 public:
23 typedef JAWS_Cache_Manager<EXT_ID, FACT, H_FN, E_FN> Cache_Manager;
24 typedef JAWS_Cache_Heap_Item<EXT_ID, FACT, H_FN, E_FN> Cache_Heap_Item;
26 JAWS_Cache_Heap (ACE_Allocator *alloc = 0, size_t maxsize = 8192);
27 // maxsize is the total number of objects the in memory cache is
28 // willing to manage
30 ~JAWS_Cache_Heap (void);
32 int is_empty (void) const;
33 int is_full (void) const;
35 size_t size (void) const;
36 size_t maxsize (void) const;
38 int maxsize (Cache_Manager *cm, size_t new_maxsize);
39 // attempt to grow (or shrink) the heap. Return 0 on success, -1 on
40 // error.
42 int insert (const EXT_ID &ext_id, JAWS_Cache_Object *const &int_id);
43 // attempt to insert int_id into heap.
45 int remove (EXT_ID &ext_id, JAWS_Cache_Object *&int_id);
46 // attempt to remove the top element of heap.
48 int remove (void *item);
49 // treat item as a Cache_Heap_Item, and remove it from the heap
51 int adjust (void *item);
52 // treat item as a Cache_Heap_Item, and alter its heap position
54 protected:
56 void insert_i (Cache_Heap_Item *item);
57 // insert item into heap.
59 void remove_i (size_t pos);
60 // remove the element residing at pos, but do not delete it.
62 void remove_i (void);
63 // remove the element residing at the top of heap, but do not delete it.
65 private:
67 ACE_Allocator *allocator_;
69 size_t maxsize_;
70 size_t size_;
72 Cache_Heap_Item **heap_;
77 template <class EXT_ID, class FACT, class H_FN, class E_FN>
78 class JAWS_Cache_Heap_Item
81 friend class JAWS_Cache_Heap<EXT_ID, FACT, H_FN, E_FN>;
83 public:
85 JAWS_Cache_Heap_Item (const EXT_ID &ext_id, JAWS_Cache_Object *const &int_id);
86 unsigned int priority (void);
88 private:
90 EXT_ID ext_id_;
91 JAWS_Cache_Object *int_id_;
93 size_t heap_idx_;
97 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
98 #include "JAWS/Cache_Heap_T.cpp"
99 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
101 #endif /* JAWS_CACHE_HEAP_T_H */