PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

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

#
C Header | 306 lines | 204 code | 30 blank | 72 comment | 10 complexity | ddadfdd9752a6a209b77b2e7505129ef 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. // This really should be inside litObjectSelectByNameRE::IsValid and
  67. // listObjectSelectByKeyValueRE:IsValid, but Cygwin
  68. // crashes on exit if functions have local static variables with complex types
  69. static csString error_string;
  70. /**
  71. * Select an object based on regexp on name.
  72. */
  73. class litObjectSelectByNameRE : public litObjectSelect
  74. {
  75. private:
  76. csRegExpMatcher matcher;
  77. public:
  78. litObjectSelectByNameRE (const char* name_re) : matcher (name_re) { }
  79. virtual ~litObjectSelectByNameRE () { }
  80. virtual const char* IsValid ()
  81. {
  82. csRegExpMatchError rc = matcher.Match ("");
  83. if (rc == csrxNoError || rc == csrxNoMatch) return 0;
  84. error_string.Format ("Regexp error %d", (int)rc);
  85. return error_string;
  86. }
  87. virtual bool SelectObject (iObject* obj)
  88. {
  89. return matcher.Match (obj->GetName ()) == csrxNoError;
  90. }
  91. };
  92. /**
  93. * Select an object based on mesh wrapper flags.
  94. */
  95. class litObjectSelectByMWFlags : public litObjectSelect
  96. {
  97. private:
  98. uint32 value, mask;
  99. public:
  100. litObjectSelectByMWFlags (uint32 mask, uint32 value)
  101. {
  102. litObjectSelectByMWFlags::mask = mask;
  103. litObjectSelectByMWFlags::value = value;
  104. }
  105. virtual ~litObjectSelectByMWFlags () { }
  106. virtual bool SelectObject (iObject* obj);
  107. };
  108. /**
  109. * Select an object based on mesh object flags.
  110. */
  111. class litObjectSelectByMOFlags : public litObjectSelect
  112. {
  113. private:
  114. uint32 value, mask;
  115. public:
  116. litObjectSelectByMOFlags (uint32 mask, uint32 value)
  117. {
  118. litObjectSelectByMOFlags::mask = mask;
  119. litObjectSelectByMOFlags::value = value;
  120. }
  121. virtual ~litObjectSelectByMOFlags () { }
  122. virtual bool SelectObject (iObject* obj);
  123. };
  124. /**
  125. * Select an object based on mesh type.
  126. */
  127. class litObjectSelectByType : public litObjectSelect
  128. {
  129. private:
  130. char* type;
  131. public:
  132. litObjectSelectByType (const char* type)
  133. {
  134. litObjectSelectByType::type = csStrNew (type);
  135. }
  136. virtual ~litObjectSelectByType ()
  137. {
  138. delete[] type;
  139. }
  140. virtual bool SelectObject (iObject* obj);
  141. };
  142. /**
  143. * Select an object based on the presence of a key value pair.
  144. */
  145. class litObjectSelectByKeyValue : public litObjectSelect
  146. {
  147. private:
  148. char* keyname;
  149. char* keyattrtype;
  150. char* keyattrvalue;
  151. public:
  152. litObjectSelectByKeyValue (const char* keyname,
  153. const char* keyattrtype, const char* keyattrvalue)
  154. {
  155. litObjectSelectByKeyValue::keyname = csStrNew (keyname);
  156. litObjectSelectByKeyValue::keyattrtype = csStrNew (keyattrtype);
  157. litObjectSelectByKeyValue::keyattrvalue = csStrNew (keyattrvalue);
  158. }
  159. virtual ~litObjectSelectByKeyValue ()
  160. {
  161. delete[] keyname;
  162. delete[] keyattrtype;
  163. delete[] keyattrvalue;
  164. }
  165. virtual bool SelectObject (iObject* obj);
  166. };
  167. /**
  168. * Select an object based on the presence of a key value pair.
  169. * Regex version.
  170. */
  171. class litObjectSelectByKeyValueRE : public litObjectSelect
  172. {
  173. private:
  174. char* keyname;
  175. char* keyattrtype;
  176. csRegExpMatcher matcher;
  177. public:
  178. litObjectSelectByKeyValueRE (const char* keyname,
  179. const char* keyattrtype, const char* keyattrvalue)
  180. : matcher (keyattrvalue)
  181. {
  182. litObjectSelectByKeyValueRE::keyname = csStrNew (keyname);
  183. litObjectSelectByKeyValueRE::keyattrtype = csStrNew (keyattrtype);
  184. }
  185. virtual ~litObjectSelectByKeyValueRE ()
  186. {
  187. delete[] keyname;
  188. delete[] keyattrtype;
  189. }
  190. virtual const char* IsValid ()
  191. {
  192. csRegExpMatchError rc = matcher.Match ("");
  193. if (rc == csrxNoError || rc == csrxNoMatch) return 0;
  194. error_string.Format ("Regexp error %d", (int)rc);
  195. return error_string;
  196. }
  197. virtual bool SelectObject (iObject* obj);
  198. };
  199. /**
  200. * Mesh selector that can hold children (other object
  201. * selectors).
  202. */
  203. class litObjectSelectChildren : public litObjectSelect
  204. {
  205. protected:
  206. csRefArray<litObjectSelect> a;
  207. public:
  208. litObjectSelectChildren () { }
  209. virtual ~litObjectSelectChildren () { }
  210. void AddMeshSelect (litObjectSelect* ms)
  211. {
  212. a.Push (ms);
  213. }
  214. };
  215. /**
  216. * Logical and of two other object selectors.
  217. */
  218. class litObjectSelectAnd : public litObjectSelectChildren
  219. {
  220. public:
  221. litObjectSelectAnd () { }
  222. virtual ~litObjectSelectAnd () { }
  223. virtual bool SelectObject (iObject* obj);
  224. };
  225. /**
  226. * Logical or of two other object selectors.
  227. */
  228. class litObjectSelectOr : public litObjectSelectChildren
  229. {
  230. public:
  231. litObjectSelectOr () { }
  232. virtual ~litObjectSelectOr () { }
  233. virtual bool SelectObject (iObject* obj);
  234. };
  235. /**
  236. * Logical not of other object selector.
  237. */
  238. class litObjectSelectNot : public litObjectSelect
  239. {
  240. private:
  241. csRef<litObjectSelect> a;
  242. public:
  243. litObjectSelectNot (litObjectSelect* a)
  244. {
  245. litObjectSelectNot::a = a;
  246. }
  247. virtual ~litObjectSelectNot () { }
  248. virtual bool SelectObject (iObject* obj)
  249. {
  250. return !a->SelectObject (obj);
  251. }
  252. };
  253. /**
  254. * Select everything.
  255. */
  256. class litObjectSelectAll : public litObjectSelect
  257. {
  258. public:
  259. litObjectSelectAll () { }
  260. virtual ~litObjectSelectAll () { }
  261. virtual bool SelectObject (iObject*) { return true; }
  262. };
  263. /**
  264. * Select nothing.
  265. */
  266. class litObjectSelectNone : public litObjectSelect
  267. {
  268. public:
  269. litObjectSelectNone () { }
  270. virtual ~litObjectSelectNone () { }
  271. virtual bool SelectObject (iObject*) { return false; }
  272. };
  273. #endif // __LITMESHSEL_H__