scide: LookupDialog - redo lookup on classes after partial lookup
[supercollider.git] / SCClassLibrary / Common / Unix / UnixFILE.sc
blobd00c7418f39224dc97f36d81c49a8b3d1818e749
1 UnixFILE : IOStream {
2         // abstract class. Use File or Pipe.
4         classvar <openFiles;
5         var fileptr;
6         // this only supports file sizes < 2^31 for now
8         *closeAll {
9                 if (openFiles.notNil, {
10                         openFiles.copy.do({ arg file; file.close; });
11                 });
12                 openFiles = nil;
13         }
14         isOpen {
15                 ^fileptr.notNil
16         }
18         next { ^this.getChar }
19         nextN { arg n;
20                 ^String.fill(n, { this.next; });
21         }
22         contents {
23                 ^this.readAllString;
24         }
26         put { arg item; this.write(item); }
27         putAll { arg aCollection;
28                 if (aCollection.isKindOf(RawArray), {
29                         this.write( aCollection );
30                 },{
31                         aCollection.do({ arg item; this.write(item) });
32                 });
33         }
35         flush {
36                 _FileFlush
37                 ^this.primitiveFailed
38         }
40         write { arg item;
41                 /* writes any of the following items in big endian byte order:
42                         a double float,
43                         a 32 bit int,
44                         a char,
45                         the name of a Symbol as chars,
46                         RawArrays,
47                                 (i.e. Strings, Int8Arrays, Int16Arrays,
48                                 Signals, etc.)
49                 */
50                 _FileWrite
51                 ^this.primitiveFailed;
52         }
53         read { arg buffer;
54                 // reads big endian data
55                 // buffer should be a RawArray.
56                 // fills the buffer, or as much is available.
57                 // returns bytes read.
58                 _FileReadRaw;
59                 ^this.primitiveFailed;
60         }
62         writeLE { arg item;
63                 /* writes any of the following items in little endian byte order:
64                         a double float,
65                         a 32 bit int,
66                         a char,
67                         the name of a Symbol as chars,
68                         RawArrays,
69                                 (i.e. Strings, Int8Arrays, Int16Arrays,
70                                 Signals, etc.)
71                 */
72                 _FileWriteLE
73                 ^this.primitiveFailed;
74         }
75         readLE { arg buffer;
76                 // reads little endian data
77                 // buffer should be a RawArray.
78                 // fills the buffer, or as much is available.
79                 // returns bytes read.
80                 _FileReadRawLE;
81                 ^this.primitiveFailed;
82         }
84         getLine { arg maxSize=1024;
85                 var string;
86                 string = String.newClear(maxSize);
87                 ^this.prGetLine(string);
88         }
89         prGetLine { arg argString;
90                 // returns a string up to lesser of next newline
91                 // or length-1 of the argument string
92                 _FileReadLine;
93                 ^this.primitiveFailed;
94         }
96         // for more fine grained control these read and write a single
97         // item of the specified type and size
98         getChar { _FileGetChar; ^this.primitiveFailed; }
99         getInt8 { _FileGetInt8; ^this.primitiveFailed; }
100         getInt16 { _FileGetInt16; ^this.primitiveFailed; }
101         getInt32 { _FileGetInt32; ^this.primitiveFailed; }
102         getFloat { _FileGetFloat; ^this.primitiveFailed; }
103         getDouble { _FileGetDouble; ^this.primitiveFailed; }
104         getInt16LE { _FileGetInt16LE; ^this.primitiveFailed; }
105         getInt32LE { _FileGetInt32LE; ^this.primitiveFailed; }
106         getFloatLE { _FileGetFloatLE; ^this.primitiveFailed; }
107         getDoubleLE { _FileGetDoubleLE; ^this.primitiveFailed; }
109         putChar { arg aChar; _FilePutChar; ^this.primitiveFailed; }
110         putInt8 { arg anInteger; _FilePutInt8; ^this.primitiveFailed; }
111         putInt16 { arg anInteger; _FilePutInt16; ^this.primitiveFailed; }
112         putInt32 { arg anInteger; _FilePutInt32; ^this.primitiveFailed; }
113         putFloat { arg aFloat; _FilePutFloat; ^this.primitiveFailed; }
114         putDouble { arg aFloat; _FilePutDouble; ^this.primitiveFailed; }
115         putInt16LE { arg anInteger; _FilePutInt16LE; ^this.primitiveFailed; }
116         putInt32LE { arg anInteger; _FilePutInt32LE; ^this.primitiveFailed; }
117         putFloatLE { arg aFloat; _FilePutFloatLE; ^this.primitiveFailed; }
118         putDoubleLE { arg aFloat; _FilePutDoubleLE; ^this.primitiveFailed; }
119         putString { arg aString; _FilePutString; ^this.primitiveFailed; }
120         putString0 { arg aString;
121                 this.putString(aString);
122                 this.putInt8(0);
123         }
124         putPascalString { arg aString;
125                 this.putInt8(aString.size);
126                 this.putString(aString);
127         }
128         getPascalString {
129                 var size, string;
130                 size = this.getInt8;
131                 string = String.newClear(size);
132                 this.read(string);
133                 ^string
134         }
135         // PRIVATE
136         addOpenFile {
137                 openFiles = openFiles.add(this);
138         }