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 
58 {
59  char *cache;
60  char *writeBuffer;
61  size_t cacheLength, writeBufferLength;
62  BOOL writeBufferEnabled;
63  BOOL blocking;
64  BOOL waitingForDelimiter;
65 }
66 
67 #ifdef OF_HAVE_PROPERTIES
68 @property (getter=isBlocking) BOOL blocking;
69 @property (readonly, getter=isAtEndOfStream) BOOL atEndOfStream;
70 #endif
71 
77 - (BOOL)isAtEndOfStream;
78 
93 - (size_t)readIntoBuffer: (void*)buffer
94  length: (size_t)size;
95 
111  - (void)readIntoBuffer: (void*)buffer
112  exactLength: (size_t)length;
113 
138 - (void)asyncReadIntoBuffer: (void*)buffer
139  length: (size_t)length
140  target: (id)target
141  selector: (SEL)selector;
142 
165  - (void)asyncReadIntoBuffer: (void*)buffer
166  exactLength: (size_t)length
167  target: (id)target
168  selector: (SEL)selector;
169 
170 #ifdef OF_HAVE_BLOCKS
171 
191 - (void)asyncReadIntoBuffer: (void*)buffer
192  length: (size_t)length
193  block: (of_stream_async_read_block_t)block;
194 
213  - (void)asyncReadIntoBuffer: (void*)buffer
214  exactLength: (size_t)length
215  block: (of_stream_async_read_block_t)block;
216 #endif
217 
226 - (uint8_t)readInt8;
227 
236 - (uint16_t)readBigEndianInt16;
237 
246 - (uint32_t)readBigEndianInt32;
247 
256 - (uint64_t)readBigEndianInt64;
257 
266 - (float)readBigEndianFloat;
267 
276 - (double)readBigEndianDouble;
277 
290 - (size_t)readBigEndianInt16sIntoBuffer: (uint16_t*)buffer
291  count: (size_t)nInt16s;
292 
305 - (size_t)readBigEndianInt32sIntoBuffer: (uint32_t*)buffer
306  count: (size_t)nInt32s;
307 
320 - (size_t)readBigEndianInt64sIntoBuffer: (uint64_t*)buffer
321  count: (size_t)nInt64s;
322 
335 - (size_t)readBigEndianFloatsIntoBuffer: (float*)buffer
336  count: (size_t)nFloats;
337 
350 - (size_t)readBigEndianDoublesIntoBuffer: (double*)buffer
351  count: (size_t)nDoubles;
352 
361 - (uint16_t)readLittleEndianInt16;
362 
371 - (uint32_t)readLittleEndianInt32;
372 
381 - (uint64_t)readLittleEndianInt64;
382 
391 - (float)readLittleEndianFloat;
392 
401 - (double)readLittleEndianDouble;
402 
415 - (size_t)readLittleEndianInt16sIntoBuffer: (uint16_t*)buffer
416  count: (size_t)nInt16s;
417 
430 - (size_t)readLittleEndianInt32sIntoBuffer: (uint32_t*)buffer
431  count: (size_t)nInt32s;
432 
445 - (size_t)readLittleEndianInt64sIntoBuffer: (uint64_t*)buffer
446  count: (size_t)nInt64s;
447 
460 - (size_t)readLittleEndianFloatsIntoBuffer: (float*)buffer
461  count: (size_t)nFloats;
462 
475 - (size_t)readLittleEndianDoublesIntoBuffer: (double*)buffer
476  count: (size_t)nDoubles;
477 
488 - (OFDataArray*)readDataArrayWithSize: (size_t)size;
489 
501 - (OFDataArray*)readDataArrayWithItemSize: (size_t)itemSize
502  count: (size_t)nItems;
503 
510 - (OFDataArray*)readDataArrayTillEndOfStream;
511 
526 - (OFString*)readStringWithLength: (size_t)length;
527 
543 - (OFString*)readStringWithLength: (size_t)length
544  encoding: (of_string_encoding_t)encoding;
545 
552 - (OFString*)readLine;
553 
562 - (OFString*)readLineWithEncoding: (of_string_encoding_t)encoding;
563 
577 - (void)asyncReadLineWithTarget: (id)target
578  selector: (SEL)selector;
579 
594 - (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
595  target: (id)target
596  selector: (SEL)selector;
597 
598 #ifdef OF_HAVE_BLOCKS
599 
608 - (void)asyncReadLineWithBlock: (of_stream_async_read_line_block_t)block;
609 
620 - (void)asyncReadLineWithEncoding: (of_string_encoding_t)encoding
621  block: (of_stream_async_read_line_block_t)block;
622 #endif
623 
631 - (OFString*)tryReadLine;
632 
642 - (OFString*)tryReadLineWithEncoding: (of_string_encoding_t)encoding;
643 
652 - (OFString*)readTillDelimiter: (OFString*)delimiter;
653 
663 - (OFString*)readTillDelimiter: (OFString*)delimiter
664  encoding: (of_string_encoding_t)encoding;
665 
675 - (OFString*)tryReadTillDelimiter: (OFString*)delimiter;
676 
687 - (OFString*)tryReadTillDelimiter: (OFString*)delimiter
688  encoding: (of_string_encoding_t)encoding;
689 
695 - (BOOL)writeBufferEnabled;
696 
702 - (void)setWriteBufferEnabled: (BOOL)enable;
703 
707 - (void)flushWriteBuffer;
708 
715 - (void)writeBuffer: (const void*)buffer
716  length: (size_t)length;
717 
723 - (void)writeInt8: (uint8_t)int8;
724 
730 - (void)writeBigEndianInt16: (uint16_t)int16;
731 
737 - (void)writeBigEndianInt32: (uint32_t)int32;
738 
744 - (void)writeBigEndianInt64: (uint64_t)int64;
745 
751 - (void)writeBigEndianFloat: (float)float_;
752 
758 - (void)writeBigEndianDouble: (double)double_;
759 
769 - (size_t)writeBigEndianInt16s: (const uint16_t*)buffer
770  count: (size_t)nInt16s;
771 
781 - (size_t)writeBigEndianInt32s: (const uint32_t*)buffer
782  count: (size_t)nInt32s;
783 
793 - (size_t)writeBigEndianInt64s: (const uint64_t*)buffer
794  count: (size_t)nInt64s;
795 
805 - (size_t)writeBigEndianFloats: (const float*)buffer
806  count: (size_t)nFloats;
807 
817 - (size_t)writeBigEndianDoubles: (const double*)buffer
818  count: (size_t)nDoubles;
819 
825 - (void)writeLittleEndianInt16: (uint16_t)int16;
826 
832 - (void)writeLittleEndianInt32: (uint32_t)int32;
833 
839 - (void)writeLittleEndianInt64: (uint64_t)int64;
840 
846 - (void)writeLittleEndianFloat: (float)float_;
847 
853 - (void)writeLittleEndianDouble: (double)double_;
854 
864 - (size_t)writeLittleEndianInt16s: (const uint16_t*)buffer
865  count: (size_t)nInt16s;
866 
876 - (size_t)writeLittleEndianInt32s: (const uint32_t*)buffer
877  count: (size_t)nInt32s;
878 
888 - (size_t)writeLittleEndianInt64s: (const uint64_t*)buffer
889  count: (size_t)nInt64s;
890 
900 - (size_t)writeLittleEndianFloats: (const float*)buffer
901  count: (size_t)nFloats;
902 
912 - (size_t)writeLittleEndianDoubles: (const double*)buffer
913  count: (size_t)nDoubles;
914 
921 - (size_t)writeDataArray: (OFDataArray*)dataArray;
922 
929 - (size_t)writeString: (OFString*)string;
930 
937 - (size_t)writeLine: (OFString*)string;
938 
948 - (size_t)writeFormat: (OFConstantString*)format, ...;
949 
960 - (size_t)writeFormat: (OFConstantString*)format
961  arguments: (va_list)arguments;
962 
968 - (size_t)pendingBytes;
969 
975 - (BOOL)isBlocking;
976 
985 - (void)setBlocking: (BOOL)enable;
986 
992 - (int)fileDescriptorForReading;
993 
999 - (int)fileDescriptorForWriting;
1000 
1004 - (void)close;
1005 
1017 - (size_t)lowlevelReadIntoBuffer: (void*)buffer
1018  length: (size_t)length;
1019 
1030 - (void)lowlevelWriteBuffer: (const void*)buffer
1031  length: (size_t)length;
1032 
1043 - (BOOL)lowlevelIsAtEndOfStream;
1044 
1045 - (BOOL)OF_isWaitingForDelimiter;
1046 @end