Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.0 KiB

  1. #ifndef _INC_DSKQUOTA_DBLNUL_H
  2. #define _INC_DSKQUOTA_DBLNUL_H
  3. //
  4. // For iterating over items in a double-nul terminated list of
  5. // text strings.
  6. //
  7. class DblNulTermListIter
  8. {
  9. public:
  10. explicit DblNulTermListIter(LPCTSTR pszList)
  11. : m_pszList(pszList),
  12. m_pszCurrent(pszList) { }
  13. ~DblNulTermListIter(void) { }
  14. bool Next(LPCTSTR *ppszItem);
  15. void Reset(void)
  16. { m_pszCurrent = m_pszList; }
  17. private:
  18. LPCTSTR m_pszList;
  19. LPCTSTR m_pszCurrent;
  20. };
  21. class DblNulTermList
  22. {
  23. public:
  24. explicit DblNulTermList(int cchGrow = MAX_PATH)
  25. : m_psz(new TCHAR[1]),
  26. m_cchAlloc(1),
  27. m_cchUsed(0),
  28. m_cStrings(0),
  29. m_cchGrow(cchGrow) { *m_psz = TEXT('\0'); }
  30. ~DblNulTermList(void)
  31. { delete[] m_psz; }
  32. bool AddString(const CString& s)
  33. { return AddString(s.Cstr(), s.Length()); }
  34. bool AddString(LPCTSTR psz)
  35. { return AddString(psz, psz ? lstrlen(psz) : 0); }
  36. int Count(void) const
  37. { return m_cStrings; }
  38. operator LPCTSTR ()
  39. { return m_psz; }
  40. DblNulTermListIter CreateIterator(void) const
  41. { return DblNulTermListIter(m_psz); }
  42. #if DBG
  43. void Dump(void) const;
  44. #endif
  45. private:
  46. LPTSTR m_psz; // The text buffer.
  47. int m_cchAlloc; // Total allocation in chars.
  48. int m_cchUsed; // Total used excluding FINAL nul term.
  49. int m_cchGrow; // How much to grow each expansion.
  50. int m_cStrings; // Count of strings in list.
  51. bool AddString(LPCTSTR psz, int cch);
  52. bool Grow(void);
  53. //
  54. // Prevent copy.
  55. //
  56. DblNulTermList(const DblNulTermList& rhs);
  57. DblNulTermList& operator = (const DblNulTermList& rhs);
  58. };
  59. #endif // INC_DSKQUOTA_DBLNUL_H