]> www.ginac.de Git - cln.git/blob - include/cln/io.h
* All Files have been modified for inclusion of namespace cln;
[cln.git] / include / cln / io.h
1 // I/O through <stdio.h> or <iostream>
2
3 #ifndef _CL_IO_H
4 #define _CL_IO_H
5
6 #include "cln/types.h"
7 #include "cln/modules.h"
8
9 // I/O through <iostream>
10
11 #ifdef floor
12   #undef floor
13   #include <iostream>
14   #define floor cln_floor
15 #else
16   #include <iostream>
17 #endif
18
19 namespace cln {
20
21 typedef std::istream& cl_istream;
22 typedef std::ostream& cl_ostream;
23 extern cl_istream stdin;
24 extern cl_ostream stdout;
25 extern cl_ostream stderr;
26 extern std::ostream* cl_debugout_stream;
27 #define cl_debugout  (*cl_debugout_stream)
28
29 // Elementary operations on cl_istream
30
31 #define cl_EOF  (-1)
32
33 inline int freadchar (cl_istream stream)
34 {
35         char c;
36         if (stream.get(c))
37                 return c;
38         else
39                 // EOF or error
40                 return cl_EOF;
41 }
42
43 inline int funreadchar (cl_istream stream, int c)
44 {
45         if (c != cl_EOF)
46                 stream.putback((char)c);
47         return c;
48 }
49
50 // Elementary operations on cl_ostream
51
52 inline void fprintchar (cl_ostream stream, char c)
53 {
54         stream.put(c);
55 }
56
57 inline void fprint (cl_ostream stream, const char * string)
58 {
59         stream << string;
60 }
61
62
63 extern void fprintdecimal (cl_ostream stream, unsigned long x);
64 extern void fprintdecimal (cl_ostream stream, long x);
65
66 inline void fprintdecimal (cl_ostream stream, unsigned int x)
67 {
68         fprintdecimal(stream,(unsigned long)x);
69 }
70 inline void fprintdecimal (cl_ostream stream, int x)
71 {
72         fprintdecimal(stream,(long)x);
73 }
74
75 extern void fprinthexadecimal (cl_ostream stream, unsigned long x);
76 extern void fprinthexadecimal (cl_ostream stream, long x);
77
78 inline void fprinthexadecimal (cl_ostream stream, unsigned int x)
79 {
80         fprinthexadecimal(stream,(unsigned long)x);
81 }
82 inline void fprinthexadecimal (cl_ostream stream, int x)
83 {
84         fprinthexadecimal(stream,(long)x);
85 }
86
87
88 class cl_print_flags;
89 class cl_print_number_flags;
90 class cl_print_real_flags;
91 class cl_print_rational_flags;
92 class cl_print_float_flags;
93 CL_REQUIRE(cl_prin_globals)
94
95
96 // Define the customary << and >> operators.
97
98 #define CL_DEFINE_PRINT_OPERATOR(_class_)  \
99 inline cl_ostream operator<< (cl_ostream stream, const _class_& x)      \
100 {                                                                       \
101         fprint(stream,x);                                               \
102         return stream;                                                  \
103 }
104         
105 }  // namespace cln
106
107 #endif /* _CL_IO_H */