summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-05-24 15:10:19 +0000
committerMike Buland <eichlan@xagasoft.com>2010-05-24 15:10:19 +0000
commitecc191f590f76584a14c9c51727412b0b7b3086e (patch)
treeb27ee434ed541ba3a386ff6a3238f66b9451ef22 /src
parent71191e311d949b1b7bdd74fc36a14306f492c181 (diff)
downloadlibbu++-ecc191f590f76584a14c9c51727412b0b7b3086e.tar.gz
libbu++-ecc191f590f76584a14c9c51727412b0b7b3086e.tar.bz2
libbu++-ecc191f590f76584a14c9c51727412b0b7b3086e.tar.xz
libbu++-ecc191f590f76584a14c9c51727412b0b7b3086e.zip
Changed the Bu::Stream API, setSize is now standard. There may be a few more
things that should be added. A few of them still need to be implemented. I know that truncate for Bu::File is possible on windows, I've used it before, but hell if I can find it. Myriad also needs the setSize function completed.
Diffstat (limited to 'src')
-rw-r--r--src/file.cpp14
-rw-r--r--src/file.h12
-rw-r--r--src/filter.cpp4
-rw-r--r--src/filter.h6
-rw-r--r--src/membuf.cpp9
-rw-r--r--src/membuf.h1
-rw-r--r--src/myriad.cpp6
-rw-r--r--src/myriad.h2
-rw-r--r--src/myriadstream.cpp7
-rw-r--r--src/myriadstream.h1
-rw-r--r--src/process.cpp4
-rw-r--r--src/process.h2
-rw-r--r--src/queuebuf.cpp4
-rw-r--r--src/queuebuf.h1
-rw-r--r--src/socket.cpp4
-rw-r--r--src/socket.h2
-rw-r--r--src/stdstream.cpp4
-rw-r--r--src/stdstream.h1
-rw-r--r--src/stream.h8
-rw-r--r--src/unit/myriad.unit2
-rw-r--r--src/unitsuite.cpp14
-rw-r--r--src/unitsuite.h5
22 files changed, 101 insertions, 12 deletions
diff --git a/src/file.cpp b/src/file.cpp
index f1f63e4..a0c3fd8 100644
--- a/src/file.cpp
+++ b/src/file.cpp
@@ -187,19 +187,27 @@ void Bu::File::setBlocking( bool bBlocking )
187#endif 187#endif
188} 188}
189 189
190#ifndef WIN32
191Bu::File Bu::File::tempFile( Bu::FString &sName ) 190Bu::File Bu::File::tempFile( Bu::FString &sName )
192{ 191{
192#ifndef WIN32
193 int afh_d = mkstemp( sName.getStr() ); 193 int afh_d = mkstemp( sName.getStr() );
194 194
195 return Bu::File( afh_d ); 195 return Bu::File( afh_d );
196#else
197 return Bu::File( sName, Bu::File::Write|Bu::File::Create );
198#endif
196} 199}
197 200
198void Bu::File::truncate( long nSize ) 201void Bu::File::setSize( long iSize )
199{ 202{
200 ftruncate( fd, nSize ); 203#ifndef WIN32
204 ftruncate( fd, iSize );
205#else
206#warning Bu::File::setSize not implemented on this platform
207#endif
201} 208}
202 209
210#ifndef WIN32
203void Bu::File::chmod( mode_t t ) 211void Bu::File::chmod( mode_t t )
204{ 212{
205 fchmod( fd, t ); 213 fchmod( fd, t );
diff --git a/src/file.h b/src/file.h
index 5eca3c1..b2cd2a4 100644
--- a/src/file.h
+++ b/src/file.h
@@ -69,6 +69,9 @@ namespace Bu
69 WriteNew = 0x0E ///< Create a file (or truncate) for writing. 69 WriteNew = 0x0E ///< Create a file (or truncate) for writing.
70 /// Same as Write|Create|Truncate 70 /// Same as Write|Create|Truncate
71 }; 71 };
72
73 virtual void setSize( long iSize );
74
72 /** 75 /**
73 * Create a temp file and return its handle. The file is opened 76 * Create a temp file and return its handle. The file is opened
74 * Read/Write. 77 * Read/Write.
@@ -77,16 +80,9 @@ namespace Bu
77 * characters. 80 * characters.
78 *@returns (Bu::File) A file object representing your temp file. 81 *@returns (Bu::File) A file object representing your temp file.
79 */ 82 */
80#ifndef WIN32
81 static Bu::File tempFile( Bu::FString &sName ); 83 static Bu::File tempFile( Bu::FString &sName );
82 84
83 /** 85#ifndef WIN32
84 * Set the size of the file to (nSize). You can either grow or shrink
85 * the file.
86 *@param nSize (long) The new size of the file.
87 */
88 void truncate( long nSize );
89
90 /** 86 /**
91 * Change the file access permissions. 87 * Change the file access permissions.
92 *@param t (mode_t) The new file access permissions. 88 *@param t (mode_t) The new file access permissions.
diff --git a/src/filter.cpp b/src/filter.cpp
index 4208555..8dc3694 100644
--- a/src/filter.cpp
+++ b/src/filter.cpp
@@ -87,6 +87,10 @@ void Bu::Filter::setBlocking( bool bBlocking )
87 rNext.setBlocking( bBlocking ); 87 rNext.setBlocking( bBlocking );
88} 88}
89 89
90void Bu::Filter::setSize( long iSize )
91{
92}
93
90void Bu::Filter::flush() 94void Bu::Filter::flush()
91{ 95{
92 rNext.flush(); 96 rNext.flush();
diff --git a/src/filter.h b/src/filter.h
index 67ffce2..5507daa 100644
--- a/src/filter.h
+++ b/src/filter.h
@@ -62,6 +62,12 @@ namespace Bu
62 virtual bool isBlocking(); 62 virtual bool isBlocking();
63 virtual void setBlocking( bool bBlocking=true ); 63 virtual void setBlocking( bool bBlocking=true );
64 64
65 /**
66 * Most filters won't re-implement this, it doesn't make a lot of sense
67 * for filters, in general.
68 */
69 virtual void setSize( long iSize );
70
65 protected: 71 protected:
66 Bu::Stream &rNext; 72 Bu::Stream &rNext;
67 73
diff --git a/src/membuf.cpp b/src/membuf.cpp
index 0c1c441..b822641 100644
--- a/src/membuf.cpp
+++ b/src/membuf.cpp
@@ -140,6 +140,15 @@ void Bu::MemBuf::setBlocking( bool )
140{ 140{
141} 141}
142 142
143void Bu::MemBuf::setSize( long iSize )
144{
145 if( iSize < 0 )
146 iSize = 0;
147 sBuf.setSize( iSize );
148 if( nPos > iSize )
149 nPos = iSize;
150}
151
143Bu::FString &Bu::MemBuf::getString() 152Bu::FString &Bu::MemBuf::getString()
144{ 153{
145 return sBuf; 154 return sBuf;
diff --git a/src/membuf.h b/src/membuf.h
index c6c8079..9e406c1 100644
--- a/src/membuf.h
+++ b/src/membuf.h
@@ -45,6 +45,7 @@ namespace Bu
45 virtual bool isSeekable(); 45 virtual bool isSeekable();
46 virtual bool isBlocking(); 46 virtual bool isBlocking();
47 virtual void setBlocking( bool bBlocking=true ); 47 virtual void setBlocking( bool bBlocking=true );
48 virtual void setSize( long iSize );
48 49
49 Bu::FString &getString(); 50 Bu::FString &getString();
50 void setString( const Bu::FString &sNewData ); 51 void setString( const Bu::FString &sNewData );
diff --git a/src/myriad.cpp b/src/myriad.cpp
index 4476d53..044e35e 100644
--- a/src/myriad.cpp
+++ b/src/myriad.cpp
@@ -426,3 +426,9 @@ void Bu::Myriad::syncBlock( Block *pBlock )
426 } 426 }
427} 427}
428 428
429void Bu::Myriad::setStreamSize( Stream *pStream, long iSize )
430{
431 sio << "Oh man, you have to implement Bu::Myriad::setStreamSize!!! (line "
432 << __LINE__ << ")" << sio.nl;
433}
434
diff --git a/src/myriad.h b/src/myriad.h
index 9bbc812..8e7cfb1 100644
--- a/src/myriad.h
+++ b/src/myriad.h
@@ -150,6 +150,8 @@ namespace Bu
150 void releaseBlock( Block *pBlock ); 150 void releaseBlock( Block *pBlock );
151 void syncBlock( Block *pBlock ); 151 void syncBlock( Block *pBlock );
152 152
153 void setStreamSize( Stream *pStream, long iSize );
154
153 private: 155 private:
154 Bu::Stream &sStore; 156 Bu::Stream &sStore;
155 int iBlockSize; 157 int iBlockSize;
diff --git a/src/myriadstream.cpp b/src/myriadstream.cpp
index 2218ae4..41c5b53 100644
--- a/src/myriadstream.cpp
+++ b/src/myriadstream.cpp
@@ -281,3 +281,10 @@ void Bu::MyriadStream::setBlocking( bool /*bBlocking*/ )
281{ 281{
282} 282}
283 283
284void Bu::MyriadStream::setSize( long iSize )
285{
286 rMyriad.setStreamSize( pStream, iSize );
287 if( iPos > iSize )
288 iPos = iSize;
289}
290
diff --git a/src/myriadstream.h b/src/myriadstream.h
index e2e3ba7..1a5e552 100644
--- a/src/myriadstream.h
+++ b/src/myriadstream.h
@@ -43,6 +43,7 @@ namespace Bu
43 virtual bool isSeekable(); 43 virtual bool isSeekable();
44 virtual bool isBlocking(); 44 virtual bool isBlocking();
45 virtual void setBlocking( bool bBlocking=true ); 45 virtual void setBlocking( bool bBlocking=true );
46 virtual void setSize( long iSize );
46 47
47 private: 48 private:
48 Myriad &rMyriad; 49 Myriad &rMyriad;
diff --git a/src/process.cpp b/src/process.cpp
index 7cb5983..2d8eda0 100644
--- a/src/process.cpp
+++ b/src/process.cpp
@@ -278,6 +278,10 @@ void Bu::Process::setBlocking( bool bBlocking )
278 this->bBlocking = bBlocking; 278 this->bBlocking = bBlocking;
279} 279}
280 280
281void Bu::Process::setSize( long iSize )
282{
283}
284
281void Bu::Process::select( bool &bStdOut, bool &bStdErr ) 285void Bu::Process::select( bool &bStdOut, bool &bStdErr )
282{ 286{
283 fd_set rfds; 287 fd_set rfds;
diff --git a/src/process.h b/src/process.h
index 3fcf1f2..68678bd 100644
--- a/src/process.h
+++ b/src/process.h
@@ -68,6 +68,8 @@ namespace Bu
68 virtual bool isBlocking(); 68 virtual bool isBlocking();
69 virtual void setBlocking( bool bBlocking=true ); 69 virtual void setBlocking( bool bBlocking=true );
70 70
71 virtual void setSize( long iSize );
72
71 void select( bool &bStdOut, bool &bStdErr ); 73 void select( bool &bStdOut, bool &bStdErr );
72 74
73 bool isRunning(); 75 bool isRunning();
diff --git a/src/queuebuf.cpp b/src/queuebuf.cpp
index 01d92f8..1a902bc 100644
--- a/src/queuebuf.cpp
+++ b/src/queuebuf.cpp
@@ -249,6 +249,10 @@ void Bu::QueueBuf::setBlocking( bool )
249{ 249{
250} 250}
251 251
252void Bu::QueueBuf::setSize( long iSize )
253{
254}
255
252void Bu::QueueBuf::addBlock() 256void Bu::QueueBuf::addBlock()
253{ 257{
254 lBlocks.append( new char[iBlockSize] ); 258 lBlocks.append( new char[iBlockSize] );
diff --git a/src/queuebuf.h b/src/queuebuf.h
index 382863d..395c6ba 100644
--- a/src/queuebuf.h
+++ b/src/queuebuf.h
@@ -45,6 +45,7 @@ namespace Bu
45 virtual bool isSeekable(); 45 virtual bool isSeekable();
46 virtual bool isBlocking(); 46 virtual bool isBlocking();
47 virtual void setBlocking( bool bBlocking=true ); 47 virtual void setBlocking( bool bBlocking=true );
48 virtual void setSize( long iSize );
48 49
49 private: 50 private:
50 void addBlock(); 51 void addBlock();
diff --git a/src/socket.cpp b/src/socket.cpp
index 6a30f44..41e0763 100644
--- a/src/socket.cpp
+++ b/src/socket.cpp
@@ -405,6 +405,10 @@ void Bu::Socket::setBlocking( bool bBlocking )
405#endif 405#endif
406} 406}
407 407
408void Bu::Socket::setSize( long iSize )
409{
410}
411
408void Bu::Socket::flush() 412void Bu::Socket::flush()
409{ 413{
410} 414}
diff --git a/src/socket.h b/src/socket.h
index f907b95..c8f78f0 100644
--- a/src/socket.h
+++ b/src/socket.h
@@ -92,6 +92,8 @@ namespace Bu
92 virtual bool isBlocking(); 92 virtual bool isBlocking();
93 virtual void setBlocking( bool bBlocking=true ); 93 virtual void setBlocking( bool bBlocking=true );
94 94
95 virtual void setSize( long iSize );
96
95 Bu::FString getAddress() const; 97 Bu::FString getAddress() const;
96 operator int() const; 98 operator int() const;
97 99
diff --git a/src/stdstream.cpp b/src/stdstream.cpp
index fb6cd36..4c2c828 100644
--- a/src/stdstream.cpp
+++ b/src/stdstream.cpp
@@ -96,3 +96,7 @@ void Bu::StdStream::setBlocking( bool )
96{ 96{
97} 97}
98 98
99void Bu::StdStream::setSize( long iSize )
100{
101}
102
diff --git a/src/stdstream.h b/src/stdstream.h
index 144a24f..4efeece 100644
--- a/src/stdstream.h
+++ b/src/stdstream.h
@@ -40,6 +40,7 @@ namespace Bu
40 virtual bool isSeekable(); 40 virtual bool isSeekable();
41 virtual bool isBlocking(); 41 virtual bool isBlocking();
42 virtual void setBlocking( bool bBlocking=true ); 42 virtual void setBlocking( bool bBlocking=true );
43 virtual void setSize( long iSize );
43 }; 44 };
44} 45}
45 46
diff --git a/src/stream.h b/src/stream.h
index bfe3ef9..0ea5560 100644
--- a/src/stream.h
+++ b/src/stream.h
@@ -152,6 +152,14 @@ namespace Bu
152 */ 152 */
153 virtual void setBlocking( bool bBlocking=true ) = 0; 153 virtual void setBlocking( bool bBlocking=true ) = 0;
154 154
155 /**
156 * Set the size of the stream, this does not apply to many types of
157 * streams. For those that it does apply to, data will be added or
158 * removed from the end of the stream, but the content of the added
159 * data is undefined.
160 */
161 virtual void setSize( long iSize ) = 0;
162
155 public: // Filters 163 public: // Filters
156 164
157 165
diff --git a/src/unit/myriad.unit b/src/unit/myriad.unit
index bc05bf7..cf861a3 100644
--- a/src/unit/myriad.unit
+++ b/src/unit/myriad.unit
@@ -76,7 +76,7 @@ suite Myriad
76 { 76 {
77 FString sFileName("myriad-XXXXXXX"); 77 FString sFileName("myriad-XXXXXXX");
78 78
79 File::tempFile( sFileName ); 79 tempFile( sFileName );
80 File fMyriad( sFileName, File::WriteNew|File::Read ); 80 File fMyriad( sFileName, File::WriteNew|File::Read );
81 Myriad m( fMyriad ); 81 Myriad m( fMyriad );
82 m.initialize( 64 ); 82 m.initialize( 64 );
diff --git a/src/unitsuite.cpp b/src/unitsuite.cpp
index a66160e..51cca10 100644
--- a/src/unitsuite.cpp
+++ b/src/unitsuite.cpp
@@ -6,6 +6,9 @@
6 */ 6 */
7 7
8#include "bu/unitsuite.h" 8#include "bu/unitsuite.h"
9#include "bu/file.h"
10
11#include <unistd.h>
9 12
10Bu::UnitSuite::UnitSuite() : 13Bu::UnitSuite::UnitSuite() :
11 iOptions( 0 ) 14 iOptions( 0 )
@@ -102,9 +105,20 @@ int Bu::UnitSuite::run( int /*argc*/, char * /*argv */ [] )
102 if( iUPass == 0 && iUFail == 0 ) 105 if( iUPass == 0 && iUFail == 0 )
103 printf("\tNothing unexpected.\n\n"); 106 printf("\tNothing unexpected.\n\n");
104 107
108 for( StrList::iterator i = lFileCleanup.begin(); i; i++ )
109 {
110 unlink( (*i).getStr() );
111 }
112
105 return 0; 113 return 0;
106} 114}
107 115
116void Bu::UnitSuite::tempFile( Bu::FString &sFileName )
117{
118 Bu::File::tempFile( sFileName );
119 lFileCleanup.append( sFileName );
120}
121
108void Bu::UnitSuite::add( Test fTest, const Bu::FString &sName, Expect e ) 122void Bu::UnitSuite::add( Test fTest, const Bu::FString &sName, Expect e )
109{ 123{
110 TestInfo ti; 124 TestInfo ti;
diff --git a/src/unitsuite.h b/src/unitsuite.h
index ad6bedb..7d026c2 100644
--- a/src/unitsuite.h
+++ b/src/unitsuite.h
@@ -61,6 +61,8 @@ namespace Bu
61 61
62 int run( int argc=0, char *argv[]=NULL ); 62 int run( int argc=0, char *argv[]=NULL );
63 63
64 void tempFile( Bu::FString &sFileName );
65
64 typedef void (UnitSuite::*Test)(); 66 typedef void (UnitSuite::*Test)();
65 67
66 class Failed 68 class Failed
@@ -105,6 +107,9 @@ namespace Bu
105 FString sSuiteName; 107 FString sSuiteName;
106 108
107 int iOptions; 109 int iOptions;
110
111 typedef Bu::List<Bu::FString> StrList;
112 StrList lFileCleanup;
108 }; 113 };
109} 114}
110 115