cwFlowTypes.h/cpp,cwFlow.cpp,cwFlowNet.cpp : Updates to support recd_fmt_t.

Changed cfg_to_value() to value_from_cfg() and moved it to cwFlowValue.
This commit is contained in:
kevin 2024-11-25 09:57:29 -05:00
parent e3423e775e
commit 5d748bdb7e
4 changed files with 41 additions and 70 deletions

View File

@ -75,7 +75,7 @@ namespace cw
{ "midi_file", &midi_file::members },
{ "midi_merge", &midi_merge::members },
{ "score_player", &score_player::members },
{ "midi_to_msg", &midi_to_msg::members },
// { "midi_to_msg", &midi_to_msg::members },
{ "score_follower", &score_follower::members },
{ nullptr, nullptr }
};
@ -233,6 +233,7 @@ namespace cw
if((rc = vd->cfg->getv_opt("flags", var_flags_obj,
"type", var_value_type_str,
"value", vd->val_cfg,
"fmt", vd->fmt_cfg,
"proxy", proxy_string )) != kOkRC )
{
rc = cwLogError(rc,"Parsing optional fields failed.");
@ -241,11 +242,23 @@ namespace cw
// convert the type string to a numeric type flag
if( var_value_type_str != nullptr )
{
if( (vd->type = value_type_label_to_flag( var_value_type_str )) == kInvalidTId )
{
rc = cwLogError(kSyntaxErrorRC,"Invalid variable description type flag: '%s' was encountered.", var_value_type_str );
goto errLabel;
}
}
// if this is a 'record' type with a 'fmt' specifier
if( vd->type & kRBufTFl && vd->fmt_cfg != nullptr )
{
if((rc = recd_format_create( vd->fmt.recd_fmt, vd->fmt_cfg )) != kOkRC )
{
rc = cwLogError(rc,"The record type associated with the 'fmt' field could not be created.");
goto errLabel;
}
}
// parse the proxy string into it's two parts: <proc>.<var>
if( proxy_string != nullptr )

View File

@ -1954,6 +1954,7 @@ namespace cw
goto errLabel;
}
// Connect the proxied vars in this subnet proc to their respective proxy vars.
if((rc = _subnet_connect_proxy_vars( proc, proxyVarL )) != kOkRC )
{
@ -2267,7 +2268,7 @@ namespace cw
preset_value_t* preset_value = mem::allocZ<preset_value_t>();
// cfg to value
if((rc = cfg_to_value( value_cfg, preset_value->value )) != kOkRC )
if((rc = value_from_cfg( value_cfg, preset_value->value )) != kOkRC )
{
rc = cwLogError(rc,"The preset cfg to value conversion failed on '%s:%i'-'%s:%i'.",cwStringNullGuard(var->label),var->label_sfx_id,cwStringNullGuard(proc->label),proc->label_sfx_id);
goto errLabel;

View File

@ -534,6 +534,9 @@ void cw::flow::var_desc_destroy( var_desc_t* var_desc )
{
if( var_desc != nullptr )
{
if( var_desc_has_recd_format(var_desc) )
recd_format_destroy(var_desc->fmt.recd_fmt);
mem::release(var_desc->proxyProcLabel);
mem::release(var_desc->proxyVarLabel);
mem::release(var_desc);
@ -621,6 +624,11 @@ cw::rc_t cw::flow::var_desc_find( class_desc_t* cd, const char* label, var_desc_
return kOkRC;
}
bool cw::flow::var_desc_has_recd_format( var_desc_t* vd )
{
return vd!=nullptr && vd->type & kRBufTFl && vd->fmt_cfg != nullptr && vd->fmt.recd_fmt != nullptr;
}
const cw::flow::class_preset_t* cw::flow::class_preset_find( const class_desc_t* cd, const char* preset_label )
{
const class_preset_t* pr;
@ -1396,6 +1404,9 @@ bool cw::flow::is_connected_to_source( const variable_t* var )
bool cw::flow::is_a_source_var( const variable_t* var )
{ return var->dst_head != nullptr; }
bool cw::flow::var_has_recd_format( const variable_t* var )
{ return var!=nullptr && var_desc_has_recd_format(var->varDesc); }
void cw::flow::var_connect( variable_t* src_var, variable_t* in_var )
{
@ -1634,77 +1645,13 @@ cw::rc_t cw::flow::var_get( variable_t* var, rbuf_t*& valRef )
cw::rc_t cw::flow::var_get( const variable_t* var, const object_t*& valRef )
{ return _val_get_driver(var,valRef); }
cw::rc_t cw::flow::cfg_to_value( const object_t* cfg, value_t& value_ref )
{
rc_t rc = kOkRC;
switch( cfg->type->id )
{
case kCharTId:
case kUInt8TId:
case kUInt16TId:
case kUInt32TId:
value_ref.tflag = kUIntTFl;
if((rc = cfg->value(value_ref.u.u)) != kOkRC )
rc = cwLogError(rc,"Conversion to uint failed.");
break;
case kInt8TId:
case kInt16TId:
case kInt32TId:
value_ref.tflag = kIntTFl;
if((rc = cfg->value(value_ref.u.i)) != kOkRC )
rc = cwLogError(rc,"Conversion to int failed.");
break;
case kInt64TId:
case kUInt64TId:
rc = cwLogError(kInvalidArgRC,"The flow system does not currently implement 64bit integers.");
goto errLabel;
break;
case kFloatTId:
value_ref.tflag = kFloatTFl;
if((rc = cfg->value(value_ref.u.f)) != kOkRC )
rc = cwLogError(rc,"Conversion to float failed.");
break;
case kDoubleTId:
value_ref.tflag = kDoubleTFl;
if((rc = cfg->value(value_ref.u.d)) != kOkRC )
rc = cwLogError(rc,"Conversion to double failed.");
break;
case kBoolTId:
value_ref.tflag = kBoolTFl;
if((rc = cfg->value(value_ref.u.b)) != kOkRC )
rc = cwLogError(rc,"Conversion to bool failed.");
break;
case kStringTId:
case kCStringTId:
value_ref.tflag = kStringTFl;
if((rc = cfg->value(value_ref.u.s)) != kOkRC )
rc = cwLogError(rc,"Conversion to string failed.");
break;
default:
value_ref.tflag = kCfgTFl;
value_ref.u.cfg = cfg;
}
errLabel:
return rc;
}
cw::rc_t cw::flow::var_set_from_cfg( variable_t* var, const object_t* cfg_value )
{
rc_t rc = kOkRC;
value_t v;
if((rc = cfg_to_value(cfg_value, v)) != kOkRC )
if((rc = value_from_cfg(cfg_value, v)) != kOkRC )
goto errLabel;
if((rc = var_set(var,&v)) != kOkRC )

View File

@ -34,11 +34,17 @@ namespace cw
{
const object_t* cfg; // The cfg object that describes this variable from 'flow_class'.
const object_t* val_cfg; // An object containing the default value for this variable.
const object_t* fmt_cfg; // An object containg the format (e.g. record fields) information
const char* label; // Name of this var.
unsigned type; // Value type id (e.g. kBoolTFl, kIntTFl, ...)
unsigned flags; // Attributes for this var. (e.g. kSrcVarFl )
const char* docText; // User help string for this var.
union
{
recd_fmt_t* recd_fmt; // the 'recd_type.base' is never set in 'recd_type' because it is only valid once the var is instantiated
} fmt;
char* proxyProcLabel;
char* proxyVarLabel;
@ -291,6 +297,8 @@ namespace cw
const var_desc_t* var_desc_find( const class_desc_t* cd, const char* var_label );
rc_t var_desc_find( class_desc_t* cd, const char* var_label, var_desc_t*& vdRef );
bool var_desc_has_recd_format( var_desc_t* vd );
const class_preset_t* class_preset_find( const class_desc_t* cd, const char* preset_label );
//------------------------------------------------------------------------------------------------------------------------
@ -389,6 +397,9 @@ namespace cw
// Return true if this var is acting as a source for another var.
bool is_a_source_var( const variable_t* var );
// Returns true if var->varDesc->fmt.recd_fmt is valid.
bool var_has_recd_format( const variable_t* var );
// Connect in_var to src_var.
void var_connect( variable_t* src_var, variable_t* in_var );
@ -529,7 +540,6 @@ namespace cw
rc_t var_channel_count( proc_t* proc, const char* label, unsigned sfx_idx, unsigned& chCntRef );
rc_t var_channel_count( const variable_t* var, unsigned& chCntRef );
rc_t cfg_to_value( const object_t* cfg, value_t& value_ref );
//