summaryrefslogtreecommitdiff
path: root/src/fbasicstring.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/fbasicstring.h')
-rw-r--r--src/fbasicstring.h108
1 files changed, 31 insertions, 77 deletions
diff --git a/src/fbasicstring.h b/src/fbasicstring.h
index 225bc80..0e63efe 100644
--- a/src/fbasicstring.h
+++ b/src/fbasicstring.h
@@ -15,10 +15,13 @@
15#include <wordexp.h> 15#include <wordexp.h>
16#endif 16#endif
17 17
18#include "bu/archival.h"
19#include "bu/archive.h"
20#include "bu/util.h" 18#include "bu/util.h"
21#include "bu/sharedcore.h" 19#include "bu/sharedcore.h"
20#include "bu/exceptionbase.h"
21#include "bu/archivebase.h"
22#include "bu/list.h"
23
24#include <string.h>
22 25
23namespace Bu 26namespace Bu
24{ 27{
@@ -30,21 +33,8 @@ namespace Bu
30 FStringChunk *pNext; 33 FStringChunk *pNext;
31 }; 34 };
32 35
33#ifndef VALTEST 36#define cpy( dest, src, size ) Bu::memcpy( dest, src, size*sizeof(chr) )
34#define cpy( dest, src, size ) memcpy( dest, src, size*sizeof(chr) )
35#endif
36 37
37#ifdef VALTEST
38 void cpy( chr *dest, const chr *src, long count ) const
39 {
40 for( int j = 0; j < count; j++ )
41 {
42 *dest = *src;
43 dest++;
44 src++;
45 }
46 }
47#endif
48 template<typename chr, int nMinSize, typename chralloc, typename chunkalloc> 38 template<typename chr, int nMinSize, typename chralloc, typename chunkalloc>
49 struct FStringCore 39 struct FStringCore
50 { 40 {
@@ -185,7 +175,7 @@ namespace Bu
185 *@param chunkalloc (typename) Memory Allocator for chr chunks 175 *@param chunkalloc (typename) Memory Allocator for chr chunks
186 */ 176 */
187 template< typename chr, int nMinSize=256, typename chralloc=std::allocator<chr>, typename chunkalloc=std::allocator<struct FStringChunk<chr> > > 177 template< typename chr, int nMinSize=256, typename chralloc=std::allocator<chr>, typename chunkalloc=std::allocator<struct FStringChunk<chr> > >
188 class FBasicString : public SharedCore< FStringCore<chr, nMinSize, chralloc, chunkalloc> >, public Archival 178 class FBasicString : public SharedCore< FStringCore<chr, nMinSize, chralloc, chunkalloc> >
189 { 179 {
190 protected: 180 protected:
191 typedef struct FStringChunk<chr> Chunk; 181 typedef struct FStringChunk<chr> Chunk;
@@ -211,8 +201,7 @@ namespace Bu
211 } 201 }
212 202
213 FBasicString( const MyType &rSrc ) : 203 FBasicString( const MyType &rSrc ) :
214 SharedCore<Core>( rSrc ), 204 SharedCore<Core>( rSrc )
215 Archival()
216 { 205 {
217 } 206 }
218 207
@@ -1284,13 +1273,6 @@ namespace Bu
1284 return (*this); 1273 return (*this);
1285 } 1274 }
1286 1275
1287 MyType &operator=( const std::basic_string<chr> &rData )
1288 {
1289 set( rData.c_str(), rData.size() );
1290
1291 return (*this);
1292 }
1293
1294 MyType operator+( const MyType &rRight ) const 1276 MyType operator+( const MyType &rRight ) const
1295 { 1277 {
1296 MyType ret( *this ); 1278 MyType ret( *this );
@@ -1505,8 +1487,8 @@ namespace Bu
1505 flatten(); 1487 flatten();
1506 pData.flatten(); 1488 pData.flatten();
1507 1489
1508 const chr *a = pData.core->pFirst->pData; 1490 const chr *a = core->pFirst->pData;
1509 chr *b = core->pFirst->pData; 1491 chr *b = pData.core->pFirst->pData;
1510 for( long j = 0; j < core->nLength; j++, a++, b++ ) 1492 for( long j = 0; j < core->nLength; j++, a++, b++ )
1511 { 1493 {
1512 if( *a != *b ) 1494 if( *a != *b )
@@ -1521,8 +1503,8 @@ namespace Bu
1521 flatten(); 1503 flatten();
1522 pData.flatten(); 1504 pData.flatten();
1523 1505
1524 const chr *a = pData.core->pFirst->pData; 1506 const chr *a = core->pFirst->pData;
1525 chr *b = core->pFirst->pData; 1507 chr *b = pData.core->pFirst->pData;
1526 for( long j = 0; j < core->nLength; j++, a++, b++ ) 1508 for( long j = 0; j < core->nLength; j++, a++, b++ )
1527 { 1509 {
1528 if( *a != *b ) 1510 if( *a != *b )
@@ -1902,51 +1884,6 @@ namespace Bu
1902 va_end( ap ); 1884 va_end( ap );
1903 } 1885 }
1904 1886
1905 /**
1906 * Function the archiver calls to archive your FString.
1907 *@param ar (Archive) The archive which is archiving your FString.
1908 */
1909 void archive( class Archive &ar )
1910 {
1911 if( ar.isLoading() )
1912 {
1913 _hardCopy();
1914 core->clear();
1915 long nLen;
1916 ar >> nLen;
1917
1918 if( nLen > 0 )
1919 {
1920 Chunk *pNew = core->newChunk( nLen );
1921 ar.read( pNew->pData, nLen*sizeof(chr) );
1922 core->appendChunk( pNew );
1923 }
1924 }
1925 else
1926 {
1927 flatten();
1928
1929 ar << core->nLength;
1930 if( core->nLength )
1931 ar.write( core->pFirst->pData, core->nLength*sizeof(chr) );
1932 }
1933 }
1934 /*
1935 void archive( class Archive &ar ) const
1936 {
1937 if( ar.isLoading() )
1938 {
1939 }
1940 else
1941 {
1942 flatten();
1943
1944 ar << core->nLength;
1945 if( core->nLength )
1946 ar.write( core->pFirst->pData, core->nLength*sizeof(chr) );
1947 }
1948 }*/
1949
1950 iterator begin() 1887 iterator begin()
1951 { 1888 {
1952 if( core->nLength == 0 ) 1889 if( core->nLength == 0 )
@@ -2016,10 +1953,27 @@ namespace Bu
2016 ret.append( rRight ); 1953 ret.append( rRight );
2017 return ret; 1954 return ret;
2018 } 1955 }
1956
1957 template<class chr, int b, class c, class d>
1958 ArchiveBase &operator<<( ArchiveBase &ar, const FBasicString<chr, b, c, d> &s )
1959 {
1960 long n = s.getSize();
1961 ar << n;
1962 ar.write( s.getConstStr(), n );
1963 return ar;
1964 }
1965
1966 template<class chr, int b, class c, class d>
1967 ArchiveBase &operator>>( ArchiveBase &ar, FBasicString<chr, b, c, d> &s )
1968 {
1969 long n;
1970 ar >> n;
1971 s.setSize( n );
1972 ar.read( s.getStr(), n );
1973 return ar;
1974 }
2019} 1975}
2020 1976
2021#ifndef VALTEST
2022#undef cpy 1977#undef cpy
2023#endif
2024 1978
2025#endif 1979#endif