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.

103 lines
3.3 KiB

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