]> www.ginac.de Git - cln.git/blob - include/cln/integer_io.h
Ensure that makeinfo ≥ 6.8 checks the @menu structure.
[cln.git] / include / cln / integer_io.h
1 // I/O of integers.
2
3 #ifndef _CL_INTEGER_IO_H
4 #define _CL_INTEGER_IO_H
5
6 #include "cln/number_io.h"
7 #include "cln/integer_class.h"
8
9 namespace cln {
10
11 // Input functions
12
13 // Wandelt eine Zeichenkette mit Integer-Syntax in ein Integer um.
14 // Punkte werden überlesen.
15 // read_integer(base,sign,string,index1,index2)
16 // > base: Lesebasis (>=2, <=36)
17 // > sign: Vorzeichen (/=0 falls negativ)
18 // > string: Simple-String (enthält Ziffern mit Wert <base und evtl. Punkt)
19 // > index1: Index der ersten Ziffer
20 // > index2: Index nach der letzten Ziffer
21 //   (also index2-index1 Ziffern, incl. evtl. Dezimalpunkt am Schluß)
22 // < ergebnis: Integer
23 extern const cl_I read_integer (unsigned int base,
24                   cl_signean sign, const char * string, uintC index1, uintC index2);
25
26 // The following does strictly the same as the general read_complex.
27 // It is here only so that you don't need the rational, complex and float number
28 // readers in order to read an integer. ("Treeshaking")
29 extern const cl_I read_integer (const cl_read_flags& flags, const char * string, const char * string_limit, const char * * end_of_parse);
30 extern const cl_I read_integer (std::istream& stream, const cl_read_flags& flags);
31
32 inline std::istream& operator>> (std::istream& stream, cl_I& result)
33 {
34         extern cl_read_flags cl_I_read_flags;
35         result = read_integer(stream,cl_I_read_flags);
36         return stream;
37 }
38
39
40 // Output functions
41
42 // Liefert zu einem Integer >=0  (write-to-string integer :base 10 :radix nil),
43 // also die Ziffernfolge als String.
44 // Mit malloc_hook() alloziert, mit free_hook() freizugeben.
45 extern char * cl_decimal_string (const cl_I& x);
46
47 // Gibt ein Integer aus.
48 // print_integer(stream,base,z);
49 // > z: Integer
50 // > base: Basis (>=2, <=36)
51 // > stream: Stream
52 extern void print_integer (std::ostream& stream, unsigned int base, const cl_I& z);
53 // Dasselbe als String. Mit malloc_hook() alloziert, mit free_hook() freizugeben.
54 extern char * print_integer_to_string (unsigned int base, const cl_I& z);
55
56 inline void fprintdecimal (std::ostream& stream, const cl_I& x)
57 {
58         print_integer(stream,10,x);
59 }
60
61 inline void fprintbinary (std::ostream& stream, const cl_I& x)
62 {
63         print_integer(stream,2,x);
64 }
65
66 inline void fprintoctal (std::ostream& stream, const cl_I& x)
67 {
68         print_integer(stream,8,x);
69 }
70
71 inline void fprinthexadecimal (std::ostream& stream, const cl_I& x)
72 {
73         print_integer(stream,16,x);
74 }
75
76 // Gibt eine Zahl aus.
77 // print_integer(stream,flags,z);
78 // > z: Zahl
79 // > stream: Stream
80 // > flags: Ausgabe-Parameter
81 extern void print_integer (std::ostream& stream, const cl_print_flags& flags, const cl_I& z);
82 extern void print_integer (std::ostream& stream, const cl_print_number_flags& flags, const cl_I& z);
83 extern void print_integer (std::ostream& stream, const cl_print_real_flags& flags, const cl_I& z);
84 extern void print_integer (std::ostream& stream, const cl_print_rational_flags& flags, const cl_I& z);
85
86 // The following does strictly the same as the general `fprint' for numbers.
87 // It is here only so that you don't need the rational number printer
88 // in order to print an integer. ("Treeshaking")
89
90 inline void fprint (std::ostream& stream, const cl_I& x)
91 {
92         extern cl_print_flags default_print_flags;
93         print_integer(stream,default_print_flags,x);
94 }
95
96 CL_DEFINE_PRINT_OPERATOR(cl_I)
97
98 }  // namespace cln
99
100 #endif /* _CL_INTEGER_IO_H */