cwFlowValues.h/cpp : Added recd_copy() and added req_fieldL to recd_fmt_t.
This commit is contained in:
parent
fac5b2b31a
commit
db3e96cdf6
@ -156,7 +156,7 @@ namespace cw
|
||||
|
||||
if( textIsEqual(type_label,"group") )
|
||||
{
|
||||
const object_t* field_dict;
|
||||
const object_t* field_dict = nullptr;
|
||||
|
||||
field->group_fl = true;
|
||||
|
||||
@ -1412,12 +1412,14 @@ cw::rc_t cw::flow::value_set( value_t* val, const char* v )
|
||||
switch( val->tflag & kTypeMask )
|
||||
{
|
||||
case kStringTFl:
|
||||
val->u.s=mem::duplStr(v); break;
|
||||
val->u.s=mem::duplStr(v);
|
||||
break;
|
||||
|
||||
case kInvalidTFl:
|
||||
val->u.s = mem::duplStr(v);
|
||||
val->tflag = kStringTFl;
|
||||
break;
|
||||
|
||||
default:
|
||||
rc = cwLogError(kTypeMismatchRC,"A string could not be converted to a %s (0x%x).",_typeFlagToLabel(val->tflag),val->tflag);
|
||||
}
|
||||
@ -1710,17 +1712,25 @@ cw::rc_t cw::flow::recd_format_create( recd_fmt_t*& recd_fmt_ref, const object_t
|
||||
|
||||
recd_fmt = mem::allocZ<recd_fmt_t>();
|
||||
|
||||
if((rc = recd_type_create(recd_fmt->recd_type,nullptr,cfg)) != kOkRC )
|
||||
goto errLabel;
|
||||
if( cfg->find( "fields" ) != nullptr )
|
||||
if((rc = recd_type_create(recd_fmt->recd_type,nullptr,cfg)) != kOkRC )
|
||||
goto errLabel;
|
||||
|
||||
recd_fmt->alloc_cnt = dflt_alloc_cnt;
|
||||
|
||||
if((rc =cfg->getv_opt("alloc_cnt",recd_fmt->alloc_cnt)) != kOkRC )
|
||||
if((rc =cfg->getv_opt("alloc_cnt",recd_fmt->alloc_cnt,
|
||||
"required",recd_fmt->req_fieldL)) != kOkRC )
|
||||
{
|
||||
rc = cwLogError(rc,"Error parsing record format 'alloc_cnt'.");
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
if(recd_fmt->req_fieldL != nullptr && !recd_fmt->req_fieldL->is_list() )
|
||||
{
|
||||
rc = cwLogError(rc,"The 'required' field list is not a list.");
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
recd_fmt_ref = recd_fmt;
|
||||
|
||||
errLabel:
|
||||
@ -1874,6 +1884,38 @@ cw::rc_t cw::flow::recd_array_create( recd_array_t*& recd_array_ref, recd_type_t
|
||||
return rc;
|
||||
}
|
||||
|
||||
cw::rc_t cw::flow::recd_copy( const recd_type_t* recd_type, const recd_t* recdA, unsigned recdN, recd_array_t* recd_array )
|
||||
{
|
||||
rc_t rc = kOkRC;
|
||||
|
||||
if( recd_array->allocRecdN < recdN )
|
||||
{
|
||||
rc = cwLogError(kBufTooSmallRC,"Not enough space in the destination record array.");
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
if( recd_type->fieldN != recd_array->type->fieldN )
|
||||
{
|
||||
rc = cwLogError(kInvalidArgRC,"Field count mismatch between source and destination records..");
|
||||
goto errLabel;
|
||||
}
|
||||
|
||||
|
||||
for(unsigned i=0; i<recdN; ++i)
|
||||
for(unsigned j=0; j<recd_type->fieldN; ++j)
|
||||
{
|
||||
recd_array->recdA[i].valA[j] = recdA[i].valA[j];
|
||||
recd_array->recdA[i].base = recdA[i].base;
|
||||
}
|
||||
|
||||
errLabel:
|
||||
if( rc!=kOkRC )
|
||||
rc = cwLogError(rc,"Record copy failed.");
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
cw::rc_t cw::flow::recd_array_destroy( recd_array_t*& recd_array_ref )
|
||||
{
|
||||
if( recd_array_ref != nullptr )
|
||||
|
@ -272,8 +272,9 @@ namespace cw
|
||||
|
||||
typedef struct recd_fmt_str
|
||||
{
|
||||
unsigned alloc_cnt; // count of records to pre-allocate
|
||||
recd_type_t* recd_type; // record type for this variable
|
||||
unsigned alloc_cnt; // count of records to pre-allocate
|
||||
const object_t* req_fieldL; // label of required fields
|
||||
recd_type_t* recd_type; // record type for this variable
|
||||
} recd_fmt_t;
|
||||
|
||||
typedef struct recd_array_str
|
||||
@ -414,6 +415,12 @@ namespace cw
|
||||
// Create/destroy a buffer of records.
|
||||
rc_t recd_array_create( recd_array_t*& recd_array_ref, recd_type_t* recd_type, const recd_type_t* base, unsigned allocRecdN );
|
||||
rc_t recd_array_destroy( recd_array_t*& recd_array_ref );
|
||||
|
||||
// Copy records into a recd_array. This function fails if there are less than
|
||||
// 'src_recdN' records already allocated in 'dest_recd_array'.
|
||||
// The source and destination record types should be the same, but this
|
||||
// function does very little to verify that the actually are.
|
||||
rc_t recd_copy( const recd_type_t* src_recd_type, const recd_t* src_recdA, unsigned src_recdN, recd_array_t* dest_recd_array );
|
||||
|
||||
rc_t value_test( const test::test_args_t& args );
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user