aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-04-10 06:23:07 +0000
committerMike Buland <eichlan@xagasoft.com>2009-04-10 06:23:07 +0000
commitfc96db275f65a9d5adc4a40758f50297fc5bdbf0 (patch)
tree6757c7e3dd2f008a243f50c3d1cc2c8fb42b7a94
parenteb23533db14ce9d712dad87b08e4df11d77fa3d3 (diff)
downloadlibbu++-fc96db275f65a9d5adc4a40758f50297fc5bdbf0.tar.gz
libbu++-fc96db275f65a9d5adc4a40758f50297fc5bdbf0.tar.bz2
libbu++-fc96db275f65a9d5adc4a40758f50297fc5bdbf0.tar.xz
libbu++-fc96db275f65a9d5adc4a40758f50297fc5bdbf0.zip
Added some new goodness to the fbasicstring, fixing some inconsistancies and
adding some more helpers. Hopefully this won't affect anything, but if it complains about any functions not working the way they used to, see if they're returning an int or an iterator. I made several functions handle iterators instead of ints, the int versions have an "Idx" suffix added now. I'm trying to switch entirely to iterators to reduce flattening and increase performance and stability. Also...something must have changed in the cache code...
-rw-r--r--src/cache.h7
-rw-r--r--src/fbasicstring.h98
-rw-r--r--src/tests/cache.cpp5
-rw-r--r--src/unit/fstring.unit9
4 files changed, 110 insertions, 9 deletions
diff --git a/src/cache.h b/src/cache.h
index f36c29b..2b93479 100644
--- a/src/cache.h
+++ b/src/cache.h
@@ -90,7 +90,12 @@ namespace Bu
90 return pData; 90 return pData;
91 } 91 }
92 92
93 bool isLoaded() const 93 bool isValid() const
94 {
95 return pCache != NULL;
96 }
97
98 bool isBound() const
94 { 99 {
95 return pData != NULL; 100 return pData != NULL;
96 } 101 }
diff --git a/src/fbasicstring.h b/src/fbasicstring.h
index a532d69..853625c 100644
--- a/src/fbasicstring.h
+++ b/src/fbasicstring.h
@@ -947,7 +947,7 @@ namespace Bu
947 return pFirst->pData; 947 return pFirst->pData;
948 } 948 }
949 949
950 MyType getSubStr( long iStart, long iSize=-1 ) const 950 MyType getSubStrIdx( long iStart, long iSize=-1 ) const
951 { 951 {
952 if( iStart < 0 ) 952 if( iStart < 0 )
953 iStart = 0; 953 iStart = 0;
@@ -965,6 +965,50 @@ namespace Bu
965 return ret; 965 return ret;
966 } 966 }
967 967
968 MyType getSubStr( const_iterator iBegin,
969 const_iterator iEnd=typename MyType::const_iterator() ) const
970 {
971 if( !iBegin.isValid() )
972 return MyType();
973 if( iBegin.pChunk == iEnd.pChunk )
974 {
975 return MyType( iBegin.pChunk->pData+iBegin.iPos,
976 iEnd.iPos-iBegin.iPos );
977 }
978 else if( !iEnd.isValid() )
979 {
980 MyType ret;
981 ret.append(
982 iBegin.pChunk->pData+iBegin.iPos,
983 iBegin.pChunk->nLength-iBegin.iPos
984 );
985 for( Chunk *pCur = iBegin.pChunk->pNext;
986 pCur; pCur = pCur->pNext )
987 {
988 ret.append( pCur->pData, pCur->nLength );
989 }
990 return ret;
991 }
992 else
993 {
994 MyType ret;
995 ret.append(
996 iBegin.pChunk->pData+iBegin.iPos,
997 iBegin.pChunk->nLength-iBegin.iPos
998 );
999 for( Chunk *pCur = iBegin.pChunk->pNext;
1000 pCur != iEnd.pChunk; pCur = pCur->pNext )
1001 {
1002 ret.append( pCur->pData, pCur->nLength );
1003 }
1004 ret.append(
1005 iEnd.pChunk->pData,
1006 iEnd.iPos
1007 );
1008 return ret;
1009 }
1010 }
1011
968 /** 1012 /**
969 * (std::string compatability) Get a pointer to the string array. 1013 * (std::string compatability) Get a pointer to the string array.
970 *@returns (chr *) The string data. 1014 *@returns (chr *) The string data.
@@ -1401,6 +1445,7 @@ namespace Bu
1401 const_iterator find( const chr cChar, 1445 const_iterator find( const chr cChar,
1402 const_iterator iStart=typename MyType::const_iterator() ) const 1446 const_iterator iStart=typename MyType::const_iterator() ) const
1403 { 1447 {
1448 if( !iStart ) iStart = begin();
1404 for( ; iStart; iStart++ ) 1449 for( ; iStart; iStart++ )
1405 { 1450 {
1406 if( cChar == *iStart ) 1451 if( cChar == *iStart )
@@ -1412,6 +1457,7 @@ namespace Bu
1412 const_iterator find( const chr *sText, int nLen, 1457 const_iterator find( const chr *sText, int nLen,
1413 const_iterator iStart=typename MyType::const_iterator() ) const 1458 const_iterator iStart=typename MyType::const_iterator() ) const
1414 { 1459 {
1460 if( !iStart ) iStart = begin();
1415 for( ; iStart; iStart++ ) 1461 for( ; iStart; iStart++ )
1416 { 1462 {
1417 if( iStart.compare( sText, nLen ) ) 1463 if( iStart.compare( sText, nLen ) )
@@ -1423,6 +1469,7 @@ namespace Bu
1423 const_iterator find( const MyType &rStr, 1469 const_iterator find( const MyType &rStr,
1424 const_iterator iStart=typename MyType::const_iterator() ) const 1470 const_iterator iStart=typename MyType::const_iterator() ) const
1425 { 1471 {
1472 if( !iStart ) iStart = begin();
1426 for( ; iStart; iStart++ ) 1473 for( ; iStart; iStart++ )
1427 { 1474 {
1428 if( iStart.compare( rStr ) ) 1475 if( iStart.compare( rStr ) )
@@ -1434,6 +1481,7 @@ namespace Bu
1434 const_iterator find( const MyType &rStr, int nLen, 1481 const_iterator find( const MyType &rStr, int nLen,
1435 const_iterator iStart=typename MyType::const_iterator() ) const 1482 const_iterator iStart=typename MyType::const_iterator() ) const
1436 { 1483 {
1484 if( !iStart ) iStart = begin();
1437 for( ; iStart; iStart++ ) 1485 for( ; iStart; iStart++ )
1438 { 1486 {
1439 if( iStart.compare( rStr, nLen ) ) 1487 if( iStart.compare( rStr, nLen ) )
@@ -1442,6 +1490,54 @@ namespace Bu
1442 return end(); 1490 return end();
1443 } 1491 }
1444 1492
1493 iterator find( const chr cChar,
1494 const_iterator iStart=typename MyType::const_iterator() )
1495 {
1496 if( !iStart ) iStart = begin();
1497 for( ; iStart; iStart++ )
1498 {
1499 if( cChar == *iStart )
1500 return iterator( iStart.pChunk, iStart.iPos );
1501 }
1502 return end();
1503 }
1504
1505 iterator find( const chr *sText, int nLen,
1506 const_iterator iStart=typename MyType::const_iterator() )
1507 {
1508 if( !iStart ) iStart = begin();
1509 for( ; iStart; iStart++ )
1510 {
1511 if( iStart.compare( sText, nLen ) )
1512 return iterator( iStart.pChunk, iStart.iPos );
1513 }
1514 return end();
1515 }
1516
1517 iterator find( const MyType &rStr,
1518 const_iterator iStart=typename MyType::const_iterator() )
1519 {
1520 if( !iStart ) iStart = begin();
1521 for( ; iStart; iStart++ )
1522 {
1523 if( iStart.compare( rStr ) )
1524 return iterator( iStart.pChunk, iStart.iPos );
1525 }
1526 return end();
1527 }
1528
1529 iterator find( const MyType &rStr, int nLen,
1530 const_iterator iStart=typename MyType::const_iterator() )
1531 {
1532 if( !iStart ) iStart = begin();
1533 for( ; iStart; iStart++ )
1534 {
1535 if( iStart.compare( rStr, nLen ) )
1536 return iterator( iStart.pChunk, iStart.iPos );
1537 }
1538 return end();
1539 }
1540
1445 /** 1541 /**
1446 * Find the index of the first occurrance of cChar 1542 * Find the index of the first occurrance of cChar
1447 *@param sText (const chr *) The string to search for. 1543 *@param sText (const chr *) The string to search for.
diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp
index 8d95a9d..5d542ed 100644
--- a/src/tests/cache.cpp
+++ b/src/tests/cache.cpp
@@ -171,6 +171,7 @@ public:
171 171
172 virtual bool shouldSync( Bob *, const long &, time_t ) 172 virtual bool shouldSync( Bob *, const long &, time_t )
173 { 173 {
174 return false;
174 } 175 }
175 176
176private: 177private:
@@ -224,9 +225,9 @@ int main( int argc, char *argv[] )
224 case 'l': 225 case 'l':
225 { 226 {
226 BobCache::Ptr pBob = cBob.getLazy( strtol( argv[2], NULL, 0 ) ); 227 BobCache::Ptr pBob = cBob.getLazy( strtol( argv[2], NULL, 0 ) );
227 printf("isLoaded: %s\n", pBob.isLoaded()?"yes":"no"); 228 printf("isBound: %s\n", pBob.isBound()?"yes":"no");
228 printf("Value = %d\n", pBob->getInt() ); 229 printf("Value = %d\n", pBob->getInt() );
229 printf("isLoaded: %s\n", pBob.isLoaded()?"yes":"no"); 230 printf("isBound: %s\n", pBob.isBound()?"yes":"no");
230 } 231 }
231 return 0; 232 return 0;
232 } 233 }
diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit
index fbebd39..7314095 100644
--- a/src/unit/fstring.unit
+++ b/src/unit/fstring.unit
@@ -141,11 +141,10 @@
141{%subStr1} 141{%subStr1}
142{ 142{
143 Bu::FString a("abcdefghijklmnop"); 143 Bu::FString a("abcdefghijklmnop");
144 unitTest( a.getSubStr( 5, 3 ) == "fgh" ); 144 Bu::FString::iterator i = a.find('f');
145 unitTest( a.getSubStr( 10 ) == "klmnop" ); 145 unitTest( a.getSubStr( i, Bu::FString::iterator() ) == "fghijklmnop" );
146 unitTest( a.getSubStr( 40 ) == "" ); 146 Bu::FString::iterator j = i.find('l');
147 unitTest( a.getSubStr( -10 ) == "abcdefghijklmnop" ); 147 unitTest( a.getSubStr( i, j ) == "fghijk" );
148 unitTest( a.getSubStr( -15, 4 ) == "abcd" );
149} 148}
150 149
151{%compareSub1} 150{%compareSub1}