Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / Cache_Heap_T.h
blobd89f5195055e859e67117d05d7f406b43e1f3ff0
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:
22 typedef JAWS_Cache_Manager<EXT_ID, FACT, H_FN, E_FN> Cache_Manager;
23 typedef JAWS_Cache_Heap_Item<EXT_ID, FACT, H_FN, E_FN> Cache_Heap_Item;
25 JAWS_Cache_Heap (ACE_Allocator *alloc = 0, size_t maxsize = 8192);
26 // maxsize is the total number of objects the in memory cache is
27 // willing to manage
29 ~JAWS_Cache_Heap ();
31 int is_empty () const;
32 int is_full () const;
34 size_t size () const;
35 size_t maxsize () const;
37 int maxsize (Cache_Manager *cm, size_t new_maxsize);
38 // attempt to grow (or shrink) the heap. Return 0 on success, -1 on
39 // error.
41 int insert (const EXT_ID &ext_id, JAWS_Cache_Object *const &int_id);
42 // attempt to insert int_id into heap.
44 int remove (EXT_ID &ext_id, JAWS_Cache_Object *&int_id);
45 // attempt to remove the top element of heap.
47 int remove (void *item);
48 // treat item as a Cache_Heap_Item, and remove it from the heap
50 int adjust (void *item);
51 // treat item as a Cache_Heap_Item, and alter its heap position
53 protected:
54 void insert_i (Cache_Heap_Item *item);
55 // insert item into heap.
57 void remove_i (size_t pos);
58 // remove the element residing at pos, but do not delete it.
60 void remove_i ();
61 // remove the element residing at the top of heap, but do not delete it.
63 private:
64 ACE_Allocator *allocator_;
66 size_t maxsize_;
67 size_t size_;
69 Cache_Heap_Item **heap_;
73 template <class EXT_ID, class FACT, class H_FN, class E_FN>
74 class JAWS_Cache_Heap_Item
76 friend class JAWS_Cache_Heap<EXT_ID, FACT, H_FN, E_FN>;
78 public:
79 JAWS_Cache_Heap_Item (const EXT_ID &ext_id, JAWS_Cache_Object *const &int_id);
80 unsigned int priority ();
82 private:
83 EXT_ID ext_id_;
84 JAWS_Cache_Object *int_id_;
86 size_t heap_idx_;
89 #include "JAWS/Cache_Heap_T.cpp"
91 #endif /* JAWS_CACHE_HEAP_T_H */