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
,
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_
);
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
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
*,
57 this->maxsize_
= new_maxsize
;
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_ */
68 if (this->size_
++ == 0)
69 this->head_
= this->tail_
= item
;
72 this->tail_
->next_
= item
;
73 item
->prev_
= this->tail_
;
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
)
85 Cache_List_Item
*item
= 0;
86 ACE_NEW_MALLOC_RETURN (item
,
88 this->allocator_
->malloc (sizeof (Cache_List_Item
)),
89 Cache_List_Item (ext_id
, int_id
), -1);
91 this->insert_i (item
);
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 */
101 this->item_
= this->head_
;
102 if (this->head_
== this->tail_
)
104 this->head_
= this->tail_
= 0;
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
)
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;
135 item
->next_
->prev_
= item
->prev_
;
136 item
->prev_
->next_
= item
->next_
;
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 ())
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
);
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
)
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
);
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
)
189 Cache_List_Item
*real_item
= (Cache_List_Item
*) item
;
191 this->remove_i (real_item
);
192 this->insert_i (real_item
);
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
)
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 */