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.

83 lines
2.3 KiB

  1. // MethodHelp.h -- Helpers for class methods
  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(SLBCCI_METHODHELP_H)
  8. #define SLBCCI_METHODHELP_H
  9. // Note: This file should only be included by the CCI, not directly
  10. // by the client.
  11. namespace cci
  12. {
  13. // Similar to std:unary_function, AccessorMethod and ModifierMethod
  14. // help build templates dealing with method accessors and modifiers.
  15. template<class T, class C>
  16. struct AccessorMethod
  17. {
  18. typedef void ArgumentType;
  19. typedef T ResultType;
  20. typedef ResultType (C::*AccessorPtr)(ArgumentType) const;
  21. };
  22. template<class T, class C>
  23. struct ModifierMethod
  24. {
  25. typedef T const &ArgumentType;
  26. typedef void ResultType;
  27. typedef ResultType (C::*ModifierPtr)(ArgumentType);
  28. };
  29. // MemberAccessType and MemberModifierType are conceptually
  30. // equivalent to the C++ member function functors series
  31. // (e.g. std::mem_ref_fun_t) except they deal with invoking the
  32. // requested routine without a return (MemberModifierType).
  33. // MemberAccessType is like std::mem_ref_fun_t but included here
  34. // to contract MemberModifierType.
  35. template<class T, class C>
  36. class MemberAccessorType
  37. : public AccessorMethod<T, C>
  38. {
  39. public:
  40. explicit
  41. MemberAccessorType(AccessorPtr ap)
  42. : m_ap(ap)
  43. {}
  44. ResultType
  45. operator()(C &rObject) const
  46. {
  47. return (rObject.*m_ap)();
  48. }
  49. private:
  50. AccessorMethod<T, C>::AccessorPtr m_ap;
  51. };
  52. template<class T, class C>
  53. class MemberModifierType
  54. : public ModifierMethod<T, C>
  55. {
  56. public:
  57. explicit
  58. MemberModifierType(ModifierPtr mp)
  59. : m_mp(mp)
  60. {};
  61. ResultType
  62. operator()(C &rObject, ArgumentType Arg) const
  63. {
  64. (rObject.*m_mp)(Arg);
  65. }
  66. private:
  67. ModifierMethod<T, C>::ModifierPtr m_mp;
  68. };
  69. } // namespace cci
  70. #endif // SLBCCI_METHODHELP_H