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.

64 lines
1.6 KiB

  1. /*
  2. * s i m p s t r . h
  3. *
  4. * Author: Greg Friedman
  5. *
  6. * Purpose: Simple string class.
  7. *
  8. * Copyright (C) Microsoft Corp. 1998.
  9. */
  10. #ifndef __SIMPSTR_H
  11. #define __SIMPSTR_H
  12. class CSimpleString
  13. {
  14. public:
  15. CSimpleString(void) : m_pRep(NULL) { }
  16. CSimpleString(const CSimpleString& other) : m_pRep(NULL) { if (other.m_pRep) _AcquireRep(other.m_pRep); }
  17. ~CSimpleString(void) { if (m_pRep) _ReleaseRep(); }
  18. CSimpleString& operator=(const CSimpleString& other) { _AcquireRep(other.m_pRep); return *this; }
  19. BOOL operator==(const CSimpleString& rhs) const;
  20. HRESULT SetString(LPCSTR psz);
  21. HRESULT AdoptString(LPSTR psz);
  22. inline BOOL IsNull(void) const { return !m_pRep || !m_pRep->m_pszString; }
  23. inline BOOL IsEmpty(void) const { return (IsNull() || *(m_pRep->m_pszString) == 0); }
  24. inline LPCSTR GetString(void) const { return (m_pRep ? m_pRep->m_pszString : NULL); }
  25. private:
  26. struct SRep
  27. {
  28. LPCSTR m_pszString;
  29. long m_cRef;
  30. };
  31. void _AcquireRep(SRep* pRep);
  32. void _ReleaseRep();
  33. HRESULT _AllocateRep(LPCSTR pszString, BOOL fAdopted);
  34. private:
  35. SRep *m_pRep;
  36. };
  37. // compare two strings. this function can be used by any stl-type sorted collection
  38. // to satisfy the comparator requirement.
  39. inline BOOL operator<(const CSimpleString& lhs, const CSimpleString& rhs)
  40. {
  41. LPCSTR pszLeft = lhs.GetString();
  42. LPCSTR pszRight = rhs.GetString();
  43. if (!pszLeft)
  44. pszLeft = "";
  45. if (!pszRight)
  46. pszRight = "";
  47. return (lstrcmp(pszLeft, pszRight) < 0);
  48. }
  49. #endif