diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/file.h | 18 | ||||
-rw-r--r-- | src/list.h | 92 | ||||
-rw-r--r-- | src/sptr.h | 45 | ||||
-rw-r--r-- | src/stream.h | 58 |
4 files changed, 213 insertions, 0 deletions
@@ -39,6 +39,14 @@ namespace Bu | |||
39 | virtual bool isBlocking(); | 39 | virtual bool isBlocking(); |
40 | virtual void setBlocking( bool bBlocking=true ); | 40 | virtual void setBlocking( bool bBlocking=true ); |
41 | 41 | ||
42 | /** | ||
43 | * Create a temp file and return its handle | ||
44 | *@param sName (Bu::FString) Give in the form: "/tmp/tmpfileXXXXXXXX" | ||
45 | * It will alter your (sName) setting the 'X's to random | ||
46 | * characters. | ||
47 | *@param sFlags (const char *) Standard file flags 'rb'... etc.. | ||
48 | *@returns (Bu::File) A file object representing your temp file. | ||
49 | */ | ||
42 | inline static Bu::File tempFile( Bu::FString &sName, const char *sFlags ) | 50 | inline static Bu::File tempFile( Bu::FString &sName, const char *sFlags ) |
43 | { | 51 | { |
44 | int afh_d = mkstemp( sName.getStr() ); | 52 | int afh_d = mkstemp( sName.getStr() ); |
@@ -46,7 +54,17 @@ namespace Bu | |||
46 | return Bu::File( afh_d, sFlags ); | 54 | return Bu::File( afh_d, sFlags ); |
47 | } | 55 | } |
48 | 56 | ||
57 | /** | ||
58 | * Set the size of the file to (nSize). You can either grow or shrink | ||
59 | * the file. | ||
60 | *@param nSize (long) The new size of the file. | ||
61 | */ | ||
49 | void truncate( long nSize ); | 62 | void truncate( long nSize ); |
63 | |||
64 | /** | ||
65 | * Change the file access permissions. | ||
66 | *@param t (mode_t) The new file access permissions. | ||
67 | */ | ||
50 | void chmod( mode_t t ); | 68 | void chmod( mode_t t ); |
51 | 69 | ||
52 | private: | 70 | private: |
@@ -115,6 +115,10 @@ namespace Bu | |||
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | /** | ||
119 | * Prepend a value to the list. | ||
120 | *@param v (const value_type &) The value to prepend. | ||
121 | */ | ||
118 | void prepend( const value &v ) | 122 | void prepend( const value &v ) |
119 | { | 123 | { |
120 | Link *pNew = la.allocate( 1 ); | 124 | Link *pNew = la.allocate( 1 ); |
@@ -136,6 +140,9 @@ namespace Bu | |||
136 | } | 140 | } |
137 | } | 141 | } |
138 | 142 | ||
143 | /** | ||
144 | * An iterator to iterate through your list. | ||
145 | */ | ||
139 | typedef struct iterator | 146 | typedef struct iterator |
140 | { | 147 | { |
141 | friend class List<value, valuealloc, linkalloc>; | 148 | friend class List<value, valuealloc, linkalloc>; |
@@ -152,36 +159,67 @@ namespace Bu | |||
152 | } | 159 | } |
153 | 160 | ||
154 | public: | 161 | public: |
162 | /** | ||
163 | * Equals comparison operator. | ||
164 | *@param oth (const iterator &) The iterator to compare to. | ||
165 | *@returns (bool) Are they equal? | ||
166 | */ | ||
155 | bool operator==( const iterator &oth ) const | 167 | bool operator==( const iterator &oth ) const |
156 | { | 168 | { |
157 | return ( pLink == oth.pLink ); | 169 | return ( pLink == oth.pLink ); |
158 | } | 170 | } |
159 | 171 | ||
172 | /** | ||
173 | * Equals comparison operator. | ||
174 | *@param pOth (const Link *) The link to compare to. | ||
175 | *@returns (bool) Are they equal? | ||
176 | */ | ||
160 | bool operator==( const Link *pOth ) const | 177 | bool operator==( const Link *pOth ) const |
161 | { | 178 | { |
162 | return ( pLink == pOth ); | 179 | return ( pLink == pOth ); |
163 | } | 180 | } |
164 | 181 | ||
182 | /** | ||
183 | * Not equals comparison operator. | ||
184 | *@param oth (const iterator &) The iterator to compare to. | ||
185 | *@returns (bool) Are they not equal? | ||
186 | */ | ||
165 | bool operator!=( const iterator &oth ) const | 187 | bool operator!=( const iterator &oth ) const |
166 | { | 188 | { |
167 | return ( pLink != oth.pLink ); | 189 | return ( pLink != oth.pLink ); |
168 | } | 190 | } |
169 | 191 | ||
192 | /** | ||
193 | * Not equals comparison operator. | ||
194 | *@param pOth (const Link *) The link to compare to. | ||
195 | *@returns (bool) Are they not equal? | ||
196 | */ | ||
170 | bool operator!=( const Link *pOth ) const | 197 | bool operator!=( const Link *pOth ) const |
171 | { | 198 | { |
172 | return ( pLink != pOth ); | 199 | return ( pLink != pOth ); |
173 | } | 200 | } |
174 | 201 | ||
202 | /** | ||
203 | * Dereference operator. | ||
204 | *@returns (value_type &) The value. | ||
205 | */ | ||
175 | value &operator*() | 206 | value &operator*() |
176 | { | 207 | { |
177 | return *(pLink->pValue); | 208 | return *(pLink->pValue); |
178 | } | 209 | } |
179 | 210 | ||
211 | /** | ||
212 | * Pointer access operator. | ||
213 | *@returns (value_type *) A pointer to the value. | ||
214 | */ | ||
180 | value *operator->() | 215 | value *operator->() |
181 | { | 216 | { |
182 | return pLink->pValue; | 217 | return pLink->pValue; |
183 | } | 218 | } |
184 | 219 | ||
220 | /** | ||
221 | * Increment operator. | ||
222 | */ | ||
185 | iterator &operator++() | 223 | iterator &operator++() |
186 | { | 224 | { |
187 | if( pLink != NULL ) | 225 | if( pLink != NULL ) |
@@ -189,6 +227,9 @@ namespace Bu | |||
189 | return *this; | 227 | return *this; |
190 | } | 228 | } |
191 | 229 | ||
230 | /** | ||
231 | * Decrement operator. | ||
232 | */ | ||
192 | iterator &operator--() | 233 | iterator &operator--() |
193 | { | 234 | { |
194 | if( pLink != NULL ) | 235 | if( pLink != NULL ) |
@@ -196,6 +237,9 @@ namespace Bu | |||
196 | return *this; | 237 | return *this; |
197 | } | 238 | } |
198 | 239 | ||
240 | /** | ||
241 | * Increment operator. | ||
242 | */ | ||
199 | iterator &operator++( int ) | 243 | iterator &operator++( int ) |
200 | { | 244 | { |
201 | if( pLink != NULL ) | 245 | if( pLink != NULL ) |
@@ -203,6 +247,9 @@ namespace Bu | |||
203 | return *this; | 247 | return *this; |
204 | } | 248 | } |
205 | 249 | ||
250 | /** | ||
251 | * Decrement operator. | ||
252 | */ | ||
206 | iterator &operator--( int ) | 253 | iterator &operator--( int ) |
207 | { | 254 | { |
208 | if( pLink != NULL ) | 255 | if( pLink != NULL ) |
@@ -210,6 +257,11 @@ namespace Bu | |||
210 | return *this; | 257 | return *this; |
211 | } | 258 | } |
212 | 259 | ||
260 | /** | ||
261 | * Assignment operator. | ||
262 | *@param oth (const iterator &) The other iterator to set this | ||
263 | * one to. | ||
264 | */ | ||
213 | iterator &operator=( const iterator &oth ) | 265 | iterator &operator=( const iterator &oth ) |
214 | { | 266 | { |
215 | pLink = oth.pLink; | 267 | pLink = oth.pLink; |
@@ -217,6 +269,9 @@ namespace Bu | |||
217 | } | 269 | } |
218 | }; | 270 | }; |
219 | 271 | ||
272 | /** | ||
273 | *@see iterator | ||
274 | */ | ||
220 | typedef struct const_iterator | 275 | typedef struct const_iterator |
221 | { | 276 | { |
222 | friend class List<value, valuealloc, linkalloc>; | 277 | friend class List<value, valuealloc, linkalloc>; |
@@ -309,21 +364,38 @@ namespace Bu | |||
309 | } | 364 | } |
310 | }; | 365 | }; |
311 | 366 | ||
367 | /** | ||
368 | * Get an iterator pointing to the first item in the list. | ||
369 | *@returns (iterator) | ||
370 | */ | ||
312 | iterator begin() | 371 | iterator begin() |
313 | { | 372 | { |
314 | return iterator( pFirst ); | 373 | return iterator( pFirst ); |
315 | } | 374 | } |
316 | 375 | ||
376 | /** | ||
377 | * Get a const iterator pointing to the first item in the list. | ||
378 | *@returns (const const_iterator) | ||
379 | */ | ||
317 | const const_iterator begin() const | 380 | const const_iterator begin() const |
318 | { | 381 | { |
319 | return const_iterator( pFirst ); | 382 | return const_iterator( pFirst ); |
320 | } | 383 | } |
321 | 384 | ||
385 | /** | ||
386 | * Get an iterator pointing to a place just past the last item in | ||
387 | * the list. | ||
388 | *@returns (const Link *) | ||
389 | */ | ||
322 | const Link *end() const | 390 | const Link *end() const |
323 | { | 391 | { |
324 | return NULL; | 392 | return NULL; |
325 | } | 393 | } |
326 | 394 | ||
395 | /** | ||
396 | * Erase an item from the list. | ||
397 | *@param i (iterator) The item to erase. | ||
398 | */ | ||
327 | void erase( iterator &i ) | 399 | void erase( iterator &i ) |
328 | { | 400 | { |
329 | Link *pCur = i.pLink; | 401 | Link *pCur = i.pLink; |
@@ -355,26 +427,46 @@ namespace Bu | |||
355 | } | 427 | } |
356 | } | 428 | } |
357 | 429 | ||
430 | /** | ||
431 | * Get the current size of the list. | ||
432 | *@returns (int) The current size of the list. | ||
433 | */ | ||
358 | int getSize() const | 434 | int getSize() const |
359 | { | 435 | { |
360 | return nSize; | 436 | return nSize; |
361 | } | 437 | } |
362 | 438 | ||
439 | /** | ||
440 | * Get the first item in the list. | ||
441 | *@returns (value_type &) The first item in the list. | ||
442 | */ | ||
363 | value &first() | 443 | value &first() |
364 | { | 444 | { |
365 | return *pFirst->pValue; | 445 | return *pFirst->pValue; |
366 | } | 446 | } |
367 | 447 | ||
448 | /** | ||
449 | * Get the first item in the list. | ||
450 | *@returns (const value_type &) The first item in the list. | ||
451 | */ | ||
368 | const value &first() const | 452 | const value &first() const |
369 | { | 453 | { |
370 | return *pFirst->pValue; | 454 | return *pFirst->pValue; |
371 | } | 455 | } |
372 | 456 | ||
457 | /** | ||
458 | * Get the last item in the list. | ||
459 | *@returns (value_type &) The last item in the list. | ||
460 | */ | ||
373 | value &last() | 461 | value &last() |
374 | { | 462 | { |
375 | return *pLast->pValue; | 463 | return *pLast->pValue; |
376 | } | 464 | } |
377 | 465 | ||
466 | /** | ||
467 | * Get the last item in the list. | ||
468 | *@returns (const value_type &) The last item in the list. | ||
469 | */ | ||
378 | const value &last() const | 470 | const value &last() const |
379 | { | 471 | { |
380 | return *pLast->pValue; | 472 | return *pLast->pValue; |
@@ -45,31 +45,55 @@ namespace Bu | |||
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | /** | ||
49 | * Get the number of references to this pointer. | ||
50 | *@returns (int32_t) The number of references to this pointer. | ||
51 | */ | ||
48 | int32_t count() const | 52 | int32_t count() const |
49 | { | 53 | { |
50 | return *pRefCnt; | 54 | return *pRefCnt; |
51 | } | 55 | } |
52 | 56 | ||
57 | /** | ||
58 | * Pointer access operator. | ||
59 | *@returns (const T *) | ||
60 | */ | ||
53 | const T *operator->() const | 61 | const T *operator->() const |
54 | { | 62 | { |
55 | return pData; | 63 | return pData; |
56 | } | 64 | } |
57 | 65 | ||
66 | /** | ||
67 | * Dereference operator. | ||
68 | *@returns (const T &) The value at the end of the pointer. | ||
69 | */ | ||
58 | const T &operator*() const | 70 | const T &operator*() const |
59 | { | 71 | { |
60 | return *pData; | 72 | return *pData; |
61 | } | 73 | } |
62 | 74 | ||
75 | /** | ||
76 | * Pointer access operator. | ||
77 | *@returns (T *) | ||
78 | */ | ||
63 | T *operator->() | 79 | T *operator->() |
64 | { | 80 | { |
65 | return pData; | 81 | return pData; |
66 | } | 82 | } |
67 | 83 | ||
84 | /** | ||
85 | * Dereference operator. | ||
86 | *@returns (T &) The value at the end of the pointer. | ||
87 | */ | ||
68 | T &operator*() | 88 | T &operator*() |
69 | { | 89 | { |
70 | return *pData; | 90 | return *pData; |
71 | } | 91 | } |
72 | 92 | ||
93 | /** | ||
94 | * Assignment operator. | ||
95 | *@param src (const SPtr<T> &) | ||
96 | */ | ||
73 | SPtr<T> operator=( const SPtr<T> &src ) | 97 | SPtr<T> operator=( const SPtr<T> &src ) |
74 | { | 98 | { |
75 | decCount(); | 99 | decCount(); |
@@ -81,6 +105,10 @@ namespace Bu | |||
81 | return *this; | 105 | return *this; |
82 | } | 106 | } |
83 | 107 | ||
108 | /** | ||
109 | * Assignment operator. | ||
110 | *@param src (const SPtr<T> &) | ||
111 | */ | ||
84 | const SPtr<T> operator=( const SPtr<T> &src ) const | 112 | const SPtr<T> operator=( const SPtr<T> &src ) const |
85 | { | 113 | { |
86 | decCount(); | 114 | decCount(); |
@@ -92,21 +120,38 @@ namespace Bu | |||
92 | return *this; | 120 | return *this; |
93 | } | 121 | } |
94 | 122 | ||
123 | /** | ||
124 | * Equals comparison operator. | ||
125 | *@param src (const SPtr<T> &) The SPtr to compare to. | ||
126 | *@returns (bool) Are the equal? | ||
127 | */ | ||
95 | bool operator==( const SPtr<T> &src ) const | 128 | bool operator==( const SPtr<T> &src ) const |
96 | { | 129 | { |
97 | return pData == src.pData; | 130 | return pData == src.pData; |
98 | } | 131 | } |
99 | 132 | ||
133 | /** | ||
134 | * Equals comparison operator. | ||
135 | *@param src (const T *) The pointer to compare to. | ||
136 | *@returns (bool) Are the equal? | ||
137 | */ | ||
100 | bool operator==( const T *src ) const | 138 | bool operator==( const T *src ) const |
101 | { | 139 | { |
102 | return pData == src; | 140 | return pData == src; |
103 | } | 141 | } |
104 | 142 | ||
143 | /** | ||
144 | * Boolean cast operator. Do we have a pointer? | ||
145 | */ | ||
105 | operator bool() const | 146 | operator bool() const |
106 | { | 147 | { |
107 | return pRefCnt != NULL; | 148 | return pRefCnt != NULL; |
108 | } | 149 | } |
109 | 150 | ||
151 | /** | ||
152 | * Do we have a pointer? | ||
153 | *@returns (bool) Do we have a pointer? | ||
154 | */ | ||
110 | bool isSet() const | 155 | bool isSet() const |
111 | { | 156 | { |
112 | return pRefCnt != NULL; | 157 | 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 | |||
22 | Stream(); | 22 | Stream(); |
23 | virtual ~Stream(); | 23 | virtual ~Stream(); |
24 | 24 | ||
25 | /** | ||
26 | * Close the stream. | ||
27 | */ | ||
25 | virtual void close() = 0; | 28 | virtual void close() = 0; |
29 | |||
30 | /** | ||
31 | * Read data from the stream into a buffer. | ||
32 | *@param pBuf (void *) Buffer which will be filled. | ||
33 | *@param nBytes (size_t) Max data to read. | ||
34 | *@returns (size_t) Amount of data read. | ||
35 | */ | ||
26 | virtual size_t read( void *pBuf, size_t nBytes ) = 0; | 36 | virtual size_t read( void *pBuf, size_t nBytes ) = 0; |
37 | |||
38 | /** | ||
39 | * Write data to the stream. | ||
40 | *@param pBuf (const void *) The data to be written. | ||
41 | *@param nBytes (size_t) Amount of data to write from pBuf. | ||
42 | *@returns (size_t) Amount of data actually written. | ||
43 | */ | ||
27 | virtual size_t write( const void *pBuf, size_t nBytes ) = 0; | 44 | virtual size_t write( const void *pBuf, size_t nBytes ) = 0; |
28 | 45 | ||
46 | /** | ||
47 | * Get the current position in the stream. | ||
48 | *@returns (long) The current position in the stream. | ||
49 | */ | ||
29 | virtual long tell() = 0; | 50 | virtual long tell() = 0; |
51 | |||
52 | /** | ||
53 | * Seek to a position in the stream relative to the current position. | ||
54 | *@param offset (long) Offset from current position to seek to. | ||
55 | */ | ||
30 | virtual void seek( long offset ) = 0; | 56 | virtual void seek( long offset ) = 0; |
57 | |||
58 | /** | ||
59 | * Set position in the stream relative to the start of the stream. | ||
60 | *@param pos (long) The position. | ||
61 | */ | ||
31 | virtual void setPos( long pos ) = 0; | 62 | virtual void setPos( long pos ) = 0; |
63 | |||
64 | /** | ||
65 | * Set position in the stream relative to the end of the stream. | ||
66 | *@param pos (long) The position. | ||
67 | */ | ||
32 | virtual void setPosEnd( long pos ) = 0; | 68 | virtual void setPosEnd( long pos ) = 0; |
69 | |||
70 | /** | ||
71 | * Are we at the end of the stream? | ||
72 | *@returns (bool) Are we at the end of the stream? | ||
73 | */ | ||
33 | virtual bool isEOS() = 0; | 74 | virtual bool isEOS() = 0; |
75 | |||
76 | /** | ||
77 | * Is the stream open? | ||
78 | *@returns (bool) Is the stream open? | ||
79 | */ | ||
34 | virtual bool isOpen() = 0; | 80 | virtual bool isOpen() = 0; |
35 | 81 | ||
82 | /** | ||
83 | * Flush any data still held in buffers. | ||
84 | */ | ||
36 | virtual void flush() = 0; | 85 | virtual void flush() = 0; |
37 | 86 | ||
38 | /** | 87 | /** |
@@ -71,7 +120,16 @@ namespace Bu | |||
71 | */ | 120 | */ |
72 | virtual bool isSeekable() = 0; | 121 | virtual bool isSeekable() = 0; |
73 | 122 | ||
123 | /** | ||
124 | * Are we currently set to block mode? | ||
125 | *@returns (bool) | ||
126 | */ | ||
74 | virtual bool isBlocking() = 0; | 127 | virtual bool isBlocking() = 0; |
128 | |||
129 | /** | ||
130 | * Set stream to blocking or non-blocking mode. | ||
131 | *@param bBlocking (bool) Whether we should block or not. | ||
132 | */ | ||
75 | virtual void setBlocking( bool bBlocking=true ) = 0; | 133 | virtual void setBlocking( bool bBlocking=true ) = 0; |
76 | 134 | ||
77 | public: // Filters | 135 | public: // Filters |