1
0

cfgitem.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. #ifndef _CFGITEM_H
  2. #define _CFGITEM_H
  3. #include <bfc/dispatch.h>
  4. #include <bfc/platform/types.h>
  5. #include <bfc/platform/guid.h>
  6. #include <bfc/wasabi_std.h>
  7. class ifc_dependent;
  8. class ifc_window;
  9. /* A CfgItem is a named, possibly unique (if GUID is set) interface to
  10. an object with 0 or more named attributes. If offers api_dependent-based callbacks
  11. when those attributes change.
  12. */
  13. // abstract base class presented to the world
  14. /**
  15. @short Base Config Item
  16. @ver 1.0
  17. @author Nullsoft
  18. @see CfgItemI
  19. */
  20. class NOVTABLE CfgItem : public Dispatchable
  21. {
  22. public:
  23. /**
  24. */
  25. static const GUID *depend_getClassGuid() {
  26. // {B4BE480E-2005-457c-A445-294F12387E74}
  27. static const GUID ret =
  28. { 0xb4be480e, 0x2005, 0x457c, { 0xa4, 0x45, 0x29, 0x4f, 0x12, 0x38, 0x7e, 0x74 } };
  29. return &ret;
  30. }
  31. const wchar_t *getName();
  32. /**
  33. Get the GUID
  34. */
  35. GUID getGuid();
  36. /**
  37. Get the number of attributes
  38. associated with this configuration
  39. item.
  40. @ret Number of attributes for this configuration item.
  41. */
  42. int getNumAttributes();
  43. const wchar_t *enumAttribute(int n);
  44. // so people can watch you for changes
  45. ifc_dependent *getDependencyPtr();
  46. // return * to your config xml if you want to specify it
  47. const wchar_t *getConfigXML();
  48. void onCfgGroupCreate(ifc_window *cfggroup, const wchar_t *attrname=NULL);
  49. void onCfgGroupDelete(ifc_window *cfggroup);
  50. // if you have child cfgitems, list them here
  51. int getNumChildren();
  52. CfgItem *enumChild(int n);
  53. GUID getParentGuid();
  54. void onRegister(); // kernel calls these
  55. void onDeregister();
  56. int getAttributeType(const wchar_t *name);
  57. const wchar_t *getAttributeConfigGroup(const wchar_t *name);
  58. int getDataLen(const wchar_t *name);
  59. int getData(const wchar_t *name, wchar_t *data, int data_len);
  60. int setData(const wchar_t *name, const wchar_t *data);
  61. int getDataAsInt(const wchar_t *name, int def_val=0)
  62. {
  63. wchar_t buf[256];
  64. if (getData(name, buf, sizeof(buf))==-1) return def_val;
  65. return WTOI(buf);
  66. }
  67. void setDataAsInt(const wchar_t *name, int val) {
  68. wchar_t buf[256];
  69. WCSNPRINTF(buf, 256, L"%d", val); // this uses SPRINTF ON PURPOSE, motherfucker BU
  70. setData(name, buf);
  71. }
  72. double getDataAsFloat(const wchar_t *name, double def_val=0) {
  73. wchar_t buf[256];
  74. if (getData(name, buf, sizeof(buf))==-1) return def_val;
  75. return WTOF(buf);
  76. }
  77. void setDataAsFloat(const wchar_t *name, double val) {
  78. wchar_t buf[256];
  79. WCSNPRINTF(buf, 256, L"%f", val); // this uses SPRINTF ON PURPOSE, motherfucker BU
  80. setData(name, buf);
  81. }
  82. int addAttribute(const wchar_t *name, const wchar_t *defval);
  83. int delAttribute(const wchar_t *name);
  84. enum {
  85. Event_ATTRIBUTE_ADDED=100, // ptr is name of attrib
  86. Event_ATTRIBUTE_REMOVED=200,// ptr is name of attrib
  87. Event_ATTRIBUTE_CHANGED=300, // ptr is name of attrib
  88. Event_NAMECHANGE=400,
  89. };
  90. protected:
  91. enum {
  92. CFGITEM_GETNAME=100,
  93. CFGITEM_GETGUID=110,
  94. CFGITEM_GETNUMATTRIBUTES=200,
  95. CFGITEM_ENUMATTRIBUTE=210,
  96. CFGITEM_GETDEPENDENCYPTR=300,
  97. CFGITEM_GETNUMCHILDREN=400,
  98. CFGITEM_ENUMCHILD=410,
  99. CFGITEM_GETPARENTGUID=420,
  100. CFGITEM_ONREGISTER=500,
  101. CFGITEM_ONDEREGISTER=510,
  102. CFGITEM_GETCONFIGXML=600,
  103. CFGITEM_ONCFGGROUPCREATE=610,
  104. CFGITEM_ONCFGGROUPDELETE=620,
  105. CFGITEM_GETATTRIBUTETYPE=700,
  106. CFGITEM_GETATTRIBUTECONFIGGROUP=710,
  107. CFGITEM_GETDATALEN=800,
  108. CFGITEM_GETDATA=810,
  109. CFGITEM_SETDATA=820,
  110. CFGITEM_ADDATTRIB=830,
  111. CFGITEM_DELATTRIB=840,
  112. };
  113. };
  114. inline const wchar_t *CfgItem::getName() {
  115. return _call(CFGITEM_GETNAME, L"");
  116. }
  117. inline GUID CfgItem::getGuid() {
  118. return _call(CFGITEM_GETGUID, INVALID_GUID);
  119. }
  120. inline int CfgItem::getNumAttributes() {
  121. return _call(CFGITEM_GETNUMATTRIBUTES, 0);
  122. }
  123. inline const wchar_t *CfgItem::enumAttribute(int n) {
  124. return _call(CFGITEM_ENUMATTRIBUTE, (const wchar_t *)NULL, n);
  125. }
  126. inline ifc_dependent *CfgItem::getDependencyPtr() {
  127. return _call(CFGITEM_GETDEPENDENCYPTR, (ifc_dependent*)NULL);
  128. }
  129. inline const wchar_t *CfgItem::getConfigXML() {
  130. return _call(CFGITEM_GETCONFIGXML, (const wchar_t*)NULL);
  131. }
  132. inline void CfgItem::onCfgGroupCreate(ifc_window *cfggroup, const wchar_t *attrname) {
  133. _voidcall(CFGITEM_ONCFGGROUPCREATE, cfggroup, attrname);
  134. }
  135. inline void CfgItem::onCfgGroupDelete(ifc_window *cfggroup) {
  136. _voidcall(CFGITEM_ONCFGGROUPDELETE, cfggroup);
  137. }
  138. inline int CfgItem::getNumChildren() {
  139. return _call(CFGITEM_GETNUMCHILDREN, 0);
  140. }
  141. inline CfgItem *CfgItem::enumChild(int n) {
  142. return _call(CFGITEM_ENUMCHILD, (CfgItem*)NULL, n);
  143. }
  144. inline
  145. GUID CfgItem::getParentGuid() {
  146. return _call(CFGITEM_GETPARENTGUID, INVALID_GUID);
  147. }
  148. inline void CfgItem::onRegister() { _voidcall(CFGITEM_ONREGISTER); }
  149. inline void CfgItem::onDeregister() { _voidcall(CFGITEM_ONDEREGISTER); }
  150. inline
  151. int CfgItem::getAttributeType(const wchar_t *name) {
  152. return _call(CFGITEM_GETATTRIBUTETYPE, 0, name);
  153. }
  154. inline
  155. const wchar_t *CfgItem::getAttributeConfigGroup(const wchar_t *name) {
  156. return _call(CFGITEM_GETATTRIBUTECONFIGGROUP, (const wchar_t *)NULL, name);
  157. }
  158. inline
  159. int CfgItem::getDataLen(const wchar_t *name) {
  160. return _call(CFGITEM_GETDATALEN, -1, name);
  161. }
  162. inline
  163. int CfgItem::getData(const wchar_t *name, wchar_t *data, int data_len) {
  164. return _call(CFGITEM_GETDATA, -1, name, data, data_len);
  165. }
  166. inline
  167. int CfgItem::setData(const wchar_t *name, const wchar_t *data) {
  168. return _call(CFGITEM_SETDATA, -1, name, data);
  169. }
  170. inline
  171. int CfgItem::addAttribute(const wchar_t *name, const wchar_t *defval) {
  172. return _call(CFGITEM_ADDATTRIB, 0, name, defval);
  173. }
  174. inline
  175. int CfgItem::delAttribute(const wchar_t *name) {
  176. return _call(CFGITEM_DELATTRIB, 0, name);
  177. }
  178. inline int _intVal(CfgItem *cfgitem, const wchar_t *name, int def_val=0) {
  179. if (cfgitem == NULL) return def_val;
  180. return cfgitem->getDataAsInt(name, def_val);
  181. }
  182. #define _int_getValue _intVal
  183. //CUT kill these
  184. inline void _int_setValue(CfgItem *cfgitem, const wchar_t *name, int val) {
  185. cfgitem->setDataAsInt(name, val);
  186. }
  187. // CfgItemI is in cfgitemi.h if you need it
  188. #endif