1
0

api_config.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. DISPATCH_CODES
  28. {
  29. API_CONFIG_GETGROUP = 10,
  30. API_CONFIG_REGISTERGROUP = 20,
  31. };
  32. };
  33. inline ifc_configgroup *api_config::GetGroup( GUID groupGUID )
  34. {
  35. return _call( API_CONFIG_GETGROUP, (ifc_configgroup *)0, groupGUID );
  36. }
  37. inline void api_config::RegisterGroup( ifc_configgroup *newGroup )
  38. {
  39. _voidcall( API_CONFIG_REGISTERGROUP, newGroup );
  40. }
  41. inline bool api_config::GetBool( GUID groupGUID, const wchar_t *configItem, bool defaultValue )
  42. {
  43. ifc_configgroup *group = GetGroup( groupGUID );
  44. if ( group )
  45. {
  46. ifc_configitem *item = group->GetItem( configItem );
  47. if ( item )
  48. return item->GetBool();
  49. }
  50. return defaultValue;
  51. }
  52. inline uintptr_t api_config::GetUnsigned( GUID groupGUID, const wchar_t *configItem, uintptr_t defaultValue )
  53. {
  54. ifc_configgroup *group = GetGroup( groupGUID );
  55. if ( group )
  56. {
  57. ifc_configitem *item = group->GetItem( configItem );
  58. if ( item )
  59. return item->GetUnsigned();
  60. }
  61. return defaultValue;
  62. }
  63. inline intptr_t api_config::GetInt( GUID groupGUID, const wchar_t *configItem, intptr_t defaultValue )
  64. {
  65. ifc_configgroup *group = GetGroup( groupGUID );
  66. if ( group )
  67. {
  68. ifc_configitem *item = group->GetItem( configItem );
  69. if ( item )
  70. return item->GetInt();
  71. }
  72. return defaultValue;
  73. }
  74. inline float api_config::GetFloat( GUID groupGUID, const wchar_t *configItem, float defaultValue )
  75. {
  76. ifc_configgroup *group = GetGroup( groupGUID );
  77. if ( group )
  78. {
  79. ifc_configitem *item = group->GetItem( configItem );
  80. if ( item )
  81. return item->GetFloat();
  82. }
  83. return defaultValue;
  84. }
  85. inline const wchar_t *api_config::GetString( GUID groupGUID, const wchar_t *configItem, const wchar_t *defaultValue )
  86. {
  87. ifc_configgroup *group = GetGroup( groupGUID );
  88. if ( group )
  89. {
  90. ifc_configitem *item = group->GetItem( configItem );
  91. if ( item )
  92. return item->GetString();
  93. }
  94. return defaultValue;
  95. }
  96. inline ifc_configitem *api_config::GetItem( GUID groupGUID, const wchar_t *configItem )
  97. {
  98. ifc_configgroup *group = GetGroup( groupGUID );
  99. if ( group )
  100. return group->GetItem( configItem );
  101. return 0;
  102. }
  103. // {AEFBF8BE-E0AA-4318-8CC1-4353410B64DC}
  104. static const GUID AgaveConfigGUID =
  105. { 0xaefbf8be, 0xe0aa, 0x4318, { 0x8c, 0xc1, 0x43, 0x53, 0x41, 0xb, 0x64, 0xdc } };
  106. extern api_config *configApi;
  107. #ifndef AGAVE_API_CONFIG
  108. #define AGAVE_API_CONFIG configApi
  109. #endif // !AGAVE_API_CONFIG
  110. #endif