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.

133 lines
4.7 KiB

  1. // Registry.h -- Registry template class definition
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work, created
  3. // 1999. This computer program includes Confidential, Proprietary
  4. // Information and is a Trade Secret of Schlumberger Technology Corp. All
  5. // use, disclosure, and/or reproduction is prohibited unless authorized
  6. // in writing. All Rights Reserved.
  7. #if !defined(SLBCSP_REGISTRY_H)
  8. #define SLBCSP_REGISTRY_H
  9. #include "Lockable.h"
  10. #include "Guarded.h"
  11. #include "MapUtility.h"
  12. // Companion to Registrar, the Registry template class maintains a
  13. // collection of T pointers indexed by Key.
  14. template<typename Collection>
  15. class Registry
  16. : public Lockable
  17. {
  18. public:
  19. // Types
  20. typedef Collection CollectionType;
  21. // C'tors/D'tors
  22. // Constructs the registry. If fSetup is true, then space is
  23. // allocated for the registry; otherwise operator() will return 0
  24. // until Setup is called. This supports lazy initialization.
  25. explicit
  26. Registry();
  27. ~Registry();
  28. // Operators
  29. CollectionType &
  30. operator()();
  31. // Operations
  32. // Access
  33. // Predicates
  34. protected:
  35. // Types
  36. // C'tors/D'tors
  37. // Operators
  38. // Operations
  39. // Access
  40. // Predicates
  41. // Variables
  42. private:
  43. // Types
  44. // C'tors/D'tors
  45. Registry(Registry const &rhs); // not defined, copying not allowed
  46. // Operators
  47. Registry &
  48. operator=(Registry const &rhs); // not defined, assignment not allowed
  49. // Operations
  50. // Access
  51. // Predicates
  52. // Variables
  53. CollectionType m_collection;
  54. };
  55. ///////////////////////// TEMPLATE METHODS ///////////////////////////////
  56. /////////////////////////////// HELPERS ///////////////////////////////////
  57. template<class C, class Op>
  58. void
  59. ForEachEnrollee(Registry<C const> &rRegistry,
  60. Op &rProc)
  61. {
  62. Guarded<Lockable *> guard(&rRegistry); // serialize registry access
  63. C const &rcollection = (rRegistry)();
  64. ForEachMappedValue(rcollection.begin(), rcollection.end(),
  65. rProc);
  66. }
  67. /////////////////////////// PUBLIC /////////////////////////////////
  68. // Types
  69. // C'tors/D'tors
  70. template<typename Collection>
  71. Registry<Collection>::Registry()
  72. : Lockable(),
  73. m_collection()
  74. {}
  75. template<typename Collection>
  76. Registry<Collection>::~Registry()
  77. {}
  78. // Operators
  79. template<typename Collection>
  80. Registry<Collection>::CollectionType &
  81. Registry<Collection>::operator()()
  82. {
  83. return m_collection;
  84. }
  85. // Operations
  86. // Access
  87. // Predicates
  88. // Static Variables
  89. /////////////////////////// PROTECTED /////////////////////////////////
  90. // C'tors/D'tors
  91. // Operators
  92. // Operations
  93. // Access
  94. // Predicates
  95. // Static Variables
  96. /////////////////////////// PRIVATE /////////////////////////////////
  97. // C'tors/D'tors
  98. // Operators
  99. // Operations
  100. // Access
  101. // Predicates
  102. // Static Variables
  103. #endif // SLBCSP_REGISTRY_H