__reader.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #ifndef AFUN_READER_H_
  2. #define AFUN_READER_H_
  3. #include <stdio.h>
  4. #include "aFunCoreExport.h" // reader.h 不包含 aFunCoreExport.h
  5. #include "tool.hpp"
  6. #include "reader.hpp"
  7. #define DEFAULT_BUF_SIZE (1024)
  8. #define NEW_BUF_SIZE (512)
  9. typedef struct af_Reader af_Reader;
  10. typedef size_t readerFunc(void *data, char *dest, size_t len, int *mode);
  11. NEW_DLC_SYMBOL(readerFunc, readerFunc);
  12. typedef void destructReaderFunc(void *data);
  13. NEW_DLC_SYMBOL(destructReaderFunc, destructReaderFunc);
  14. struct af_Reader {
  15. DLC_SYMBOL(readerFunc) read_func;
  16. DLC_SYMBOL(destructReaderFunc) destruct;
  17. void *data;
  18. size_t data_size;
  19. char *buf;
  20. size_t buf_size; // buf的长度-1
  21. char *read;
  22. bool read_end;
  23. bool read_error;
  24. FileLine line;
  25. FilePath file;
  26. bool init; // 是否初始化
  27. };
  28. /* Reader 创建与释放 */
  29. AFUN_CORE_NO_EXPORT af_Reader *makeReader(FileLine line, ConstFilePath file,
  30. DLC_SYMBOL(readerFunc) read_func, DLC_SYMBOL(destructReaderFunc) destruct_func,
  31. size_t data_size);
  32. AFUN_CORE_NO_EXPORT void freeReader(af_Reader *reader);
  33. /* Reader 初始化函数 */
  34. AFUN_CORE_NO_EXPORT af_Reader *initReader(af_Reader *reader);
  35. /* Reader 操作哈桑 */
  36. AFUN_CORE_NO_EXPORT char *readWord(size_t del_index, af_Reader *reader);
  37. AFUN_CORE_NO_EXPORT char getChar(af_Reader *reader);
  38. AFUN_CORE_NO_EXPORT void *getReaderData(af_Reader *reader);
  39. #endif //AFUN_READER_H_