tool-stdio.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #ifndef AFUN_STDIO_H
  2. #define AFUN_STDIO_H
  3. #include <cstdio>
  4. #include <cinttypes>
  5. #include "tool-type.h"
  6. #include "aFunToolExport.h"
  7. namespace aFuntool {
  8. AFUN_TOOL_EXPORT int fgets_stdin(char **dest, int len);
  9. AFUN_TOOL_EXPORT bool checkStdin();
  10. AFUN_TOOL_EXPORT bool fclear_stdin();
  11. static bool clear_ferror(FILE *file);
  12. static bool clear_stdin();
  13. }
  14. #ifdef aFunWIN32_NO_CYGWIN
  15. #ifdef _MSC_VER
  16. #pragma warning(disable : 5105) // 关闭 5105 的警告输出 (Windows.h中使用)
  17. #endif
  18. #include <conio.h>
  19. #include <io.h>
  20. #include <Windows.h>
  21. namespace aFuntool {
  22. AFUN_TOOL_EXPORT void stdio_signal_init(bool signal);
  23. AFUN_TOOL_EXPORT bool stdio_check_signal();
  24. AFUN_TOOL_EXPORT int convertMultiByte(char **dest, const char *str, UINT from, UINT to); // win32 特有函数
  25. AFUN_TOOL_EXPORT int convertWideByte(wchar_t **dest, const char *str, UINT from); // win32 特有函数
  26. AFUN_TOOL_EXPORT int convertFromWideByte(char **dest, const wchar_t *str, UINT to);
  27. AFUN_TOOL_EXPORT int fgetc_stdin();
  28. AFUN_TOOL_EXPORT char *fgets_stdin_(char *buf, size_t len);
  29. AFUN_TOOL_EXPORT int fungetc_stdin(int ch);
  30. AFUN_TOOL_EXPORT int fputs_std_(const char *str, FILE *std);
  31. static int fputs_stdout(const char *str);
  32. static int fputs_stderr(const char *str);
  33. AFUN_TOOL_EXPORT size_t vprintf_std_(FILE *std, size_t buf_len, const char *format, va_list ap);
  34. static size_t vprintf_stderr(size_t buf_len, const char *format, va_list ap);
  35. static size_t vprintf_stdout(size_t buf_len, const char *format, va_list ap);
  36. static size_t printf_stdout(size_t buf_len, const char *format, ...);
  37. static size_t printf_stderr(size_t buf_len, const char *format, ...);
  38. }
  39. #else
  40. namespace aFuntool {
  41. static int fgetc_stdin();
  42. static int fgets_stdin_(char *buf, int len, FILE *file);
  43. static int fungetc_stdin(char ch);
  44. static int fputs_stdout(const char *str);
  45. static int fputs_stderr(const char *str);
  46. static int vprintf_stdout(size_t, const char *format, va_list ap);
  47. static int vprintf_stderr(size_t, const char *format, va_list ap);
  48. static size_t printf_stdout(size_t, const char *format, ...);
  49. static size_t printf_stderr(size_t, const char *format, ...);
  50. }
  51. #endif
  52. namespace aFuntool {
  53. class OutStream {
  54. typedef size_t PrintFunction(size_t, const char *, ...);
  55. PrintFunction *func;
  56. public:
  57. inline explicit OutStream(PrintFunction *func_);
  58. inline OutStream &operator<<(signed char a);
  59. inline OutStream &operator<<(short a);
  60. inline OutStream &operator<<(int a);
  61. inline OutStream &operator<<(long a);
  62. inline OutStream &operator<<(long long a);
  63. inline OutStream &operator<<(unsigned char a);
  64. inline OutStream &operator<<(unsigned short a);
  65. inline OutStream &operator<<(unsigned int a);
  66. inline OutStream &operator<<(unsigned long a);
  67. inline OutStream &operator<<(unsigned long long a);
  68. inline OutStream &operator<<(float a);
  69. inline OutStream &operator<<(double a);
  70. inline OutStream &operator<<(long double a);
  71. inline OutStream &operator<<(const char *a);
  72. inline OutStream &operator<<(const std::string &a);
  73. inline OutStream &operator<<(const void *a);
  74. };
  75. AFUN_TOOL_EXPORT extern OutStream cout;
  76. AFUN_TOOL_EXPORT extern OutStream cerr;
  77. }
  78. #include "tool-stdio.inline.h"
  79. #endif //AFUN_STDIO_H