From 539d6bf53bcece62e29d3d7d900b83dc03275b65 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 20 Aug 2009 22:25:50 +0000 Subject: Added a typedef to the cache, and most list manipulation functions now return a reference to the list, so you can chain appends and whatnot. --- src/cache.h | 20 +++++++++++++++++++- src/list.cpp | 1 - src/list.h | 42 +++++++++++++++++++++++++++++------------- 3 files changed, 48 insertions(+), 15 deletions(-) (limited to 'src') 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 return hEnt.has( cId ) || pStore->has( cId ); } + /** + * Retrieve an object from the cache and return a pointer to it. + * The object returned may be loaded from backend storage if needed, + * or the currently live object will be returned. + *@param cId The id of the object to load. + *@returns A pointer to the object. + */ Ptr get( const keytype &cId ) { TRACE( cId ); @@ -242,6 +249,16 @@ namespace Bu } } + /** + * Retrieve a handle to an object without loading it now. This function + * will return a pointer that has not yet been "realized" but can be + * used normally. Upon initial use in any way the object will be + * loaded from the cache, either linking against the already loaded + * object or loading it fresh from the backend storage. The advantage + * of this is that you recieve a usable handle to the data, but it + * does not count as a reference yet, meaning that the data is loaded + * when you need it, not before. + */ Ptr getLazy( const keytype &cId ) { TRACE( cId ); @@ -297,7 +314,8 @@ namespace Bu hEnt.erase( cId ); } - Bu::List getKeys() + typedef Bu::List KeyList; + KeyList getKeys() { return pStore->getKeys(); } 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 @@ #include "bu/list.h" -template class Bu::List; diff --git a/src/list.h b/src/list.h index d711a2e..d06bc9e 100644 --- a/src/list.h +++ b/src/list.h @@ -239,10 +239,12 @@ namespace Bu core->clear(); } - void enqueue( const value &v ) + MyType &enqueue( const value &v ) { _hardCopy(); append( v ); + + return *this; } value dequeue() @@ -259,13 +261,15 @@ namespace Bu * Append a value to the list. *@param v (const value_type &) The value to append. */ - void append( const value &v ) + MyType &append( const value &v ) { _hardCopy(); core->append( v ); + + return *this; } - void append( const MyType &rSrc ) + MyType &append( const MyType &rSrc ) { _hardCopy(); for( typename MyType::const_iterator i = rSrc.begin(); @@ -273,23 +277,27 @@ namespace Bu { core->append( *i ); } + + return *this; } /** * Prepend a value to the list. *@param v (const value_type &) The value to prepend. */ - void prepend( const value &v ) + MyType &prepend( const value &v ) { _hardCopy(); core->prepend( v ); + + return *this; } /** * Prepend another list to the front of this one. This will prepend * the rSrc list in reverse order...I may fix that later. */ - void prepend( const MyType &rSrc ) + MyType &prepend( const MyType &rSrc ) { _hardCopy(); for( typename MyType::const_iterator i = rSrc.begin(); @@ -297,13 +305,17 @@ namespace Bu { core->prepend( *i ); } + + return *this; } - void insert( MyType::iterator &i, const value &v ) + MyType &insert( MyType::iterator &i, const value &v ) { _hardCopy(); core->insert( i.pLink, v ); + + return *this; } /** @@ -313,14 +325,14 @@ namespace Bu * List all items will be sorted. To use this, the value type must * support the > operator. */ - void insertSorted( const value &v ) + MyType &insertSorted( const value &v ) { _hardCopy(); if( core->pFirst == NULL ) { // Empty list core->append( v ); - return; + return *this; } else { @@ -330,13 +342,13 @@ namespace Bu if( !core->cmp( v, *(pCur->pValue)) ) { core->insert( pCur, v ); - return; + return *this; } pCur = pCur->pNext; if( pCur == NULL ) { core->append( v ); - return; + return *this; } } } @@ -641,26 +653,30 @@ namespace Bu * Erase an item from the list. *@param i (iterator) The item to erase. */ - void erase( iterator i ) + MyType &erase( iterator i ) { _hardCopy(); core->erase( i.pLink ); + + return *this; } /** * Erase an item from the list if you already know the item. *@param v The item to find and erase. */ - void erase( const value &v ) + MyType &erase( const value &v ) { for( const_iterator i = begin(); i != end(); i++ ) { if( (*i) == v ) { erase( i ); - return; + return *this; } } + + return *this; } /** -- cgit v1.2.3