datablock.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. #ifndef __DATABLOCK_H
  2. #define __DATABLOCK_H
  3. #include <stdio.h>
  4. #include <cstdint>
  5. #include "datastring.h"
  6. #include "idisposable.h"
  7. class datablock:public datastring,public idisposable
  8. {
  9. public:
  10. datablock(int len); // Makes a garbage string of len bytes. Allocates capacity to len+1.
  11. datablock(const char *input); // Makes a deep copy of input.
  12. datablock(const char *input,int len); // Makes a deep copy of input.
  13. datablock(datastring input); // Makes a deep copy of input.
  14. ~datablock();
  15. int capacity; // The total number of bytes in data[].
  16. void dispose(); // "delete this"; Used by idisposable base class.
  17. datablock *clone(); // Makes a shallow copy by incrementing usage.
  18. void initialize(int len);
  19. void clear(); // Deallocate data[] and set capacity,length to 0.
  20. datablock &operator=(datastring input);
  21. datablock &operator=(const char *input);
  22. datablock &operator+=(datastring input);
  23. datablock &operator+=(const char *input);
  24. datablock &operator=(int64_t input);
  25. datablock &operator+=(int64_t input);
  26. datablock &operator+=(datablock &input);
  27. bool append(const char *input,int len);
  28. int compare(datastring &item);
  29. int compare(datablock &item);
  30. bool alter(datastring &item,int offset); // Alters the data block starting at offset.
  31. };
  32. #endif