From f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 3 Apr 2007 03:49:53 +0000 Subject: Ok, no code is left in src, it's all in src/old. We'll gradually move code back into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier. --- src/list.h | 101 ------------------------------------------------------------- 1 file changed, 101 deletions(-) delete mode 100644 src/list.h (limited to 'src/list.h') diff --git a/src/list.h b/src/list.h deleted file mode 100644 index c71b328..0000000 --- a/src/list.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef LIST_H -#define LIST_H - - -/** The basic List class ADT. This, on it's own, does absolutely nothing, but - * does define all standard interface functions to access a list. - *@author Mike Buland - */ -class List -{ -public: - /** - * Construct a list. - */ - List(); - - /** - * Desconstruct a list. - */ - virtual ~List(); - - /** Gets the value at a specified index. - *@param nIndex The index of the item to return. - *@returns The specified item, or NULL if the index was beyond the range - * of the list. - *@author Mike Buland - */ - virtual void *getAt( int nIndex ) = 0; - - /** Append the given data to the end of the list. This increases the - * size of the list by one. - *@param pData The data to append to the list. - *@author Mike Buland - */ - virtual void append( void *pData ) = 0; - - /** Inserts an item at the specified position in the list. The - * new item takes the index that you specify, and all other items - * are moved up one position. The size of the list is increased by - * one. - *@param pData The value to insert into the list. - *@param nPos Where to insert the data into the list. - *@author Mike Buland - */ - virtual void insertBefore( void *pData, int nPos = 0 ) = 0; - - /** Determines the size of the list, in elements. - *@returns The size of the list. - *@author Mike Buland - */ - virtual int getSize( ) = 0; - - /** Determines if the list is empty or not. - *@returns True if the list is empty, or false if the list has - * data in it (if the size is greater than zero). - *@author Mike Buland - */ - virtual bool isEmpty( ) = 0; - - /** Deletes an item at the specified index and moves all other - * values down one index. The size of the list is decreased by one. - *@param nIndex The index of the item to delete. - *@author Mike Buland - */ - virtual void deleteAt( int nIndex ) = 0; - - /** Completely empties the list, and sets the effective size to - * zero. - *@author Mike Buland - */ - virtual void empty() = 0; - - /** Sets the size of the list. This can be larger or smaller - * than what it was previously. If larger, new blank items will - * be added to the end of the list. If smaller than the old list - * items will be deleted from the end. - *@param nNewSize The new size of the list. - *@author Mike Buland - */ - virtual void setSize( int nNewSize ) = 0; - - /** Sets a member at a specified location to a new value. - * If the member being set is outside of the range of the - * current list it should be expanded. - *@param nIndex The zero-based index of the item to change. - *@param pData The new value for that index. - *@author Mike Buland - */ - virtual void setAt( int nIndex, void *pData ) = 0; - - /** Makes the List work like an array. Just say listObj[2] to get - * the third element. - *@param nIndex The index to access in the list. - *@returns A pointer to the data at element index. - *@author Mike Buland - */ - void *operator[]( int nIndex ) { return getAt( nIndex ); }; -}; - -#endif - -- cgit v1.2.3 From 033c41ed57348abb3a418166b1fb39bfad3312de Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 11 May 2007 07:51:40 +0000 Subject: Added a list template class, seems to work pretty well for now, I may have forgotten proper cleanup in the deconstructor, but besides that you can do almost everything you need. I'll make a slist/stack next, probably with the same basic code, just a different structure (not doubley-linked). The xml system from old-libbu++ is almost completely converted, I was going to re-write it, but this seemed easier at first, it may not have been, we'll see. It almost parses everything again, and almost outputs again, and it does use streams now. The FString is partway to doing minimum chunk allocations, so that adding single-characters will be really fast up to the minimum chunk size. I also figured out how to add this optimization without any extra variables taking up space, and it's optional in the template, which is cool. You can specify the size of the blocks (default 256 bytes), if it's 0 then they'll be like the old FString, 1 chunk per operation. The next FString update should be allowing efficient removal from the begining of the string by faking it, and simply moving a secondary base pointer ahead, and then optimizing appends after that fact to simply move the existing data around if you shouldn't have to re-allocate (alla FlexBuf). The final fun addition that I'm planning is a simple switch in the template (boolean) that will switch an FString into a thread-safe mode without changing the interface or anything that you can do with them at all. It may increasing memory usage, but they should still be better than std::strings, and totally thread-safe. The best part of that is that if it's done with a boolean template parameter and if statements that only test that parameter controlling flow, the code that you don't want (threadsafe/non-threadsafe) won't be included at all post-optimization. --- src/fstring.h | 14 +++-- src/list.cpp | 2 + src/list.h | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/tests/list.cpp | 22 +++++++ src/tests/xml.cpp | 6 +- src/xmldocument.cpp | 20 +++--- src/xmldocument.h | 8 +-- src/xmlnode.cpp | 106 ++++++++++--------------------- src/xmlnode.h | 101 +++++++++++------------------- src/xmlreader.cpp | 170 +++++++++++++++++++++++++------------------------- src/xmlreader.h | 31 ++++----- src/xmlwriter.cpp | 62 +++++++++--------- src/xmlwriter.h | 16 ++--- 13 files changed, 428 insertions(+), 306 deletions(-) create mode 100644 src/list.cpp create mode 100644 src/list.h create mode 100644 src/tests/list.cpp (limited to 'src/list.h') diff --git a/src/fstring.h b/src/fstring.h index 877e5a7..f738f63 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -28,7 +28,7 @@ namespace Bu * data is actually copied. This also means that you never need to put any * FBasicString into a ref-counting container class. */ - template< typename chr, typename chralloc=std::allocator, typename chunkalloc=std::allocator > > + template< typename chr, int nMinSize=256, typename chralloc=std::allocator, typename chunkalloc=std::allocator > > class FBasicString : public Archival { #ifndef VALTEST @@ -36,7 +36,7 @@ namespace Bu #endif private: typedef struct FStringChunk Chunk; - typedef struct FBasicString MyType; + typedef struct FBasicString MyType; public: FBasicString() : @@ -131,6 +131,11 @@ namespace Bu appendChunk( pNew ); } + void append( const chr cData ) + { + append( &cData, 1 ); + } + void prepend( const chr *pData ) { long nLen; @@ -231,8 +236,7 @@ namespace Bu MyType &operator +=( const chr pData ) { - chr tmp[2] = { pData, (chr)0 }; - append( tmp ); + append( &pData, 1 ); return (*this); } @@ -475,7 +479,7 @@ namespace Bu } } - void copyFrom( const FBasicString &rSrc ) + void copyFrom( const FBasicString &rSrc ) { if( rSrc.pFirst == NULL ) return; diff --git a/src/list.cpp b/src/list.cpp new file mode 100644 index 0000000..abe92ad --- /dev/null +++ b/src/list.cpp @@ -0,0 +1,2 @@ +#include "bu/list.h" + diff --git a/src/list.h b/src/list.h new file mode 100644 index 0000000..ec63496 --- /dev/null +++ b/src/list.h @@ -0,0 +1,176 @@ +#ifndef LIST_H +#define LIST_H + +#include +#include "bu/exceptionbase.h" + +namespace Bu +{ + template + struct ListLink + { + value *pValue; + ListLink *pNext; + ListLink *pPrev; + }; + template, typename linkalloc=std::allocator > > + class List + { + private: + typedef struct ListLink Link; + typedef class List MyType; + + public: + List() : + pFirst( NULL ), + pLast( NULL ) + { + } + + void append( value v ) + { + Link *pNew = la.allocate( sizeof( Link ) ); + pNew->pValue = va.allocate( sizeof( value ) ); + va.construct( pNew->pValue, v ); + if( pFirst == NULL ) + { + // Empty list + pFirst = pLast = pNew; + pNew->pNext = pNew->pPrev = NULL; + } + else + { + pNew->pNext = NULL; + pNew->pPrev = pLast; + pLast->pNext = pNew; + pLast = pNew; + } + } + + void prepend( value v ) + { + Link *pNew = la.allocate( sizeof( Link ) ); + pNew->pValue = va.allocate( sizeof( value ) ); + va.construct( pNew->pValue, v ); + if( pFirst == NULL ) + { + // Empty list + pFirst = pLast = pNew; + pNew->pNext = pNew->pPrev = NULL; + } + else + { + pNew->pNext = pFirst; + pNew->pPrev = NULL; + pFirst->pPrev = pNew; + pFirst = pNew; + } + } + + typedef struct iterator + { + friend class List; + private: + Link *pLink; + iterator() : + pLink( NULL ) + { + } + + iterator( Link *pLink ) : + pLink( pLink ) + { + } + + public: + bool operator==( const iterator &oth ) + { + return ( pLink == oth.pLink ); + } + + bool operator==( const Link *pOth ) + { + return ( pLink == pOth ); + } + + bool operator!=( const iterator &oth ) + { + return ( pLink != oth.pLink ); + } + + bool operator!=( const Link *pOth ) + { + return ( pLink != pOth ); + } + + value &operator*() + { + return *(pLink->pValue); + } + + value *operator->() + { + return pLink->pValue(); + } + + iterator operator++() + { + if( pLink != NULL ) + pLink = pLink->pNext; + return *this; + } + + iterator operator--() + { + if( pLink != NULL ) + pLink = pLink->pPrev; + return *this; + } + + iterator operator++( int ) + { + if( pLink != NULL ) + pLink = pLink->pNext; + return *this; + } + + iterator operator--( int ) + { + if( pLink != NULL ) + pLink = pLink->pPrev; + return *this; + } + + iterator operator=( const iterator &oth ) + { + pLink = oth.pLink; + } + }; + + iterator begin() + { + return iterator( pFirst ); + } + + const Link *end() + { + return NULL; + } + + int getSize() + { + int j = 0; + for( Link *pCur = pFirst; pCur; pCur = pCur->pNext ) + j++; + return j; + } + + private: + Link *pFirst; + Link *pLast; + linkalloc la; + valuealloc va; + }; +} + +#endif diff --git a/src/tests/list.cpp b/src/tests/list.cpp new file mode 100644 index 0000000..34ab656 --- /dev/null +++ b/src/tests/list.cpp @@ -0,0 +1,22 @@ +#include "bu/list.h" + +int main() +{ + Bu::List l; + + l.append( 0 ); + + for( int j = 3; j <= 21; j += 3 ) + { + l.append( j ); + l.prepend( -j ); + } + + for( Bu::List::iterator i = l.begin(); i != l.end(); i++ ) + { + printf("%d ", *i ); + } + + printf("\n\n"); +} + diff --git a/src/tests/xml.cpp b/src/tests/xml.cpp index 9ef6a7e..9689a28 100644 --- a/src/tests/xml.cpp +++ b/src/tests/xml.cpp @@ -6,9 +6,9 @@ int main() { Bu::File f("test.xml", "r"); - Bu::XmlReader xr( f ); - - xr.read(); + XmlReader xr( f ); + + //xr.read(); return 0; } diff --git a/src/xmldocument.cpp b/src/xmldocument.cpp index d7867d5..95b9788 100644 --- a/src/xmldocument.cpp +++ b/src/xmldocument.cpp @@ -1,6 +1,6 @@ #include #include -#include "xmlwriter.h" +#include "xmldocument.h" XmlDocument::XmlDocument( XmlNode *pRoot ) { @@ -17,28 +17,23 @@ XmlDocument::~XmlDocument() } } -void XmlDocument::addNode( const char *sName, const char *sContent, bool bClose ) +void XmlDocument::addNode( const Bu::FString &sName ) { if( pRoot == NULL ) { // This is the first node, so ignore position and just insert it. - pCurrent = pRoot = new XmlNode( sName, NULL, sContent ); + pCurrent = pRoot = new XmlNode( sName ); } else { - pCurrent = pCurrent->addChild( sName, sContent ); - } - - if( bClose ) - { - closeNode(); + pCurrent = pCurrent->addChild( sName ); } } - +/* void XmlDocument::setName( const char *sName ) { pCurrent->setName( sName ); -} +}*/ bool XmlDocument::isCompleted() { @@ -143,7 +138,8 @@ void XmlDocument::setContent( const char *sContent ) { if( pCurrent ) { - pCurrent->setContent( sContent ); + printf("XmlDocument::setContent: not yet implemented.\n"); + //pCurrent->setContent( sContent ); } } diff --git a/src/xmldocument.h b/src/xmldocument.h index 6671c41..e0c36eb 100644 --- a/src/xmldocument.h +++ b/src/xmldocument.h @@ -39,13 +39,7 @@ public: * the node and setting the content and name. If this is set to true the * node is appended, but the context node doesn't change. */ - void addNode( const char *sName=NULL, const char *sContent=NULL, bool bClose=false ); - - /** - * Set the name of the current node context. - *@param sName The new name of the node. - */ - void setName( const char *sName ); + void addNode( const Bu::FString &sName ); /** * Close the current node context. This will move the current context to diff --git a/src/xmlnode.cpp b/src/xmlnode.cpp index b1ed9a9..96d5850 100644 --- a/src/xmlnode.cpp +++ b/src/xmlnode.cpp @@ -1,53 +1,15 @@ #include "xmlnode.h" -#include "hashfunctionstring.h" -XmlNode::XmlNode( const char *sName, XmlNode *pParent, const char *sContent ) : - hProperties( new HashFunctionString(), 53, false ), - hChildren( new HashFunctionString(), 53, true ) +XmlNode::XmlNode( const Bu::FString &sName, XmlNode *pParent ) : + sName( sName ), + pParent( pParent ) { - this->pParent = pParent; - if( sName != NULL ) - { - setName( sName ); - } - if( sContent != NULL ) - { - this->sPreContent = new std::string( sContent ); - } - else - { - this->sPreContent = NULL; - } - nCurContent = 0; } XmlNode::~XmlNode() { - for( int j = 0; j < lChildren.getSize(); j++ ) - { - delete (XmlNode *)lChildren[j]; - } - for( int j = 0; j < lPropNames.getSize(); j++ ) - { - delete (std::string *)lPropNames[j]; - } - for( int j = 0; j < lPropValues.getSize(); j++ ) - { - delete (std::string *)lPropValues[j]; - } - for( int j = 0; j < lPostContent.getSize(); j++ ) - { - if( lPostContent[j] != NULL ) - { - delete (std::string *)lPostContent[j]; - } - } - if( sPreContent ) - { - delete sPreContent; - } } - +/* void XmlNode::setName( const char *sName ) { if( pParent ) @@ -120,18 +82,18 @@ const char *XmlNode::getContent( int nIndex ) } return NULL; -} +}*/ -XmlNode *XmlNode::addChild( const char *sName, const char *sContent ) +XmlNode *XmlNode::addChild( const Bu::FString &sName ) { - return addChild( new XmlNode( sName, this, sContent ) ); + return addChild( new XmlNode( sName, this ) ); } XmlNode *XmlNode::addChild( XmlNode *pNode ) { - lChildren.append( pNode ); - lPostContent.append( NULL ); - nCurContent++; + Child c = { typeNode }; + c.pNode = pNode; + lChildren.append( c ); pNode->pParent = this; return pNode; @@ -142,21 +104,16 @@ XmlNode *XmlNode::getParent() return pParent; } -void XmlNode::addProperty( const char *sName, const char *sValue ) +void XmlNode::addProperty( const Bu::FString &sName, const Bu::FString &sValue ) { - std::string *pName = new std::string( sName ); - std::string *pValue = new std::string( sValue ); - - hProperties.insert( pName->c_str(), pValue->c_str() ); - lPropNames.append( pName ); - lPropValues.append( pValue ); + hProperties.insert( sName, sValue ); } int XmlNode::getNumProperties() { - return lPropNames.getSize(); + return hProperties.size(); } - +/* const char *XmlNode::getPropertyName( int nIndex ) { std::string *tmp = ((std::string *)lPropNames[nIndex]); @@ -172,15 +129,12 @@ const char *XmlNode::getProperty( int nIndex ) return NULL; return tmp->c_str(); } - -const char *XmlNode::getProperty( const char *sName ) +*/ +Bu::FString XmlNode::getProperty( const Bu::FString &sName ) { - const char *tmp = (const char *)hProperties[sName]; - if( tmp == NULL ) - return NULL; - return tmp; + return hProperties[sName]; } - +/* void XmlNode::deleteProperty( int nIndex ) { hProperties.del( ((std::string *)lPropNames[nIndex])->c_str() ); @@ -194,29 +148,33 @@ void XmlNode::deleteProperty( int nIndex ) bool XmlNode::hasChildren() { - return lChildren.getSize()>0; -} + return hChildren.getSize()>0; +}*/ int XmlNode::getNumChildren() { return lChildren.getSize(); } - +/* XmlNode *XmlNode::getChild( int nIndex ) { return (XmlNode *)lChildren[nIndex]; } - -XmlNode *XmlNode::getChild( const char *sName, int nSkip ) +*/ +XmlNode *XmlNode::getChild( const Bu::FString &sName, int nSkip ) { - return (XmlNode *)hChildren.get( sName, nSkip ); + if( !hChildren.has( sName ) ) + return NULL; + + Bu::List::iterator i = hChildren[sName]->begin(); + return *i; } -const char *XmlNode::getName() +Bu::FString XmlNode::getName() { - return sName.c_str(); + return sName; } - +/* void XmlNode::deleteNode( int nIndex, const char *sReplacementText ) { XmlNode *xRet = detatchNode( nIndex, sReplacementText ); @@ -442,4 +400,4 @@ void XmlNode::deleteNodeKeepChildren( int nIndex ) void XmlNode::replaceNodeWithChildren( int nIndex, XmlNode *pNewNode ) { } - +*/ diff --git a/src/xmlnode.h b/src/xmlnode.h index 7525306..c895cd8 100644 --- a/src/xmlnode.h +++ b/src/xmlnode.h @@ -2,8 +2,9 @@ #define XMLNODE #include -#include "linkedlist.h" -#include "hashtable.h" +#include "bu/list.h" +#include "bu/hash.h" +#include "bu/fstring.h" /** * Maintains all data pertient to an XML node, including sub-nodes and content. @@ -25,9 +26,8 @@ public: *@param sContent The initial content string. */ XmlNode( - const char *sName=NULL, - XmlNode *pParent = NULL, - const char *sContent=NULL + const Bu::FString &sName, + XmlNode *pParent=NULL ); /** @@ -39,7 +39,7 @@ public: * Change the name of the node. *@param sName The new name of the node. */ - void setName( const char *sName ); + //void setName( const char *sName ); /** * Construct a new node and add it as a child to this node, also return a @@ -48,7 +48,7 @@ public: *@param sContent The initial content of the new node. *@returns A pointer to the newly created child node. */ - XmlNode *addChild( const char *sName, const char *sContent=NULL ); + XmlNode *addChild( const Bu::FString &sName ); /** * Add an already created XmlNode as a child to this node. The new child @@ -65,7 +65,7 @@ public: * in use will overwrite that property. *@param sValue The textual value of the property. */ - void addProperty( const char *sName, const char *sValue ); + void addProperty( const Bu::FString &sName, const Bu::FString &sValue ); /** * Get a pointer to the parent node, if any. @@ -85,14 +85,6 @@ public: */ int getNumChildren(); - /** - * Get a child node at a specific index. - *@param nIndex The zero-based index of the child to retreive. - *@returns A pointer to the child, or NULL if you requested an invalid - * index. - */ - XmlNode *getChild( int nIndex ); - /** * Get a child with the specified name, and possibly skip value. For an * explination of skip values see the HashTable. @@ -101,14 +93,14 @@ public: *@returns A pointer to the child, or NULL if no child with that name was * found. */ - XmlNode *getChild( const char *sName, int nSkip=0 ); + XmlNode *getChild( const Bu::FString &sName, int nSkip=0 ); /** * Get a pointer to the name of this node. Do not change this, use setName * instead. *@returns A pointer to the name of this node. */ - const char *getName(); + Bu::FString getName(); /** * Set the content of this node, optionally at a specific index. Using the @@ -116,14 +108,7 @@ public: *@param sContent The content string to use. *@param nIndex The index of the content. */ - void setContent( const char *sContent, int nIndex=-1 ); - - /** - * Get the content string at a given index, or zero for initial content. - *@param nIndex The index of the content. - *@returns A pointer to the content at that location. - */ - const char *getContent( int nIndex = 0 ); + //void setContent( const char *sContent, int nIndex=-1 ); /** * Get the number of properties in this node. @@ -131,37 +116,13 @@ public: */ int getNumProperties(); - /** - * Get a property's name by index. - *@param nIndex The index of the property to examine. - *@returns A pointer to the name of the property specified, or NULL if none - * found. - */ - const char *getPropertyName( int nIndex ); - - /** - * Get a proprty's value by index. - *@param nIndex The index of the property to examine. - *@returns A pointer to the value of the property specified, or NULL if none - * found. - */ - const char *getProperty( int nIndex ); - /** * Get a propery's value by name. *@param sName The name of the property to examine. *@returns A pointer to the value of the property specified, or NULL if none * found. */ - const char *getProperty( const char *sName ); - - /** - * Delete a property by index. - *@param nIndex The index of the property to delete. - *@returns True if the property was found and deleted, false if it wasn't - * found. - */ - void deleteProperty( int nIndex ); + Bu::FString getProperty( const Bu::FString &sName ); /** * Delete a child node, possibly replacing it with some text. This actually @@ -171,7 +132,7 @@ public: *@returns True of the node was found, and deleted, false if it wasn't * found. */ - void deleteNode( int nIndex, const char *sReplacementText = NULL ); + //void deleteNode( int nIndex, const char *sReplacementText = NULL ); /** * Delete a given node, but move all of it's children and content up to @@ -180,7 +141,7 @@ public: *@param nIndex The node to delete. *@returns True if the node was found and deleted, false if it wasn't. */ - void deleteNodeKeepChildren( int nIndex ); + //void deleteNodeKeepChildren( int nIndex ); /** * Detatch a given child node from this node. This effectively works just @@ -192,7 +153,7 @@ public: *@returns A pointer to the newly detatched node, which then passes * ownership to the caller. */ - XmlNode *detatchNode( int nIndex, const char *sReplacementText = NULL ); + //XmlNode *detatchNode( int nIndex, const char *sReplacementText = NULL ); /** * Replace a given node with a different node that is not currently owned by @@ -201,7 +162,7 @@ public: *@param pNewNode The new node to replace the old node with. *@returns True if the node was found and replaced, false if it wasn't. */ - void replaceNode( int nIndex, XmlNode *pNewNode ); + //void replaceNode( int nIndex, XmlNode *pNewNode ); /** * Replace a given node with the children and content of a given node. @@ -210,24 +171,34 @@ public: * replace the node specified by nIndex. *@returns True if the node was found and replaced, false if it wasn't. */ - void replaceNodeWithChildren( int nIndex, XmlNode *pNewNode ); + //void replaceNodeWithChildren( int nIndex, XmlNode *pNewNode ); /** * Get a copy of this node and all children. getCopy is recursive, so * beware copying large trees of xml. *@returns A newly created copy of this node and all of it's children. */ - XmlNode *getCopy(); + //XmlNode *getCopy(); + + enum ChildType + { + typeNode, + typeContent + }; private: - std::string sName; /**< The name of the node. */ - std::string *sPreContent; /**< The content that goes before any node. */ - LinkedList lChildren; /**< The children. */ - LinkedList lPostContent; /**< The content that comes after children. */ - HashTable hProperties; /**< Property hashtable. */ - HashTable hChildren; /**< Children hashtable. */ - LinkedList lPropNames; /**< List of property names. */ - LinkedList lPropValues; /**< List of property values. */ + typedef struct + { + uint8_t nType; + union { + XmlNode *pNode; + Bu::FString *pContent; + }; + } Child; + Bu::FString sName; /**< The name of the node. */ + Bu::List lChildren; /**< The children. */ + Bu::Hash hProperties; /**< Property hashtable. */ + Bu::Hash > hChildren; /**< Children hashtable. */ XmlNode *pParent; /**< A pointer to the parent of this node. */ int nCurContent; /**< The current content we're on, for using the -1 on setContent. */ diff --git a/src/xmlreader.cpp b/src/xmlreader.cpp index 18df69c..38cad5f 100644 --- a/src/xmlreader.cpp +++ b/src/xmlreader.cpp @@ -1,32 +1,49 @@ -#include "xmlreader.h" -#include "exceptions.h" +#include "bu/xmlreader.h" +#include "bu/exceptions.h" #include -#include "hashfunctionstring.h" -XmlReader::XmlReader( bool bStrip ) : - bStrip( bStrip ), - htEntity( new HashFunctionString(), 11 ) +XmlReader::XmlReader( Bu::Stream &sIn, bool bStrip ) : + sIn( sIn ), + bStrip( bStrip ) { + buildDoc(); } XmlReader::~XmlReader() { - void *i = htEntity.getFirstItemPos(); - while( (i = htEntity.getNextItemPos( i ) ) ) +} + +char XmlReader::getChar( int nIndex ) +{ + if( sBuf.getSize() <= nIndex ) { - free( (char *)(htEntity.getItemID( i )) ); - delete (StaticString *)htEntity.getItemData( i ); + int nInc = nIndex-sBuf.getSize()+1; + char *buf = new char[nInc]; + sIn.read( buf, nInc ); + sBuf.append( buf, nInc ); + delete[] buf; } + + return sBuf[nIndex]; } -void XmlReader::addEntity( const char *name, const char *value ) +void XmlReader::usedChar( int nAmnt ) { - if( htEntity[name] ) return; - - char *sName = strdup( name ); - StaticString *sValue = new StaticString( value ); + if( nAmnt >= sBuf.getSize() ) + { + sBuf.clear(); + } + else + { + char *s = sBuf.getStr(); + memcpy( s, s+nAmnt, sBuf.getSize()-nAmnt ); + sBuf.resize( sBuf.getSize()-nAmnt ); + } +} - htEntity.insert( sName, sValue ); +void XmlReader::addEntity( const Bu::FString &name, const Bu::FString &value ) +{ + htEntity[name] = value; } #define gcall( x ) if( x == false ) return false; @@ -99,7 +116,7 @@ void XmlReader::entity() { usedChar( 2 ); ws(); - std::string buf; + Bu::FString buf; for(;;) { char chr = getChar(); @@ -111,7 +128,7 @@ void XmlReader::entity() if( strcmp( buf.c_str(), "ENTITY") == 0 ) { ws(); - std::string name; + Bu::FString name; for(;;) { char chr = getChar(); @@ -124,21 +141,19 @@ void XmlReader::entity() usedChar(); if( quot != '\'' && quot != '\"' ) { - throw XmlException( + throw Bu::XmlException( "Only quoted entity values are supported." ); } - std::string value; + Bu::FString value; for(;;) { char chr = getChar(); usedChar(); if( chr == '&' ) { - StaticString *tmp = getEscape(); - if( tmp == NULL ) throw XmlException("Entity thing"); - value += tmp->getString(); - delete tmp; + Bu::FString tmp = getEscape(); + value += tmp; } else if( chr == quot ) { @@ -158,7 +173,7 @@ void XmlReader::entity() } else { - throw XmlException( + throw Bu::XmlException( "Malformed ENTITY: unexpected '%c' found.", getChar() ); @@ -166,7 +181,7 @@ void XmlReader::entity() } else { - throw XmlException( + throw Bu::XmlException( "Unsupported header symbol: %s", buf.c_str() ); @@ -203,12 +218,12 @@ bool XmlReader::node() } else { - throw XmlException("Close node in singleNode malformed!"); + throw Bu::XmlException("Close node in singleNode malformed!"); } } else { - throw XmlException("Close node expected, but not found."); + throw Bu::XmlException("Close node expected, but not found."); return false; } @@ -224,7 +239,7 @@ bool XmlReader::startNode() if( getChar() == '/' ) { // Heh, it's actually a close node, go figure - FlexBuf fbName; + Bu::FString sName; usedChar(); gcall( ws() ); @@ -235,19 +250,19 @@ bool XmlReader::startNode() { // Here we actually compare the name we got to the name // we already set, they have to match exactly. - if( !strcasecmp( getCurrent()->getName(), fbName.getData() ) ) + if( getCurrent()->getName() == sName ) { closeNode(); break; } else { - throw XmlException("Got a mismatched node close tag."); + throw Bu::XmlException("Got a mismatched node close tag."); } } else { - fbName.appendData( chr ); + sName += chr; usedChar(); } } @@ -260,13 +275,13 @@ bool XmlReader::startNode() } else { - throw XmlException("Got extra junk data instead of node close tag."); + throw Bu::XmlException("Got extra junk data instead of node close tag."); } } else { // We're good, format is consistant - addNode(); + //addNode(); // Skip extra whitespace gcall( ws() ); @@ -278,7 +293,7 @@ bool XmlReader::startNode() } else { - throw XmlException("Expected to find node opening char, '<'."); + throw Bu::XmlException("Expected to find node opening char, '<'."); } return true; @@ -286,19 +301,19 @@ bool XmlReader::startNode() bool XmlReader::name() { - FlexBuf fbName; + Bu::FString sName; while( true ) { char chr = getChar(); if( isws( chr ) || chr == '>' || chr == '/' ) { - setName( fbName.getData() ); + addNode( sName ); return true; } else { - fbName.appendData( chr ); + sName += chr; usedChar(); } } @@ -325,7 +340,7 @@ bool XmlReader::paramlist() return true; } -StaticString *XmlReader::getEscape() +Bu::FString XmlReader::getEscape() { if( getChar( 1 ) == '#' ) { @@ -349,12 +364,12 @@ StaticString *XmlReader::getEscape() buf[0] = (char)strtol( buf, (char **)NULL, base ); buf[1] = '\0'; - return new StaticString( buf ); + return buf; } else { // ...otherwise replace with the appropriate string... - std::string buf; + Bu::FString buf; usedChar(); for(;;) { @@ -364,18 +379,14 @@ StaticString *XmlReader::getEscape() buf += cbuf; } - StaticString *tmp = (StaticString *)htEntity[buf.c_str()]; - if( tmp == NULL ) return NULL; - - StaticString *ret = new StaticString( *tmp ); - return ret; + return htEntity[buf]; } } bool XmlReader::param() { - FlexBuf fbName; - FlexBuf fbValue; + Bu::FString sName; + Bu::FString sValue; while( true ) { @@ -386,7 +397,7 @@ bool XmlReader::param() } else { - fbName.appendData( chr ); + sName.append( chr ); usedChar(); } } @@ -411,21 +422,18 @@ bool XmlReader::param() if( chr == '"' ) { usedChar(); - addProperty( fbName.getData(), fbValue.getData() ); + addProperty( sName.getStr(), sValue.getStr() ); return true; } else { if( chr == '&' ) { - StaticString *tmp = getEscape(); - if( tmp == NULL ) return false; - fbValue.appendData( tmp->getString() ); - delete tmp; + sValue += getEscape(); } else { - fbValue.appendData( chr ); + sValue += chr; usedChar(); } } @@ -439,21 +447,18 @@ bool XmlReader::param() chr = getChar(); if( isws( chr ) || chr == '/' || chr == '>' ) { - addProperty( fbName.getData(), fbValue.getData() ); + addProperty( sName.getStr(), sValue.getStr() ); return true; } else { if( chr == '&' ) { - StaticString *tmp = getEscape(); - if( tmp == NULL ) return false; - fbValue.appendData( tmp->getString() ); - delete tmp; + sValue += getEscape(); } else { - fbValue.appendData( chr ); + sValue += chr; usedChar(); } } @@ -462,7 +467,7 @@ bool XmlReader::param() } else { - throw XmlException("Expected an equals to seperate the params."); + throw Bu::XmlException("Expected an equals to seperate the params."); return false; } @@ -471,7 +476,7 @@ bool XmlReader::param() bool XmlReader::content() { - FlexBuf fbContent; + Bu::FString sContent; if( bStrip ) gcall( ws() ); @@ -482,37 +487,37 @@ bool XmlReader::content() { if( getChar(1) == '/' ) { - if( fbContent.getLength() > 0 ) + if( sContent.getSize() > 0 ) { if( bStrip ) { int j; - for( j = fbContent.getLength()-1; isws(fbContent.getData()[j]); j-- ); - ((char *)fbContent.getData())[j+1] = '\0'; + for( j = sContent.getSize()-1; isws(sContent[j]); j-- ); + sContent[j+1] = '\0'; } - setContent( fbContent.getData() ); + setContent( sContent.getStr() ); } usedChar( 2 ); gcall( ws() ); - FlexBuf fbName; + Bu::FString sName; while( true ) { chr = getChar(); if( isws( chr ) || chr == '>' ) { - if( !strcasecmp( getCurrent()->getName(), fbName.getData() ) ) + if( !strcasecmp( getCurrent()->getName().getStr(), sName.getStr() ) ) { closeNode(); break; } else { - throw XmlException("Mismatched close tag found: <%s> to <%s>.", getCurrent()->getName(), fbName.getData() ); + throw Bu::XmlException("Mismatched close tag found: <%s> to <%s>.", getCurrent()->getName().getStr(), sName.getStr() ); } } else { - fbName.appendData( chr ); + sName += chr; usedChar(); } } @@ -524,7 +529,7 @@ bool XmlReader::content() } else { - throw XmlException("Malformed close tag."); + throw Bu::XmlException("Malformed close tag."); } } else if( getChar(1) == '!' ) @@ -534,7 +539,7 @@ bool XmlReader::content() getChar(3) != '-' ) { // Not a valid XML comment - throw XmlException("Malformed comment start tag found."); + throw Bu::XmlException("Malformed comment start tag found."); } usedChar( 4 ); @@ -549,7 +554,7 @@ bool XmlReader::content() // The next one has to be a '>' now if( getChar( 2 ) != '>' ) { - throw XmlException("Malformed comment close tag found. You cannot have a '--' that isn't followed by a '>' in a comment."); + throw Bu::XmlException("Malformed comment close tag found. You cannot have a '--' that isn't followed by a '>' in a comment."); } usedChar( 3 ); break; @@ -569,16 +574,16 @@ bool XmlReader::content() } else { - if( fbContent.getLength() > 0 ) + if( sContent.getSize() > 0 ) { if( bStrip ) { int j; - for( j = fbContent.getLength()-1; isws(fbContent.getData()[j]); j-- ); - ((char *)fbContent.getData())[j+1] = '\0'; + for( j = sContent.getSize()-1; isws(sContent[j]); j-- ); + sContent[j+1] = '\0'; } - setContent( fbContent.getData() ); - fbContent.clearData(); + setContent( sContent.getStr() ); + sContent.clear(); } gcall( node() ); } @@ -587,14 +592,11 @@ bool XmlReader::content() } else if( chr == '&' ) { - StaticString *tmp = getEscape(); - if( tmp == NULL ) return false; - fbContent.appendData( tmp->getString() ); - delete tmp; + sContent += getEscape(); } else { - fbContent.appendData( chr ); + sContent += chr; usedChar(); } } diff --git a/src/xmlreader.h b/src/xmlreader.h index c8f7202..7c85ddb 100644 --- a/src/xmlreader.h +++ b/src/xmlreader.h @@ -2,10 +2,10 @@ #define XMLREADER #include -#include "xmldocument.h" -#include "flexbuf.h" -#include "hashtable.h" -#include "staticstring.h" +#include "bu/xmldocument.h" +#include "bu/hash.h" +#include "bu/fstring.h" +#include "bu/stream.h" /** * Takes care of reading in xml formatted data from a file. This could/should @@ -32,7 +32,7 @@ public: * in content, a-la html. *@param bStrip Strip out leading and trailing whitespace? */ - XmlReader( bool bStrip=false ); + XmlReader( Bu::Stream &sIn, bool bStrip=false ); /** * Destroy this XmlReader. @@ -54,12 +54,12 @@ private: *@returns A single character at the requested position, or 0 for end of * stream. */ - virtual char getChar( int nIndex = 0 ) = 0; + virtual char getChar( int nIndex = 0 ); /** * Called to increment the current stream position by a single character. */ - virtual void usedChar( int nAmnt = 1) = 0; + virtual void usedChar( int nAmnt = 1 ); /** * Automoton function: is whitespace. @@ -108,9 +108,9 @@ private: *@param name The name of the entity *@param value The value of the entity */ - void addEntity( const char *name, const char *value ); + void addEntity( const Bu::FString &name, const Bu::FString &value ); - StaticString *getEscape(); + Bu::FString getEscape(); /** * Automoton function: paramlist. Processes a list of node params. @@ -130,12 +130,15 @@ private: */ bool content(); - FlexBuf fbContent; /**< buffer for the current node's content. */ - FlexBuf fbParamName; /**< buffer for the current param's name. */ - FlexBuf fbParamValue; /**< buffer for the current param's value. */ - bool bStrip; /**< Are we stripping whitespace? */ + Bu::FString sContent; /**< buffer for the current node's content. */ + Bu::FString sParamName; /**< buffer for the current param's name. */ + Bu::FString sParamValue; /**< buffer for the current param's value. */ + Bu::Stream &sIn; + bool bStrip; /**< Are we stripping whitespace? */ - HashTable htEntity; /**< Entity type definitions. */ + Bu::Hash htEntity; /**< Entity type definitions. */ + + Bu::FString sBuf; }; #endif diff --git a/src/xmlwriter.cpp b/src/xmlwriter.cpp index 56880b6..7dc6ca9 100644 --- a/src/xmlwriter.cpp +++ b/src/xmlwriter.cpp @@ -2,17 +2,10 @@ #include #include "xmlwriter.h" -XmlWriter::XmlWriter( const char *sIndent, XmlNode *pRoot ) : - XmlDocument( pRoot ) +XmlWriter::XmlWriter( const Bu::FString &sIndent, XmlNode *pRoot ) : + XmlDocument( pRoot ), + sIndent( sIndent ) { - if( sIndent == NULL ) - { - this->sIndent = ""; - } - else - { - this->sIndent = sIndent; - } } XmlWriter::~XmlWriter() @@ -24,7 +17,7 @@ void XmlWriter::write() write( getRoot(), sIndent.c_str() ); } -void XmlWriter::write( XmlNode *pRoot, const char *sIndent ) +void XmlWriter::write( XmlNode *pRoot, const Bu::FString &sIndent ) { writeNode( pRoot, 0, sIndent ); } @@ -39,7 +32,7 @@ void XmlWriter::closeNode() } } -void XmlWriter::writeIndent( int nIndent, const char *sIndent ) +void XmlWriter::writeIndent( int nIndent, const Bu::FString &sIndent ) { if( sIndent == NULL ) return; for( int j = 0; j < nIndent; j++ ) @@ -48,26 +41,27 @@ void XmlWriter::writeIndent( int nIndent, const char *sIndent ) } } -std::string XmlWriter::escape( std::string sIn ) +Bu::FString XmlWriter::escape( const Bu::FString &sIn ) { - std::string sOut; + Bu::FString sOut; - std::string::const_iterator i; - for( i = sIn.begin(); i != sIn.end(); i++ ) + int nMax = sIn.getSize(); + for( int j = 0; j < nMax; j++ ) { - if( ((*i >= ' ' && *i <= '9') || - (*i >= 'a' && *i <= 'z') || - (*i >= 'A' && *i <= 'Z') ) && - (*i != '\"' && *i != '\'' && *i != '&') + char c = sIn[j]; + if( ((c >= ' ' && c <= '9') || + (c >= 'a' && c <= 'z') || + (c >= 'A' && c <= 'Z') ) && + (c != '\"' && c != '\'' && c != '&') ) { - sOut += *i; + sOut += c; } else { sOut += "&#"; char buf[4]; - sprintf( buf, "%u", (unsigned char)*i ); + sprintf( buf, "%u", (unsigned char)c ); sOut += buf; sOut += ';'; } @@ -76,19 +70,19 @@ std::string XmlWriter::escape( std::string sIn ) return sOut; } -void XmlWriter::writeNodeProps( XmlNode *pNode, int nIndent, const char *sIndent ) +void XmlWriter::writeNodeProps( XmlNode *pNode, int nIndent, const Bu::FString &sIndent ) { for( int j = 0; j < pNode->getNumProperties(); j++ ) { writeString(" "); - writeString( pNode->getPropertyName( j ) ); + //writeString( pNode->getPropertyName( j ) ); writeString("=\""); - writeString( escape( pNode->getProperty( j ) ).c_str() ); + //writeString( escape( pNode->getProperty( j ) ).c_str() ); writeString("\""); } } -void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent ) +void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const Bu::FString &sIndent ) { if( pNode->hasChildren() ) { @@ -96,15 +90,15 @@ void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent ) writeString("<"); writeString( pNode->getName() ); writeNodeProps( pNode, nIndent, sIndent ); - if( sIndent ) + if( sIndent != "" ) writeString(">\n"); else writeString(">"); - +/* if( pNode->getContent( 0 ) ) { writeIndent( nIndent+1, sIndent ); - if( sIndent ) + if( sIndent != "" ) { writeString( pNode->getContent( 0 ) ); writeString("\n"); @@ -129,9 +123,9 @@ void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent ) writeString( pNode->getContent( j+1 ) ); } } - +*/ writeIndent( nIndent, sIndent ); - if( sIndent ) + if( sIndent != "" ) { writeString("getName() ); @@ -143,7 +137,7 @@ void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent ) writeString( pNode->getName() ); writeString(">"); } - } + }/* else if( pNode->getContent() ) { writeIndent( nIndent, sIndent ); @@ -157,14 +151,14 @@ void XmlWriter::writeNode( XmlNode *pNode, int nIndent, const char *sIndent ) writeString(">"); if( sIndent ) writeString("\n"); - } + }*/ else { writeIndent( nIndent, sIndent ); writeString("<"); writeString( pNode->getName() ); writeNodeProps( pNode, nIndent, sIndent ); - if( sIndent ) + if( sIndent != "" ) writeString("/>\n"); else writeString("/>"); diff --git a/src/xmlwriter.h b/src/xmlwriter.h index c48e810..7e3c876 100644 --- a/src/xmlwriter.h +++ b/src/xmlwriter.h @@ -31,7 +31,7 @@ public: * this to a tab or some spaces it will never effect the content of your * file. */ - XmlWriter( const char *sIndent=NULL, XmlNode *pRoot=NULL ); + XmlWriter( const Bu::FString &sIndent="", XmlNode *pRoot=NULL ); /** * Destroy the writer. @@ -49,16 +49,16 @@ public: void write(); private: - std::string sIndent; /**< The indent string */ + Bu::FString sIndent; /**< The indent string */ - std::string escape( std::string sIn ); + Bu::FString escape( const Bu::FString &sIn ); /** * Write the file. *@param pNode The root node *@param sIndent The indent text. */ - void write( XmlNode *pNode, const char *sIndent=NULL ); + void write( XmlNode *pNode, const Bu::FString &sIndent ); /** * Write a node in the file, including children. @@ -66,7 +66,7 @@ private: *@param nIndent The indent level (the number of times to include sIndent) *@param sIndent The indent text. */ - void writeNode( XmlNode *pNode, int nIndent, const char *sIndent ); + void writeNode( XmlNode *pNode, int nIndent, const Bu::FString &sIndent ); /** * Write the properties of a node. @@ -74,14 +74,14 @@ private: *@param nIndent The indent level of the containing node *@param sIndent The indent text. */ - void writeNodeProps( XmlNode *pNode, int nIndent, const char *sIndent ); + void writeNodeProps( XmlNode *pNode, int nIndent, const Bu::FString &sIndent ); /** * Called to write the actual indent. *@param nIndent The indent level. *@param sIndent The indent text. */ - void writeIndent( int nIndent, const char *sIndent ); + void writeIndent( int nIndent, const Bu::FString &sIndent ); /** * This is the function that must be overridden in order to use this class. @@ -90,7 +90,7 @@ private: * will break the XML formatting. *@param sString The string data to write to the output. */ - virtual void writeString( const char *sString ) = 0; + virtual void writeString( const Bu::FString &sString ) = 0; }; #endif -- cgit v1.2.3 From dda94f3b53e02e117e6eb5758afa1410e1664c9f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 15 May 2007 05:25:19 +0000 Subject: SPtr is now Bu::ified, and the List class now acts the way we think const lists should act, you can't change anything in there. I'm still debating changing the const_iterator to a constIterator, or something else that's more Bu::worthy. Heh, the namespaces are funny...ok...I'm really tired. --- src/list.h | 214 ++++++++++++++++++++++++++++++++++++++++++++++++----- src/old/sptr.cpp | 1 - src/old/sptr.h | 99 ------------------------- src/serversocket.h | 10 ++- src/sptr.cpp | 1 + src/sptr.h | 147 ++++++++++++++++++++++++++++++++++++ src/tests/list.cpp | 31 ++++++++ 7 files changed, 382 insertions(+), 121 deletions(-) delete mode 100644 src/old/sptr.cpp delete mode 100644 src/old/sptr.h create mode 100644 src/sptr.cpp create mode 100644 src/sptr.h (limited to 'src/list.h') diff --git a/src/list.h b/src/list.h index ec63496..4d16872 100644 --- a/src/list.h +++ b/src/list.h @@ -13,6 +13,15 @@ namespace Bu ListLink *pNext; ListLink *pPrev; }; + + /** + * Linked list template container. This class is similar to the stl list + * class except for a few minor changes. First, it doesn't mimic a stack or + * queue, use the Stack or Queue clasess for that. Second, when const, all + * members are only accessable const. Third, erasing a location does not + * invalidate the iterator, it simply points to the next valid location, or + * end() if there are no more. + */ template, typename linkalloc=std::allocator > > class List { @@ -23,15 +32,59 @@ namespace Bu public: List() : pFirst( NULL ), - pLast( NULL ) + pLast( NULL ), + nSize( 0 ) + { + } + + List( const MyType &src ) : + pFirst( NULL ), + pLast( NULL ), + nSize( 0 ) + { + for( Link *pCur = src.pFirst; pCur; pCur = pCur->pNext ) + { + append( *pCur->pValue ); + } + } + + ~List() + { + clear(); + } + + MyType &operator=( const MyType &src ) { + clear(); + for( Link *pCur = src.pFirst; pCur; pCur = pCur->pNext ) + { + append( *pCur->pValue ); + } + } + + void clear() + { + Link *pCur = pFirst; + for(;;) + { + if( pCur == NULL ) break; + va.destroy( pCur->pValue ); + va.deallocate( pCur->pValue, sizeof( value ) ); + Link *pTmp = pCur->pNext; + la.destroy( pCur ); + la.deallocate( pCur, sizeof( Link ) ); + pCur = pTmp; + } + pFirst = pLast = NULL; + nSize = 0; } - void append( value v ) + void append( const value &v ) { Link *pNew = la.allocate( sizeof( Link ) ); pNew->pValue = va.allocate( sizeof( value ) ); va.construct( pNew->pValue, v ); + nSize++; if( pFirst == NULL ) { // Empty list @@ -47,11 +100,12 @@ namespace Bu } } - void prepend( value v ) + void prepend( const value &v ) { Link *pNew = la.allocate( sizeof( Link ) ); pNew->pValue = va.allocate( sizeof( value ) ); va.construct( pNew->pValue, v ); + nSize++; if( pFirst == NULL ) { // Empty list @@ -83,22 +137,22 @@ namespace Bu } public: - bool operator==( const iterator &oth ) + bool operator==( const iterator &oth ) const { return ( pLink == oth.pLink ); } - bool operator==( const Link *pOth ) + bool operator==( const Link *pOth ) const { return ( pLink == pOth ); } - bool operator!=( const iterator &oth ) + bool operator!=( const iterator &oth ) const { return ( pLink != oth.pLink ); } - bool operator!=( const Link *pOth ) + bool operator!=( const Link *pOth ) const { return ( pLink != pOth ); } @@ -110,40 +164,128 @@ namespace Bu value *operator->() { - return pLink->pValue(); + return pLink->pValue; } - iterator operator++() + iterator &operator++() { if( pLink != NULL ) pLink = pLink->pNext; return *this; } - iterator operator--() + iterator &operator--() { if( pLink != NULL ) pLink = pLink->pPrev; return *this; } - iterator operator++( int ) + iterator &operator++( int ) { if( pLink != NULL ) pLink = pLink->pNext; return *this; } - iterator operator--( int ) + iterator &operator--( int ) { if( pLink != NULL ) pLink = pLink->pPrev; return *this; } - iterator operator=( const iterator &oth ) + iterator &operator=( const iterator &oth ) { pLink = oth.pLink; + return *this; + } + }; + + typedef struct const_iterator + { + friend class List; + private: + Link *pLink; + const_iterator() : + pLink( NULL ) + { + } + + const_iterator( Link *pLink ) : + pLink( pLink ) + { + } + + public: + bool operator==( const const_iterator &oth ) const + { + return ( pLink == oth.pLink ); + } + + bool operator==( const Link *pOth ) const + { + return ( pLink == pOth ); + } + + bool operator!=( const const_iterator &oth ) const + { + return ( pLink != oth.pLink ); + } + + bool operator!=( const Link *pOth ) const + { + return ( pLink != pOth ); + } + + const value &operator*() + { + return *(pLink->pValue); + } + + const value *operator->() + { + return pLink->pValue; + } + + const_iterator &operator++() + { + if( pLink != NULL ) + pLink = pLink->pNext; + return *this; + } + + const_iterator &operator--() + { + if( pLink != NULL ) + pLink = pLink->pPrev; + return *this; + } + + const_iterator &operator++( int ) + { + if( pLink != NULL ) + pLink = pLink->pNext; + return *this; + } + + const_iterator &operator--( int ) + { + if( pLink != NULL ) + pLink = pLink->pPrev; + return *this; + } + + const_iterator &operator=( const iterator &oth ) + { + pLink = oth.pLink; + return *this; + } + + const_iterator &operator=( const const_iterator &oth ) + { + pLink = oth.pLink; + return *this; } }; @@ -152,17 +294,50 @@ namespace Bu return iterator( pFirst ); } - const Link *end() + const const_iterator begin() const + { + return const_iterator( pFirst ); + } + + const Link *end() const { return NULL; } - int getSize() + void erase( iterator &i ) + { + Link *pCur = i.pLink; + Link *pPrev = pCur->pPrev; + if( pPrev == NULL ) + { + va.destroy( pCur->pValue ); + va.deallocate( pCur->pValue, sizeof( value ) ); + pFirst = pCur->pNext; + la.destroy( pCur ); + la.deallocate( pCur, sizeof( Link ) ); + if( pFirst == NULL ) + pLast = NULL; + nSize--; + i.pLink = pFirst; + } + else + { + va.destroy( pCur->pValue ); + va.deallocate( pCur->pValue, sizeof( value ) ); + Link *pTmp = pCur->pNext; + la.destroy( pCur ); + la.deallocate( pCur, sizeof( Link ) ); + pPrev->pNext = pTmp; + if( pTmp != NULL ) + pTmp->pPrev = pPrev; + nSize--; + i.pLink = pTmp; + } + } + + int getSize() const { - int j = 0; - for( Link *pCur = pFirst; pCur; pCur = pCur->pNext ) - j++; - return j; + return nSize; } private: @@ -170,6 +345,7 @@ namespace Bu Link *pLast; linkalloc la; valuealloc va; + int nSize; }; } diff --git a/src/old/sptr.cpp b/src/old/sptr.cpp deleted file mode 100644 index 7f5e894..0000000 --- a/src/old/sptr.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "sptr.h" diff --git a/src/old/sptr.h b/src/old/sptr.h deleted file mode 100644 index deae94d..0000000 --- a/src/old/sptr.h +++ /dev/null @@ -1,99 +0,0 @@ -#ifndef SPTR_H -#define SPTR_H - -#include -#include - -template -class SPtr -{ -public: - SPtr() : - pRefCnt( NULL ), - pData( NULL ) - { - } - - ~SPtr() - { - decCount(); - } - - SPtr( const SPtr &src ) : - pRefCnt( src.pRefCnt ), - pData( src.pData ) - { - if( pRefCnt ) - (*pRefCnt) += 1; - } - - SPtr( T *pSrc ) : - pRefCnt( NULL ), - pData( pSrc ) - { - pRefCnt = new int32_t; - (*pRefCnt) = 1; - } - - int32_t count() - { - return *pRefCnt; - } - - T *operator->() const - { - return pData; - } - - T *operator*() const - { - return pData; - } - - SPtr operator=( const SPtr &src ) - { - decCount(); - pRefCnt = src.pRefCnt; - pData = src.pData; - (*pRefCnt) += 1; - - return *this; - } - - bool operator==( const SPtr &src ) - { - return pData == src.pData; - } - - operator bool() - { - return pRefCnt != NULL; - } - - bool isSet() - { - return pRefCnt != NULL; - } - -private: - void decCount() - { - if( pRefCnt ) - { - (*pRefCnt) -= 1; - //printf("Decrementing ref-count to %d\n", *pRefCnt ); - if( (*pRefCnt) == 0 ) - { - delete pRefCnt; - delete pData; - pRefCnt = NULL; - pData = NULL; - } - } - } - - int32_t *pRefCnt; - T *pData; -}; - -#endif diff --git a/src/serversocket.h b/src/serversocket.h index 9a26e2d..f146d91 100644 --- a/src/serversocket.h +++ b/src/serversocket.h @@ -2,13 +2,19 @@ #define SERVER_SOCKET_H #include -#include "fstring.h" -#include "socket.h" +#include "bu/fstring.h" namespace Bu { /** + * A single tcp/ip server socket. When created the server socket will bind + * to the specified interface and port, and immediately begin listening for + * connections. When connections come in they are pooled by the networking + * drivers in the kernel until they are accepted, this means that failure + * to keep space in the connection pool will result in connection refusals. * + * Although the accept function returns an integral file descriptor, it is + * designed to be used with the Socket class. */ class ServerSocket { diff --git a/src/sptr.cpp b/src/sptr.cpp new file mode 100644 index 0000000..8ea7f8f --- /dev/null +++ b/src/sptr.cpp @@ -0,0 +1 @@ +#include "bu/sptr.h" diff --git a/src/sptr.h b/src/sptr.h new file mode 100644 index 0000000..faa8524 --- /dev/null +++ b/src/sptr.h @@ -0,0 +1,147 @@ +#ifndef SPTR_H +#define SPTR_H + +#include +#include + +namespace Bu +{ + template class SPtr; + template< typename Tb, typename Ta > SPtr SPtrCast( SPtr src ); + + template + class SPtr + { + template + friend SPtr SPtrCast( SPtr pt ); + public: + SPtr() : + pRefCnt( NULL ), + pData( NULL ) + { + } + + ~SPtr() + { + decCount(); + } + + SPtr( const SPtr &src ) : + pRefCnt( src.pRefCnt ), + pData( src.pData ) + { + if( pRefCnt ) + (*pRefCnt) += 1; + } + + SPtr( T *pSrc ) : + pRefCnt( NULL ), + pData( pSrc ) + { + if( pData ) + { + pRefCnt = new int32_t; + (*pRefCnt) = 1; + } + } + + int32_t count() const + { + return *pRefCnt; + } + + const T *operator->() const + { + return pData; + } + + const T &operator*() const + { + return *pData; + } + + T *operator->() + { + return pData; + } + + T &operator*() + { + return *pData; + } + + SPtr operator=( const SPtr &src ) + { + decCount(); + pRefCnt = src.pRefCnt; + pData = src.pData; + if( pRefCnt ) + (*pRefCnt) += 1; + + return *this; + } + + const SPtr operator=( const SPtr &src ) const + { + decCount(); + pRefCnt = src.pRefCnt; + pData = src.pData; + if( pRefCnt ) + (*pRefCnt) += 1; + + return *this; + } + + bool operator==( const SPtr &src ) const + { + return pData == src.pData; + } + + bool operator==( const T *src ) const + { + return pData == src; + } + + operator bool() const + { + return pRefCnt != NULL; + } + + bool isSet() const + { + return pRefCnt != NULL; + } + + private: + void decCount() const + { + if( pRefCnt ) + { + (*pRefCnt) -= 1; + //printf("Decrementing ref-count to %d\n", *pRefCnt ); + if( (*pRefCnt) == 0 ) + { + delete pRefCnt; + delete pData; + pRefCnt = NULL; + pData = NULL; + } + } + } + + mutable int32_t *pRefCnt; + mutable T *pData; + }; + + template< typename Tb, typename Ta > SPtr SPtrCast( SPtr src ) + { + SPtr ret; + ret.pRefCnt = src.pRefCnt; + ret.pData = dynamic_cast(src.pData); + if( ret.pRefCnt ) + (*(ret.pRefCnt)) += 1; + return ret; + } +} + +#endif diff --git a/src/tests/list.cpp b/src/tests/list.cpp index 34ab656..12807a5 100644 --- a/src/tests/list.cpp +++ b/src/tests/list.cpp @@ -1,4 +1,10 @@ #include "bu/list.h" +#include + +typedef struct Bob +{ + int nID; +} Bob; int main() { @@ -16,7 +22,32 @@ int main() { printf("%d ", *i ); } + printf("\n"); + for( Bu::List::iterator i = l.begin(); i != l.end(); i++ ) + { + l.erase( i ); + if( i != l.end() ) + printf("%d ", *i ); + } + + printf("\n\n"); + Bu::List lb; + for( int j = 0; j < 10; j++ ) + { + Bob b; + b.nID = j; + lb.append( b ); + } + + const Bu::List rb = lb; + + for( Bu::List::const_iterator i = rb.begin(); i != rb.end(); i++ ) + { + //i->nID += 2; + //(*i).nID = 4; + printf("%d ", i->nID ); + } printf("\n\n"); } -- cgit v1.2.3 From e0e7932a122614a0ff566fbfd8de5776de8b9f6d Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 17 May 2007 05:56:26 +0000 Subject: Lots of cool new stuff, the Server class actually works for everything except actually interacting with clients, and the Client class is almost there, except that it doesn't really do anything yet. --- src/client.cpp | 9 +++++++ src/client.h | 23 +++++++++++++++++ src/file.cpp | 10 +++++++ src/file.h | 3 +++ src/list.h | 5 ++++ src/old/singleton.h | 59 ------------------------------------------ src/server.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/server.h | 49 +++++++++++++++++++++++++++++++++++ src/serversocket.cpp | 5 ++++ src/serversocket.h | 3 ++- src/singleton.h | 62 ++++++++++++++++++++++++++++++++++++++++++++ src/socket.cpp | 9 +++++++ src/socket.h | 3 ++- src/stream.h | 3 +++ src/tests/hash.cpp | 24 +++++++++++++++++ 15 files changed, 279 insertions(+), 61 deletions(-) create mode 100644 src/client.cpp create mode 100644 src/client.h delete mode 100644 src/old/singleton.h create mode 100644 src/server.cpp create mode 100644 src/server.h create mode 100644 src/singleton.h create mode 100644 src/tests/hash.cpp (limited to 'src/list.h') diff --git a/src/client.cpp b/src/client.cpp new file mode 100644 index 0000000..a048ca3 --- /dev/null +++ b/src/client.cpp @@ -0,0 +1,9 @@ +#include "client.h" + +Bu::Client::Client() +{ +} + +Bu::Client::~Client() +{ +} diff --git a/src/client.h b/src/client.h new file mode 100644 index 0000000..27fbad4 --- /dev/null +++ b/src/client.h @@ -0,0 +1,23 @@ +#ifndef CLIENT_H +#define CLIENT_H + +#include +#include "bu/socket.h" + +namespace Bu +{ + /** + * + */ + class Client + { + public: + Client(); + virtual ~Client(); + + private: + + }; +} + +#endif diff --git a/src/file.cpp b/src/file.cpp index 5de5f6c..26986a5 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -98,3 +98,13 @@ bool Bu::File::canSeek() return true; } +bool Bu::File::isBlocking() +{ + return true; +} + +void Bu::File::setBlocking( bool bBlocking ) +{ + return; +} + diff --git a/src/file.h b/src/file.h index bbc620c..ee3fdb3 100644 --- a/src/file.h +++ b/src/file.h @@ -27,6 +27,9 @@ namespace Bu virtual bool canWrite(); virtual bool canSeek(); + virtual bool isBlocking(); + virtual void setBlocking( bool bBlocking=true ); + private: FILE *fh; diff --git a/src/list.h b/src/list.h index 4d16872..6081ea5 100644 --- a/src/list.h +++ b/src/list.h @@ -217,6 +217,11 @@ namespace Bu { } + const_iterator( const iterator &i ) : + pLink( i.pLink ) + { + } + public: bool operator==( const const_iterator &oth ) const { diff --git a/src/old/singleton.h b/src/old/singleton.h deleted file mode 100644 index 47adbd5..0000000 --- a/src/old/singleton.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef SINGLETON_H -#define SINGLETON_H - -#include - -/** - * Provides singleton functionality in a modular sort of way. Make this the - * base class of any other class and you immediately gain singleton - * functionality. Be sure to make your constructor and various functions use - * intellegent scoping. Cleanup and instantiation are performed automatically - * for you at first use and program exit. There are two things that you must - * do when using this template, first is to inherit from it with the name of - * your class filling in for T and then make this class a friend of your class. - *@code - * // Making the Single Singleton: - * class Single : public Singleton - * { - * friend class Singleton; - * protected: - * Single(); - * ... - * }; - @endcode - * You can still add public functions and variables to your new Singleton child - * class, but your constructor should be protected (hence the need for the - * friend decleration). - *@author Mike Buland - */ -template -class Singleton -{ -protected: - /** - * Private constructor. This constructor is empty but has a body so that - * you can make your own override of it. Be sure that you're override is - * also protected. - */ - Singleton() {}; - -private: - /** - * Copy constructor, defined so that you could write your own as well. - */ - Singleton( const Singleton& ); - -public: - /** - * Get a handle to the contained instance of the contained class. It is - * a reference. - *@returns A reference to the contained object. - */ - static T &getInstance() - { - static T i; - return i; - } -}; - -#endif diff --git a/src/server.cpp b/src/server.cpp new file mode 100644 index 0000000..f93238c --- /dev/null +++ b/src/server.cpp @@ -0,0 +1,73 @@ +#include "server.h" +#include + +Bu::Server::Server() : + nTimeoutSec( 0 ), + nTimeoutUSec( 0 ) +{ + FD_ZERO( &fdActive ); +} + +Bu::Server::~Server() +{ +} + +void Bu::Server::addPort( int nPort, int nPoolSize ) +{ + ServerSocket *s = new ServerSocket( nPort, nPoolSize ); + int nSocket = s->getSocket(); + FD_SET( nSocket, &fdActive ); + hServers.insert( nSocket, s ); +} + +void Bu::Server::addPort( const FString &sAddr, int nPort, int nPoolSize ) +{ + ServerSocket *s = new ServerSocket( sAddr, nPort, nPoolSize ); + int nSocket = s->getSocket(); + FD_SET( nSocket, &fdActive ); + hServers.insert( nSocket, s ); +} + +void Bu::Server::setTimeout( int nTimeoutSec, int nTimeoutUSec ) +{ + this->nTimeoutSec = nTimeoutSec; + this->nTimeoutUSec = nTimeoutUSec; +} + +void Bu::Server::scan() +{ + struct timeval xTimeout = { nTimeoutSec, nTimeoutUSec }; + + fd_set fdRead = fdActive; + fd_set fdWrite = fdActive; + fd_set fdException = fdActive; + + if( TEMP_FAILURE_RETRY( select( FD_SETSIZE, &fdRead, NULL, &fdException, &xTimeout ) ) < 0 ) + { + throw ExceptionBase("Error attempting to scan open connections."); + } + + for( int j = 0; j < FD_SETSIZE; j++ ) + { + if( FD_ISSET( j, &fdRead ) ) + { + if( hServers.has( j ) ) + { + addClient( hServers.get( j )->accept() ); + } + else + { + + } + } + } +} + +void Bu::Server::addClient( int nSocket ) +{ + FD_SET( nSocket, &fdActive ); + + Client *c = new Client(); + hClients.insert( nSocket, c ); +} + diff --git a/src/server.h b/src/server.h new file mode 100644 index 0000000..9f4f459 --- /dev/null +++ b/src/server.h @@ -0,0 +1,49 @@ +#ifndef SERVER_H +#define SERVER_H + +#include +#include "bu/serversocket.h" +#include "bu/list.h" +#include "bu/client.h" + +namespace Bu +{ + /** + * Core of a network server. This class is distinct from a ServerSocket in + * that a ServerSocket is one listening socket, nothing more. Socket will + * manage a pool of both ServerSockets and connected Sockets along with + * their protocols and buffers. + * + * To start serving on a new port, use the addPort functions. Each call to + * addPort creates a new ServerSocket, starts it listening, and adds it to + * the server pool. + * + * All of the real work is done by scan, which will wait for up + * to the timeout set by setTimeout before returning if there is no data + * pending. scan should probably be called in some sort of tight + * loop, possibly in it's own thread, or in the main control loop. + */ + class Server + { + public: + Server(); + virtual ~Server(); + + void addPort( int nPort, int nPoolSize=40 ); + void addPort( const FString &sAddr, int nPort, int nPoolSize=40 ); + + void scan(); + void setTimeout( int nTimeoutSec, int nTimeoutUSec=0 ); + + void addClient( int nSocket ); + + private: + int nTimeoutSec; + int nTimeoutUSec; + fd_set fdActive; + Hash hServers; + Hash hClients; + }; +} + +#endif diff --git a/src/serversocket.cpp b/src/serversocket.cpp index c53c80d..9c8f743 100644 --- a/src/serversocket.cpp +++ b/src/serversocket.cpp @@ -85,6 +85,11 @@ void Bu::ServerSocket::startServer( struct sockaddr_in &name, int nPoolSize ) FD_SET( nServer, &fdActive ); } +int Bu::ServerSocket::getSocket() +{ + return nServer; +} + int Bu::ServerSocket::accept( int nTimeoutSec, int nTimeoutUSec ) { fd_set fdRead = fdActive; diff --git a/src/serversocket.h b/src/serversocket.h index f146d91..d2601e4 100644 --- a/src/serversocket.h +++ b/src/serversocket.h @@ -23,7 +23,8 @@ namespace Bu ServerSocket( const FString &sAddr, int nPort, int nPoolSize=40 ); virtual ~ServerSocket(); - int accept( int nTimeoutSec, int nTimeoutUSec ); + int accept( int nTimeoutSec=0, int nTimeoutUSec=0 ); + int getSocket(); private: void startServer( struct sockaddr_in &name, int nPoolSize ); diff --git a/src/singleton.h b/src/singleton.h new file mode 100644 index 0000000..4976a61 --- /dev/null +++ b/src/singleton.h @@ -0,0 +1,62 @@ +#ifndef SINGLETON_H +#define SINGLETON_H + +#include + +namespace Bu +{ + /** + * Provides singleton functionality in a modular sort of way. Make this the + * base class of any other class and you immediately gain singleton + * functionality. Be sure to make your constructor and various functions use + * intellegent scoping. Cleanup and instantiation are performed automatically + * for you at first use and program exit. There are two things that you must + * do when using this template, first is to inherit from it with the name of + * your class filling in for T and then make this class a friend of your class. + *@code + * // Making the Single Singleton: + * class Single : public Singleton + * { + * friend class Singleton; + * protected: + * Single(); + * ... + * }; + @endcode + * You can still add public functions and variables to your new Singleton child + * class, but your constructor should be protected (hence the need for the + * friend decleration). + *@author Mike Buland + */ + template + class Singleton + { + protected: + /** + * Private constructor. This constructor is empty but has a body so that + * you can make your own override of it. Be sure that you're override is + * also protected. + */ + Singleton() {}; + + private: + /** + * Copy constructor, defined so that you could write your own as well. + */ + Singleton( const Singleton& ); + + public: + /** + * Get a handle to the contained instance of the contained class. It is + * a reference. + *@returns A reference to the contained object. + */ + static T &getInstance() + { + static T i; + return i; + } + }; +} + +#endif diff --git a/src/socket.cpp b/src/socket.cpp index 455b5c8..441678a 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -231,3 +231,12 @@ bool Bu::Socket::canSeek() return false; } +bool Bu::Socket::isBlocking() +{ + return false; +} + +void Bu::Socket::setBlocking( bool bBlocking ) +{ +} + diff --git a/src/socket.h b/src/socket.h index 568cad6..e65eb74 100644 --- a/src/socket.h +++ b/src/socket.h @@ -33,7 +33,8 @@ namespace Bu virtual bool canWrite(); virtual bool canSeek(); - + virtual bool isBlocking(); + virtual void setBlocking( bool bBlocking=true ); private: int nSocket; diff --git a/src/stream.h b/src/stream.h index e640959..5f586e6 100644 --- a/src/stream.h +++ b/src/stream.h @@ -36,6 +36,9 @@ namespace Bu virtual bool canWrite() = 0; virtual bool canSeek() = 0; + virtual bool isBlocking() = 0; + virtual void setBlocking( bool bBlocking=true ) = 0; + private: }; diff --git a/src/tests/hash.cpp b/src/tests/hash.cpp new file mode 100644 index 0000000..73cfb27 --- /dev/null +++ b/src/tests/hash.cpp @@ -0,0 +1,24 @@ +#include "bu/hash.h" +#include "bu/sptr.h" + +typedef struct Bob +{ + int nID; +} Bob; + +int main() +{ + Bu::Hash > lb; + for( int j = 0; j < 10; j++ ) + { + Bob *b = new Bob; + b->nID = j; + lb.insert( j, b ); + } + + for( int j = 0; j < 10; j++ ) + { + printf("%d\n", lb[j].value()->nID ); + } +} + -- cgit v1.2.3 From 8c2c728ce5aa1c1941426d0f8e9ab27762ef6754 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 5 Jun 2007 18:46:01 +0000 Subject: Added a basic ringbuffer, it should be nice and quick, but may be bad to use with objects at the moment, still contemplating that one... --- src/list.h | 20 +++++----- src/ringbuffer.cpp | 2 + src/ringbuffer.h | 100 +++++++++++++++++++++++++++++++++++++++++++++++ src/tests/ringbuffer.cpp | 29 ++++++++++++++ 4 files changed, 141 insertions(+), 10 deletions(-) create mode 100644 src/ringbuffer.cpp create mode 100644 src/ringbuffer.h create mode 100644 src/tests/ringbuffer.cpp (limited to 'src/list.h') diff --git a/src/list.h b/src/list.h index 6081ea5..ea67f45 100644 --- a/src/list.h +++ b/src/list.h @@ -69,10 +69,10 @@ namespace Bu { if( pCur == NULL ) break; va.destroy( pCur->pValue ); - va.deallocate( pCur->pValue, sizeof( value ) ); + va.deallocate( pCur->pValue, 1 ); Link *pTmp = pCur->pNext; la.destroy( pCur ); - la.deallocate( pCur, sizeof( Link ) ); + la.deallocate( pCur, 1 ); pCur = pTmp; } pFirst = pLast = NULL; @@ -81,8 +81,8 @@ namespace Bu void append( const value &v ) { - Link *pNew = la.allocate( sizeof( Link ) ); - pNew->pValue = va.allocate( sizeof( value ) ); + Link *pNew = la.allocate( 1 ); + pNew->pValue = va.allocate( 1 ); va.construct( pNew->pValue, v ); nSize++; if( pFirst == NULL ) @@ -102,8 +102,8 @@ namespace Bu void prepend( const value &v ) { - Link *pNew = la.allocate( sizeof( Link ) ); - pNew->pValue = va.allocate( sizeof( value ) ); + Link *pNew = la.allocate( 1 ); + pNew->pValue = va.allocate( 1 ); va.construct( pNew->pValue, v ); nSize++; if( pFirst == NULL ) @@ -316,10 +316,10 @@ namespace Bu if( pPrev == NULL ) { va.destroy( pCur->pValue ); - va.deallocate( pCur->pValue, sizeof( value ) ); + va.deallocate( pCur->pValue, 1 ); pFirst = pCur->pNext; la.destroy( pCur ); - la.deallocate( pCur, sizeof( Link ) ); + la.deallocate( pCur, 1 ); if( pFirst == NULL ) pLast = NULL; nSize--; @@ -328,10 +328,10 @@ namespace Bu else { va.destroy( pCur->pValue ); - va.deallocate( pCur->pValue, sizeof( value ) ); + va.deallocate( pCur->pValue, 1 ); Link *pTmp = pCur->pNext; la.destroy( pCur ); - la.deallocate( pCur, sizeof( Link ) ); + la.deallocate( pCur, 1 ); pPrev->pNext = pTmp; if( pTmp != NULL ) pTmp->pPrev = pPrev; diff --git a/src/ringbuffer.cpp b/src/ringbuffer.cpp new file mode 100644 index 0000000..feb9bc7 --- /dev/null +++ b/src/ringbuffer.cpp @@ -0,0 +1,2 @@ +#include "bu/ringbuffer.h" + diff --git a/src/ringbuffer.h b/src/ringbuffer.h new file mode 100644 index 0000000..9480043 --- /dev/null +++ b/src/ringbuffer.h @@ -0,0 +1,100 @@ +#ifndef RING_BUFFER_H +#define RING_BUFFER_H + +#include +#include "bu/exceptionbase.h" + +namespace Bu +{ + template > + class RingBuffer + { + public: + RingBuffer( int nCapacity ) : + nCapacity( nCapacity ), + nStart( -1 ), + nEnd( -2 ) + { + aData = va.allocate( nCapacity ); + for( int j = 0; j < nCapacity; j++ ) + { + va.construct( &aData[j], value() ); + } + } + + virtual ~RingBuffer() + { + for( int j = 0; j < nCapacity; j++ ) + { + va.destroy( &aData[j] ); + } + va.deallocate( aData, nCapacity ); + } + + int getCapacity() + { + return nCapacity; + } + + bool isFilled() + { + return (nStart == nEnd); + } + + bool isEmpty() + { + return (nStart == -1); + } + + void enqueue( const value &v ) + { + if( nStart == -1 ) + { + nStart = 0; + nEnd = 1; + aData[0] = v; + } + else if( nStart == nEnd ) + { + throw ExceptionBase("Hey, it's full!"); + } + else + { + aData[nEnd] = v; + nEnd = (nEnd+1)%nCapacity; + } + } + + value dequeue() + { + if( nStart == -1 ) + { + throw ExceptionBase("No data"); + } + else + { + value &v = aData[nStart]; + nStart = (nStart+1)%nCapacity; + if( nStart == nEnd ) + { + nStart = -1; + nEnd = -2; + } + return v; + } + } + + value &operator[]( int nIndex ) + { + return aData[(nIndex+nStart)%nCapacity]; + } + + private: + int nCapacity; + value *aData; + valuealloc va; + int nStart, nEnd; + }; +} + +#endif diff --git a/src/tests/ringbuffer.cpp b/src/tests/ringbuffer.cpp new file mode 100644 index 0000000..259ec1f --- /dev/null +++ b/src/tests/ringbuffer.cpp @@ -0,0 +1,29 @@ +#include "bu/ringbuffer.h" +#include + +int main() +{ + Bu::RingBuffer ibuf( 10 ); + + for( int k = 0; k < 2; k++ ) + { + int j = 1; + for(; j < 7; j++ ) + { + ibuf.enqueue( j ); + } + + for(; j < 20; j++ ) + { + ibuf.enqueue( j ); + printf("- %d\n", ibuf.dequeue() ); + } + + for(;;) + { + if( ibuf.isEmpty() ) break; + printf(". %d\n", ibuf.dequeue() ); + } + } +} + -- cgit v1.2.3 From 3c846af2fa8e4693c190c5131ec87d967eb58b3e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 6 Jun 2007 21:18:15 +0000 Subject: The TafReader is more general and much nicer, and about to actually construct nodes, that part will be exciting. I also fixed some stuff and added some new functions to List, it now has first() and last() which work just like std::list front() and back(), I may add compatibility functions later... --- src/entities/bu-class | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/list.h | 20 ++++++++++++++++++++ src/tafdocument.cpp | 9 --------- src/tafdocument.h | 22 ---------------------- src/tafnode.cpp | 16 ++++++++++++++++ src/tafnode.h | 17 ++++++++++++++++- src/tafreader.cpp | 47 ++++++++++++++++++++--------------------------- src/tafreader.h | 12 +++++++----- test.taf | 26 ++++++++++++++++++++++++++ 9 files changed, 151 insertions(+), 64 deletions(-) create mode 100644 src/entities/bu-class delete mode 100644 src/tafdocument.cpp delete mode 100644 src/tafdocument.h create mode 100644 test.taf (limited to 'src/list.h') diff --git a/src/entities/bu-class b/src/entities/bu-class new file mode 100644 index 0000000..81e3d25 --- /dev/null +++ b/src/entities/bu-class @@ -0,0 +1,46 @@ + + + + + #ifndef {=name:%uccsplit:%toupper}_H +#define {=name:%uccsplit:%toupper}_H + +#include <stdint.h> + +{?parent:"#include \"{=parent:%tolower}.h\" + +"}namespace Bu +{ + /** + * + */ + class {=name}{?parent:" : public {=parent}"} + { + public: + {=name}(); + virtual ~{=name}(); + + private: + + }; +} + +#endif + + #include "bu/{=name:%tolower}.h" + +Bu::{=name}::{=name}() +{ +} + +Bu::{=name}::~{=name}() +{ +} + + diff --git a/src/list.h b/src/list.h index ea67f45..4131987 100644 --- a/src/list.h +++ b/src/list.h @@ -344,6 +344,26 @@ namespace Bu { return nSize; } + + value &first() + { + return *pFirst->pValue; + } + + const value &first() const + { + return *pFirst->pValue; + } + + value &last() + { + return *pLast->pValue; + } + + const value &last() const + { + return *pLast->pValue; + } private: Link *pFirst; diff --git a/src/tafdocument.cpp b/src/tafdocument.cpp deleted file mode 100644 index bd44dd5..0000000 --- a/src/tafdocument.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "tafdocument.h" - -Bu::TafDocument::TafDocument() -{ -} - -Bu::TafDocument::~TafDocument() -{ -} diff --git a/src/tafdocument.h b/src/tafdocument.h deleted file mode 100644 index 171f829..0000000 --- a/src/tafdocument.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef BU_TAF_DOCUMENT_H -#define BU_TAF_DOCUMENT_H - -#include - -namespace Bu -{ - /** - * - */ - class TafDocument - { - public: - TafDocument(); - virtual ~TafDocument(); - - private: - - }; -} - -#endif diff --git a/src/tafnode.cpp b/src/tafnode.cpp index c9756ec..01880d9 100644 --- a/src/tafnode.cpp +++ b/src/tafnode.cpp @@ -7,3 +7,19 @@ Bu::TafNode::TafNode() Bu::TafNode::~TafNode() { } + +void Bu::TafNode::setProperty( Bu::FString sName, Bu::FString sValue ) +{ + if( hProp.has( sName ) ) + { + hProp.insert( sName, PropList() ); + } + + hProp.get( sName ).append( sValue ); +} + +const Bu::TafNode::PropList &Bu::TafNode::getProperty( const Bu::FString &sName ) +{ + return hProp.get( sName ); +} + diff --git a/src/tafnode.h b/src/tafnode.h index 34f5289..e962e88 100644 --- a/src/tafnode.h +++ b/src/tafnode.h @@ -2,6 +2,9 @@ #define BU_TAF_NODE_H #include +#include "bu/fstring.h" +#include "bu/hash.h" +#include "bu/list.h" namespace Bu { @@ -10,12 +13,24 @@ namespace Bu */ class TafNode { + public: + typedef Bu::List PropList; + typedef Bu::Hash PropHash; + typedef Bu::List NodeList; + typedef Bu::Hash NodeHash; + public: TafNode(); virtual ~TafNode(); - private: + void setProperty( Bu::FString sName, Bu::FString sValue ); + const PropList &getProperty( const Bu::FString &sName ); + private: + Bu::FString sName; + PropHash hProp; + NodeHash hChildren; }; } + #endif diff --git a/src/tafreader.cpp b/src/tafreader.cpp index 91aa9f2..3bca3d1 100644 --- a/src/tafreader.cpp +++ b/src/tafreader.cpp @@ -2,6 +2,8 @@ #include "bu/exceptions.h" #include "bu/fstring.h" +using namespace Bu; + Bu::TafReader::TafReader( Bu::Stream &sIn ) : sIn( sIn ) { @@ -13,22 +15,18 @@ Bu::TafReader::~TafReader() { } +Bu::TafNode *Bu::TafReader::readNode() +{ +} + void Bu::TafReader::node() { ws(); if( c != '{' ) - throw Bu::TafException("Expected '{'"); + throw TafException("Expected '{'"); next(); ws(); - Bu::FString sName; - for(;;) - { - if( c == ':' ) - break; - else - sName += c; - next(); - } + FString sName = readStr(); next(); printf("Node[%s]:\n", sName.getStr() ); @@ -56,15 +54,7 @@ void Bu::TafReader::nodeContent() void Bu::TafReader::nodeProperty() { - Bu::FString sName; - for(;;) - { - if( isws() || c == '=' ) - break; - else - sName += c; - next(); - } + FString sName = readStr(); ws(); if( c != '=' ) { @@ -72,8 +62,14 @@ void Bu::TafReader::nodeProperty() return; } next(); + FString sValue = readStr(); + printf(" %s = %s\n", sName.getStr(), sValue.getStr() ); +} + +Bu::FString Bu::TafReader::readStr() +{ ws(); - Bu::FString sValue; + FString s; if( c == '"' ) { next(); @@ -98,7 +94,7 @@ void Bu::TafReader::nodeProperty() } else if( c == '"' ) break; - sValue += c; + s += c; next(); } next(); @@ -107,17 +103,14 @@ void Bu::TafReader::nodeProperty() { for(;;) { - if( isws() || c == '}' || c == '{' ) + if( isws() || c == '}' || c == '{' || c == ':' || c == '=' ) break; - sValue += c; + s += c; next(); } } - printf(" %s = %s\n", sName.getStr(), sValue.getStr() ); -} -FString Bu::TafReader::readStr() -{ + return s; } void Bu::TafReader::ws() diff --git a/src/tafreader.h b/src/tafreader.h index 127b571..4da800c 100644 --- a/src/tafreader.h +++ b/src/tafreader.h @@ -2,20 +2,23 @@ #define BU_TAF_READER_H #include -#include "bu/tafdocument.h" +#include "bu/tafnode.h" #include "bu/stream.h" +#include "bu/fstring.h" namespace Bu { /** * */ - class TafReader : public Bu::TafDocument + class TafReader { public: TafReader( Bu::Stream &sIn ); virtual ~TafReader(); + Bu::TafNode *readNode(); + private: void node(); void nodeContent(); @@ -23,10 +26,9 @@ namespace Bu void ws(); bool isws(); void next(); - FString readStr(); + Bu::FString readStr(); char c; - Stream &sIn; - + Bu::Stream &sIn; }; } diff --git a/test.taf b/test.taf new file mode 100644 index 0000000..045b042 --- /dev/null +++ b/test.taf @@ -0,0 +1,26 @@ +{player: + password = "aoeuaoeuao" + userclass = "implementor" + species = "human" + sex = "male" + active + startroom = "Salourn::Xagafinelle's Room" + {stats: str=14 dex=12 spd=12 enr=7 rea=12 wil=10 int=13 cha=14} + {hp: cur = 100 max = 100} + {en: cur = 100 max = 100} + attackrate = 30 + gold = 0 + {inventory: + {: count=1 id="Salourn::Dark Blade"} + {: count=1 id="Salourn::Dark Suit"} + {: count=3 id="Salourn::Small Fig"} + } + {aliases: + {: key="." value="say"} + {: key="," value="yell"} + {: key="li" value="lightning"} + } + description = "They appear to be rather average looking, not particularly + tall or short, with facial features that are difficult to remember even + seconds after witnessing them." +} -- cgit v1.2.3 From 5292e5831934dc719d1ac06332bd252abe4ac3bc Mon Sep 17 00:00:00 2001 From: David Date: Mon, 18 Jun 2007 19:41:34 +0000 Subject: david - writing code documentation... --- src/fstring.h | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/hash.h | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/list.h | 15 ++++++ 3 files changed, 306 insertions(+) (limited to 'src/list.h') diff --git a/src/fstring.h b/src/fstring.h index 93a0042..9d88bd4 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -29,6 +29,11 @@ namespace Bu * almost no overhead in time or memory since a reference is created and no * data is actually copied. This also means that you never need to put any * FBasicString into a ref-counting container class. + * + *@param chr (typename) Type of character (i.e. char) + *@param nMinSize (int) Chunk size (default: 256) + *@param chralloc (typename) Memory Allocator for chr + *@param chunkalloc (typename) Memory Allocator for chr chunks */ template< typename chr, int nMinSize=256, typename chralloc=std::allocator, typename chunkalloc=std::allocator > > class FBasicString : public Archival @@ -113,6 +118,14 @@ namespace Bu clear(); } + /** + *@todo void append( const MyType & sData ) + */ + + /** + * Append data to your string. + *@param pData (const chr *) The data to append. + */ void append( const chr *pData ) { long nLen; @@ -126,6 +139,11 @@ namespace Bu appendChunk( pNew ); } + /** + * Append data to your string. + *@param pData (const chr *) The data to append. + *@param nLen (long) The length of the data to append. + */ void append( const chr *pData, long nLen ) { if( nLen == 0 ) @@ -138,16 +156,28 @@ namespace Bu appendChunk( pNew ); } + /** + * Append a single chr to your string. + *@param cData (const chr &) The character to append. + */ void append( const chr &cData ) { append( &cData, 1 ); } + /** + * Prepend another FString to this one. + *@param sData (MyType &) The FString to prepend. + */ void prepend( const MyType & sData ) { prepend( sData.getStr(), sData.getSize() ); } + /** + * Prepend data to your string. + *@param pData (const chr *) The data to prepend. + */ void prepend( const chr *pData ) { long nLen; @@ -159,6 +189,11 @@ namespace Bu prependChunk( pNew ); } + /** + * Prepend data to your string. + *@param pData (const chr *) The data to prepend. + *@param nLen (long) The length of the data to prepend. + */ void prepend( const chr *pData, long nLen ) { Chunk *pNew = newChunk( nLen ); @@ -168,11 +203,22 @@ namespace Bu prependChunk( pNew ); } + /** + *@todo void prepend( const chr &cData ) + */ + + /** + * Clear all data from the string. + */ void clear() { realClear(); } + /** + * Force the string to resize + *@param nNewSize (long) The new size of the string. + */ void resize( long nNewSize ) { if( nLength == nNewSize ) @@ -190,11 +236,19 @@ namespace Bu nLength = nNewSize; } + /** + * Get the current size of the string. + *@returns (long) The current size of the string. + */ long getSize() const { return nLength; } + /** + * Get a pointer to the string array. + *@returns (chr *) The string data. + */ chr *getStr() { if( pFirst == NULL ) @@ -204,6 +258,10 @@ namespace Bu return pFirst->pData; } + /** + * Get a const pointer to the string array. + *@returns (const chr *) The string data. + */ const chr *getStr() const { if( pFirst == NULL ) @@ -213,6 +271,10 @@ namespace Bu return pFirst->pData; } + /** + * (std::string compatability) Get a pointer to the string array. + *@returns (chr *) The string data. + */ chr *c_str() { if( pFirst == NULL ) @@ -222,6 +284,10 @@ namespace Bu return pFirst->pData; } + /** + * (std::string compatability) Get a const pointer to the string array. + *@returns (const chr *) The string data. + */ const chr *c_str() const { if( pFirst == NULL ) @@ -231,6 +297,10 @@ namespace Bu return pFirst->pData; } + /** + * Plus equals operator for FString. + *@param pData (const chr *) The data to append to your FString. + */ MyType &operator +=( const chr *pData ) { append( pData ); @@ -238,6 +308,10 @@ namespace Bu return (*this); } + /** + * Plus equals operator for FString. + *@param pData (const MyType &) The FString to append to your FString. + */ MyType &operator +=( const MyType &rSrc ) { if( rSrc.nLength == 0 ) @@ -248,6 +322,10 @@ namespace Bu return (*this); } + /** + * Plus equals operator for FString. + *@param pData (const chr) The character to append to your FString. + */ MyType &operator +=( const chr pData ) { append( &pData, 1 ); @@ -255,6 +333,11 @@ namespace Bu return (*this); } + /** + * Assignment operator. + *@param pData (const chr *) The character array to append to your + * FString. + */ MyType &operator =( const chr *pData ) { clear(); @@ -263,18 +346,31 @@ namespace Bu return (*this); } + /** + * Reset your FString to this character array. + *@param pData (const chr *) The character array to set your FString to. + */ void set( const chr *pData ) { clear(); append( pData ); } + /** + * Reset your FString to this character array. + *@param pData (const chr *) The character array to set your FString to. + *@param nSize (long) The length of the inputted character array. + */ void set( const chr *pData, long nSize ) { clear(); append( pData, nSize ); } + /** + * Assignment operator. + *@param rSrc (const MyType &) The FString to set your FString to. + */ MyType &operator =( const MyType &rSrc ) { //if( rSrc.isFlat() ) @@ -290,6 +386,11 @@ namespace Bu return (*this); } + /** + * Equals comparison operator. + *@param pData (const chr *) The character array to compare your FString + * to. + */ bool operator ==( const chr *pData ) const { if( pFirst == NULL ) { @@ -310,6 +411,10 @@ namespace Bu return true; } + /** + * Equals comparison operator. + *@param pData (const MyType &) The FString to compare your FString to. + */ bool operator ==( const MyType &pData ) const { if( pFirst == pData.pFirst ) @@ -330,16 +435,30 @@ namespace Bu return true; } + /** + * Not equals comparison operator. + *@param pData (const chr *) The character array to compare your FString + * to. + */ bool operator !=(const chr *pData ) const { return !(*this == pData); } + /** + * Not equals comparison operator. + *@param pData (const MyType &) The FString to compare your FString to. + */ bool operator !=(const MyType &pData ) const { return !(*this == pData); } + /** + * Indexing operator + *@param nIndex (long) The index of the character you want. + *@returns (chr &) The character at position (nIndex). + */ chr &operator[]( long nIndex ) { flatten(); @@ -347,6 +466,11 @@ namespace Bu return pFirst->pData[nIndex]; } + /** + * Const indexing operator + *@param nIndex (long) The index of the character you want. + *@returns (const chr &) The character at position (nIndex). + */ const chr &operator[]( long nIndex ) const { flatten(); @@ -354,6 +478,11 @@ namespace Bu return pFirst->pData[nIndex]; } + /** + * Is the character at index (nIndex) white space? + *@param nIndex (long) The index of the character you want to check. + *@returns (bool) Is it white space? + */ bool isWS( long nIndex ) const { flatten(); @@ -362,6 +491,11 @@ namespace Bu || pFirst->pData[nIndex]=='\r' || pFirst->pData[nIndex]=='\n'; } + /** + * Is the character at index (nIndex) a letter? + *@param nIndex (long) The index of the character you want to check. + *@returns (bool) Is it a letter? + */ bool isAlpha( long nIndex ) const { flatten(); @@ -370,6 +504,9 @@ namespace Bu || (pFirst->pData[nIndex] >= 'A' && pFirst->pData[nIndex] <= 'Z'); } + /** + * Convert your alpha characters to lower case. + */ void toLower() { flatten(); @@ -382,6 +519,9 @@ namespace Bu } } + /** + * Convert your alpha characters to upper case. + */ void toUpper() { flatten(); @@ -394,6 +534,11 @@ namespace Bu } } + /** + * Find the index of the first occurrance of (sText) + *@param sText (const char *) The string to search for. + *@returns (long) The index of the first occurrance. -1 for not found. + */ long find( const char *sText ) { long nTLen = strlen( sText ); @@ -406,6 +551,11 @@ namespace Bu return -1; } + /** + * Do a reverse search for (sText) + *@param sText (const char *) The string to search for. + *@returns (long) The index of the last occurrance. -1 for not found. + */ long rfind( const char *sText ) { long nTLen = strlen( sText ); @@ -418,6 +568,10 @@ namespace Bu return -1; } + /** + * Function the archiver calls to archive your FString. + *@param ar (Archive) The archive which is archiving your FString. + */ void archive( class Archive &ar ) { if( ar.isLoading() ) diff --git a/src/hash.h b/src/hash.h index 1bb25c9..6c4a443 100644 --- a/src/hash.h +++ b/src/hash.h @@ -71,6 +71,10 @@ namespace Bu bool bFilled; public: + /** + * Cast operator for HashProxy. + *@returns (value_type &) The value the HashProxy is pointing to. + */ operator _value &() { if( bFilled == false ) @@ -81,6 +85,10 @@ namespace Bu return *pValue; } + /** + * Direct function for retrieving a value out of the HashProxy. + *@returns (value_type &) The value pointed to by this HashProxy. + */ _value &value() { if( bFilled == false ) @@ -91,11 +99,17 @@ namespace Bu return *pValue; } + /** + * Whether this HashProxy points to something real or not. + */ bool isFilled() { return bFilled; } + /** + * Erase the data pointed to by this HashProxy. + */ void erase() { if( bFilled ) @@ -105,6 +119,10 @@ namespace Bu } } + /** + * Assign data to this point in the hash table. + *@param nval (value_type) the data to assign. + */ _value operator=( _value nval ) { if( bFilled ) @@ -122,6 +140,11 @@ namespace Bu return nval; } + /** + * Pointer extraction operator. Access to members of data pointed to + * by HashProxy. + *@returns (value_type *) + */ _value *operator->() { if( bFilled == false ) @@ -133,6 +156,15 @@ namespace Bu } }; + /** + * Libbu Template Hash Table + *@param key (typename) The datatype of the hashtable keys + *@param value (typename) The datatype of the hashtable data + *@param sizecalc (typename) Functor to compute new table size on rehash + *@param keyalloc (typename) Memory allocator for hashtable keys + *@param valuealloc (typename) Memory allocator for hashtable values + *@param challoc (typename) Byte allocator for bitflags + */ template class Hash { @@ -186,6 +218,10 @@ namespace Bu } } + /** + * Hashtable assignment operator. Clears this hashtable and + * copies RH into it. + */ Hash &operator=( const Hash &src ) { for( uint32_t j = 0; j < nCapacity; j++ ) @@ -244,26 +280,49 @@ namespace Bu ca.deallocate( aHashCodes, nCapacity ); } + /** + * Get the current hash table capacity. (Changes at re-hash) + *@returns (uint32_t) The current capacity. + */ uint32_t getCapacity() { return nCapacity; } + /** + * Get the number of hash locations spoken for. (Including + * not-yet-cleaned-up deleted items.) + *@returns (uint32_t) The current fill state. + */ uint32_t getFill() { return nFilled; } + /** + * Get the number of items stored in the hash table. + *@returns (uint32_t) The number of items stored in the hash table. + */ uint32_t size() { return nFilled-nDeleted; } + /** + * Get the number of items which have been deleted, but not yet + * cleaned up. + *@returns (uint32_t) The number of deleted items. + */ uint32_t getDeleted() { return nDeleted; } + /** + * Hash table index operator + *@param k (key_type) Key of data to be retrieved. + *@returns (HashProxy) Proxy pointing to the data. + */ virtual HashProxy operator[]( key k ) { uint32_t hash = __calcHashCode( k ); @@ -280,6 +339,11 @@ namespace Bu } } + /** + * Insert a value (v) under key (k) into the hash table + *@param k (key_type) Key to list the value under. + *@param v (value_type) Value to store in the hash table. + */ virtual void insert( key k, value v ) { uint32_t hash = __calcHashCode( k ); @@ -299,6 +363,10 @@ namespace Bu } } + /** + * Remove a value from the hash table. + *@param k (key_type) The data under this key will be erased. + */ virtual void erase( key k ) { uint32_t hash = __calcHashCode( k ); @@ -313,6 +381,11 @@ namespace Bu } struct iterator; + + /** + * Remove a value from the hash pointed to from an iterator. + *@param i (iterator &) The data to be erased. + */ virtual void erase( struct iterator &i ) { if( this != &i.hsh ) @@ -324,6 +397,9 @@ namespace Bu } } + /** + * Remove all data from the hash table. + */ virtual void clear() { for( uint32_t j = 0; j < nCapacity; j++ ) @@ -340,6 +416,11 @@ namespace Bu clearBits(); } + /** + * Get an item of data from the hash table. + *@param k (key_type) Key pointing to the data to be retrieved. + *@returns (value_type &) The data pointed to by (k). + */ virtual value &get( key k ) { uint32_t hash = __calcHashCode( k ); @@ -359,6 +440,12 @@ namespace Bu } } + /** + * Get a const item of data from the hash table. + *@param k (key_type) Key pointing to the data to be retrieved. + *@returns (const value_type &) A const version of the data pointed + * to by (k). + */ virtual const value &get( key k ) const { uint32_t hash = __calcHashCode( k ); @@ -378,6 +465,11 @@ namespace Bu } } + /** + * Does the hash table contain an item under key (k). + *@param k (key_type) The key to check. + *@returns (bool) Whether there was an item in the hash under key (k). + */ virtual bool has( key k ) { bool bFill; @@ -386,6 +478,9 @@ namespace Bu return bFill; } + /** + * Iteration structure for iterating through the hash. + */ typedef struct iterator { friend class Hash; @@ -410,6 +505,9 @@ namespace Bu bool bFinished; public: + /** + * Iterator incrementation operator. Move the iterator forward. + */ iterator operator++( int ) { if( bFinished == false ) @@ -418,6 +516,9 @@ namespace Bu return *this; } + /** + * Iterator incrementation operator. Move the iterator forward. + */ iterator operator++() { if( bFinished == false ) @@ -426,6 +527,9 @@ namespace Bu return *this; } + /** + * Iterator equality comparison operator. Iterators the same? + */ bool operator==( const iterator &oth ) { if( bFinished != oth.bFinished ) @@ -442,11 +546,17 @@ namespace Bu } } + /** + * Iterator not equality comparison operator. Not the same? + */ bool operator!=( const iterator &oth ) { return !(*this == oth ); } + /** + * Iterator assignment operator. + */ iterator operator=( const iterator &oth ) { if( &hsh != &oth.hsh ) @@ -456,32 +566,59 @@ namespace Bu bFinished = oth.bFinished; } + /** + * Iterator dereference operator... err.. get the value + *@returns (value_type &) The value behind this iterator. + */ value &operator *() { return hsh.getValueAtPos( nPos ); } + /** + * Get the key behind this iterator. + *@returns (key_type &) The key behind this iterator. + */ key &getKey() { return hsh.getKeyAtPos( nPos ); } + /** + * Get the value behind this iterator. + *@returs (value_type &) The value behind this iterator. + */ value &getValue() { return hsh.getValueAtPos( nPos ); } }; + /** + * Get an iterator pointing to the first item in the hash table. + *@returns (iterator) An iterator pointing to the first item in the + * hash table. + */ iterator begin() { return iterator( *this ); } + /** + * Get an iterator pointing to a point just past the last item in the + * hash table. + *@returns (iterator) An iterator pointing to a point just past the + * last item in the hash table. + */ iterator end() { return iterator( *this, true ); } + /** + * Get a list of all the keys in the hash table. + *@returns (std::list) The list of keys in the hash table. + */ std::list getKeys() { std::list lKeys; diff --git a/src/list.h b/src/list.h index 4131987..9d1f904 100644 --- a/src/list.h +++ b/src/list.h @@ -21,6 +21,10 @@ namespace Bu * members are only accessable const. Third, erasing a location does not * invalidate the iterator, it simply points to the next valid location, or * end() if there are no more. + * + *@param value (typename) The type of data to store in your list + *@param valuealloc (typename) Memory Allocator for your value type + *@param linkalloc (typename) Memory Allocator for the list links. */ template, typename linkalloc=std::allocator > > class List @@ -53,6 +57,10 @@ namespace Bu clear(); } + /** + * Assignment operator. + *@param src (const MyType &) The list to assign to your list. + */ MyType &operator=( const MyType &src ) { clear(); @@ -62,6 +70,9 @@ namespace Bu } } + /** + * Clear the data from the list. + */ void clear() { Link *pCur = pFirst; @@ -79,6 +90,10 @@ namespace Bu nSize = 0; } + /** + * Append a value to the list. + *@param v (const value_type &) The value to append. + */ void append( const value &v ) { Link *pNew = la.allocate( 1 ); -- cgit v1.2.3 From 6f94639a3f5e20e1c635b2d8676086464d7cba2e Mon Sep 17 00:00:00 2001 From: David Date: Mon, 18 Jun 2007 20:45:45 +0000 Subject: david - did more documenting --- src/file.h | 18 ++++++++++++ src/list.h | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/sptr.h | 45 +++++++++++++++++++++++++++++ src/stream.h | 58 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 213 insertions(+) (limited to 'src/list.h') diff --git a/src/file.h b/src/file.h index fe8dbda..1a4421b 100644 --- a/src/file.h +++ b/src/file.h @@ -39,6 +39,14 @@ namespace Bu virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); + /** + * Create a temp file and return its handle + *@param sName (Bu::FString) Give in the form: "/tmp/tmpfileXXXXXXXX" + * It will alter your (sName) setting the 'X's to random + * characters. + *@param sFlags (const char *) Standard file flags 'rb'... etc.. + *@returns (Bu::File) A file object representing your temp file. + */ inline static Bu::File tempFile( Bu::FString &sName, const char *sFlags ) { int afh_d = mkstemp( sName.getStr() ); @@ -46,7 +54,17 @@ namespace Bu return Bu::File( afh_d, sFlags ); } + /** + * Set the size of the file to (nSize). You can either grow or shrink + * the file. + *@param nSize (long) The new size of the file. + */ void truncate( long nSize ); + + /** + * Change the file access permissions. + *@param t (mode_t) The new file access permissions. + */ void chmod( mode_t t ); private: diff --git a/src/list.h b/src/list.h index 9d1f904..314459e 100644 --- a/src/list.h +++ b/src/list.h @@ -115,6 +115,10 @@ namespace Bu } } + /** + * Prepend a value to the list. + *@param v (const value_type &) The value to prepend. + */ void prepend( const value &v ) { Link *pNew = la.allocate( 1 ); @@ -136,6 +140,9 @@ namespace Bu } } + /** + * An iterator to iterate through your list. + */ typedef struct iterator { friend class List; @@ -152,36 +159,67 @@ namespace Bu } public: + /** + * Equals comparison operator. + *@param oth (const iterator &) The iterator to compare to. + *@returns (bool) Are they equal? + */ bool operator==( const iterator &oth ) const { return ( pLink == oth.pLink ); } + /** + * Equals comparison operator. + *@param pOth (const Link *) The link to compare to. + *@returns (bool) Are they equal? + */ bool operator==( const Link *pOth ) const { return ( pLink == pOth ); } + /** + * Not equals comparison operator. + *@param oth (const iterator &) The iterator to compare to. + *@returns (bool) Are they not equal? + */ bool operator!=( const iterator &oth ) const { return ( pLink != oth.pLink ); } + /** + * Not equals comparison operator. + *@param pOth (const Link *) The link to compare to. + *@returns (bool) Are they not equal? + */ bool operator!=( const Link *pOth ) const { return ( pLink != pOth ); } + /** + * Dereference operator. + *@returns (value_type &) The value. + */ value &operator*() { return *(pLink->pValue); } + /** + * Pointer access operator. + *@returns (value_type *) A pointer to the value. + */ value *operator->() { return pLink->pValue; } + /** + * Increment operator. + */ iterator &operator++() { if( pLink != NULL ) @@ -189,6 +227,9 @@ namespace Bu return *this; } + /** + * Decrement operator. + */ iterator &operator--() { if( pLink != NULL ) @@ -196,6 +237,9 @@ namespace Bu return *this; } + /** + * Increment operator. + */ iterator &operator++( int ) { if( pLink != NULL ) @@ -203,6 +247,9 @@ namespace Bu return *this; } + /** + * Decrement operator. + */ iterator &operator--( int ) { if( pLink != NULL ) @@ -210,6 +257,11 @@ namespace Bu return *this; } + /** + * Assignment operator. + *@param oth (const iterator &) The other iterator to set this + * one to. + */ iterator &operator=( const iterator &oth ) { pLink = oth.pLink; @@ -217,6 +269,9 @@ namespace Bu } }; + /** + *@see iterator + */ typedef struct const_iterator { friend class List; @@ -309,21 +364,38 @@ namespace Bu } }; + /** + * Get an iterator pointing to the first item in the list. + *@returns (iterator) + */ iterator begin() { return iterator( pFirst ); } + /** + * Get a const iterator pointing to the first item in the list. + *@returns (const const_iterator) + */ const const_iterator begin() const { return const_iterator( pFirst ); } + /** + * Get an iterator pointing to a place just past the last item in + * the list. + *@returns (const Link *) + */ const Link *end() const { return NULL; } + /** + * Erase an item from the list. + *@param i (iterator) The item to erase. + */ void erase( iterator &i ) { Link *pCur = i.pLink; @@ -355,26 +427,46 @@ namespace Bu } } + /** + * Get the current size of the list. + *@returns (int) The current size of the list. + */ int getSize() const { return nSize; } + /** + * Get the first item in the list. + *@returns (value_type &) The first item in the list. + */ value &first() { return *pFirst->pValue; } + /** + * Get the first item in the list. + *@returns (const value_type &) The first item in the list. + */ const value &first() const { return *pFirst->pValue; } + /** + * Get the last item in the list. + *@returns (value_type &) The last item in the list. + */ value &last() { return *pLast->pValue; } + /** + * Get the last item in the list. + *@returns (const value_type &) The last item in the list. + */ const value &last() const { return *pLast->pValue; diff --git a/src/sptr.h b/src/sptr.h index faa8524..4baa697 100644 --- a/src/sptr.h +++ b/src/sptr.h @@ -45,31 +45,55 @@ namespace Bu } } + /** + * Get the number of references to this pointer. + *@returns (int32_t) The number of references to this pointer. + */ int32_t count() const { return *pRefCnt; } + /** + * Pointer access operator. + *@returns (const T *) + */ const T *operator->() const { return pData; } + /** + * Dereference operator. + *@returns (const T &) The value at the end of the pointer. + */ const T &operator*() const { return *pData; } + /** + * Pointer access operator. + *@returns (T *) + */ T *operator->() { return pData; } + /** + * Dereference operator. + *@returns (T &) The value at the end of the pointer. + */ T &operator*() { return *pData; } + /** + * Assignment operator. + *@param src (const SPtr &) + */ SPtr operator=( const SPtr &src ) { decCount(); @@ -81,6 +105,10 @@ namespace Bu return *this; } + /** + * Assignment operator. + *@param src (const SPtr &) + */ const SPtr operator=( const SPtr &src ) const { decCount(); @@ -92,21 +120,38 @@ namespace Bu return *this; } + /** + * Equals comparison operator. + *@param src (const SPtr &) The SPtr to compare to. + *@returns (bool) Are the equal? + */ bool operator==( const SPtr &src ) const { return pData == src.pData; } + /** + * Equals comparison operator. + *@param src (const T *) The pointer to compare to. + *@returns (bool) Are the equal? + */ bool operator==( const T *src ) const { return pData == src; } + /** + * Boolean cast operator. Do we have a pointer? + */ operator bool() const { return pRefCnt != NULL; } + /** + * Do we have a pointer? + *@returns (bool) Do we have a pointer? + */ bool isSet() const { return pRefCnt != NULL; diff --git a/src/stream.h b/src/stream.h index ba070d3..056de0c 100644 --- a/src/stream.h +++ b/src/stream.h @@ -22,17 +22,66 @@ namespace Bu Stream(); virtual ~Stream(); + /** + * Close the stream. + */ virtual void close() = 0; + + /** + * Read data from the stream into a buffer. + *@param pBuf (void *) Buffer which will be filled. + *@param nBytes (size_t) Max data to read. + *@returns (size_t) Amount of data read. + */ virtual size_t read( void *pBuf, size_t nBytes ) = 0; + + /** + * Write data to the stream. + *@param pBuf (const void *) The data to be written. + *@param nBytes (size_t) Amount of data to write from pBuf. + *@returns (size_t) Amount of data actually written. + */ virtual size_t write( const void *pBuf, size_t nBytes ) = 0; + /** + * Get the current position in the stream. + *@returns (long) The current position in the stream. + */ virtual long tell() = 0; + + /** + * Seek to a position in the stream relative to the current position. + *@param offset (long) Offset from current position to seek to. + */ virtual void seek( long offset ) = 0; + + /** + * Set position in the stream relative to the start of the stream. + *@param pos (long) The position. + */ virtual void setPos( long pos ) = 0; + + /** + * Set position in the stream relative to the end of the stream. + *@param pos (long) The position. + */ virtual void setPosEnd( long pos ) = 0; + + /** + * Are we at the end of the stream? + *@returns (bool) Are we at the end of the stream? + */ virtual bool isEOS() = 0; + + /** + * Is the stream open? + *@returns (bool) Is the stream open? + */ virtual bool isOpen() = 0; + /** + * Flush any data still held in buffers. + */ virtual void flush() = 0; /** @@ -71,7 +120,16 @@ namespace Bu */ virtual bool isSeekable() = 0; + /** + * Are we currently set to block mode? + *@returns (bool) + */ virtual bool isBlocking() = 0; + + /** + * Set stream to blocking or non-blocking mode. + *@param bBlocking (bool) Whether we should block or not. + */ virtual void setBlocking( bool bBlocking=true ) = 0; public: // Filters -- cgit v1.2.3 From 932677862376e9642a496a15b7f09f1106f495a5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 28 Jun 2007 20:49:39 +0000 Subject: Many minor changes, hopefully the header fixes will keep future header macro conflicts from happening. And, from now on, other projects should do -Ilibbu++ not -Ilibbu++/src so we can get ready for an installed version of libbu++. --- bu | 1 + src/archival.h | 4 ++-- src/archive.h | 4 ++-- src/atom.h | 4 ++-- src/bzip2.h | 4 ++-- src/client.h | 4 ++-- src/exceptionbase.h | 4 ++-- src/exceptions.h | 4 ++-- src/file.h | 4 ++-- src/filter.h | 4 ++-- src/fstring.h | 4 ++-- src/hash.h | 4 ++-- src/ito.h | 4 ++-- src/itoatom.h | 4 ++-- src/itocondition.h | 4 ++-- src/itomutex.h | 4 ++-- src/itoqueue.h | 4 ++-- src/linkmessage.h | 4 ++-- src/list.h | 4 ++-- src/membuf.h | 4 ++-- src/paramproc.h | 4 ++-- src/plugger.h | 4 ++-- src/programchain.h | 4 ++-- src/programlink.h | 4 ++-- src/protocol.h | 4 ++-- src/ringbuffer.h | 4 ++-- src/server.h | 4 ++-- src/serversocket.h | 4 ++-- src/singleton.h | 4 ++-- src/socket.h | 4 ++-- src/sptr.h | 4 ++-- src/stream.h | 4 ++-- src/unitsuite.h | 4 ++-- 33 files changed, 65 insertions(+), 64 deletions(-) create mode 120000 bu (limited to 'src/list.h') diff --git a/bu b/bu new file mode 120000 index 0000000..02b8847 --- /dev/null +++ b/bu @@ -0,0 +1 @@ +src/bu/ \ No newline at end of file diff --git a/src/archival.h b/src/archival.h index e2c803c..8be3308 100644 --- a/src/archival.h +++ b/src/archival.h @@ -1,5 +1,5 @@ -#ifndef ARCHIVAL_H -#define ARCHIVAL_H +#ifndef BU_ARCHIVAL_H +#define BU_ARCHIVAL_H namespace Bu { diff --git a/src/archive.h b/src/archive.h index 05c6f57..6c0c1df 100644 --- a/src/archive.h +++ b/src/archive.h @@ -1,5 +1,5 @@ -#ifndef ARCHIVE_H -#define ARCHIVE_H +#ifndef BU_ARCHIVE_H +#define BU_ARCHIVE_H #include #include diff --git a/src/atom.h b/src/atom.h index a0469b6..fad47eb 100644 --- a/src/atom.h +++ b/src/atom.h @@ -1,5 +1,5 @@ -#ifndef ATOM_H -#define ATOM_H +#ifndef BU_ATOM_H +#define BU_ATOM_H #include #include diff --git a/src/bzip2.h b/src/bzip2.h index 25f10c5..0a111e8 100644 --- a/src/bzip2.h +++ b/src/bzip2.h @@ -1,5 +1,5 @@ -#ifndef B_ZIP2_H -#define B_ZIP2_H +#ifndef BU_BZIP2_H +#define BU_BZIP2_H #include #include diff --git a/src/client.h b/src/client.h index 02ba077..cee558d 100644 --- a/src/client.h +++ b/src/client.h @@ -1,5 +1,5 @@ -#ifndef CLIENT_H -#define CLIENT_H +#ifndef BU_CLIENT_H +#define BU_CLIENT_H #include diff --git a/src/exceptionbase.h b/src/exceptionbase.h index fd78089..24e4bbf 100644 --- a/src/exceptionbase.h +++ b/src/exceptionbase.h @@ -1,5 +1,5 @@ -#ifndef EXCEPTION_BASE_H -#define EXCEPTION_BASE_H +#ifndef BU_EXCEPTION_BASE_H +#define BU_EXCEPTION_BASE_H #include #include diff --git a/src/exceptions.h b/src/exceptions.h index d5a9d39..b824b91 100644 --- a/src/exceptions.h +++ b/src/exceptions.h @@ -1,5 +1,5 @@ -#ifndef EXCEPTIONS_H -#define EXCEPTIONS_H +#ifndef BU_EXCEPTIONS_H +#define BU_EXCEPTIONS_H #include "exceptionbase.h" #include diff --git a/src/file.h b/src/file.h index 0f638a7..d4e43eb 100644 --- a/src/file.h +++ b/src/file.h @@ -1,5 +1,5 @@ -#ifndef FILE_H -#define FILE_H +#ifndef BU_FILE_H +#define BU_FILE_H #include diff --git a/src/filter.h b/src/filter.h index 7bb04bc..bd557b2 100644 --- a/src/filter.h +++ b/src/filter.h @@ -1,5 +1,5 @@ -#ifndef FILTER_H -#define FILTER_H +#ifndef BU_FILTER_H +#define BU_FILTER_H #include diff --git a/src/fstring.h b/src/fstring.h index 7180f5f..bf6518b 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -1,5 +1,5 @@ -#ifndef F_STRING_H -#define F_STRING_H +#ifndef BU_F_STRING_H +#define BU_F_STRING_H #include #include diff --git a/src/hash.h b/src/hash.h index 6c4a443..0fa3af7 100644 --- a/src/hash.h +++ b/src/hash.h @@ -1,5 +1,5 @@ -#ifndef HASH_H -#define HASH_H +#ifndef BU_HASH_H +#define BU_HASH_H #include #include diff --git a/src/ito.h b/src/ito.h index 01253f5..c062052 100644 --- a/src/ito.h +++ b/src/ito.h @@ -1,5 +1,5 @@ -#ifndef ITO_H -#define ITO_H +#ifndef BU_ITO_H +#define BU_ITO_H #include diff --git a/src/itoatom.h b/src/itoatom.h index 96090f2..7fc9090 100644 --- a/src/itoatom.h +++ b/src/itoatom.h @@ -1,5 +1,5 @@ -#ifndef ITO_QUEUE_H -#define ITO_QUEUE_H +#ifndef BU_ITO_QUEUE_H +#define BU_ITO_QUEUE_H #include diff --git a/src/itocondition.h b/src/itocondition.h index 4771b22..1793f81 100644 --- a/src/itocondition.h +++ b/src/itocondition.h @@ -1,5 +1,5 @@ -#ifndef ITO_CONDITION_H -#define ITO_CONDITION_H +#ifndef BU_ITO_CONDITION_H +#define BU_ITO_CONDITION_H #include diff --git a/src/itomutex.h b/src/itomutex.h index 80956b8..9c9d205 100644 --- a/src/itomutex.h +++ b/src/itomutex.h @@ -1,5 +1,5 @@ -#ifndef ITO_MUTEX_H -#define ITO_MUTEX_H +#ifndef BU_ITO_MUTEX_H +#define BU_ITO_MUTEX_H #include diff --git a/src/itoqueue.h b/src/itoqueue.h index 322698d..75a2f27 100644 --- a/src/itoqueue.h +++ b/src/itoqueue.h @@ -1,5 +1,5 @@ -#ifndef ITO_QUEUE_H -#define ITO_QUEUE_H +#ifndef BU_ITO_QUEUE_H +#define BU_ITO_QUEUE_H #include diff --git a/src/linkmessage.h b/src/linkmessage.h index 64b8bc2..baa22a6 100644 --- a/src/linkmessage.h +++ b/src/linkmessage.h @@ -1,8 +1,8 @@ /**\file linkmessage.h */ -#ifndef LINKMESSAGE_H -#define LINKMESSAGE_H +#ifndef BU_LINKMESSAGE_H +#define BU_LINKMESSAGE_H namespace Bu { diff --git a/src/list.h b/src/list.h index 314459e..6235619 100644 --- a/src/list.h +++ b/src/list.h @@ -1,5 +1,5 @@ -#ifndef LIST_H -#define LIST_H +#ifndef BU_LIST_H +#define BU_LIST_H #include #include "bu/exceptionbase.h" diff --git a/src/membuf.h b/src/membuf.h index 877b35e..b82f943 100644 --- a/src/membuf.h +++ b/src/membuf.h @@ -1,5 +1,5 @@ -#ifndef MEM_BUF_H -#define MEM_BUF_H +#ifndef BU_MEM_BUF_H +#define BU_MEM_BUF_H #include diff --git a/src/paramproc.h b/src/paramproc.h index beee4a0..2bca588 100644 --- a/src/paramproc.h +++ b/src/paramproc.h @@ -1,5 +1,5 @@ -#ifndef PARAM_PROC_H -#define PARAM_PROC_H +#ifndef BU_PARAM_PROC_H +#define BU_PARAM_PROC_H #include #include diff --git a/src/plugger.h b/src/plugger.h index 4d2e7af..79a3271 100644 --- a/src/plugger.h +++ b/src/plugger.h @@ -1,5 +1,5 @@ -#ifndef PLUGGER_H -#define PLUGGER_H +#ifndef BU_PLUGGER_H +#define BU_PLUGGER_H #include "bu/hash.h" diff --git a/src/programchain.h b/src/programchain.h index e73d659..336a9f1 100644 --- a/src/programchain.h +++ b/src/programchain.h @@ -1,5 +1,5 @@ -#ifndef PROGRAMCHAIN_H -#define PROGRAMCHAIN_H +#ifndef BU_PROGRAMCHAIN_H +#define BU_PROGRAMCHAIN_H #include "bu/list.h" #include "bu/linkmessage.h" diff --git a/src/programlink.h b/src/programlink.h index 7c31a18..07d7489 100644 --- a/src/programlink.h +++ b/src/programlink.h @@ -1,5 +1,5 @@ -#ifndef PROGRAMLINK_H -#define PROGRAMLINK_H +#ifndef BU_PROGRAMLINK_H +#define BU_PROGRAMLINK_H #include "bu/linkmessage.h" #include "bu/programchain.h" diff --git a/src/protocol.h b/src/protocol.h index 3accd99..c7a9275 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -1,5 +1,5 @@ -#ifndef PROTOCOL_H -#define PROTOCOL_H +#ifndef BU_PROTOCOL_H +#define BU_PROTOCOL_H #include diff --git a/src/ringbuffer.h b/src/ringbuffer.h index 625f65b..be80e2f 100644 --- a/src/ringbuffer.h +++ b/src/ringbuffer.h @@ -1,5 +1,5 @@ -#ifndef RING_BUFFER_H -#define RING_BUFFER_H +#ifndef BU_RING_BUFFER_H +#define BU_RING_BUFFER_H #include #include "bu/exceptionbase.h" diff --git a/src/server.h b/src/server.h index 07eef95..302b6e3 100644 --- a/src/server.h +++ b/src/server.h @@ -1,5 +1,5 @@ -#ifndef SERVER_H -#define SERVER_H +#ifndef BU_SERVER_H +#define BU_SERVER_H #include diff --git a/src/serversocket.h b/src/serversocket.h index cb86078..b4ee247 100644 --- a/src/serversocket.h +++ b/src/serversocket.h @@ -1,5 +1,5 @@ -#ifndef SERVER_SOCKET_H -#define SERVER_SOCKET_H +#ifndef BU_SERVER_SOCKET_H +#define BU_SERVER_SOCKET_H #include #include "bu/fstring.h" diff --git a/src/singleton.h b/src/singleton.h index 4976a61..c43d71b 100644 --- a/src/singleton.h +++ b/src/singleton.h @@ -1,5 +1,5 @@ -#ifndef SINGLETON_H -#define SINGLETON_H +#ifndef BU_SINGLETON_H +#define BU_SINGLETON_H #include diff --git a/src/socket.h b/src/socket.h index c9dbd8d..0ccee3b 100644 --- a/src/socket.h +++ b/src/socket.h @@ -1,5 +1,5 @@ -#ifndef SOCKET_H -#define SOCKET_H +#ifndef BU_SOCKET_H +#define BU_SOCKET_H #include diff --git a/src/sptr.h b/src/sptr.h index 4baa697..75851a6 100644 --- a/src/sptr.h +++ b/src/sptr.h @@ -1,5 +1,5 @@ -#ifndef SPTR_H -#define SPTR_H +#ifndef BU_SPTR_H +#define BU_SPTR_H #include #include diff --git a/src/stream.h b/src/stream.h index 056de0c..1e236a6 100644 --- a/src/stream.h +++ b/src/stream.h @@ -1,5 +1,5 @@ -#ifndef STREAM_H -#define STREAM_H +#ifndef BU_STREAM_H +#define BU_STREAM_H #include #include diff --git a/src/unitsuite.h b/src/unitsuite.h index 6e9270a..578b4cc 100644 --- a/src/unitsuite.h +++ b/src/unitsuite.h @@ -1,5 +1,5 @@ -#ifndef UNIT_SUITE_H -#define UNIT_SUITE_H +#ifndef BU_UNIT_SUITE_H +#define BU_UNIT_SUITE_H #include #include -- cgit v1.2.3 From bd865cee5f89116c1f054cd0e5c275e97c2d0a9b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 2 Jul 2007 20:35:44 +0000 Subject: The list has an isEmpty funcion, and the socket may have a new read function soon, check it out...later... --- src/list.h | 5 +++++ src/socket.cpp | 4 ++++ src/socket.h | 1 + 3 files changed, 10 insertions(+) (limited to 'src/list.h') diff --git a/src/list.h b/src/list.h index 6235619..e05ebbc 100644 --- a/src/list.h +++ b/src/list.h @@ -471,6 +471,11 @@ namespace Bu { return *pLast->pValue; } + + const bool isEmpty() const + { + return (nSize == 0); + } private: Link *pFirst; diff --git a/src/socket.cpp b/src/socket.cpp index 5a3097c..e567061 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -174,6 +174,10 @@ size_t Bu::Socket::read( void *pBuf, size_t nBytes ) return nRead; } +//size_t Bu::Socket::read( void *pBuf, size_t nBytes, uint32_t nTimeout ) +//{ +//} + size_t Bu::Socket::write( const void *pBuf, size_t nBytes ) { int nWrote = TEMP_FAILURE_RETRY( ::write( nSocket, pBuf, nBytes ) ); diff --git a/src/socket.h b/src/socket.h index 9e36041..c291549 100644 --- a/src/socket.h +++ b/src/socket.h @@ -21,6 +21,7 @@ namespace Bu virtual void close(); //virtual void read(); virtual size_t read( void *pBuf, size_t nBytes ); + virtual size_t read( void *pBuf, size_t nBytes, uint32_t nTimeout ); virtual size_t write( const void *pBuf, size_t nBytes ); virtual long tell(); -- cgit v1.2.3