PageRenderTime 47ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/CS/migrated/tags/PRE_EVENT_UNION_REMOVAL/apps/tools/lighter/litobjsel.h

#
C Header | 303 lines | 205 code | 29 blank | 69 comment | 10 complexity | 618bebb1ec012f18ffc3b6800b463440 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, LGPL-2.0
  1. /*
  2. Copyright (C) 2004 by Jorrit Tyberghein
  3. This library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Library General Public
  5. License as published by the Free Software Foundation; either
  6. version 2 of the License, or (at your option) any later version.
  7. This library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Library General Public License for more details.
  11. You should have received a copy of the GNU Library General Public
  12. License along with this library; if not, write to the Free
  13. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. */
  15. #ifndef __LITMESHSEL_H__
  16. #define __LITMESHSEL_H__
  17. #include <stdarg.h>
  18. #include <csutil/util.h>
  19. #include <csutil/ref.h>
  20. #include <csutil/refarr.h>
  21. #include <csutil/refcount.h>
  22. #include <csutil/flags.h>
  23. #include "csutil/regexp.h"
  24. #include <iutil/object.h>
  25. #include <iengine/mesh.h>
  26. #include <imesh/object.h>
  27. /**
  28. * This abstract class indicates when an object is selected or not
  29. * Subclasses of this class will control how exactly the object is selected.
  30. */
  31. class litObjectSelect : public csRefCount
  32. {
  33. public:
  34. virtual ~litObjectSelect () { }
  35. /**
  36. * Return 0 if this selector is valid, otherwise returns an error
  37. * string with error.
  38. */
  39. virtual const char* IsValid () { return 0; }
  40. /**
  41. * Return true if this object should be selected.
  42. */
  43. virtual bool SelectObject (iObject*) = 0;
  44. };
  45. /**
  46. * Select an object based on name.
  47. */
  48. class litObjectSelectByName : public litObjectSelect
  49. {
  50. private:
  51. char* name;
  52. public:
  53. litObjectSelectByName (const char* name)
  54. {
  55. litObjectSelectByName::name = csStrNew (name);
  56. }
  57. virtual ~litObjectSelectByName ()
  58. {
  59. delete[] name;
  60. }
  61. virtual bool SelectObject (iObject* obj)
  62. {
  63. return strcmp (name, obj->GetName ()) == 0;
  64. }
  65. };
  66. /**
  67. * Select an object based on regexp on name.
  68. */
  69. class litObjectSelectByNameRE : public litObjectSelect
  70. {
  71. private:
  72. csRegExpMatcher matcher;
  73. public:
  74. litObjectSelectByNameRE (const char* name_re) : matcher (name_re) { }
  75. virtual ~litObjectSelectByNameRE () { }
  76. virtual const char* IsValid ()
  77. {
  78. csRegExpMatchError rc = matcher.Match ("");
  79. if (rc == csrxNoError || rc == csrxNoMatch) return 0;
  80. static csString error_string;
  81. error_string.Format ("Regexp error %d", (int)rc);
  82. return error_string;
  83. }
  84. virtual bool SelectObject (iObject* obj)
  85. {
  86. return matcher.Match (obj->GetName ()) == csrxNoError;
  87. }
  88. };
  89. /**
  90. * Select an object based on mesh wrapper flags.
  91. */
  92. class litObjectSelectByMWFlags : public litObjectSelect
  93. {
  94. private:
  95. uint32 value, mask;
  96. public:
  97. litObjectSelectByMWFlags (uint32 mask, uint32 value)
  98. {
  99. litObjectSelectByMWFlags::mask = mask;
  100. litObjectSelectByMWFlags::value = value;
  101. }
  102. virtual ~litObjectSelectByMWFlags () { }
  103. virtual bool SelectObject (iObject* obj);
  104. };
  105. /**
  106. * Select an object based on mesh object flags.
  107. */
  108. class litObjectSelectByMOFlags : public litObjectSelect
  109. {
  110. private:
  111. uint32 value, mask;
  112. public:
  113. litObjectSelectByMOFlags (uint32 mask, uint32 value)
  114. {
  115. litObjectSelectByMOFlags::mask = mask;
  116. litObjectSelectByMOFlags::value = value;
  117. }
  118. virtual ~litObjectSelectByMOFlags () { }
  119. virtual bool SelectObject (iObject* obj);
  120. };
  121. /**
  122. * Select an object based on mesh type.
  123. */
  124. class litObjectSelectByType : public litObjectSelect
  125. {
  126. private:
  127. char* type;
  128. public:
  129. litObjectSelectByType (const char* type)
  130. {
  131. litObjectSelectByType::type = csStrNew (type);
  132. }
  133. virtual ~litObjectSelectByType ()
  134. {
  135. delete[] type;
  136. }
  137. virtual bool SelectObject (iObject* obj);
  138. };
  139. /**
  140. * Select an object based on the presence of a key value pair.
  141. */
  142. class litObjectSelectByKeyValue : public litObjectSelect
  143. {
  144. private:
  145. char* keyname;
  146. char* keyattrtype;
  147. char* keyattrvalue;
  148. public:
  149. litObjectSelectByKeyValue (const char* keyname,
  150. const char* keyattrtype, const char* keyattrvalue)
  151. {
  152. litObjectSelectByKeyValue::keyname = csStrNew (keyname);
  153. litObjectSelectByKeyValue::keyattrtype = csStrNew (keyattrtype);
  154. litObjectSelectByKeyValue::keyattrvalue = csStrNew (keyattrvalue);
  155. }
  156. virtual ~litObjectSelectByKeyValue ()
  157. {
  158. delete[] keyname;
  159. delete[] keyattrtype;
  160. delete[] keyattrvalue;
  161. }
  162. virtual bool SelectObject (iObject* obj);
  163. };
  164. /**
  165. * Select an object based on the presence of a key value pair.
  166. * Regex version.
  167. */
  168. class litObjectSelectByKeyValueRE : public litObjectSelect
  169. {
  170. private:
  171. char* keyname;
  172. char* keyattrtype;
  173. csRegExpMatcher matcher;
  174. public:
  175. litObjectSelectByKeyValueRE (const char* keyname,
  176. const char* keyattrtype, const char* keyattrvalue)
  177. : matcher (keyattrvalue)
  178. {
  179. litObjectSelectByKeyValueRE::keyname = csStrNew (keyname);
  180. litObjectSelectByKeyValueRE::keyattrtype = csStrNew (keyattrtype);
  181. }
  182. virtual ~litObjectSelectByKeyValueRE ()
  183. {
  184. delete[] keyname;
  185. delete[] keyattrtype;
  186. }
  187. virtual const char* IsValid ()
  188. {
  189. csRegExpMatchError rc = matcher.Match ("");
  190. if (rc == csrxNoError || rc == csrxNoMatch) return 0;
  191. static csString error_string;
  192. error_string.Format ("Regexp error %d", (int)rc);
  193. return error_string;
  194. }
  195. virtual bool SelectObject (iObject* obj);
  196. };
  197. /**
  198. * Mesh selector that can hold children (other object
  199. * selectors).
  200. */
  201. class litObjectSelectChildren : public litObjectSelect
  202. {
  203. protected:
  204. csRefArray<litObjectSelect> a;
  205. public:
  206. litObjectSelectChildren () { }
  207. virtual ~litObjectSelectChildren () { }
  208. void AddMeshSelect (litObjectSelect* ms)
  209. {
  210. a.Push (ms);
  211. }
  212. };
  213. /**
  214. * Logical and of two other object selectors.
  215. */
  216. class litObjectSelectAnd : public litObjectSelectChildren
  217. {
  218. public:
  219. litObjectSelectAnd () { }
  220. virtual ~litObjectSelectAnd () { }
  221. virtual bool SelectObject (iObject* obj);
  222. };
  223. /**
  224. * Logical or of two other object selectors.
  225. */
  226. class litObjectSelectOr : public litObjectSelectChildren
  227. {
  228. public:
  229. litObjectSelectOr () { }
  230. virtual ~litObjectSelectOr () { }
  231. virtual bool SelectObject (iObject* obj);
  232. };
  233. /**
  234. * Logical not of other object selector.
  235. */
  236. class litObjectSelectNot : public litObjectSelect
  237. {
  238. private:
  239. csRef<litObjectSelect> a;
  240. public:
  241. litObjectSelectNot (litObjectSelect* a)
  242. {
  243. litObjectSelectNot::a = a;
  244. }
  245. virtual ~litObjectSelectNot () { }
  246. virtual bool SelectObject (iObject* obj)
  247. {
  248. return !a->SelectObject (obj);
  249. }
  250. };
  251. /**
  252. * Select everything.
  253. */
  254. class litObjectSelectAll : public litObjectSelect
  255. {
  256. public:
  257. litObjectSelectAll () { }
  258. virtual ~litObjectSelectAll () { }
  259. virtual bool SelectObject (iObject*) { return true; }
  260. };
  261. /**
  262. * Select nothing.
  263. */
  264. class litObjectSelectNone : public litObjectSelect
  265. {
  266. public:
  267. litObjectSelectNone () { }
  268. virtual ~litObjectSelectNone () { }
  269. virtual bool SelectObject (iObject*) { return false; }
  270. };
  271. #endif // __LITMESHSEL_H__