Line data Source code
1 : /* Macros for extracting config values out of a pod */ 2 : 3 : #define CFG_POP( type, cfg_path ) \ 4 2052 : do { \ 5 2052 : char const * key = #cfg_path; \ 6 2052 : fd_pod_info_t info[1]; \ 7 2052 : if( fd_pod_query( pod, key, info ) ) break; \ 8 2052 : if( FD_UNLIKELY( !fdctl_cfg_get_##type( &config->cfg_path, sizeof(config->cfg_path), \ 9 420 : info, key ) ) ) \ 10 420 : return NULL; \ 11 420 : fd_pod_remove( pod, key ); \ 12 420 : } while(0) 13 : 14 : #define CFG_POP1( type, toml_path, cfg_path ) \ 15 60 : do { \ 16 60 : char const * key = #toml_path; \ 17 60 : fd_pod_info_t info[1]; \ 18 60 : if( fd_pod_query( pod, key, info ) ) break; \ 19 60 : if( FD_UNLIKELY( !fdctl_cfg_get_##type( &config->cfg_path, sizeof(config->cfg_path), \ 20 15 : info, key ) ) ) \ 21 15 : return NULL; \ 22 15 : fd_pod_remove( pod, key ); \ 23 15 : } while(0) 24 : 25 : #define CFG_POP_ARRAY( type, cfg_path ) \ 26 84 : do { \ 27 84 : char const * key = #cfg_path; \ 28 84 : fd_pod_info_t info[1]; \ 29 84 : if( fd_pod_query( pod, key, info ) ) break; \ 30 84 : if( FD_UNLIKELY( info->val_type!=FD_POD_VAL_TYPE_SUBPOD ) ) { \ 31 0 : FD_LOG_WARNING(( "`%s`: expected array", key )); \ 32 0 : return NULL; \ 33 0 : } \ 34 24 : ulong arr_len = sizeof( config->cfg_path ) / sizeof( config->cfg_path[ 0 ] ); \ 35 24 : ulong j = 0UL; \ 36 30 : for( fd_pod_iter_t iter = fd_pod_iter_init( info->val ); !fd_pod_iter_done( iter ); iter = fd_pod_iter_next( iter ) ) { \ 37 6 : if( FD_UNLIKELY( j>=arr_len ) ) { \ 38 0 : FD_LOG_WARNING(( "`%s`: too many values (max %lu)", key, arr_len )); \ 39 0 : return NULL; \ 40 0 : } \ 41 6 : fd_pod_info_t sub_info = fd_pod_iter_info( iter ); \ 42 6 : fdctl_cfg_get_##type( &config->cfg_path[j], sizeof(config->cfg_path[j]), &sub_info, key ); \ 43 6 : j++; \ 44 6 : } \ 45 24 : config->cfg_path ## _cnt = j; \ 46 24 : fd_pod_remove( pod, key ); \ 47 24 : } while(0) 48 : 49 : #define CFG_POP1_ARRAY( type, toml_path, cfg_path ) \ 50 12 : do { \ 51 12 : char const * key = #toml_path; \ 52 12 : fd_pod_info_t info[1]; \ 53 12 : if( fd_pod_query( pod, key, info ) ) break; \ 54 12 : if( FD_UNLIKELY( info->val_type!=FD_POD_VAL_TYPE_SUBPOD ) ) { \ 55 0 : FD_LOG_WARNING(( "`%s`: expected array", key )); \ 56 0 : return NULL; \ 57 0 : } \ 58 3 : ulong arr_len = sizeof( config->cfg_path ) / sizeof( config->cfg_path[ 0 ] ); \ 59 3 : ulong j = 0UL; \ 60 3 : for( fd_pod_iter_t iter = fd_pod_iter_init( info->val ); !fd_pod_iter_done( iter ); iter = fd_pod_iter_next( iter ) ) { \ 61 0 : if( FD_UNLIKELY( j>=arr_len ) ) { \ 62 0 : FD_LOG_WARNING(( "`%s`: too many values (max %lu)", key, arr_len )); \ 63 0 : return NULL; \ 64 0 : } \ 65 0 : fd_pod_info_t sub_info = fd_pod_iter_info( iter ); \ 66 0 : fdctl_cfg_get_##type( &config->cfg_path[j], sizeof(config->cfg_path[j]), &sub_info, key ); \ 67 0 : j++; \ 68 0 : } \ 69 3 : config->cfg_path ## _cnt = j; \ 70 3 : fd_pod_remove( pod, key ); \ 71 3 : } while(0)