Преглед изворни кода

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.
master
kevin пре 11 година
родитељ
комит
80498f4f79
2 измењених фајлова са 29 додато и 4 уклоњено
  1. 13
    0
      cmData.c
  2. 16
    4
      cmData.h

+ 13
- 0
cmData.c Прегледај датотеку

1284
 {
1284
 {
1285
   assert( cmDataIsStruct(p) );
1285
   assert( cmDataIsStruct(p) );
1286
   
1286
   
1287
+
1288
+  cmDataUnlink(p);
1289
+
1287
   p->u.child    = parent->u.child;
1290
   p->u.child    = parent->u.child;
1288
   parent->u.child = p;
1291
   parent->u.child = p;
1292
+  p->parent = parent;
1289
   return p;
1293
   return p;
1290
 }
1294
 }
1291
 
1295
 
1294
   assert( cmDataIsStruct(parent) );
1298
   assert( cmDataIsStruct(parent) );
1295
   assert( parent->tid != kRecordDtId || (parent->tid == kRecordDtId && p->tid==kPairDtId));
1299
   assert( parent->tid != kRecordDtId || (parent->tid == kRecordDtId && p->tid==kPairDtId));
1296
 
1300
 
1301
+  cmDataUnlink(p);
1302
+
1297
   cmData_t* cp = parent->u.child;
1303
   cmData_t* cp = parent->u.child;
1298
   if( cp == NULL )
1304
   if( cp == NULL )
1299
     parent->u.child = p;
1305
     parent->u.child = p;
1307
       }
1313
       }
1308
   }
1314
   }
1309
 
1315
 
1316
+  p->parent  = parent;
1310
   p->sibling = NULL;
1317
   p->sibling = NULL;
1311
   return p;
1318
   return p;
1312
 }
1319
 }
1316
   if( !cmDataIsStruct(parent) )
1323
   if( !cmDataIsStruct(parent) )
1317
     return NULL;
1324
     return NULL;
1318
 
1325
 
1326
+  cmDataUnlink(p);
1327
+
1319
   unsigned  n  = 0;
1328
   unsigned  n  = 0;
1320
   cmData_t* cp = parent->u.child;
1329
   cmData_t* cp = parent->u.child;
1321
   cmData_t* pp = NULL;
1330
   cmData_t* pp = NULL;
1339
     ++n;
1348
     ++n;
1340
   }
1349
   }
1341
 
1350
 
1351
+  p->parent = parent;
1352
+
1342
   return p;
1353
   return p;
1343
   
1354
   
1344
 }
1355
 }
1422
   p->parent = parent;
1433
   p->parent = parent;
1423
   p->flags   = 0;
1434
   p->flags   = 0;
1424
   p->u.child = NULL;
1435
   p->u.child = NULL;
1436
+  cmDataAppendChild(p,key);
1437
+  cmDataAppendChild(p,value);
1425
   return p;
1438
   return p;
1426
 }
1439
 }
1427
 
1440
 

+ 16
- 4
cmData.h Прегледај датотеку

125
 
125
 
126
   bool cmDataIsValue(  const cmData_t* p );
126
   bool cmDataIsValue(  const cmData_t* p );
127
   bool cmDataIsPtr(    const cmData_t* p );
127
   bool cmDataIsPtr(    const cmData_t* p );
128
-  bool cmDataIsStruct( const cmData_t* p );
128
+  bool cmDataIsStruct( const cmData_t* p ); // is a pair,list or record
129
 
129
 
130
   /*
130
   /*
131
     TODO:
131
     TODO:
367
 
367
 
368
   // Prepend 'p' to 'parents' child list.
368
   // Prepend 'p' to 'parents' child list.
369
   // The source node 'p' is not duplicated  it is simply linked in.
369
   // The source node 'p' is not duplicated  it is simply linked in.
370
+  // 'p' is automatically unlinked prior to being prepended.
370
   // Returns 'p'. 
371
   // Returns 'p'. 
371
   cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p );
372
   cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p );
372
 
373
 
373
   // Append 'p' to the end of 'parent' child list.
374
   // Append 'p' to the end of 'parent' child list.
374
   // The source node 'p' is not duplicated it is simply linked in.
375
   // The source node 'p' is not duplicated it is simply linked in.
375
-  // Returns 'p'.
376
+  // 'p' is automatically unlinked prior to being appended.
377
+  // Returns 'p'. 
376
   cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p );
378
   cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p );
377
 
379
 
378
   // Insert 'p' at index.  Index must be in the range: 
380
   // Insert 'p' at index.  Index must be in the range: 
379
   // 0 to cmDataChildCount(parent).
381
   // 0 to cmDataChildCount(parent).
380
   // The source node 'p' is not duplicated it is simply linked in.
382
   // The source node 'p' is not duplicated it is simply linked in.
383
+  // 'p' is automatically unlinked prior to being inserted.
381
   // Returns 'p'.
384
   // Returns 'p'.
382
   cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p );
385
   cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p );
383
 
386
 
408
   // The data space for the 'label' string is dynamically allocated.
411
   // The data space for the 'label' string is dynamically allocated.
409
   cmData_t* cmDataPairSetKeyLabel(  cmData_t* p, const cmChar_t* label );
412
   cmData_t* cmDataPairSetKeyLabel(  cmData_t* p, const cmChar_t* label );
410
 
413
 
414
+  // Create a pair value by assigning a key and value to 'p'.
415
+  // 'p' is unlinked and freed prior to the key value assignment.
416
+  // 'key' and 'value' are simply linked in they are not duplicated or reallocated.
411
   cmData_t* cmDataMakePair(       cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value );
417
   cmData_t* cmDataMakePair(       cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value );
412
 
418
 
413
-  // Dynamically allocate a pair node 
419
+  // Dynamically allocate a pair node. Both the key and value nodes are reallocated.
414
   cmData_t* cmDataAllocPair(      cmData_t* parent, const cmData_t* key,  const cmData_t* value );
420
   cmData_t* cmDataAllocPair(      cmData_t* parent, const cmData_t* key,  const cmData_t* value );
421
+
422
+  // Dynamically allocate the id but link (w/o realloc) the value.
415
   cmData_t* cmDataAllocPairId(    cmData_t* parent, unsigned  keyId,       cmData_t* value );
423
   cmData_t* cmDataAllocPairId(    cmData_t* parent, unsigned  keyId,       cmData_t* value );
416
-  // The data space for the 'label' string is dynamically allocated.
424
+
425
+  // Dynamically allocate the label but link (w/o realloc) the value.
417
   cmData_t* cmDataAllocPairLabel( cmData_t* parent, const cmChar_t* label, cmData_t* value );
426
   cmData_t* cmDataAllocPairLabel( cmData_t* parent, const cmChar_t* label, cmData_t* value );
418
 
427
 
419
   //----------------------------------------------------------------------------
428
   //----------------------------------------------------------------------------
476
   cmData_t*       cmRecdMake( cmData_t* parent, cmData_t* p );
485
   cmData_t*       cmRecdMake( cmData_t* parent, cmData_t* p );
477
   cmData_t*       cmRecdAlloc( cmData_t* parent );
486
   cmData_t*       cmRecdAlloc( cmData_t* parent );
478
   
487
   
488
+  // Append a pair node by linking the pair node 'pair' to the record node 'p'.
489
+  // 'pair' is simply linked to 'p' via cmDataAppendChild() no 
490
+  // reallocation or duplicattion takes place.
479
   cmData_t*       cmRecdAppendPair( cmData_t* p, cmData_t* pair );
491
   cmData_t*       cmRecdAppendPair( cmData_t* p, cmData_t* pair );
480
 
492
 
481
 
493
 

Loading…
Откажи
Сачувај