1
0

grow_buf.h 977 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef _PFC_GROW_BUF_H_
  2. #define _PFC_GROW_BUF_H_
  3. class grow_buf
  4. {
  5. private:
  6. void * ptr;
  7. int size,used;
  8. void makespace(int);
  9. public:
  10. grow_buf(int init_size = 0)
  11. {
  12. if (init_size<8) init_size=8;
  13. size = 0;
  14. used = 0;
  15. ptr = 0;
  16. makespace(init_size);
  17. }
  18. ~grow_buf() {reset();}
  19. inline const void * get_ptr_c() const {return ptr;}
  20. inline void * get_ptr() {return ptr;}
  21. inline int get_size() const {return used;}
  22. inline void truncate(int z) {if (z<used) used=z;}
  23. void * finish();
  24. void reset();
  25. bool write(const void * data, size_t bytes);
  26. void write_ptr(const void * data, int bytes,int offset);
  27. inline void write_byte(BYTE b) {write(&b,1);}
  28. inline void write_word(WORD w) {write(&w,2);}
  29. inline void write_dword(DWORD dw) {write(&dw,4);}
  30. inline void write_byte_ptr(BYTE b,int ptr) {write_ptr(&b,1,ptr);}
  31. inline void write_word_ptr(WORD w,int ptr) {write_ptr(&w,2,ptr);}
  32. inline void write_dword_ptr(DWORD dw,int ptr) {write_ptr(&dw,4,ptr);}
  33. };
  34. #endif