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.

149 lines
4.4 KiB

  1. // CntrEnum.cpp -- Card Container Enumerator
  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. #include "StdAfx.h"
  8. #include "NoWarning.h"
  9. #include "ForceLib.h"
  10. #include <algorithm>
  11. #include <numeric>
  12. #include <cciCont.h>
  13. #include "Secured.h"
  14. #include "CntrEnum.h"
  15. using namespace std;
  16. using namespace cci;
  17. /////////////////////////// LOCAL/HELPER /////////////////////////////////
  18. namespace
  19. {
  20. vector<string>
  21. AccumulateUniqueNameOf(vector<string> &rvsNames,
  22. CContainer &rcntr)
  23. {
  24. string sName(rcntr->Name());
  25. if (rvsNames.end() == find(rvsNames.begin(), rvsNames.end(), sName))
  26. rvsNames.push_back(sName);
  27. return rvsNames;
  28. }
  29. class ContainerNameAccumulator
  30. : public unary_function<HCardContext const, void>
  31. {
  32. public:
  33. explicit
  34. ContainerNameAccumulator(vector<string> &rvsContainers)
  35. : m_rvsContainers(rvsContainers)
  36. {}
  37. result_type
  38. operator()(argument_type &rhcardctx) const
  39. {
  40. try
  41. {
  42. vector<CContainer> vContainers(rhcardctx->Card()->EnumContainers());
  43. vector<string> vs(accumulate(vContainers.begin(),
  44. vContainers.end(),
  45. m_rvsContainers,
  46. AccumulateUniqueNameOf));
  47. m_rvsContainers.insert(m_rvsContainers.end(),
  48. vs.begin(), vs.end());
  49. }
  50. catch(...)
  51. {
  52. // ignore cards we have problems with
  53. }
  54. }
  55. private:
  56. vector<string> &m_rvsContainers;
  57. };
  58. }
  59. /////////////////////////// PUBLIC /////////////////////////////////
  60. // Types
  61. // C'tors/D'tors
  62. ContainerEnumerator::ContainerEnumerator()
  63. : m_vsNames(),
  64. m_it(m_vsNames.end())
  65. {}
  66. ContainerEnumerator::ContainerEnumerator(list<HCardContext> const &rlHCardContexts)
  67. {
  68. for_each(rlHCardContexts.begin(), rlHCardContexts.end(),
  69. ContainerNameAccumulator(m_vsNames));
  70. m_it = m_vsNames.begin();
  71. }
  72. ContainerEnumerator::ContainerEnumerator(ContainerEnumerator const &rhs)
  73. {
  74. *this = rhs;
  75. }
  76. // Operators
  77. ContainerEnumerator &
  78. ContainerEnumerator::operator=(ContainerEnumerator const &rhs)
  79. {
  80. if (this != &rhs)
  81. {
  82. m_vsNames = rhs.m_vsNames;
  83. m_it = m_vsNames.begin();
  84. advance(m_it, distance(rhs.m_vsNames.begin(), rhs.m_it));
  85. }
  86. return *this;
  87. }
  88. // Operations
  89. // Access
  90. vector<string>::const_iterator &
  91. ContainerEnumerator::Iterator()
  92. {
  93. return m_it;
  94. }
  95. vector<string> const &
  96. ContainerEnumerator::Names() const
  97. {
  98. return m_vsNames;
  99. }
  100. // Predicates
  101. // Static Variables
  102. /////////////////////////// PROTECTED /////////////////////////////////
  103. // C'tors/D'tors
  104. // Operators
  105. // Operations
  106. // Access
  107. // Predicates
  108. // Static Variables
  109. /////////////////////////// PRIVATE /////////////////////////////////
  110. // C'tors/D'tors
  111. // Operators
  112. // Operations
  113. // Access
  114. // Predicates
  115. // Static Variables