Counter Strike : Global Offensive Source Code
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.

154 lines
4.6 KiB

  1. // responserules_cli.h
  2. #pragma once
  3. using namespace System;
  4. #pragma unmanaged
  5. namespace ResponseRules
  6. {
  7. /// forward declare unmanaged implementation
  8. class CriteriaSet;
  9. }
  10. #pragma managed
  11. #include "response_types_marshal.h"
  12. namespace ResponseRulesCLI {
  13. typedef CCLIUtlDictEnumerable< ResponseRules::Criteria, short, ResponseRulesCLI::Criterion > CriterionDictWrapper_t;
  14. typedef CCLIUtlDictEnumerable< ResponseRules::ResponseGroup, short, ResponseRulesCLI::ResponseGroup > ResponseGroupDictWrapper_t;
  15. // enumerations aren't used right now it seems.
  16. // typedef CCLIUtlDictEnumerable< ResponseRules::CResponseSystem::Enumeration, short, System::Single > EnumerationDictWrapper_t;
  17. /// Encapsulates an entire response system based on a file,
  18. /// containing responses, rules, criteria, and other data.
  19. public ref class ResponseSystemCLI
  20. {
  21. public:
  22. // Allocate the native object on the C++ Heap via a constructor
  23. ResponseSystemCLI();
  24. // Deallocate the native object on a destructor
  25. ~ResponseSystemCLI() ;
  26. /// Load this system from a talker file.
  27. virtual void LoadFromFile( String^ filename );
  28. int CountRules();
  29. property ResponseGroupDictWrapper_t ^ResponseGroupsDict
  30. {
  31. ResponseGroupDictWrapper_t ^get() { return m_ResponseGroupsDict; }
  32. }
  33. property CriterionDictWrapper_t ^CriteriaDict
  34. {
  35. CriterionDictWrapper_t ^get() { return m_CriteriaDict; }
  36. }
  37. /*
  38. property EnumerationDictWrapper_t ^EnumerationsDict
  39. {
  40. EnumerationDictWrapper_t ^get() { return m_EnumerationsDict; }
  41. }
  42. */
  43. /// interface to enumerate rules.
  44. ref class RulesAsList : public System::Collections::IEnumerable, System::Collections::Specialized::INotifyCollectionChanged
  45. {
  46. public:
  47. ref struct RulesIterator : System::Collections::IEnumerator
  48. {
  49. public:
  50. RulesIterator( ResponseSystemCLI^ enumerable ) :
  51. m_System(enumerable), m_bIsBefore(false), m_idx(ResponseRules::ResponseRulePartition::InvalidIdx()) {Reset();};
  52. virtual void Reset();
  53. virtual bool MoveNext(); // return false when falling off the end
  54. property Object^ Current
  55. {
  56. virtual Object^ get();
  57. };
  58. protected:
  59. bool m_bIsBefore; // is "one before" everything in the array, required by iterator interface
  60. bool IsValid() ;
  61. ResponseSystemCLI ^m_System; ///< the system I iterate
  62. ResponseRules::ResponseRulePartition::tIndex m_idx;
  63. };
  64. RulesAsList( ResponseSystemCLI^ owner ) : m_owner(owner) {};
  65. property int Count
  66. {
  67. int get() { return m_owner->GetNativePtr()->CountRules(); }
  68. }
  69. virtual System::Collections::IEnumerator^ GetEnumerator()
  70. {
  71. return gcnew RulesIterator(m_owner);
  72. }
  73. #pragma region INotifyCollectionChanged interface
  74. System::Collections::Specialized::NotifyCollectionChangedEventHandler ^m_CollectionChanged;
  75. virtual event System::Collections::Specialized::NotifyCollectionChangedEventHandler ^CollectionChanged
  76. {
  77. void add(System::Collections::Specialized::NotifyCollectionChangedEventHandler ^ d) {
  78. m_CollectionChanged += d;
  79. }
  80. void remove(System::Collections::Specialized::NotifyCollectionChangedEventHandler ^ d) {
  81. m_CollectionChanged -= d;
  82. }
  83. }
  84. virtual void OnCollectionChanged(System::Collections::Specialized::NotifyCollectionChangedEventArgs ^e)
  85. {
  86. if (m_CollectionChanged != nullptr)
  87. {
  88. m_CollectionChanged(this, e);
  89. }
  90. }
  91. #pragma endregion
  92. private:
  93. ResponseSystemCLI^ m_owner;
  94. };
  95. property RulesAsList^ Rules
  96. {
  97. RulesAsList^ get() { return m_RulesContainer; };
  98. }
  99. #pragma region "Queries Into Response System"
  100. /// Given a dictionary of key:value pairs (the contexts and their values),
  101. /// find the best matching rule.
  102. Rule ^FindBestMatchingRule( System::Collections::IDictionary ^facts );
  103. /// Find *all* rules that match the given criteria, in sorted order of best to worst.
  104. array< System::Collections::Generic::KeyValuePair<Rule ^,float> >^ FindAllRulesMatchingCriteria( System::Collections::IDictionary ^facts );
  105. #pragma endregion
  106. /// please be careful
  107. ResponseSystemImplementationCLI *GetNativePtr();
  108. protected:
  109. // Deallocate the native object on the finalizer just in case no destructor is called
  110. !ResponseSystemCLI() ;
  111. ResponseSystemImplementationCLI *m_pImpl;
  112. void TurnIDictIntoCriteriaSet( System::Collections::IDictionary ^facts, ResponseRules::CriteriaSet *critset );
  113. Rule ^RuleFromIdx( ResponseRules::ResponseRulePartition::tIndex idx );
  114. private:
  115. CriterionDictWrapper_t ^m_CriteriaDict;
  116. ResponseGroupDictWrapper_t ^m_ResponseGroupsDict;
  117. // EnumerationDictWrapper_t ^m_EnumerationsDict;
  118. RulesAsList ^m_RulesContainer;
  119. };
  120. }