cmData.h/c: cmDataPrepend/Insert/AppendChild() now automatically unlinks the
new child prior to relinking it to it's new parent. Fixed bug in cmDataMakePair() where the key and value were never actually linked in.
This commit is contained in:
parent
b0a06eba95
commit
80498f4f79
13
cmData.c
13
cmData.c
@ -1284,8 +1284,12 @@ cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p )
|
|||||||
{
|
{
|
||||||
assert( cmDataIsStruct(p) );
|
assert( cmDataIsStruct(p) );
|
||||||
|
|
||||||
|
|
||||||
|
cmDataUnlink(p);
|
||||||
|
|
||||||
p->u.child = parent->u.child;
|
p->u.child = parent->u.child;
|
||||||
parent->u.child = p;
|
parent->u.child = p;
|
||||||
|
p->parent = parent;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1294,6 +1298,8 @@ cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p )
|
|||||||
assert( cmDataIsStruct(parent) );
|
assert( cmDataIsStruct(parent) );
|
||||||
assert( parent->tid != kRecordDtId || (parent->tid == kRecordDtId && p->tid==kPairDtId));
|
assert( parent->tid != kRecordDtId || (parent->tid == kRecordDtId && p->tid==kPairDtId));
|
||||||
|
|
||||||
|
cmDataUnlink(p);
|
||||||
|
|
||||||
cmData_t* cp = parent->u.child;
|
cmData_t* cp = parent->u.child;
|
||||||
if( cp == NULL )
|
if( cp == NULL )
|
||||||
parent->u.child = p;
|
parent->u.child = p;
|
||||||
@ -1307,6 +1313,7 @@ cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p->parent = parent;
|
||||||
p->sibling = NULL;
|
p->sibling = NULL;
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
@ -1316,6 +1323,8 @@ cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p )
|
|||||||
if( !cmDataIsStruct(parent) )
|
if( !cmDataIsStruct(parent) )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
cmDataUnlink(p);
|
||||||
|
|
||||||
unsigned n = 0;
|
unsigned n = 0;
|
||||||
cmData_t* cp = parent->u.child;
|
cmData_t* cp = parent->u.child;
|
||||||
cmData_t* pp = NULL;
|
cmData_t* pp = NULL;
|
||||||
@ -1339,6 +1348,8 @@ cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p )
|
|||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p->parent = parent;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1422,6 +1433,8 @@ cmData_t* cmDataMakePair( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t
|
|||||||
p->parent = parent;
|
p->parent = parent;
|
||||||
p->flags = 0;
|
p->flags = 0;
|
||||||
p->u.child = NULL;
|
p->u.child = NULL;
|
||||||
|
cmDataAppendChild(p,key);
|
||||||
|
cmDataAppendChild(p,value);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
20
cmData.h
20
cmData.h
@ -125,7 +125,7 @@ extern "C" {
|
|||||||
|
|
||||||
bool cmDataIsValue( const cmData_t* p );
|
bool cmDataIsValue( const cmData_t* p );
|
||||||
bool cmDataIsPtr( const cmData_t* p );
|
bool cmDataIsPtr( const cmData_t* p );
|
||||||
bool cmDataIsStruct( const cmData_t* p );
|
bool cmDataIsStruct( const cmData_t* p ); // is a pair,list or record
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO:
|
TODO:
|
||||||
@ -367,17 +367,20 @@ extern "C" {
|
|||||||
|
|
||||||
// Prepend 'p' to 'parents' child list.
|
// Prepend 'p' to 'parents' child list.
|
||||||
// The source node 'p' is not duplicated it is simply linked in.
|
// The source node 'p' is not duplicated it is simply linked in.
|
||||||
|
// 'p' is automatically unlinked prior to being prepended.
|
||||||
// Returns 'p'.
|
// Returns 'p'.
|
||||||
cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p );
|
cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p );
|
||||||
|
|
||||||
// Append 'p' to the end of 'parent' child list.
|
// Append 'p' to the end of 'parent' child list.
|
||||||
// The source node 'p' is not duplicated it is simply linked in.
|
// The source node 'p' is not duplicated it is simply linked in.
|
||||||
// Returns 'p'.
|
// 'p' is automatically unlinked prior to being appended.
|
||||||
|
// Returns 'p'.
|
||||||
cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p );
|
cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p );
|
||||||
|
|
||||||
// Insert 'p' at index. Index must be in the range:
|
// Insert 'p' at index. Index must be in the range:
|
||||||
// 0 to cmDataChildCount(parent).
|
// 0 to cmDataChildCount(parent).
|
||||||
// The source node 'p' is not duplicated it is simply linked in.
|
// The source node 'p' is not duplicated it is simply linked in.
|
||||||
|
// 'p' is automatically unlinked prior to being inserted.
|
||||||
// Returns 'p'.
|
// Returns 'p'.
|
||||||
cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p );
|
cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p );
|
||||||
|
|
||||||
@ -408,12 +411,18 @@ extern "C" {
|
|||||||
// The data space for the 'label' string is dynamically allocated.
|
// The data space for the 'label' string is dynamically allocated.
|
||||||
cmData_t* cmDataPairSetKeyLabel( cmData_t* p, const cmChar_t* label );
|
cmData_t* cmDataPairSetKeyLabel( cmData_t* p, const cmChar_t* label );
|
||||||
|
|
||||||
|
// Create a pair value by assigning a key and value to 'p'.
|
||||||
|
// 'p' is unlinked and freed prior to the key value assignment.
|
||||||
|
// 'key' and 'value' are simply linked in they are not duplicated or reallocated.
|
||||||
cmData_t* cmDataMakePair( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value );
|
cmData_t* cmDataMakePair( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value );
|
||||||
|
|
||||||
// Dynamically allocate a pair node
|
// Dynamically allocate a pair node. Both the key and value nodes are reallocated.
|
||||||
cmData_t* cmDataAllocPair( cmData_t* parent, const cmData_t* key, const cmData_t* value );
|
cmData_t* cmDataAllocPair( cmData_t* parent, const cmData_t* key, const cmData_t* value );
|
||||||
|
|
||||||
|
// Dynamically allocate the id but link (w/o realloc) the value.
|
||||||
cmData_t* cmDataAllocPairId( cmData_t* parent, unsigned keyId, cmData_t* value );
|
cmData_t* cmDataAllocPairId( cmData_t* parent, unsigned keyId, cmData_t* value );
|
||||||
// The data space for the 'label' string is dynamically allocated.
|
|
||||||
|
// Dynamically allocate the label but link (w/o realloc) the value.
|
||||||
cmData_t* cmDataAllocPairLabel( cmData_t* parent, const cmChar_t* label, cmData_t* value );
|
cmData_t* cmDataAllocPairLabel( cmData_t* parent, const cmChar_t* label, cmData_t* value );
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -476,6 +485,9 @@ extern "C" {
|
|||||||
cmData_t* cmRecdMake( cmData_t* parent, cmData_t* p );
|
cmData_t* cmRecdMake( cmData_t* parent, cmData_t* p );
|
||||||
cmData_t* cmRecdAlloc( cmData_t* parent );
|
cmData_t* cmRecdAlloc( cmData_t* parent );
|
||||||
|
|
||||||
|
// Append a pair node by linking the pair node 'pair' to the record node 'p'.
|
||||||
|
// 'pair' is simply linked to 'p' via cmDataAppendChild() no
|
||||||
|
// reallocation or duplicattion takes place.
|
||||||
cmData_t* cmRecdAppendPair( cmData_t* p, cmData_t* pair );
|
cmData_t* cmRecdAppendPair( cmData_t* p, cmData_t* pair );
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user