]> www.ginac.de Git - cln.git/blob - include/cln/integer_io.h
Make index variables uintC.
[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 // Undocumented 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 // Documented input functions
33
34 inline std::istream& operator>> (std::istream& stream, cl_I& result)
35 {
36         extern cl_read_flags cl_I_read_flags;
37         result = read_integer(stream,cl_I_read_flags);
38         return stream;
39 }
40
41
42 // Undocumented output functions
43
44 // Liefert zu einem Integer >=0  (write-to-string integer :base 10 :radix nil),
45 // also die Ziffernfolge als String.
46 // Mit malloc_hook() alloziert, mit free_hook() freizugeben.
47 extern char * cl_decimal_string (const cl_I& x);
48
49 // Gibt ein Integer aus.
50 // print_integer(stream,base,z);
51 // > z: Integer
52 // > base: Basis (>=2, <=36)
53 // > stream: Stream
54 extern void print_integer (std::ostream& stream, unsigned int base, const cl_I& z);
55 // Dasselbe als String. Mit malloc_hook() alloziert, mit free_hook() freizugeben.
56 extern char * print_integer_to_string (unsigned int base, const cl_I& z);
57
58
59 // Documented output functions
60
61 inline void fprintdecimal (std::ostream& stream, const cl_I& x)
62 {
63         print_integer(stream,10,x);
64 }
65
66 inline void fprintbinary (std::ostream& stream, const cl_I& x)
67 {
68         print_integer(stream,2,x);
69 }
70
71 inline void fprintoctal (std::ostream& stream, const cl_I& x)
72 {
73         print_integer(stream,8,x);
74 }
75
76 inline void fprinthexadecimal (std::ostream& stream, const cl_I& x)
77 {
78         print_integer(stream,16,x);
79 }
80
81 // Gibt eine Zahl aus.
82 // print_integer(stream,flags,z);
83 // > z: Zahl
84 // > stream: Stream
85 // > flags: Ausgabe-Parameter
86 extern void print_integer (std::ostream& stream, const cl_print_flags& flags, const cl_I& z);
87 extern void print_integer (std::ostream& stream, const cl_print_number_flags& flags, const cl_I& z);
88 extern void print_integer (std::ostream& stream, const cl_print_real_flags& flags, const cl_I& z);
89 extern void print_integer (std::ostream& stream, const cl_print_rational_flags& flags, const cl_I& z);
90
91 // The following does strictly the same as the general `fprint' for numbers.
92 // It is here only so that you don't need the rational number printer
93 // in order to print an integer. ("Treeshaking")
94
95 inline void fprint (std::ostream& stream, const cl_I& x)
96 {
97         extern cl_print_flags default_print_flags;
98         print_integer(stream,default_print_flags,x);
99 }
100
101 CL_DEFINE_PRINT_OPERATOR(cl_I)
102
103 }  // namespace cln
104
105 #endif /* _CL_INTEGER_IO_H */