libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmPrefs.h 8.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #ifndef cmPrefs_h
  2. #define cmPrefs_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. typedef unsigned cmPrRC_t;
  7. typedef cmHandle_t cmPrH_t;
  8. enum
  9. {
  10. kOkPrRC = cmOkRC,
  11. kJsonFailPrRC,
  12. kLHeapFailPrRC,
  13. kCbNotFoundPrRC,
  14. kVarNotFoundPrRC,
  15. kBufTooSmallPrRC,
  16. kCvtErrPrRC,
  17. kInvalidIdPrRC,
  18. kInvalidIndexPrRC,
  19. kWriteFileFailPrRC,
  20. kNodeCreateFailPrRC,
  21. kDuplicateIdPrRC
  22. };
  23. typedef void (*cmPrefsOnChangeFunc_t)( cmPrH_t h, void* cbDataPtr, unsigned id );
  24. extern cmPrH_t cmPrNullHandle;
  25. // 'cbFunc' is optional
  26. cmPrRC_t cmPrefsInitialize( cmPrH_t* hp, const cmChar_t* fn, cmPrefsOnChangeFunc_t cbFunc, void* cbDataPtr, cmCtx_t* ctx );
  27. cmPrRC_t cmPrefsFinalize( cmPrH_t* hp );
  28. bool cmPrefsIsValid( cmPrH_t h );
  29. // Return last RC.
  30. cmPrRC_t cmPrefsRC( cmPrH_t h);
  31. // Return last RC and set new RC.
  32. cmPrRC_t cmPrefsSetRC( cmPrH_t h, cmPrRC_t rc );
  33. cmPrRC_t cmPrefsInstallCallback( cmPrH_t h, cmPrefsOnChangeFunc_t cbFunc, void* cbDataPtr );
  34. cmPrRC_t cmPrefsRemoveCallback( cmPrH_t h, cmPrefsOnChangeFunc_t cbFunc );
  35. // Return cmInvalidId if the no variable is found with the requested path.
  36. unsigned cmPrefsId( cmPrH_t h, const cmChar_t* pathStr, bool reportNotFoundFl );
  37. // Returns -1 (and generates an error msg) if no pref. variable
  38. // is associated with id. Returns 1 if the variable is a scalar.
  39. unsigned cmPrefsEleCount( cmPrH_t h, unsigned id );
  40. // On input *'eleCntPtr' must contain the number of elements in the buffer pointed to by 'vp'.
  41. // On return *'eleCntPtr' contains the actuall number of elements returned by the function.
  42. cmPrRC_t cmPrefsGetBool( cmPrH_t h, unsigned id, bool* vp, unsigned* eleCntPtr );
  43. cmPrRC_t cmPrefsGetInt( cmPrH_t h, unsigned id, int* vp, unsigned* eleCntPtr );
  44. cmPrRC_t cmPrefsGetReal( cmPrH_t h, unsigned id, double* vp, unsigned* eleCntPtr );
  45. cmPrRC_t cmPrefsGetString( cmPrH_t h, unsigned id, const cmChar_t** vp, unsigned* eleCntPtr );
  46. // Simplified scalar interface - check cmPrefsRC() for errors.
  47. bool cmPrefsBool( cmPrH_t h, unsigned id );
  48. unsigned cmPrefsUInt( cmPrH_t h, unsigned id );
  49. int cmPrefsInt( cmPrH_t h, unsigned id );
  50. float cmPrefsFloat( cmPrH_t h, unsigned id );
  51. double cmPrefsReal( cmPrH_t h, unsigned id );
  52. const cmChar_t* cmPrefsString( cmPrH_t h, unsigned id );
  53. // Simplified scalar interface w/ default values - check cmPrefsRC() for errors.
  54. // Returns the stored preference variable unless 'pathStr' does not identify a variable
  55. // or if 'h' is not valid. In either of these cases 'dfltVal' is returned.
  56. bool cmPrefsBoolDef( cmPrH_t h, const cmChar_t* pathStr, bool dfltVal );
  57. unsigned cmPrefsUIntDef( cmPrH_t h, const cmChar_t* pathStr, unsigned dfltVal );
  58. int cmPrefsIntDef( cmPrH_t h, const cmChar_t* pathStr, int dfltVal );
  59. float cmPrefsFloatDef( cmPrH_t h, const cmChar_t* pathStr, float dfltVal );
  60. double cmPrefsRealDef( cmPrH_t h, const cmChar_t* pathStr, double dfltVal );
  61. const cmChar_t* cmPrefsStringDef( cmPrH_t h, const cmChar_t* pathStr, const cmChar_t* dfltVal );
  62. // Get a scalar value.
  63. cmPrRC_t cmPrefsScalarBool( cmPrH_t h, const cmChar_t* pathStr, bool* retValPtr );
  64. cmPrRC_t cmPrefsScalarUInt( cmPrH_t h, const cmChar_t* pathStr, unsigned* retValPtr );
  65. cmPrRC_t cmPrefsScalarInt( cmPrH_t h, const cmChar_t* pathStr, int* retValPtr );
  66. cmPrRC_t cmPrefsScalarFloat( cmPrH_t h, const cmChar_t* pathStr, float* retValPtr );
  67. cmPrRC_t cmPrefsScalarReal( cmPrH_t h, const cmChar_t* pathStr, double* retValPtr );
  68. cmPrRC_t cmPrefsScalarString( cmPrH_t h, const cmChar_t* pathStr, const cmChar_t** retValPtr );
  69. // Simplified array interface - check cmPrefsRC() for errors
  70. // Returns cmInvalidCnt if 'id' is invalid or 0 if the identified var. is a scalar.
  71. unsigned cmPrefsArrayElementCount( cmPrH_t h, unsigned id );
  72. bool cmPrefsBoolEle( cmPrH_t h, unsigned id, unsigned idx );
  73. unsigned cmPrefsUIntEle( cmPrH_t h, unsigned id, unsigned idx );
  74. int cmPrefsIntEle( cmPrH_t h, unsigned id, unsigned idx );
  75. float cmPrefsFloatEle( cmPrH_t h, unsigned id, unsigned idx );
  76. double cmPrefsRealEle( cmPrH_t h, unsigned id, unsigned idx );
  77. const cmChar_t* cmPrefsStringEle( cmPrH_t h, unsigned id, unsigned idx );
  78. // Set a preference value.
  79. // The size of array variables is allowed to shrink or grow but the type (bool/int/real/string)
  80. // must match.
  81. //
  82. // Note that the following limitations apply:
  83. // 1) This interface allows setting the value of an existing preference variable.
  84. // New variables may not be added.
  85. // 2) The type (bool/int/real/string) of the variable must match the value.
  86. // (e.g. 'int' type variables can only be set via cmPrefsSetInt()).
  87. // 3) For scalar (non-array) variables *eleCntPtr must be set to 1.
  88. //
  89. cmPrRC_t cmPrefsSetBool( cmPrH_t h, unsigned id, const bool* vp, const unsigned* eleCntPtr );
  90. cmPrRC_t cmPrefsSetInt( cmPrH_t h, unsigned id, const int* vp, const unsigned* eleCntPtr );
  91. cmPrRC_t cmPrefsSetReal( cmPrH_t h, unsigned id, const double* vp, const unsigned* eleCntPtr );
  92. cmPrRC_t cmPrefsSetString( cmPrH_t h, unsigned id, const cmChar_t** vp, const unsigned* eleCntPtr );
  93. cmPrRC_t cmPrefsSetScalarBool( cmPrH_t h, const cmChar_t* pathStr, bool val );
  94. cmPrRC_t cmPrefsSetScalarUInt( cmPrH_t h, const cmChar_t* pathStr, unsigned val );
  95. cmPrRC_t cmPrefsSetScalarInt( cmPrH_t h, const cmChar_t* pathStr, int val );
  96. cmPrRC_t cmPrefsSetScalarFloat( cmPrH_t h, const cmChar_t* pathStr, float val );
  97. cmPrRC_t cmPrefsSetScalarReal( cmPrH_t h, const cmChar_t* pathStr, double val );
  98. cmPrRC_t cmPrefsSetScalarString( cmPrH_t h, const cmChar_t* pathStr, const cmChar_t* val );
  99. // Create a new preference variable and set it's value to 'val'.
  100. // If a variable with the same path and type already exists and kForceValuePrFl is set then update it's value to 'val'.
  101. // Note that in this case if kForceValuePrFl is not set then the function returns quietly.
  102. //
  103. // If a variable with the same path but a different type exists then an error is returned.
  104. //
  105. // Set kForceValuePrFl
  106. enum { kForceValuePrFl=0x01 };
  107. cmPrRC_t cmPrefsCreateBool( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, bool val );
  108. cmPrRC_t cmPrefsCreateUInt( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, unsigned val );
  109. cmPrRC_t cmPrefsCreateInt( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, int val );
  110. cmPrRC_t cmPrefsCreateFloat( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, float val );
  111. cmPrRC_t cmPrefsCreateReal( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, double val );
  112. cmPrRC_t cmPrefsCreateString( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, const cmChar_t* val );
  113. cmPrRC_t cmPrefsCreateBoolArray( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, const bool* val, unsigned eleCnt );
  114. cmPrRC_t cmPrefsCreateUIntArray( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, const unsigned* val, unsigned eleCnt );
  115. cmPrRC_t cmPrefsCreateIntArray( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, const int* val, unsigned eleCnt );
  116. cmPrRC_t cmPrefsCreateFloatArray( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, const float* val, unsigned eleCnt );
  117. cmPrRC_t cmPrefsCreateRealArray( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, const double* val, unsigned eleCnt );
  118. cmPrRC_t cmPrefsCreateStringArray( cmPrH_t h, unsigned id, const cmChar_t* pathStr, unsigned flags, const cmChar_t** val, unsigned eleCnt );
  119. bool cmPrefsIsDirty( cmPrH_t h );
  120. cmPrRC_t cmPrefsWrite( cmPrH_t h, const cmChar_t* fn );
  121. void cmPrefsTest( cmCtx_t* ctx, const char* ifn, const char* ofn );
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. #endif