]> www.ginac.de Git - cln.git/blob - include/cln/io.h
Rework of autoconfiscation infrastructure
[cln.git] / include / cln / io.h
1 // I/O through <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 // compatibility:
22 typedef std::istream& cl_istream;
23 typedef std::ostream& cl_ostream;
24 extern std::ostream* cl_debugout_stream;
25 #define cl_debugout  (*cl_debugout_stream)
26
27 // Elementary operations on std::istream&
28
29 #define cl_EOF  (-1)
30
31 inline int freadchar (std::istream& stream)
32 {
33         char c;
34         if (stream.get(c))
35                 return c;
36         else
37                 // EOF or error
38                 return cl_EOF;
39 }
40
41 inline int funreadchar (std::istream& stream, int c)
42 {
43         if (c != cl_EOF)
44                 stream.putback((char)c);
45         return c;
46 }
47
48 // Elementary operations on std::ostream&
49
50 inline void fprintchar (std::ostream& stream, char c)
51 {
52         stream.put(c);
53 }
54
55 inline void fprint (std::ostream& stream, const char * string)
56 {
57         stream << string;
58 }
59
60
61 extern void fprintdecimal (std::ostream& stream, unsigned long x);
62 extern void fprintdecimal (std::ostream& stream, long x);
63
64 inline void fprintdecimal (std::ostream& stream, unsigned int x)
65 {
66         fprintdecimal(stream,(unsigned long)x);
67 }
68 inline void fprintdecimal (std::ostream& stream, int x)
69 {
70         fprintdecimal(stream,(long)x);
71 }
72
73 extern void fprinthexadecimal (std::ostream& stream, unsigned long x);
74 extern void fprinthexadecimal (std::ostream& stream, long x);
75
76 inline void fprinthexadecimal (std::ostream& stream, unsigned int x)
77 {
78         fprinthexadecimal(stream,(unsigned long)x);
79 }
80 inline void fprinthexadecimal (std::ostream& stream, int x)
81 {
82         fprinthexadecimal(stream,(long)x);
83 }
84
85
86 class cl_print_flags;
87 class cl_print_number_flags;
88 class cl_print_real_flags;
89 class cl_print_rational_flags;
90 class cl_print_float_flags;
91 CL_REQUIRE(cl_prin_globals)
92
93
94 // Define the customary << and >> operators.
95
96 #define CL_DEFINE_PRINT_OPERATOR(_class_)  \
97 inline std::ostream& operator<< (std::ostream& stream, const _class_& x)        \
98 {                                                                       \
99         fprint(stream,x);                                               \
100         return stream;                                                  \
101 }
102         
103 }  // namespace cln
104
105 #endif /* _CL_IO_H */