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.

162 lines
3.3 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // attrdnry.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // Defines the class AttributeDictionary.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/04/2000 Original version.
  16. // 04/17/2000 Port to new dictionary API.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <proxypch.h>
  20. #include <iastlutl.h>
  21. #include <iasutil.h>
  22. #include <attrdnry.h>
  23. ///////////////////////////////////////////////////////////////////////////////
  24. //
  25. //
  26. // Various functions used for defining the indices.
  27. //
  28. ///////////////////////////////////////////////////////////////////////////////
  29. ULONG
  30. WINAPI
  31. HashById(
  32. const AttributeDefinition& def
  33. ) throw ()
  34. {
  35. return def.id;
  36. }
  37. BOOL
  38. WINAPI
  39. EqualById(
  40. const AttributeDefinition& def1, const AttributeDefinition& def2
  41. ) throw ()
  42. {
  43. return def1.id == def2.id;
  44. }
  45. ULONG
  46. WINAPI
  47. HashByVendorInfo(
  48. const AttributeDefinition& def
  49. ) throw ()
  50. {
  51. return def.vendorID | def.vendorType;
  52. }
  53. BOOL
  54. WINAPI
  55. EqualByVendorInfo(
  56. const AttributeDefinition& def1, const AttributeDefinition& def2
  57. ) throw ()
  58. {
  59. return def1.vendorID == def2.vendorID && def1.vendorType == def2.vendorType;
  60. }
  61. BOOL
  62. WINAPI
  63. FilterByVendorInfo(
  64. const AttributeDefinition& def
  65. ) throw ()
  66. {
  67. return def.vendorID != 0;
  68. }
  69. AttributeDictionary::~AttributeDictionary() throw ()
  70. {
  71. delete[] first;
  72. }
  73. HRESULT AttributeDictionary::FinalConstruct() throw ()
  74. {
  75. try
  76. {
  77. initialize();
  78. }
  79. CATCH_AND_RETURN();
  80. return S_OK;
  81. }
  82. void AttributeDictionary::initialize()
  83. {
  84. // Names of various columns in the dictionary.
  85. const PCWSTR COLUMNS[] =
  86. {
  87. L"ID",
  88. L"Syntax",
  89. L"VendorID",
  90. L"VendorTypeID",
  91. NULL
  92. };
  93. IASTL::IASDictionary dnary(COLUMNS);
  94. using _com_util::CheckError;
  95. // Allocate memory to hold the definitions.
  96. first = last = new AttributeDefinition[dnary.getNumRows()];
  97. // Iterate through the dictionary and process each definition.
  98. while (dnary.next())
  99. {
  100. // Process each database column.
  101. last->id = (ULONG)dnary.getLong(0);
  102. last->syntax = (ULONG)dnary.getLong(1);
  103. last->vendorID = (ULONG)dnary.getLong(2);
  104. last->vendorType = (ULONG)dnary.getLong(3);
  105. ++last;
  106. }
  107. /////////
  108. // Initialize the indices.
  109. /////////
  110. byID.create(
  111. first,
  112. last,
  113. HashById,
  114. EqualById
  115. );
  116. byVendorInfo.create(
  117. first,
  118. last,
  119. HashByVendorInfo,
  120. EqualByVendorInfo,
  121. FilterByVendorInfo
  122. );
  123. }
  124. const AttributeDefinition*
  125. AttributeDictionary::findByID(ULONG id) const throw ()
  126. {
  127. AttributeDefinition key;
  128. key.id = id;
  129. return byID.find(key);
  130. }
  131. const AttributeDefinition*
  132. AttributeDictionary::findByVendorInfo(
  133. ULONG vendorID,
  134. ULONG vendorType
  135. ) const throw ()
  136. {
  137. AttributeDefinition key;
  138. key.vendorID = vendorID;
  139. key.vendorType = vendorType;
  140. return byVendorInfo.find(key);
  141. }