Source code of Windows XP (NT5)
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.

96 lines
1.7 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. History:
  6. --*/
  7. #include "precomp.h"
  8. #include <assert.h>
  9. #include "pathutl.h"
  10. CRelativeObjectPath::CRelativeObjectPath()
  11. : m_pPath(NULL), m_wszRelPath(NULL), m_Parser( e_ParserAcceptAll )
  12. {
  13. }
  14. CRelativeObjectPath::~CRelativeObjectPath()
  15. {
  16. delete m_wszRelPath;
  17. if ( m_pPath != NULL )
  18. {
  19. m_Parser.Free( m_pPath );
  20. }
  21. }
  22. LPCWSTR CRelativeObjectPath::GetPath( )
  23. {
  24. assert( m_pPath != NULL );
  25. if ( m_wszRelPath != NULL )
  26. {
  27. return m_wszRelPath;
  28. }
  29. int nRes = m_Parser.Unparse( m_pPath, &m_wszRelPath );
  30. assert( nRes == CObjectPathParser::NoError );
  31. return m_wszRelPath;
  32. }
  33. BOOL CRelativeObjectPath::Parse( LPCWSTR wszPath )
  34. {
  35. int nRes;
  36. //
  37. // cannot save this relpath because it may not be normalized yet.
  38. //
  39. LPWSTR wszRelPath = CObjectPathParser::GetRelativePath( (LPWSTR)wszPath );
  40. if ( wszRelPath == NULL )
  41. {
  42. nRes = m_Parser.Parse( wszPath, &m_pPath );
  43. }
  44. else
  45. {
  46. nRes = m_Parser.Parse( wszRelPath, &m_pPath );
  47. }
  48. if ( nRes == CObjectPathParser::NoError )
  49. {
  50. if ( m_pPath->m_dwNumKeys == 1 )
  51. {
  52. delete m_pPath->m_paKeys[0]->m_pName;
  53. m_pPath->m_paKeys[0]->m_pName = NULL;
  54. }
  55. return TRUE;
  56. }
  57. return FALSE;
  58. }
  59. BOOL CRelativeObjectPath::operator==( CRelativeObjectPath& rOther )
  60. {
  61. LPCWSTR wszRelPathA = GetPath();
  62. LPCWSTR wszRelPathB = rOther.GetPath();
  63. assert( wszRelPathA != NULL );
  64. assert( wszRelPathB != NULL );
  65. if (!wszRelPathA || !wszRelPathB)
  66. return FALSE;
  67. return _wcsicmp( wszRelPathA, wszRelPathB ) == 0;
  68. }