api_config.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef NULLSOFT_AGAVE_API_CONFIG_H
  2. #define NULLSOFT_AGAVE_API_CONFIG_H
  3. #include "../../bfc/dispatch.h"
  4. #include "ifc_configgroup.h"
  5. enum
  6. {
  7. CONFIG_SUCCESS = 0,
  8. CONFIG_FAILURE = 1,
  9. CONFIG_GROUPNOTFOUND = 2,
  10. CONFIG_ITEMNOTFOUND = 3,
  11. };
  12. class api_config : public Dispatchable
  13. {
  14. protected:
  15. api_config() {}
  16. ~api_config() {}
  17. public:
  18. ifc_configgroup *GetGroup(GUID groupGUID);
  19. void RegisterGroup(ifc_configgroup *newGroup);
  20. /* Shortcut methods */
  21. bool GetBool(GUID groupGUID, const wchar_t *configItem, bool defaultValue);
  22. uintptr_t GetUnsigned(GUID groupGUID, const wchar_t *configItem, uintptr_t defaultValue);
  23. intptr_t GetInt(GUID groupGUID, const wchar_t *configItem, intptr_t defaultValue);
  24. float GetFloat(GUID groupGUID, const wchar_t *configItem, float defaultValue);
  25. const wchar_t *GetString(GUID groupGUID, const wchar_t *configItem, const wchar_t *defaultValue);
  26. ifc_configitem *GetItem(GUID groupGUID, const wchar_t *configItem);
  27. public:
  28. DISPATCH_CODES
  29. {
  30. API_CONFIG_GETGROUP = 10,
  31. API_CONFIG_REGISTERGROUP = 20,
  32. };
  33. };
  34. inline ifc_configgroup *api_config::GetGroup(GUID groupGUID)
  35. {
  36. return _call(API_CONFIG_GETGROUP, (ifc_configgroup *)0, groupGUID);
  37. }
  38. inline void api_config::RegisterGroup(ifc_configgroup *newGroup)
  39. {
  40. _voidcall(API_CONFIG_REGISTERGROUP, newGroup);
  41. }
  42. inline bool api_config::GetBool(GUID groupGUID, const wchar_t *configItem, bool defaultValue)
  43. {
  44. ifc_configgroup *group = GetGroup(groupGUID);
  45. if (group)
  46. {
  47. ifc_configitem *item = group->GetItem(configItem);
  48. if (item)
  49. return item->GetBool();
  50. }
  51. return defaultValue;
  52. }
  53. inline uintptr_t api_config::GetUnsigned(GUID groupGUID, const wchar_t *configItem, uintptr_t defaultValue)
  54. {
  55. ifc_configgroup *group = GetGroup(groupGUID);
  56. if (group)
  57. {
  58. ifc_configitem *item = group->GetItem(configItem);
  59. if (item)
  60. return item->GetUnsigned();
  61. }
  62. return defaultValue;
  63. }
  64. inline intptr_t api_config::GetInt(GUID groupGUID, const wchar_t *configItem, intptr_t defaultValue)
  65. {
  66. ifc_configgroup *group = GetGroup(groupGUID);
  67. if (group)
  68. {
  69. ifc_configitem *item = group->GetItem(configItem);
  70. if (item)
  71. return item->GetInt();
  72. }
  73. return defaultValue;
  74. }
  75. inline float api_config::GetFloat(GUID groupGUID, const wchar_t *configItem, float defaultValue)
  76. {
  77. ifc_configgroup *group = GetGroup(groupGUID);
  78. if (group)
  79. {
  80. ifc_configitem *item = group->GetItem(configItem);
  81. if (item)
  82. return item->GetFloat();
  83. }
  84. return defaultValue;
  85. }
  86. inline const wchar_t *api_config::GetString(GUID groupGUID, const wchar_t *configItem, const wchar_t *defaultValue)
  87. {
  88. ifc_configgroup *group = GetGroup(groupGUID);
  89. if (group)
  90. {
  91. ifc_configitem *item = group->GetItem(configItem);
  92. if (item)
  93. return item->GetString();
  94. }
  95. return defaultValue;
  96. }
  97. inline ifc_configitem *api_config::GetItem(GUID groupGUID, const wchar_t *configItem)
  98. {
  99. ifc_configgroup *group = GetGroup(groupGUID);
  100. if (group)
  101. {
  102. return group->GetItem(configItem);
  103. }
  104. return 0;
  105. }
  106. // {AEFBF8BE-E0AA-4318-8CC1-4353410B64DC}
  107. static const GUID AgaveConfigGUID =
  108. { 0xaefbf8be, 0xe0aa, 0x4318, { 0x8c, 0xc1, 0x43, 0x53, 0x41, 0xb, 0x64, 0xdc } };
  109. #endif