You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.3 KiB

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