diff options
Diffstat (limited to '')
-rw-r--r-- | src/cache.h | 20 | ||||
-rw-r--r-- | src/list.cpp | 1 | ||||
-rw-r--r-- | src/list.h | 42 |
3 files changed, 48 insertions, 15 deletions
diff --git a/src/cache.h b/src/cache.h index 98775d2..53b4f7a 100644 --- a/src/cache.h +++ b/src/cache.h | |||
@@ -228,6 +228,13 @@ namespace Bu | |||
228 | return hEnt.has( cId ) || pStore->has( cId ); | 228 | return hEnt.has( cId ) || pStore->has( cId ); |
229 | } | 229 | } |
230 | 230 | ||
231 | /** | ||
232 | * Retrieve an object from the cache and return a pointer to it. | ||
233 | * The object returned may be loaded from backend storage if needed, | ||
234 | * or the currently live object will be returned. | ||
235 | *@param cId The id of the object to load. | ||
236 | *@returns A pointer to the object. | ||
237 | */ | ||
231 | Ptr get( const keytype &cId ) | 238 | Ptr get( const keytype &cId ) |
232 | { | 239 | { |
233 | TRACE( cId ); | 240 | TRACE( cId ); |
@@ -242,6 +249,16 @@ namespace Bu | |||
242 | } | 249 | } |
243 | } | 250 | } |
244 | 251 | ||
252 | /** | ||
253 | * Retrieve a handle to an object without loading it now. This function | ||
254 | * will return a pointer that has not yet been "realized" but can be | ||
255 | * used normally. Upon initial use in any way the object will be | ||
256 | * loaded from the cache, either linking against the already loaded | ||
257 | * object or loading it fresh from the backend storage. The advantage | ||
258 | * of this is that you recieve a usable handle to the data, but it | ||
259 | * does not count as a reference yet, meaning that the data is loaded | ||
260 | * when you need it, not before. | ||
261 | */ | ||
245 | Ptr getLazy( const keytype &cId ) | 262 | Ptr getLazy( const keytype &cId ) |
246 | { | 263 | { |
247 | TRACE( cId ); | 264 | TRACE( cId ); |
@@ -297,7 +314,8 @@ namespace Bu | |||
297 | hEnt.erase( cId ); | 314 | hEnt.erase( cId ); |
298 | } | 315 | } |
299 | 316 | ||
300 | Bu::List<keytype> getKeys() | 317 | typedef Bu::List<keytype> KeyList; |
318 | KeyList getKeys() | ||
301 | { | 319 | { |
302 | return pStore->getKeys(); | 320 | return pStore->getKeys(); |
303 | } | 321 | } |
diff --git a/src/list.cpp b/src/list.cpp index 3f77b5c..bc7c2eb 100644 --- a/src/list.cpp +++ b/src/list.cpp | |||
@@ -7,4 +7,3 @@ | |||
7 | 7 | ||
8 | #include "bu/list.h" | 8 | #include "bu/list.h" |
9 | 9 | ||
10 | template class Bu::List<int>; | ||
@@ -239,10 +239,12 @@ namespace Bu | |||
239 | core->clear(); | 239 | core->clear(); |
240 | } | 240 | } |
241 | 241 | ||
242 | void enqueue( const value &v ) | 242 | MyType &enqueue( const value &v ) |
243 | { | 243 | { |
244 | _hardCopy(); | 244 | _hardCopy(); |
245 | append( v ); | 245 | append( v ); |
246 | |||
247 | return *this; | ||
246 | } | 248 | } |
247 | 249 | ||
248 | value dequeue() | 250 | value dequeue() |
@@ -259,13 +261,15 @@ namespace Bu | |||
259 | * Append a value to the list. | 261 | * Append a value to the list. |
260 | *@param v (const value_type &) The value to append. | 262 | *@param v (const value_type &) The value to append. |
261 | */ | 263 | */ |
262 | void append( const value &v ) | 264 | MyType &append( const value &v ) |
263 | { | 265 | { |
264 | _hardCopy(); | 266 | _hardCopy(); |
265 | core->append( v ); | 267 | core->append( v ); |
268 | |||
269 | return *this; | ||
266 | } | 270 | } |
267 | 271 | ||
268 | void append( const MyType &rSrc ) | 272 | MyType &append( const MyType &rSrc ) |
269 | { | 273 | { |
270 | _hardCopy(); | 274 | _hardCopy(); |
271 | for( typename MyType::const_iterator i = rSrc.begin(); | 275 | for( typename MyType::const_iterator i = rSrc.begin(); |
@@ -273,23 +277,27 @@ namespace Bu | |||
273 | { | 277 | { |
274 | core->append( *i ); | 278 | core->append( *i ); |
275 | } | 279 | } |
280 | |||
281 | return *this; | ||
276 | } | 282 | } |
277 | 283 | ||
278 | /** | 284 | /** |
279 | * Prepend a value to the list. | 285 | * Prepend a value to the list. |
280 | *@param v (const value_type &) The value to prepend. | 286 | *@param v (const value_type &) The value to prepend. |
281 | */ | 287 | */ |
282 | void prepend( const value &v ) | 288 | MyType &prepend( const value &v ) |
283 | { | 289 | { |
284 | _hardCopy(); | 290 | _hardCopy(); |
285 | core->prepend( v ); | 291 | core->prepend( v ); |
292 | |||
293 | return *this; | ||
286 | } | 294 | } |
287 | 295 | ||
288 | /** | 296 | /** |
289 | * Prepend another list to the front of this one. This will prepend | 297 | * Prepend another list to the front of this one. This will prepend |
290 | * the rSrc list in reverse order...I may fix that later. | 298 | * the rSrc list in reverse order...I may fix that later. |
291 | */ | 299 | */ |
292 | void prepend( const MyType &rSrc ) | 300 | MyType &prepend( const MyType &rSrc ) |
293 | { | 301 | { |
294 | _hardCopy(); | 302 | _hardCopy(); |
295 | for( typename MyType::const_iterator i = rSrc.begin(); | 303 | for( typename MyType::const_iterator i = rSrc.begin(); |
@@ -297,13 +305,17 @@ namespace Bu | |||
297 | { | 305 | { |
298 | core->prepend( *i ); | 306 | core->prepend( *i ); |
299 | } | 307 | } |
308 | |||
309 | return *this; | ||
300 | } | 310 | } |
301 | 311 | ||
302 | void insert( MyType::iterator &i, const value &v ) | 312 | MyType &insert( MyType::iterator &i, const value &v ) |
303 | { | 313 | { |
304 | _hardCopy(); | 314 | _hardCopy(); |
305 | 315 | ||
306 | core->insert( i.pLink, v ); | 316 | core->insert( i.pLink, v ); |
317 | |||
318 | return *this; | ||
307 | } | 319 | } |
308 | 320 | ||
309 | /** | 321 | /** |
@@ -313,14 +325,14 @@ namespace Bu | |||
313 | * List all items will be sorted. To use this, the value type must | 325 | * List all items will be sorted. To use this, the value type must |
314 | * support the > operator. | 326 | * support the > operator. |
315 | */ | 327 | */ |
316 | void insertSorted( const value &v ) | 328 | MyType &insertSorted( const value &v ) |
317 | { | 329 | { |
318 | _hardCopy(); | 330 | _hardCopy(); |
319 | if( core->pFirst == NULL ) | 331 | if( core->pFirst == NULL ) |
320 | { | 332 | { |
321 | // Empty list | 333 | // Empty list |
322 | core->append( v ); | 334 | core->append( v ); |
323 | return; | 335 | return *this; |
324 | } | 336 | } |
325 | else | 337 | else |
326 | { | 338 | { |
@@ -330,13 +342,13 @@ namespace Bu | |||
330 | if( !core->cmp( v, *(pCur->pValue)) ) | 342 | if( !core->cmp( v, *(pCur->pValue)) ) |
331 | { | 343 | { |
332 | core->insert( pCur, v ); | 344 | core->insert( pCur, v ); |
333 | return; | 345 | return *this; |
334 | } | 346 | } |
335 | pCur = pCur->pNext; | 347 | pCur = pCur->pNext; |
336 | if( pCur == NULL ) | 348 | if( pCur == NULL ) |
337 | { | 349 | { |
338 | core->append( v ); | 350 | core->append( v ); |
339 | return; | 351 | return *this; |
340 | } | 352 | } |
341 | } | 353 | } |
342 | } | 354 | } |
@@ -641,26 +653,30 @@ namespace Bu | |||
641 | * Erase an item from the list. | 653 | * Erase an item from the list. |
642 | *@param i (iterator) The item to erase. | 654 | *@param i (iterator) The item to erase. |
643 | */ | 655 | */ |
644 | void erase( iterator i ) | 656 | MyType &erase( iterator i ) |
645 | { | 657 | { |
646 | _hardCopy(); | 658 | _hardCopy(); |
647 | core->erase( i.pLink ); | 659 | core->erase( i.pLink ); |
660 | |||
661 | return *this; | ||
648 | } | 662 | } |
649 | 663 | ||
650 | /** | 664 | /** |
651 | * Erase an item from the list if you already know the item. | 665 | * Erase an item from the list if you already know the item. |
652 | *@param v The item to find and erase. | 666 | *@param v The item to find and erase. |
653 | */ | 667 | */ |
654 | void erase( const value &v ) | 668 | MyType &erase( const value &v ) |
655 | { | 669 | { |
656 | for( const_iterator i = begin(); i != end(); i++ ) | 670 | for( const_iterator i = begin(); i != end(); i++ ) |
657 | { | 671 | { |
658 | if( (*i) == v ) | 672 | if( (*i) == v ) |
659 | { | 673 | { |
660 | erase( i ); | 674 | erase( i ); |
661 | return; | 675 | return *this; |
662 | } | 676 | } |
663 | } | 677 | } |
678 | |||
679 | return *this; | ||
664 | } | 680 | } |
665 | 681 | ||
666 | /** | 682 | /** |