stringvector.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef NULLOSFT_MEDIALIBRARY_STRINGVECTOR_HEADER
  2. #define NULLOSFT_MEDIALIBRARY_STRINGVECTOR_HEADER
  3. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  4. #pragma once
  5. #endif
  6. // Manages strings as array. Strings a copied to the continues buffer which make it fast to access data
  7. #include <windows.h>
  8. class StringVector
  9. {
  10. public:
  11. StringVector(size_t cchAllocate = 0, int cchAllocateStep = 32);
  12. virtual ~StringVector(void);
  13. public:
  14. size_t Add(const wchar_t *entry, int cchLen); // returns index of a new created string object;
  15. size_t Add(const wchar_t *entry) { return Add(entry, -1); }
  16. BOOL Remove(size_t index);
  17. size_t Count(void); // returns count;
  18. void TrimCount(size_t newCount);
  19. void Clear(void); // makes it empty;
  20. // void Vacuum(void); // compact space;
  21. LPCWSTR GetString(size_t index); // returns string from index;
  22. int GetStringLength(size_t index); // returns string length;
  23. size_t FindString(LCID lcid, LPCWSTR string, int cchLen = -1, BOOL igonreCase = FALSE); // returns index of the string if found or -1 if no string. (uses CompareString() function)
  24. int SetAllocateStep(int cchNewStep); // Sets new allocate step and returns previous one (if newStep < 1 then just return current one).
  25. size_t GetCbAllocated(void); // returns amount of allocated memory
  26. size_t GetCchAllocated(void); // returns amount of allocated memory
  27. private:
  28. typedef struct _RECORD { size_t offset; int length; } RECORD, *HRECORD;
  29. protected:
  30. HRECORD pointers;
  31. size_t ptCount;
  32. size_t ptAllocated;
  33. LPWSTR buffer;
  34. size_t cchBuffer;
  35. LPWSTR tail;
  36. int allocateStep;
  37. };
  38. #endif //NULLOSFT_MEDIALIBRARY_STRINGVECTOR_HEADER