ObjFW
 All Classes Functions Variables
OFStream.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #ifndef __STDC_LIMIT_MACROS
18 # define __STDC_LIMIT_MACROS
19 #endif
20 #ifndef __STDC_CONSTANT_MACROS
21 # define __STDC_CONSTANT_MACROS
22 #endif
23 
24 #include <stdarg.h>
25 
26 #import "OFObject.h"
27 #import "OFString.h"
28 
29 @class OFStream;
30 @class OFDataArray;
31 @class OFException;
32 
33 #ifdef OF_HAVE_BLOCKS
34 typedef BOOL (^of_stream_async_read_block_t)(OFStream*, void*, size_t,
35  OFException*);
36 typedef BOOL (^of_stream_async_read_line_block_t)(OFStream*, OFString*,
37  OFException*);
38 #endif
39 
59 {
60  char *cache;
61  char *writeBuffer;
62  size_t cacheLength, writeBufferLength;
63  BOOL writeBufferEnabled;
64  BOOL blocking;
65  BOOL waitingForDelimiter;
66 }
67 
68 #ifdef OF_HAVE_PROPERTIES
69 @property (getter=isBlocking) BOOL blocking;
70 @property (readonly, getter=isAtEndOfStream) BOOL atEndOfStream;
71 #endif
72 
78 - (BOOL)isAtEndOfStream;
79 
94 - (size_t)readIntoBuffer: (void*)buffer
95  length: (size_t)length;
96 
112  - (void)readIntoBuffer: (void*)buffer
113  exactLength: (size_t)length;
114 
139 - (void)asyncReadIntoBuffer: (void*)buffer
140  length: (size_t)length
141  target: (id)target
142  selector: (SEL)selector;
143 
166  - (void)asyncReadIntoBuffer: (void*)buffer
167  exactLength: (size_t)length
168  target: (id)target
169  selector: (SEL)selector;
170 
171 #ifdef OF_HAVE_BLOCKS
172 
192 - (void)asyncReadIntoBuffer: (void*)buffer
193  length: (size_t)length
194  block: (of_stream_async_read_block_t)block;
195 
214  - (void)asyncReadIntoBuffer: (void*)buffer
215  exactLength: (size_t)length
216  block: (of_stream_async_read_block_t)block;
217 #endif
218 
227 - (uint8_t)readInt8;
228 
237 - (uint16_t)readBigEndianInt16;
238 
247 - (uint32_t)readBigEndianInt32;
248 
257 - (uint64_t)readBigEndianInt64;
258 
267 - (float)readBigEndianFloat;
268 
277 - (double)readBigEndianDouble;
278 
291 - (size_t)readBigEndianInt16sIntoBuffer: (uint16_t*)buffer
292  count: (size_t)count;
293 
306 - (size_t)readBigEndianInt32sIntoBuffer: (uint32_t*)buffer
307  count: (size_t)count;
308 
321 - (size_t)readBigEndianInt64sIntoBuffer: (uint64_t*)buffer
322  count: (size_t)count;
323 
336 - (size_t)readBigEndianFloatsIntoBuffer: (float*)buffer
337  count: (size_t)count;
338 
351 - (size_t)readBigEndianDoublesIntoBuffer: (double*)buffer
352  count: (size_t)count;
353 
362 - (uint16_t)readLittleEndianInt16;
363 
372 - (uint32_t)readLittleEndianInt32;
373 
382 - (uint64_t)readLittleEndianInt64;
383 
392 - (float)readLittleEndianFloat;
393 
402 - (double)readLittleEndianDouble;
403 
416 - (size_t)readLittleEndianInt16sIntoBuffer: (uint16_t*)buffer
417  count: (size_t)count;
418 
431 - (size_t)readLittleEndianInt32sIntoBuffer: (uint32_t*)buffer
432  count: (size_t)count;
433 
446 - (size_t)readLittleEndianInt64sIntoBuffer: (uint64_t*)buffer
447  count: (size_t)count;
448 
461 - (size_t)readLittleEndianFloatsIntoBuffer: (float*)buffer
462  count: (size_t)count;
463 
476 - (size_t)readLittleEndianDoublesIntoBuffer: (double*)buffer
477  count: (size_t)count;
478 
489 - (OFDataArray*)readDataArrayWithSize: (size_t)size;
490 
502 - (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize
503  count: (size_t)count;
504 
511 - (OFDataArray*)readDataArrayTillEndOfStream;
512 
527 - (OFString*)readStringWithLength: (size_t)length;
528 
544 - (OFString*)readStringWithLength: (size_t)length
545  encoding: (of_string_encoding_t)encoding;
546 
553 - (OFString*)readLine;
554 
563 - (OFString*)readLineWithEncoding: (of_string_encoding_t)encoding;
564 
578 - (void)asyncReadLineWithTarget: (id)target
579  selector: (SEL)selector;
580 
595 - (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
596  target: (id)target
597  selector: (SEL)selector;
598 
599 #ifdef OF_HAVE_BLOCKS
600 
609 - (void)asyncReadLineWithBlock: (of_stream_async_read_line_block_t)block;
610 
621 - (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
622  block: (of_stream_async_read_line_block_t)block;
623 #endif
624 
632 - (OFString*)tryReadLine;
633 
643 - (OFString*)tryReadLineWithEncoding: (of_string_encoding_t)encoding;
644 
653 - (OFString*)readTillDelimiter: (OFString*)delimiter;
654 
664 - (OFString*)readTillDelimiter: (OFString*)delimiter
665  encoding: (of_string_encoding_t)encoding;
666 
676 - (OFString*)tryReadTillDelimiter: (OFString*)delimiter;
677 
688 - (OFString*)tryReadTillDelimiter: (OFString*)delimiter
689  encoding: (of_string_encoding_t)encoding;
690 
696 - (BOOL)writeBufferEnabled;
697 
703 - (void)setWriteBufferEnabled: (BOOL)enable;
704 
708 - (void)flushWriteBuffer;
709 
716 - (void)writeBuffer: (const void*)buffer
717  length: (size_t)length;
718 
724 - (void)writeInt8: (uint8_t)int8;
725 
731 - (void)writeBigEndianInt16: (uint16_t)int16;
732 
738 - (void)writeBigEndianInt32: (uint32_t)int32;
739 
745 - (void)writeBigEndianInt64: (uint64_t)int64;
746 
752 - (void)writeBigEndianFloat: (float)float_;
753 
759 - (void)writeBigEndianDouble: (double)double_;
760 
770 - (size_t)writeBigEndianInt16s: (const uint16_t*)buffer
771  count: (size_t)count;
772 
782 - (size_t)writeBigEndianInt32s: (const uint32_t*)buffer
783  count: (size_t)count;
784 
794 - (size_t)writeBigEndianInt64s: (const uint64_t*)buffer
795  count: (size_t)count;
796 
806 - (size_t)writeBigEndianFloats: (const float*)buffer
807  count: (size_t)count;
808 
818 - (size_t)writeBigEndianDoubles: (const double*)buffer
819  count: (size_t)count;
820 
826 - (void)writeLittleEndianInt16: (uint16_t)int16;
827 
833 - (void)writeLittleEndianInt32: (uint32_t)int32;
834 
840 - (void)writeLittleEndianInt64: (uint64_t)int64;
841 
847 - (void)writeLittleEndianFloat: (float)float_;
848 
854 - (void)writeLittleEndianDouble: (double)double_;
855 
865 - (size_t)writeLittleEndianInt16s: (const uint16_t*)buffer
866  count: (size_t)count;
867 
877 - (size_t)writeLittleEndianInt32s: (const uint32_t*)buffer
878  count: (size_t)count;
879 
889 - (size_t)writeLittleEndianInt64s: (const uint64_t*)buffer
890  count: (size_t)count;
891 
901 - (size_t)writeLittleEndianFloats: (const float*)buffer
902  count: (size_t)count;
903 
913 - (size_t)writeLittleEndianDoubles: (const double*)buffer
914  count: (size_t)count;
915 
922 - (size_t)writeDataArray: (OFDataArray*)dataArray;
923 
930 - (size_t)writeString: (OFString*)string;
931 
938 - (size_t)writeLine: (OFString*)string;
939 
949 - (size_t)writeFormat: (OFConstantString*)format, ...;
950 
961 - (size_t)writeFormat: (OFConstantString*)format
962  arguments: (va_list)arguments;
963 
969 - (size_t)pendingBytes;
970 
976 - (BOOL)isBlocking;
977 
986 - (void)setBlocking: (BOOL)enable;
987 
993 - (int)fileDescriptorForReading;
994 
1000 - (int)fileDescriptorForWriting;
1001 
1005 - (void)close;
1006 
1018 - (size_t)lowlevelReadIntoBuffer: (void*)buffer
1019  length: (size_t)length;
1020 
1031 - (void)lowlevelWriteBuffer: (const void*)buffer
1032  length: (size_t)length;
1033 
1044 - (BOOL)lowlevelIsAtEndOfStream;
1045 
1046 - (BOOL)OF_isWaitingForDelimiter;
1047 @end