Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / Cache_List_T.h
blobd7fee6233659bedcba3fe3d45699b6f10d90d6f6
1 /* -*- c++ -*- */
2 #ifndef JAWS_CACHE_LIST_T_H
3 #define JAWS_CACHE_LIST_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_List_Item;
16 template <class EXT_ID, class FACT, class H_FN, class E_FN>
17 class JAWS_Cache_List
18 // Roll my own heap here. Eventually, a heap should be its own
19 // standalone data structure.
21 // This version is not a heap, but a doubly linked list. We are
22 // trying to simplify all the heap operations to be O(1).
24 public:
26 typedef JAWS_Cache_Manager<EXT_ID, FACT, H_FN, E_FN> Cache_Manager;
27 typedef JAWS_Cache_List_Item<EXT_ID, FACT, H_FN, E_FN> Cache_List_Item;
29 JAWS_Cache_List (ACE_Allocator *alloc = 0, size_t maxsize = 8192);
30 // maxsize is the total number of objects the in memory cache is
31 // willing to manage
33 ~JAWS_Cache_List (void);
35 int is_empty (void) const;
36 int is_full (void) const;
38 size_t size (void) const;
39 size_t maxsize (void) const;
41 int maxsize (Cache_Manager *cm, size_t new_maxsize);
42 // attempt to grow (or shrink) the heap. Return 0 on success, -1 on
43 // error.
45 int insert (const EXT_ID &ext_id, JAWS_Cache_Object *const &int_id);
46 // attempt to insert int_id into heap.
48 int remove (EXT_ID &ext_id, JAWS_Cache_Object *&int_id);
49 // attempt to remove the top element of heap.
51 int remove (void *item);
52 // treat item as a Cache_List_Item, and remove it from the heap
54 int adjust (void *item);
55 // treat item as a Cache_List_Item, and alter its heap position
57 protected:
59 void insert_i (Cache_List_Item *item);
60 // insert item into heap.
62 void remove_i (Cache_List_Item *item);
63 // remove the element residing at pos, but do not delete it.
65 void remove_i (void);
66 // remove the element residing at the top of heap, but do not delete it.
68 private:
70 ACE_Allocator *allocator_;
72 size_t maxsize_;
73 size_t size_;
75 Cache_List_Item *item_;
77 Cache_List_Item *head_;
78 Cache_List_Item *tail_;
83 template <class EXT_ID, class FACT, class H_FN, class E_FN>
84 class JAWS_Cache_List_Item
87 friend class JAWS_Cache_List<EXT_ID, FACT, H_FN, E_FN>;
89 public:
91 typedef JAWS_Cache_List<EXT_ID, FACT, H_FN, E_FN> Cache_List;
93 JAWS_Cache_List_Item (const EXT_ID &ext_id, JAWS_Cache_Object *const &int_id);
94 unsigned int priority (void);
96 private:
98 EXT_ID ext_id_;
99 JAWS_Cache_Object *int_id_;
101 JAWS_Cache_List_Item *next_;
102 JAWS_Cache_List_Item *prev_;
105 #if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
106 #include "JAWS/Cache_List_T.cpp"
107 #endif /* ACE_TEMPLATES_REQUIRE_SOURCE */
109 #endif /* JAWS_CACHE_LIST_T_H */