Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / apps / JAWS2 / JAWS / Cache_List_T.cpp
blobcfa66fa8ed55acc4c1cb6448738fec59a1e0c9eb
1 #ifndef JAWS_CACHE_LIST_T_CPP
2 #define JAWS_CACHE_LIST_T_CPP
4 #include "JAWS/Cache_List_T.h"
5 #include "JAWS/Cache_Manager_T.h"
7 template <class EXT_ID, class FACT, class H_FN, class E_FN>
8 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::JAWS_Cache_List (ACE_Allocator *alloc,
9 size_t maxsize)
10 : allocator_ (alloc),
11 maxsize_ (maxsize),
12 size_ (0),
13 head_ (0),
14 tail_ (0)
16 if (this->allocator_ == 0)
17 this->allocator_ = ACE_Allocator::instance ();
20 template <class EXT_ID, class FACT, class H_FN, class E_FN>
21 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::~JAWS_Cache_List ()
23 while (this->head_ != 0)
24 this->remove (this->head_);
26 this->allocator_ = 0;
29 template <class EXT_ID, class FACT, class H_FN, class E_FN> int
30 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::is_empty () const
32 return (this->size_ == 0);
35 template <class EXT_ID, class FACT, class H_FN, class E_FN> int
36 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::is_full () const
38 return (this->size_ == this->maxsize_);
41 template <class EXT_ID, class FACT, class H_FN, class E_FN> size_t
42 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::size () const
44 return this->size_;
47 template <class EXT_ID, class FACT, class H_FN, class E_FN> size_t
48 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::maxsize () const
50 return this->maxsize_;
53 template <class EXT_ID, class FACT, class H_FN, class E_FN> int
54 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::maxsize (Cache_Manager *,
55 size_t new_maxsize)
57 this->maxsize_ = new_maxsize;
58 return 0;
61 template <class EXT_ID, class FACT, class H_FN, class E_FN> void
62 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::insert_i (Cache_List_Item *item)
64 /* ASSERT: this->size_ < this->maxsize_ */
65 item->next_ = 0;
66 item->prev_ = 0;
68 if (this->size_++ == 0)
69 this->head_ = this->tail_ = item;
70 else
72 this->tail_->next_ = item;
73 item->prev_ = this->tail_;
74 this->tail_ = item;
78 template <class EXT_ID, class FACT, class H_FN, class E_FN> int
79 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::insert (const EXT_ID &ext_id,
80 JAWS_Cache_Object *const &int_id)
82 if (this->is_full ())
83 return -1;
85 Cache_List_Item *item = 0;
86 ACE_NEW_MALLOC_RETURN (item,
87 (Cache_List_Item *)
88 this->allocator_->malloc (sizeof (Cache_List_Item)),
89 Cache_List_Item (ext_id, int_id), -1);
91 this->insert_i (item);
93 return 0;
96 template <class EXT_ID, class FACT, class H_FN, class E_FN> void
97 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::remove_i ()
99 /* ASSERT: this->size_ > 0 */
100 this->size_--;
101 this->item_ = this->head_;
102 if (this->head_ == this->tail_)
104 this->head_ = this->tail_ = 0;
105 return;
108 this->head_ = this->head_->next_;
109 this->head_->prev_ = 0;
110 this->item_->next_ = 0;
113 template <class EXT_ID, class FACT, class H_FN, class E_FN> void
114 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::remove_i (Cache_List_Item *item)
116 this->size_--;
117 this->item_ = item;
119 if (item->next_ == 0 && item->prev_ == 0)
121 this->head_ = this->tail_ = 0;
123 else if (item->next_ == 0)
125 this->tail_ = item->prev_;
126 this->tail_->next_ = 0;
128 else if (item->prev_ == 0)
130 this->head_ = item->next_;
131 this->head_->prev_ = 0;
133 else
135 item->next_->prev_ = item->prev_;
136 item->prev_->next_ = item->next_;
139 item->next_ = 0;
140 item->prev_ = 0;
143 template <class EXT_ID, class FACT, class H_FN, class E_FN> int
144 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::remove (EXT_ID &ext_id,
145 JAWS_Cache_Object *&int_id)
147 if (this->is_empty ())
148 return -1;
150 this->remove_i ();
152 ext_id = this->item_->ext_id_;
153 int_id = this->item_->int_id_;
154 int_id->heap_item (0);
157 ACE_DES_FREE_TEMPLATE4(this->item_, this->allocator_->free,
158 JAWS_Cache_List_Item,
159 EXT_ID, FACT, H_FN, E_FN);
161 this->item_ = 0;
162 return 0;
165 template <class EXT_ID, class FACT, class H_FN, class E_FN> int
166 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::remove (void *item)
168 if (item == 0)
169 return 0;
171 this->remove_i ((Cache_List_Item *) item);
172 this->item_->int_id_->heap_item (0);
174 ACE_DES_FREE_TEMPLATE4(this->item_, this->allocator_->free,
175 JAWS_Cache_List_Item,
176 EXT_ID, FACT, H_FN, E_FN);
178 this->item_ = 0;
180 return 0;
183 template <class EXT_ID, class FACT, class H_FN, class E_FN> int
184 JAWS_Cache_List<EXT_ID,FACT,H_FN,E_FN>::adjust (void *item)
186 if (item == 0)
187 return 0;
189 Cache_List_Item *real_item = (Cache_List_Item *) item;
191 this->remove_i (real_item);
192 this->insert_i (real_item);
193 this->item_ = 0;
195 return 0;
199 template <class EXT_ID, class FACT, class H_FN, class E_FN>
200 JAWS_Cache_List_Item<EXT_ID,FACT,H_FN,E_FN>::
201 JAWS_Cache_List_Item (const EXT_ID &ext_id, JAWS_Cache_Object *const &int_id)
202 : ext_id_ (ext_id),
203 int_id_ (int_id)
205 this->int_id_->heap_item (this);
208 template <class EXT_ID, class FACT, class H_FN, class E_FN> unsigned int
209 JAWS_Cache_List_Item<EXT_ID,FACT,H_FN,E_FN>::priority ()
211 return this->int_id_->priority ();
215 #endif /* JAWS_CACHE_LIST_T_CPP */