2
0

tool-stdio.h 3.6 KB

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