1
0

ifc_configitem.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #ifndef NULLSOFT_AGAVE_IFC_CONFIGITEM_H
  2. #define NULLSOFT_AGAVE_IFC_CONFIGITEM_H
  3. #include <bfc/dispatch.h>
  4. #include <stddef.h>
  5. /*
  6. notes:
  7. The Set() functions are "public-facing", meaning that they can be called by anyone. If you want to make your config item read-only,
  8. then simply don't implement these. You can always make "private" Set functions in your implementation.
  9. SetStringInternal and GetStringInternal are written for use with classes to load and save from INI files (or XML files or whatever).
  10. It's up to you to figure out a clever way to encode yourself.
  11. */
  12. enum
  13. {
  14. CONFIG_ITEM_TYPE_STRING = 0,
  15. CONFIG_ITEM_TYPE_INT = 1,
  16. CONFIG_ITEM_TYPE_UNSIGNED =2,
  17. CONFIG_ITEM_TYPE_BOOL =3,
  18. CONFIG_ITEM_TYPE_BINARY =4,
  19. CONFIG_ITEM_TYPE_INT_ARRAY = 5,
  20. };
  21. class ifc_configitem : public Dispatchable
  22. {
  23. protected:
  24. ifc_configitem() {}
  25. ~ifc_configitem() {}
  26. public:
  27. const wchar_t *GetName();
  28. int GetType();
  29. const wchar_t *GetString();
  30. void SetString(const wchar_t *stringValue);
  31. intptr_t GetInt();
  32. void SetInt(intptr_t intValue);
  33. uintptr_t GetUnsigned();
  34. void SetUnsigned(uintptr_t unsignedValue);
  35. bool GetBool();
  36. void SetBool(bool boolValue);
  37. float GetFloat();
  38. void SetFloat(float floatValue);
  39. size_t GetBinarySize();
  40. size_t GetBinaryData(void *data, size_t bytes); // returns bytes written
  41. void SetBinaryData(void *data, size_t bytes);
  42. size_t GetIntArrayElements();
  43. size_t GetIntArray(intptr_t *array, size_t elements); // returns elements written
  44. void SetIntArray(intptr_t *array, size_t elements);
  45. const wchar_t *GetStringInternal(); // gets a string suitable for saving in an INI file or XML
  46. void SetStringInternal(const wchar_t *internalString);
  47. public:
  48. DISPATCH_CODES
  49. {
  50. IFC_CONFIGITEM_GETNAME = 10,
  51. IFC_CONFIGITEM_GETTYPE = 20,
  52. IFC_CONFIGITEM_GETSTRING= 30,
  53. IFC_CONFIGITEM_SETSTRING= 40,
  54. IFC_CONFIGITEM_GETINT= 50,
  55. IFC_CONFIGITEM_SETINT= 60,
  56. IFC_CONFIGITEM_GETUNSIGNED= 70,
  57. IFC_CONFIGITEM_SETUNSIGNED= 80,
  58. IFC_CONFIGITEM_GETBOOL= 90,
  59. IFC_CONFIGITEM_SETBOOL= 100,
  60. IFC_CONFIGITEM_GETBINARYSIZE= 110,
  61. IFC_CONFIGITEM_GETBINARYDATA= 120,
  62. IFC_CONFIGITEM_SETBINARYDATA= 130,
  63. IFC_CONFIGITEM_GETINTARRAYELEMENTS= 140,
  64. IFC_CONFIGITEM_GETINTARRAY= 150,
  65. IFC_CONFIGITEM_SETINTARRAY= 160,
  66. IFC_CONFIGITEM_GETSTRINGINTERNAL= 170,
  67. IFC_CONFIGITEM_SETSTRINGINTERNAL= 180,
  68. IFC_CONFIGITEM_GETFLOAT= 190,
  69. IFC_CONFIGITEM_SETFLOAT= 200,
  70. };
  71. };
  72. inline const wchar_t *ifc_configitem::GetName()
  73. {
  74. return _call(IFC_CONFIGITEM_GETNAME, (const wchar_t *)0);
  75. }
  76. inline int ifc_configitem::GetType()
  77. {
  78. return _call(IFC_CONFIGITEM_GETTYPE, (int)0);
  79. }
  80. inline const wchar_t *ifc_configitem::GetString()
  81. {
  82. return _call(IFC_CONFIGITEM_GETSTRING, (const wchar_t *)0);
  83. }
  84. inline void ifc_configitem::SetString(const wchar_t *stringValue)
  85. {
  86. _voidcall(IFC_CONFIGITEM_SETSTRING, stringValue);
  87. }
  88. inline intptr_t ifc_configitem::GetInt()
  89. {
  90. return _call(IFC_CONFIGITEM_GETINT, (intptr_t)0);
  91. }
  92. #pragma warning(push)
  93. #pragma warning(disable: 4244)
  94. inline void ifc_configitem::SetInt(intptr_t intValue)
  95. {
  96. _voidcall(IFC_CONFIGITEM_SETINT, intValue);
  97. }
  98. #pragma warning(pop)
  99. inline uintptr_t ifc_configitem::GetUnsigned()
  100. {
  101. return _call(IFC_CONFIGITEM_GETUNSIGNED, (uintptr_t)0);
  102. }
  103. inline void ifc_configitem::SetUnsigned(uintptr_t unsignedValue)
  104. {
  105. _voidcall(IFC_CONFIGITEM_SETUNSIGNED, unsignedValue);
  106. }
  107. inline bool ifc_configitem::GetBool()
  108. {
  109. return _call(IFC_CONFIGITEM_GETBOOL, (bool)false);
  110. }
  111. inline void ifc_configitem::SetBool(bool boolValue)
  112. {
  113. _voidcall(IFC_CONFIGITEM_SETBOOL, boolValue);
  114. }
  115. inline size_t ifc_configitem::GetBinarySize()
  116. {
  117. return _call(IFC_CONFIGITEM_GETBINARYSIZE, (size_t)0);
  118. }
  119. inline size_t ifc_configitem::GetBinaryData(void *data, size_t bytes)
  120. {
  121. return _call(IFC_CONFIGITEM_GETBINARYDATA, (size_t)0, data, bytes);
  122. }
  123. inline void ifc_configitem::SetBinaryData(void *data, size_t bytes)
  124. {
  125. _voidcall(IFC_CONFIGITEM_SETBINARYDATA, data, bytes);
  126. }
  127. inline size_t ifc_configitem::GetIntArrayElements()
  128. {
  129. return _call(IFC_CONFIGITEM_GETINTARRAYELEMENTS, (size_t)0);
  130. }
  131. inline size_t ifc_configitem::GetIntArray(intptr_t *array, size_t elements)
  132. {
  133. return _call(IFC_CONFIGITEM_GETINTARRAY, (size_t)0, array, elements);
  134. }
  135. inline void ifc_configitem::SetIntArray(intptr_t *array, size_t elements)
  136. {
  137. _voidcall(IFC_CONFIGITEM_SETINTARRAY, array, elements);
  138. }
  139. inline const wchar_t *ifc_configitem::GetStringInternal()
  140. {
  141. return _call(IFC_CONFIGITEM_GETSTRINGINTERNAL, (const wchar_t *)0);
  142. }
  143. inline void ifc_configitem::SetStringInternal(const wchar_t *internalString)
  144. {
  145. _voidcall(IFC_CONFIGITEM_SETSTRINGINTERNAL, internalString);
  146. }
  147. inline float ifc_configitem::GetFloat()
  148. {
  149. return _call(IFC_CONFIGITEM_GETFLOAT, (float)0);
  150. }
  151. inline void ifc_configitem::SetFloat(float floatValue)
  152. {
  153. _voidcall(IFC_CONFIGITEM_SETFLOAT, floatValue);
  154. }
  155. #endif