cwUi.cpp : _createEleFromRsrc() now duplicates the rsrc object prior to modifying it, thereby allowing a const source object.
This commit is contained in:
parent
65ad48974e
commit
a7858560a4
29
cwUi.cpp
29
cwUi.cpp
@ -328,15 +328,16 @@ namespace cw
|
|||||||
return ele;
|
return ele;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc_t _createElementsFromChildList( ui_t* p, object_t* po, unsigned wsSessId, ele_t* parentEle );
|
rc_t _createElementsFromChildList( ui_t* p, const object_t* po, unsigned wsSessId, ele_t* parentEle );
|
||||||
|
|
||||||
//
|
//
|
||||||
rc_t _createEleFromRsrsc( ui_t* p, ele_t* parentEle, const char* eleType, object_t* o, unsigned wsSessId )
|
rc_t _createEleFromRsrsc( ui_t* p, ele_t* parentEle, const char* eleType, const object_t* srcObj, unsigned wsSessId )
|
||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
object_t* co = nullptr;
|
object_t* co = nullptr;
|
||||||
ele_t* ele = nullptr;
|
ele_t* ele = nullptr;
|
||||||
char* eleName = nullptr;
|
char* eleName = nullptr;
|
||||||
|
object_t* o = srcObj->duplicate(); // duplicate the rsrc object so that we can modify it.
|
||||||
|
|
||||||
if( !o->is_dict() )
|
if( !o->is_dict() )
|
||||||
return cwLogError(kSyntaxErrorRC,"All ui element resource records must be dictionaries.");
|
return cwLogError(kSyntaxErrorRC,"All ui element resource records must be dictionaries.");
|
||||||
@ -419,12 +420,15 @@ namespace cw
|
|||||||
if( co != nullptr )
|
if( co != nullptr )
|
||||||
co->free();
|
co->free();
|
||||||
|
|
||||||
|
if( o != nullptr )
|
||||||
|
o->free();
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 'od' is an object dictionary where each pair in the dictionary has
|
// 'od' is an object dictionary where each pair in the dictionary has
|
||||||
// the form: 'eleType':{ <object> }
|
// the form: 'eleType':{ <object> }
|
||||||
rc_t _createElementsFromChildList( ui_t* p, object_t* po, unsigned wsSessId, ele_t* parentEle )
|
rc_t _createElementsFromChildList( ui_t* p, const object_t* po, unsigned wsSessId, ele_t* parentEle )
|
||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
|
|
||||||
@ -435,23 +439,25 @@ namespace cw
|
|||||||
|
|
||||||
for(unsigned i=0; i<childN; ++i)
|
for(unsigned i=0; i<childN; ++i)
|
||||||
{
|
{
|
||||||
object_t* o = po->child_ele(i);
|
const object_t* o = po->child_ele(i);
|
||||||
|
|
||||||
if( !o->is_pair() )
|
if( !o->is_pair() )
|
||||||
return cwLogError(kSyntaxErrorRC,"All object dictionary children must be pairs.");
|
return cwLogError(kSyntaxErrorRC,"All object dictionary children must be pairs.");
|
||||||
|
|
||||||
if((rc = _createEleFromRsrsc(p, parentEle, o->pair_label(), o->pair_value(), wsSessId )) != kOkRC )
|
// skip pairs whose value is not a dict
|
||||||
return rc;
|
if( o->pair_value()->is_dict() )
|
||||||
|
if((rc = _createEleFromRsrsc(p, parentEle, o->pair_label(), o->pair_value(), wsSessId )) != kOkRC )
|
||||||
|
return rc;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc_t _createFromObj( ui_t* p, object_t* o, unsigned wsSessId, unsigned parentUuId )
|
rc_t _createFromObj( ui_t* p, const object_t* o, unsigned wsSessId, unsigned parentUuId )
|
||||||
{
|
{
|
||||||
rc_t rc = kOkRC;
|
rc_t rc = kOkRC;
|
||||||
object_t* po = nullptr;
|
const object_t* po = nullptr;
|
||||||
ele_t* parentEle = nullptr;
|
ele_t* parentEle = nullptr;
|
||||||
char* eleName = nullptr;
|
char* eleName = nullptr;
|
||||||
|
|
||||||
@ -459,7 +465,6 @@ namespace cw
|
|||||||
if((po = o->find("parent",kNoRecurseFl | kOptionalFl)) == nullptr )
|
if((po = o->find("parent",kNoRecurseFl | kOptionalFl)) == nullptr )
|
||||||
return cwLogError(kSyntaxErrorRC,"UI resources must have a root 'parent' value.");
|
return cwLogError(kSyntaxErrorRC,"UI resources must have a root 'parent' value.");
|
||||||
|
|
||||||
|
|
||||||
// get the parent element name
|
// get the parent element name
|
||||||
if((rc = po->value(eleName)) != kOkRC )
|
if((rc = po->value(eleName)) != kOkRC )
|
||||||
return cwLogError(kOpFailRC,"The root 'parent' value could not be accessed.");
|
return cwLogError(kOpFailRC,"The root 'parent' value could not be accessed.");
|
||||||
@ -469,13 +474,13 @@ namespace cw
|
|||||||
return cwLogError(kSyntaxErrorRC,"A parent UI element named '%s' could not be found.",cwStringNullGuard(eleName));
|
return cwLogError(kSyntaxErrorRC,"A parent UI element named '%s' could not be found.",cwStringNullGuard(eleName));
|
||||||
|
|
||||||
// unlink the 'parent' pair
|
// unlink the 'parent' pair
|
||||||
po = po->parent;
|
//po = po->parent;
|
||||||
|
|
||||||
po->unlink();
|
//po->unlink();
|
||||||
|
|
||||||
rc = _createElementsFromChildList( p, o, wsSessId, parentEle );
|
rc = _createElementsFromChildList( p, o, wsSessId, parentEle );
|
||||||
|
|
||||||
po->free();
|
//po->free();
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user