BlockFilter.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #pragma once
  2. #include <Array.h>
  3. #include "TypeRegistry.h"
  4. class Block;
  5. class BlockFilter : public Framework::ReferenceCounter
  6. {
  7. public:
  8. BlockFilter();
  9. virtual bool test(const Block* zBlock) = 0;
  10. };
  11. class BlockFilterAnd : public BlockFilter
  12. {
  13. private:
  14. Framework::RCArray<BlockFilter> filters;
  15. public:
  16. BlockFilterAnd();
  17. bool test(const Block* zBlock) override;
  18. void addFilter(BlockFilter* filter);
  19. Framework::RCArray<BlockFilter> getFilters() const;
  20. };
  21. class BlockFilterAndFactory : public SubTypeFactory<BlockFilter, BlockFilterAnd>
  22. {
  23. public:
  24. BlockFilterAndFactory();
  25. BlockFilterAnd* fromJson(Framework::JSON::JSONObject* zJson) const override;
  26. Framework::JSON::JSONObject* toJsonObject(
  27. BlockFilterAnd* zObject) const override;
  28. JSONObjectValidationBuilder* addToValidator(
  29. JSONObjectValidationBuilder* builder) const override;
  30. const char* getTypeToken() const override;
  31. };
  32. class BlockFilterOr : public BlockFilter
  33. {
  34. private:
  35. Framework::RCArray<BlockFilter> filters;
  36. public:
  37. BlockFilterOr();
  38. bool test(const Block* zBlock) override;
  39. void addFilter(BlockFilter* filter);
  40. Framework::RCArray<BlockFilter> getFilters() const;
  41. };
  42. class BlockFilterOrFactory : public SubTypeFactory<BlockFilter, BlockFilterOr>
  43. {
  44. public:
  45. BlockFilterOrFactory();
  46. BlockFilterOr* fromJson(Framework::JSON::JSONObject* zJson) const override;
  47. Framework::JSON::JSONObject* toJsonObject(
  48. BlockFilterOr* zObject) const override;
  49. JSONObjectValidationBuilder* addToValidator(
  50. JSONObjectValidationBuilder* builder) const override;
  51. const char* getTypeToken() const override;
  52. };
  53. class BlockFilterNot : public BlockFilter
  54. {
  55. private:
  56. BlockFilter* filter;
  57. public:
  58. BlockFilterNot();
  59. ~BlockFilterNot();
  60. bool test(const Block* zBlock) override;
  61. void setFilter(BlockFilter* filter);
  62. BlockFilter* zFilter() const;
  63. };
  64. class BlockFilterNotFactory : public SubTypeFactory<BlockFilter, BlockFilterNot>
  65. {
  66. public:
  67. BlockFilterNotFactory();
  68. BlockFilterNot* fromJson(Framework::JSON::JSONObject* zJson) const override;
  69. Framework::JSON::JSONObject* toJsonObject(
  70. BlockFilterNot* zObject) const override;
  71. JSONObjectValidationBuilder* addToValidator(
  72. JSONObjectValidationBuilder* builder) const override;
  73. const char* getTypeToken() const override;
  74. };
  75. class BlockFilterBlockType : public BlockFilter
  76. {
  77. private:
  78. Framework::Array<int> blockTypeIds;
  79. public:
  80. BlockFilterBlockType();
  81. bool test(const Block* zBlock) override;
  82. void addBlockTypeId(int blockTypeId);
  83. const Framework::Array<int>& getBlockTypeIds() const;
  84. };
  85. class BlockFilterBlockTypeFactory
  86. : public SubTypeFactory<BlockFilter, BlockFilterBlockType>
  87. {
  88. public:
  89. BlockFilterBlockTypeFactory();
  90. BlockFilterBlockType* fromJson(
  91. Framework::JSON::JSONObject* zJson) const override;
  92. Framework::JSON::JSONObject* toJsonObject(
  93. BlockFilterBlockType* zObject) const override;
  94. JSONObjectValidationBuilder* addToValidator(
  95. JSONObjectValidationBuilder* builder) const override;
  96. const char* getTypeToken() const override;
  97. };
  98. class BlockFilterTypeGroup : public BlockFilter
  99. {
  100. private:
  101. Framework::RCArray<Framework::Text> groupNames;
  102. public:
  103. BlockFilterTypeGroup();
  104. bool test(const Block* zBlock) override;
  105. void addGroupName(const Framework::Text groupName);
  106. const Framework::RCArray<Framework::Text>& getGroupNames() const;
  107. };
  108. class BlockFilterTypeGroupFactory
  109. : public SubTypeFactory<BlockFilter, BlockFilterTypeGroup>
  110. {
  111. public:
  112. BlockFilterTypeGroupFactory();
  113. BlockFilterTypeGroup* fromJson(
  114. Framework::JSON::JSONObject* zJson) const override;
  115. Framework::JSON::JSONObject* toJsonObject(
  116. BlockFilterTypeGroup* zObject) const override;
  117. JSONObjectValidationBuilder* addToValidator(
  118. JSONObjectValidationBuilder* builder) const override;
  119. const char* getTypeToken() const override;
  120. };
  121. class BlockFilterMaxHardness : public BlockFilter
  122. {
  123. private:
  124. float maxHardness;
  125. public:
  126. BlockFilterMaxHardness();
  127. bool test(const Block* zBlock) override;
  128. void setMaxHardness(float maxHardness);
  129. float getMaxHardness() const;
  130. };
  131. class BlockFilterMaxHardnessFactory
  132. : public SubTypeFactory<BlockFilter, BlockFilterMaxHardness>
  133. {
  134. public:
  135. BlockFilterMaxHardnessFactory();
  136. BlockFilterMaxHardness* fromJson(
  137. Framework::JSON::JSONObject* zJson) const override;
  138. Framework::JSON::JSONObject* toJsonObject(
  139. BlockFilterMaxHardness* zObject) const override;
  140. JSONObjectValidationBuilder* addToValidator(
  141. JSONObjectValidationBuilder* builder) const override;
  142. const char* getTypeToken() const override;
  143. };
  144. class BlockFilterMinHardness : public BlockFilter
  145. {
  146. private:
  147. float minHardness;
  148. public:
  149. BlockFilterMinHardness();
  150. bool test(const Block* zBlock) override;
  151. void setMinHardness(float minHardness);
  152. float getMinHardness() const;
  153. };
  154. class BlockFilterMinHardnessFactory
  155. : public SubTypeFactory<BlockFilter, BlockFilterMinHardness>
  156. {
  157. public:
  158. BlockFilterMinHardnessFactory();
  159. BlockFilterMinHardness* fromJson(
  160. Framework::JSON::JSONObject* zJson) const override;
  161. Framework::JSON::JSONObject* toJsonObject(
  162. BlockFilterMinHardness* zObject) const override;
  163. JSONObjectValidationBuilder* addToValidator(
  164. JSONObjectValidationBuilder* builder) const override;
  165. const char* getTypeToken() const override;
  166. };
  167. class BlockFilterMaxHeat : public BlockFilter
  168. {
  169. private:
  170. float maxHeat;
  171. public:
  172. BlockFilterMaxHeat();
  173. bool test(const Block* zBlock) override;
  174. void setMaxHeat(float maxHeat);
  175. float getMaxHeat() const;
  176. };
  177. class BlockFilterMaxHeatFactory
  178. : public SubTypeFactory<BlockFilter, BlockFilterMaxHeat>
  179. {
  180. public:
  181. BlockFilterMaxHeatFactory();
  182. BlockFilterMaxHeat* fromJson(
  183. Framework::JSON::JSONObject* zJson) const override;
  184. Framework::JSON::JSONObject* toJsonObject(
  185. BlockFilterMaxHeat* zObject) const override;
  186. JSONObjectValidationBuilder* addToValidator(
  187. JSONObjectValidationBuilder* builder) const override;
  188. const char* getTypeToken() const override;
  189. };