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.

121 lines
2.5 KiB

  1. #include <iostream.h>
  2. #include <afx.h>
  3. #include <afxtempl.h>
  4. #include <objbase.h>
  5. #include <afxwin.h>
  6. #include <afxole.h>
  7. #include <afxmt.h>
  8. #include <wchar.h>
  9. #include <process.h>
  10. #include <objbase.h>
  11. #include <initguid.h>
  12. #include "debug.hpp"
  13. #include "Oid.hpp"
  14. // DESCRIPTION;
  15. // constructor, implicitly construct m_nOIDs and m_szOIDs
  16. Oid::Oid()
  17. {
  18. }
  19. // DESCRIPTION:
  20. // Adds a new Oid component to the END of the internal arrays!
  21. // PARAMETERS:
  22. // (in) integer component of the Oid
  23. // (out) symbolic name of the component
  24. // RETURN VALUE:
  25. // 0 on success, -1 on failure
  26. int Oid::AddComponent(int nOidComp, const char * szOidComp)
  27. {
  28. char *szOidCopy = NULL;
  29. _VERIFY(m_nOidComp.Add((WORD)nOidComp)!=-1, -1);
  30. if (szOidComp != NULL)
  31. {
  32. szOidCopy = new char [strlen(szOidComp)+1];
  33. _VERIFY(szOidCopy != NULL, -1);
  34. strcpy(szOidCopy, szOidComp);
  35. }
  36. m_szOidComp.Add((CObject *)szOidCopy);
  37. return 0;
  38. }
  39. // DESCRIPTION:
  40. // Reverses the components of the OID from both
  41. // m_nOidComp and m_szOidComp
  42. // RETURN VALUE:
  43. // 0 on success, -1 on failure
  44. int Oid::ReverseComponents()
  45. {
  46. INT_PTR fwd, rev;
  47. for (fwd = 0, rev=m_nOidComp.GetSize()-1;
  48. fwd < rev;
  49. fwd ++, rev--)
  50. {
  51. int nOidComp;
  52. const char *szOidComp;
  53. nOidComp = m_nOidComp.GetAt(fwd);
  54. m_nOidComp.SetAt(fwd, m_nOidComp.GetAt(rev));
  55. m_nOidComp.SetAt(rev, (WORD)nOidComp);
  56. szOidComp = (const char *)m_szOidComp.GetAt(fwd);
  57. m_szOidComp.SetAt(fwd, m_szOidComp.GetAt(rev));
  58. m_szOidComp.SetAt(rev, (CObject *)szOidComp);
  59. }
  60. return 0;
  61. }
  62. // DESCRIPTION:
  63. // Output operator, displays the whole Oid
  64. ostream& operator<< (ostream& outStream, const Oid& oid)
  65. {
  66. INT_PTR sz = oid.m_nOidComp.GetSize();
  67. _ASSERT(sz == oid.m_szOidComp.GetSize(), "Size mismatch in Oid arrays", NULL);
  68. for (INT_PTR i=0; i<sz; i++)
  69. {
  70. unsigned int nId;
  71. const char *szId;
  72. // skip over the first component zero(0)
  73. if (i == 0)
  74. continue;
  75. nId = oid.m_nOidComp.GetAt(i);
  76. szId = (const char *)oid.m_szOidComp.GetAt(i);
  77. if (szId != NULL)
  78. {
  79. outStream << szId << "(";
  80. outStream << nId << ")";
  81. }
  82. else
  83. outStream << nId;
  84. if (i != sz-1)
  85. outStream << ".";
  86. }
  87. return outStream;
  88. }
  89. // DESCRIPTION:
  90. // destructor
  91. Oid::~Oid()
  92. {
  93. /*
  94. m_nOidComp.RemoveAll();
  95. for (int i=m_szOidComp.GetSize()-1; i>=0; i--)
  96. {
  97. char *szName = (char *)m_szOidComp.GetAt(i);
  98. if (szName != NULL)
  99. {
  100. // allocated with new in the AddComponent() member function
  101. delete szName;
  102. }
  103. }
  104. m_szOidComp.RemoveAll();
  105. */
  106. }