1d0
< #include <cstdlib> /* exit() */
2a2,6
> #include <string>
> #include <list>
> #include <valarray>
> #include <vector>
> 
5c9
< #include <string>
---
> #include <cassert>
8,9d11
< 
< #include "util.h"
11d12
< #include "hash.h"
12a14,30
> #include "BlockStruct.h"
> #include "GroupStruct.h"
> #include "GroupDefStruct.h"
> #include "ZoneStruct.h"
> #include "AUStruct.h"
> #include "TimberClassStruct.h"
> #include "RegenStruct.h"
> #include "RoadRecStruct.h"
> #include "TransferStruct.h"
> #include "TargetStruct.h"
> #include "TableStruct.h"
> 
> #include "DuplicateDataException.h"
> #include "DataNotFoundException.h"
> #include "InvalidDataException.h"
> 
> 
19,22d36
<         ZONE	*zone;
<         AU	*au;
<         TIMBER_CLASS	*timber_class;
<         BLOCK	*neighbour;
25c39
<         printf("\nInitialising adjacency ...");
---
>         cout << "Initializing adjacency ...";
28,30c42,50
<         pApp->m_zoneList = (LIST_PTR *)List::reset(pApp->m_zoneList);
<         zone = (ZONE *)List::next(pApp->m_zoneList);
<         while (zone!= 0)
---
> 
>         typedef vector<ZoneStruct*>::iterator ZI;
> 
> #ifdef _TSB_AGE_DEBUG
>         int zoneCounter = 0;
>         cout << "init_adjacency: size of zone list = " << pApp->m_zoneList.size() << endl;
> #endif
> 
>         for (ZI zoneIter = pApp->m_zoneList.begin(); zoneIter != pApp->m_zoneList.end(); ++zoneIter)
32,34c52,60
<             zone->aulist= (LIST_PTR *)List::reset(zone->aulist);
<             au = static_cast<AU*>(List::next(zone->aulist));
<             while (au!= 0)
---
>             typedef vector<AUStruct*>::iterator AI;
> 
> #ifdef _TSB_AGE_DEBUG
>             int auCounter = 0;
>             cout << endl << "processing zone # " << ++zoneCounter << endl;
>             cout << "init_adjacency: size of au list = " << (*zoneIter)->aulist.size() << endl;
> #endif
> 
>             for (AI auIter = (*zoneIter)->aulist.begin(); auIter != (*zoneIter)->aulist.end(); ++auIter)
36,38c62,73
<                 au->classlist = (LIST_PTR *)List::reset(au->classlist);
<                 timber_class = (TIMBER_CLASS *)List::next(au->classlist);
<                 while (timber_class!= 0)
---
>                 AUStruct* pCurrentAU = (*auIter);
> 
>                 typedef multimap<int, TimberClassStruct*>::iterator CI;
>                 multimap<int, TimberClassStruct*>& timberClassList = (pCurrentAU)->classlist;
> 
> #ifdef _TSB_AGE_DEBUG
>                 int classCounter = 0;
>                 cout << endl << "processing au # " << ++auCounter << endl;
>                 cout << "init_adjacency: size of class list = " << timberClassList.size() << endl;
> #endif
> 
>                 for (CI classIter = timberClassList.begin(); classIter != timberClassList.end(); ++classIter)
40c75,83
<                     if (timber_class->class_type!=FssimApp::NONCONTRIBUTING)
---
>                     TimberClassStruct* pCurrentTimberClass = classIter->second;
> 
> #ifdef _TSB_AGE_DEBUG
>                     ++classCounter;
>                     cout << endl << "processing class # " << classCounter << endl;
>                     cout << endl << "init_adjacency: age: " << pCurrentTimberClass->age << endl;
> #endif
> 
>                     if (pCurrentTimberClass->class_type != GroupDefStruct::NONCONTRIBUTING)
42c85,93
<                         if ((timber_class->age-timber_class->width+1)<au->table->AdjacencyAge)
---
>                         assert(0 != pCurrentAU->table);
>                         assert(pCurrentTimberClass->parent_au != 0);
> 
> #ifdef _TSB_AGE_DEBUG
>                         cout << "processing table: " << pCurrentAU->table->id << endl;
> #endif
> 
>                         if ((pCurrentTimberClass->age - pCurrentTimberClass->width + 1) <
> 			                 pCurrentAU->table->AdjacencyAge)
44,46c95,98
<                             timber_class->parent_block->Neighbours = (LIST_PTR *)List::reset(timber_class->parent_block->Neighbours);
<                             neighbour = (BLOCK *)List::next(timber_class->parent_block->Neighbours);
<                             while (neighbour!= 0)
---
>                             list<int>::iterator neighbourIDItem =
> 			                    pCurrentTimberClass->parent_block->m_neighbourIndices.begin();
> 
>                             while (neighbourIDItem != pCurrentTimberClass->parent_block->m_neighbourIndices.end())
48,49c100,104
<                                 AdjacencyDelay = au->table->AdjacencyAge-(timber_class->age-timber_class->width+1);
<                                 if (AdjacencyDelay>neighbour->AdjacencyDelay)
---
>                                 BlockStruct* pNeighbour = BlockStruct::find(*neighbourIDItem);
>                                 AdjacencyDelay = pCurrentAU->table->AdjacencyAge -
> 				                                 (pCurrentTimberClass->age - pCurrentTimberClass->width + 1);
> 
>                                 if (AdjacencyDelay > pNeighbour->AdjacencyDelay)
51c106
<                                     neighbour->AdjacencyDelay = AdjacencyDelay;
---
>                                     pNeighbour->AdjacencyDelay = AdjacencyDelay;
53c108
<                                 neighbour = (BLOCK *)List::next(timber_class->parent_block->Neighbours);
---
>                                 neighbourIDItem++;
57d111
<                     timber_class = (TIMBER_CLASS *)List::next(au->classlist);
59d112
<                 au = static_cast<AU*>(List::next(zone->aulist));
61d113
<             zone = (ZONE *)List::next(pApp->m_zoneList);
63c115,117
<         printf("Done\n");
---
> #ifdef _TSB_VERBOSE
>         cout << "Done" << endl;
> #endif
68,72d121
<         GROUP		*group, *testgroup;
<         GROUPDEF	*gd;
<         ZONE		*zone;
<         AU		*au;
< 
74,76c123,126
<         pApp->m_groupList = (LIST_PTR *)List::reset(pApp->m_groupList);
<         group = (GROUP *)List::next(pApp->m_groupList);
<         while (group != 0)
---
> 
>         typedef vector<GroupStruct*>::iterator GI;
>         for (GI groupIter = pApp->m_groupList.begin(); //!pApp->m_groupList.empty() &&
>                 groupIter != pApp->m_groupList.end(); ++groupIter)
78,80c128,135
<             group->groupdefs = (LIST_PTR *)List::reset(group->groupdefs);
<             gd = (GROUPDEF *)List::next(group->groupdefs);
<             while (gd != 0)
---
>             GroupStruct* pGroup = *groupIter;
> 
> #ifdef _TSB_ELIGIBLE_GROUP_DEBUG
>             cout << endl << "group eligibility: group id: " << pGroup->id << endl;
> #endif
> 
>             vector<GroupDefStruct*>::iterator groupDefIter = pGroup->groupdefs.begin();
>             while (groupDefIter != pGroup->groupdefs.end())
82c137,143
<                 if (strcmp(gd->zone,FssimApp::m_kNullString)!=0)
---
>                 GroupDefStruct* pCurrentGroupDef = (*groupDefIter);
> 
> #ifdef _TSB_ELIGIBLE_GROUP_DEBUG
>                 cout << endl << "group eligibility: zone id: " << pCurrentGroupDef->m_zoneID << endl;
> #endif
> 
>                 if (pCurrentGroupDef->m_zoneID != FssimUtil::DUMMY_INPUT)
84,85c145,146
<                     zone = (ZONE *)func_find_zone(gd->zone);
<                     if (zone== 0)
---
>                     ZoneStruct* pZone = ZoneStruct::find(pCurrentGroupDef->m_zoneID);
>                     if (pCurrentGroupDef->m_auLabelIndex != FssimUtil::DUMMY_INPUT)
87,88c148,151
<                         printf("\n\nERROR: InitGroupEligibilityLists(): Could not find specified zone(%s)\n\n", gd->zone);
<                         exit(1);
---
>                         // SPECIFIC Zone/AU
>                         AUStruct* pAU = pZone->findAU(pCurrentGroupDef->m_auLabelIndex);
> 
>                         pAU->m_eligibleGroupList.push_back(pGroup->id);
90,109d152
<                     if (strcmp(gd->au,FssimApp::m_kNullString)!=0)
<                     {
<                         /* SPECIFIC ZONE/AU */
<                         au = static_cast<AU*>(func_find_au(zone, gd->au));
<                         if (au== 0)
<                         {
<                             printf("\n\nERROR: InitGroupEligibilityLists(): Could not find specified zone/AU pair(%s,%s)\n\n", gd->zone, gd->au);
<                             exit(1);
<                         }
<                         testgroup = (GROUP *)List::find(au->EligibleGroupList, group->id);
<                         if (testgroup== 0)
<                         {
< #ifdef _TSB_ELIGIBLE_GROUP_DEBUG
<                             cout << endl << "specific zone/AU: zone/au: " << endl
<                                  << zone->label << "/" << au->label << endl
<                                  << "inserting group id: " << group->id << endl;
< #endif
<                             au->EligibleGroupList = (LIST_PTR *)List::insert(au->EligibleGroupList, group, group->id);
<                         }
<                     }
112,119c155,156
<                         /* SPECIFIC ZONE/ALL AU */
<                         zone->aulist = (LIST_PTR *)List::reset(zone->aulist);
<                         au = static_cast<AU*>(List::next(zone->aulist));
<                         while (au != 0)
<                         {
<                             testgroup = (GROUP *)List::find(au->EligibleGroupList, group->id);
<                             if (testgroup== 0)
<                             {
---
>                         // SPECIFIC Zone/ALL AUs
> 
121,123c158
<                                 cout << endl << "specific zone/all AUs: zone/au: " << endl
<                                      << zone->label << "/" << au->label << endl
<                                      << "inserting group id: " << group->id << endl;
---
>                         cout << endl << "specific zone/all au: " << endl;
125,127c160,164
<                                 au->EligibleGroupList = (LIST_PTR *)List::insert(au->EligibleGroupList, group, group->id);
<                             }
<                             au = static_cast<AU*>(List::next(zone->aulist));
---
> 
>                         typedef vector<AUStruct*>::iterator AI;
>                         for (AI auIter = pZone->aulist.begin(); auIter != pZone->aulist.end(); ++auIter)
>                         {
>                             (*auIter)->m_eligibleGroupList.push_back(pGroup->id);
133c170
<                     if (strcmp(gd->au,FssimApp::m_kNullString)!=0)
---
>                     if (pCurrentGroupDef->m_auLabelIndex != FssimUtil::DUMMY_INPUT)
135,138c172,174
<                         /* ALL ZONES/SPECIFIC AUS */
<                         pApp->m_zoneList = (LIST_PTR *)List::reset(pApp->m_zoneList);
<                         zone = (ZONE *)List::next(pApp->m_zoneList);
<                         while (zone != 0)
---
>                         // ALL ZONES/SPECIFIC AUs
>                         typedef vector<ZoneStruct*>::iterator ZI;
>                         for (ZI zoneIter = pApp->m_zoneList.begin(); zoneIter != pApp->m_zoneList.end(); ++zoneIter)
140,141c176,178
<                             au = static_cast<AU*>(func_find_au(zone,gd->au));
<                             if (au != 0)
---
>                             ZoneStruct* pZone = (*zoneIter);
>                             // get the au of the zone with the same label as the groupdef's au
>                             try
143,152c180,181
<                                 testgroup = (GROUP *)List::find(au->EligibleGroupList, group->id);
<                                 if (testgroup == 0)
<                                 {
< #ifdef _TSB_ELIGIBLE_GROUP_DEBUG
<                                     cout << endl << "all zones/specific AU: zone/au: " << endl
<                                          << zone->label << "/" << au->label << endl
<                                          << "inserting group id: " << group->id << endl;
< #endif
<                                     au->EligibleGroupList = (LIST_PTR *)List::insert(au->EligibleGroupList, group, group->id);
<                                 }
---
>                                 AUStruct* pZoneAU = (*zoneIter)->findAU(pCurrentGroupDef->m_auLabelIndex);
>                                 pZoneAU->m_eligibleGroupList.push_back(pGroup->id);
154c183,186
<                             zone = (ZONE *)List::next(pApp->m_zoneList);
---
>                             catch(DataNotFoundException& e)
>                             {
>                                 // continue to next zone, no such AU's for this zone
>                             }
159,162c191,198
<                         /* ALL ZONES/ALL AUS */
<                         pApp->m_zoneList = (LIST_PTR *)List::reset(pApp->m_zoneList);
<                         zone = (ZONE *)List::next(pApp->m_zoneList);
<                         while (zone != 0)
---
>                         // ALL ZONES/ALL AUs
> 
> #ifdef _TSB_ELIGIBLE_GROUP_DEBUG
>                         cout << endl << "all zones/all AUs: zone/au: " << endl;
> #endif
> 
>                         typedef vector<ZoneStruct*>::iterator ZI;
>                         for (ZI zoneIter = pApp->m_zoneList.begin(); zoneIter != pApp->m_zoneList.end(); ++zoneIter)
164,166c200,206
<                             zone->aulist = (LIST_PTR *)List::reset(zone->aulist);
<                             au = static_cast<AU*>(List::next(zone->aulist));
<                             while (au != 0)
---
> 
> #ifdef _TSB_ELIGIBLE_GROUP_DEBUG
>                             cout << endl << "zone id: " << (*zoneIter)->id << endl;
> #endif
> 
>                             typedef vector<AUStruct*>::iterator AI;
>                             for (AI auIter = (*zoneIter)->aulist.begin(); auIter != (*zoneIter)->aulist.end(); ++auIter)
168,170c208
<                                 testgroup = (GROUP *)List::find(au->EligibleGroupList, group->id);
<                                 if (testgroup== 0)
<                                 {
---
> 
172,174c210
<                                     cout << endl << "all zones/all AUs: zone/au: " << endl
<                                          << zone->label << "/" << au->label << endl
<                                          << "inserting group id: " << group->id << endl;
---
>                                 cout << endl << "au id: " << (*auIter)->id << endl;
176,178c212
<                                     au->EligibleGroupList = (LIST_PTR *)List::insert(au->EligibleGroupList, group, group->id);
<                                 }
<                                 au = static_cast<AU*>(List::next(zone->aulist));
---
>                                 (*auIter)->m_eligibleGroupList.push_back(pGroup->id);
180d213
<                             zone = (ZONE *)List::next(pApp->m_zoneList);
184c217
<                 gd = (GROUPDEF *)List::next(group->groupdefs);
---
>                 groupDefIter++;
186c219
<             group = (GROUP *)List::next(pApp->m_groupList);
---
> 
191,192c224
<     BLOCK
<     *init_make_block(char *label)
---
>     BlockStruct* init_make_block(const char* label, const int id)
194,201c226
<         BLOCK* pBlock = 0;
<         int	HashKey;
< 
<         //pBlock = static_cast<BLOCK*>(func_find_block(label));
<         if (pBlock == 0)
<         {
<             //pBlock = static_cast<BLOCK*>(std::malloc(sizeof(BLOCK)));
<             pBlock = new BLOCK;
---
>         BlockStruct* pBlock = new BlockStruct(label, id, 0);
203c228
<             cout << "creating block at address: " << hex << (pBlock) << endl;
---
>         cout << "creating block at address: " << hex << (pBlock) << dec << endl;
205,222c230,233
<             if (pBlock== 0)
<             {
<                 printf("\n\nERROR: init_make_block(): Could not allocate new BLOCK structure\n\n");
<                 exit(1);
<             }
<             memset(pBlock->label, '\0', sizeof(pBlock->label));
<             sprintf(pBlock->label, "%s", label);
<             pBlock->AdjacencyDelay = 0;
<             pBlock->Neighbours = 0;
< 
<             HashKey = static_cast<int>(pBlock->label[0]);
<             FssimApp* pApp = FssimApp::getApp();
<             LIST_PTR* pBlockList = pApp->m_blockList;
<             pBlockList = static_cast<LIST_PTR*>(hash_insert(pBlockList, pBlock, HashKey, 0));
<             pApp->m_blockList = pBlockList;
< #ifdef _TSB_MEMORY_DEBUG
<             //cout << "Address of block list: " << (int)pBlockList << endl;
< #endif
---
>         if (pBlock == 0)
>         {
>             cerr << endl << endl << "ERROR: init_make_block(): Could not allocate new BlockStruct structure" << endl << endl;
>             throw bad_alloc();
224,225c235
< 
<         return(pBlock);
---
>         return pBlock;
229c239,241
<     TRANSFER* init_make_transfer(GROUP *group, int instart, int inend, char *inzone, char *inau, int inage, int inctype, int inrage)
---
>     TransferStruct* init_make_transfer(GroupStruct* pGroup, const int start, const int end,
>                                        const int zone, const int au, const int age,
>                                        const int ctype, const int rage)
231c243
<         TRANSFER	*transfer;
---
>         TransferStruct* transfer = new TransferStruct(start, end, zone, au, age, ctype, rage);
233,234c245
<         transfer = new TRANSFER;
<         if (transfer== 0)
---
>         if (transfer == 0)
236,237c247,248
<             printf("\n\nERROR: init_make_transfer(): Could not allocate new TRANSFER structure\n\n");
<             exit(1);
---
>             cerr << endl << endl << "ERROR: init_make_transfer(): Could not allocate new TransferStruct structure" << endl << endl;
>             throw bad_alloc();
239,244d249
<         transfer->start_period = instart;
<         transfer->end_period = inend;
<         memset(transfer->to_zone, '\0', sizeof(transfer->to_zone));
<         sprintf(transfer->to_zone, "%s", inzone);
<         memset(transfer->to_au, '\0', sizeof(transfer->to_au));
<         sprintf(transfer->to_au, "%s", inau);
246,252c251
<         transfer->to_age = inage;
<         transfer->to_ctype = inctype;
<         transfer->to_rage = inrage;
< #ifdef _TSB_REGEN_DEBUG
<             cout << "init_make_transfer: read transfer to regen age: " << inrage << endl;
< #endif
<         group->transferlist = (LIST_PTR *)List::insert(group->transferlist, transfer, 0);
---
>         pGroup->transferlist.push_back(transfer);
257,258c256,258
<     ROADREC
<     *init_make_roadrec(ZONE *parent_zone, AU *parent_au, int age, double percent, int toage, char *au, int offset, int reentry)
---
>     RoadRecStruct* init_make_roadrec(AUStruct* pParentAU, const int age,
>                                      const double percent, const int toAge, const int auLabelIndex,
>                                      const int offset, const int reEntry)
260,262c260
<         ROADREC	*r;
< 
<         if (parent_au->RoadRec!= 0)
---
>         if (pParentAU->RoadRec != 0)
264,265c262,264
<             printf("\n\nERROR: init_make_roadrec(): Duplicate RoadRec for Zone(%s)/AU(%s)\n\n", parent_zone->label, parent_au->label);
<             exit(1);
---
>             ostringstream invalidValue;
>             invalidValue << pParentAU->id;
>             throw DuplicateDataException(invalidValue.str(), "Duplicate RoadRec for AU");
267,268c266,267
<         r = new ROADREC;
<         if (r== 0)
---
>         RoadRecStruct* pRoadRec = new RoadRecStruct(auLabelIndex, age, percent, toAge, offset, reEntry);
>         if (pRoadRec == 0)
270,271c269,270
<             printf("\n\nERRROR: init_make_roadrec(): Could not allocate new ROADREC structure\n\n");
<             exit(1);
---
>             cerr << endl << endl << "ERROR: init_make_roadrec(): Could not allocate new RoadRecStruct structure" << endl << endl;
>             throw bad_alloc();
273,281c272,273
<         r->age = age;
<         r->percent = percent;
<         r->ToAge = toage;
<         r->Offset = offset;
<         r->reentry = reentry;
<         memset(r->au, '\0', sizeof(r->au));
<         sprintf(r->au, "%s", au);
<         parent_au->RoadRec = r;
<         return(r);
---
>         pParentAU->RoadRec = pRoadRec;
>         return pRoadRec;
285,286c277,278
<     REGEN
<     *init_make_regen(AU *parent_au, AU *au, int ToAge, double percent, int Offset, int reentry)
---
>     RegenStruct* init_make_regen(AUStruct* pParentAU, const int auLabelIndex, const int toAge,
>                                  const double percent, const int offset, const int reentry)
288,294c280,281
<         REGEN	*regen;
< 
<         regen = new REGEN;
< #ifdef _TSB_MEMORY_DEBUG
<             cout << "creating regen at address: " << hex << (regen) << endl;
< #endif
<         if (regen == 0)
---
>         RegenStruct* pRegen = new RegenStruct(auLabelIndex, toAge, offset, percent, reentry);
>         if (pRegen == 0)
296,297c283,284
<             printf("\n\nERROR: init_make_regen(): Could not allocate new REGEN structure\n\n");
<             exit(1);
---
>             cerr << endl << endl << "ERROR: init_make_regen(): Could not allocate new RegenStruct structure" << endl << endl;
>             throw bad_alloc();
299,305c286,287
<         regen->au = au;
<         regen->ToAge = ToAge;
<         regen->Offset = Offset;
<         regen->percent = percent;
<         regen->ReEntryLag = reentry;
<         parent_au->regenlist = (LIST_PTR *)List::insert(parent_au->regenlist, regen, 0);
<         return(regen);
---
>         pParentAU->regenlist.push_back(pRegen);
>         return pRegen;
308,309c290
<     TARGET
<     *init_make_target(ZONE *zone, GROUP *group, int utype, const char *where)
---
>     TargetStruct* init_make_target(StandSet* standSet)
311,312c292
<         TARGET		*target;
<         int		i;
---
>         FssimApp* pApp = FssimApp::getApp();
314c294
<         target = new TARGET;
---
>         TargetStruct* target = new TargetStruct( valarray<double>(0.0, pApp->m_planHorizon + 1) );
317,318c297,298
<             printf("\n\nERROR: init_make_target(Caller:%s): Could not allocate new TARGET structure\n\n", where);
<             exit(1);
---
>             cerr << endl << endl << "ERROR: init_make_target(): Could not allocate new TargetStruct structure" << endl << endl;
>             throw bad_alloc();
320,323c300
<         FssimApp* pApp = FssimApp::getApp();
<         // dynamically allocate array
<         target->max_volume = new double[pApp->m_planHorizon+1]; // allocate dynamic array
<         if (target->max_volume == 0)
---
>         if (standSet == 0)
325,326c302
<             printf("\n\nERROR: init_make_target(Caller:%s): Could not allocate new TARGET->max_volume structure\n\n", where);
<             exit(1);
---
>             throw InvalidDataException(0, "init_make_target called by null standSet parameter");
328,378c304,305
<         // dynamically allocate array
<         target->min_volume = new double[pApp->m_planHorizon+1];
<         if (target->min_volume == 0)
<         {
<             printf("\n\nERROR: init_make_target(Caller:%s): Could not allocate new TARGET->min_volume structure\n\n", where);
<             exit(1);
<         }
<         // dynamically allocate array
<         target->max_area = new double[pApp->m_planHorizon+1];
<         if (target->max_area == 0)
<         {
<             printf("\n\nERROR: init_make_target(Caller:%s): Could not allocate new TARGET->max_area structure\n\n", where);
<             exit(1);
<         }
<         // dynamically allocate array
<         target->min_area = new double[pApp->m_planHorizon+1];
<         if (target->min_area == 0)
<         {
<             printf("\n\nERROR: init_make_target(Caller:%s): Could not allocate new TARGET->min_area structure\n\n", where);
<             exit(1);
<         }
<         for(i=0;i<=pApp->m_planHorizon;i++)
<         {
<             target->max_volume[i] = FssimApp::DUMMYINPUT;
<             target->min_volume[i] = FssimApp::DUMMYINPUT;
<             target->max_area[i] = FssimApp::DUMMYINPUT;
<             target->min_area[i] = FssimApp::DUMMYINPUT;
<         }
<         if (utype == FssimApp::ZONE_TYPE)
<         {
<             if (zone == 0)
<             {
<                 printf("\n\nERROR: init_make_target(Caller:%s): 0 ZONE parameter\n\n", where);
<                 exit(1);
<             } else {
<                 zone->target = target;
<             }
<         } else if (utype == FssimApp::GROUP_TYPE)
<         {
<             if (group == 0)
<             {
<                 printf("\n\nERROR: init_make_target(Caller:%s): 0 GROUP parameter\n\n", where);
<                 exit(1);
<             } else {
<                 group->target = target;
<             }
<         } else {
<             printf("\n\nERROR: init_make_target(Caller:%s): Invalid unit-type paramater\n\n", where);
<             exit(1);
<         }
<         return(target);
---
>         standSet->target = target;
>         return target;
381,382c308,309
<     AXSDEF
<     *init_make_axsdef(ZONE *zone, GROUP *group, int utype, int start, int end, double Percent, int Sign, int Age)
---
>     AxsDefStruct* init_make_axsdef(StandSet* standSet, const int start, const int end,
>                                    const double percent, const int sign, const int age)
384,391c311,312
<         AXSDEF		*axs;
<         //TABLE		*table; // unreferenced!
< 
<         axs = new AXSDEF;
< #ifdef _TSB_MEMORY_DEBUG
<             cout << "creating axs at address: " << hex << (axs) << endl;
< #endif
<         if (axs == 0)
---
>         AxsDefStruct* pAxs = new AxsDefStruct(start, end, percent, sign, age);
>         if (pAxs == 0)
393,394c314,315
<             printf("\n\nERROR: init_make_axsdef(): Could not allocate new AXSDEF structure\n\n");
<             exit(1);
---
>             cerr << endl << endl << "ERROR: init_make_axsdef(): Could not allocate new AxsDefStruct structure" << endl << endl;
>             throw bad_alloc();
396,405c317
<         axs->start_period = start;
<         axs->end_period = end;
<         axs->Percent = Percent;
<         axs->Sign = Sign;
<         axs->Age = Age;
<         axs->NumAgeAreaElements = 0;
<         axs->AgeArea = 0;
<         axs->BaseArea = (double)0.0;
<         axs->AreaAch = (double)0.0;
<         if (utype == FssimApp::ZONE_TYPE)
---
>         if (standSet == 0)
407,415c319
<             if (zone == 0)
<             {
<                 printf("\n\nERROR: init_make_axsdef(): Attempted to insert AXSDEF record into 0 zone\n\n");
<                 exit(1);
<             }
<             zone->axslist = (LIST_PTR *)List::insert(zone->axslist, axs, 0);
< #ifdef _TSB_AXSDEF_DEBUG
<             cout << "just added axsdef to axslist of zone: " << zone->label << endl;
< #endif
---
>             throw InvalidDataException(0, "iinit_make_axsdef(): Attempted to insert AxsDefStruct record into null standSet");
417,424c321,322
<         else if (utype == FssimApp::GROUP_TYPE)
<         {
<             if (group == 0)
<             {
<                 printf("\n\nERROR: init_make_axsdef(): Attempted to insert AXSDEF record into 0 group\n\n");
<                 exit(1);
<             }
<             group->axslist = (LIST_PTR *)List::insert(group->axslist, axs, 0);
---
>         standSet->axslist.push_back(pAxs);
> 
426c324
<             cout << "just added axsdef to axslist of group: " << group->label << endl;
---
>         cout << "just added axsdef to axslist of standSet: " << standSet->label << endl;
428,434c326,327
<         }
<         else
<         {
<             printf("\n\nERROR: init_make_axsdef(): Invalid landunit type parameter\n\n");
<             exit(1);
<         }
<         return(axs);
---
> 
>         return pAxs;
437,438c330
<     TABLE
<     *init_make_table(char *label, const char *where, int id)
---
>     TableStruct* init_make_table(const char* label, const int id)
440,446c332,334
<         TABLE		*table;
<         int		i;
< 
<         /*
<         // check to see if table already exists
<         table = (TABLE *)func_find_table(label);
<         if (table != 0)
---
>         // create new table and add to pApp->m_tableList
>         TableStruct* pTable = new TableStruct(id, label);
>         if (pTable == 0)
448,449c336,337
<             printf("\n\nERROR: init_make_table(Caller:%s, %s): Duplicate table(%s)\n\n", where, label, label);
<             exit(1);
---
>             cerr << endl << endl << "ERROR: init_make_table(): Could not allocate new TableStruct structure" << endl << endl;
>             throw bad_alloc();
451,488c339
<         */
< 
<         /* create new table and add to pApp->m_tableList */
<         table = new TABLE;
< #ifdef _TSB_MEMORY_DEBUG
<             cout << "creating table at address: " << hex << (table) << endl;
< #endif
<         if (table == 0)
<         {
<             printf("\n\nERROR: init_make_table(Caller:%s): Could not allocate memory for new TABLE structure\n\n", where);
<             exit(1);
<         }
<         FssimApp* pApp = FssimApp::getApp();
<         if (-1 == id)
<         {
<             table->id = pApp->m_lastTableID++;
<         }
<         else
<         {
<             table->id = id;
<         }
<         table->Volume[0] = 0.00;
<         for(i=1;i<FssimApp::MAX_NUM_TABLE_VERTICES;i++)
<         {
<             table->Volume[i] = FssimApp::DUMMYINPUT;
<         }
<         memset(table->label, '\0', sizeof(table->label));
<         sprintf(table->label, "%s", label);
<         table->mha = 0;
<         table->AdjacencyAge = 0;
<         table->voaf1 = 1.00f;
<         table->voaf2 = 0.00f;
<         table->RefAge = 100;
< #ifdef _TSB_MEMORY_DEBUG
<             cout << "inserting table..." << endl;
< #endif
<         pApp->m_tableList = (LIST_PTR *)List::insert(pApp->m_tableList, table, table->id);
<         return(table);
---
>         return pTable;
491,492c342,343
<     GROUPDEF
<     *init_make_groupdef(GROUP *group, char *zone, char *au, char *block, int low_age, int high_age, int ctype)
---
>     GroupDefStruct* init_make_groupdef(GroupStruct* pGroup, const int zone, const int au, const int block,
>                                        const int lowAge, const int highAge, const int ctype)
494,498c345,347
<         GROUPDEF	*gd;
< 
<         /* create new group def and add to group->groupdefs list */
<         gd = new GROUPDEF;
<         if (gd == 0)
---
>         // create new group def and add to group->groupdefs list
>         GroupDefStruct*  pGroupDef = new GroupDefStruct(zone, au, block, lowAge, highAge, ctype);
>         if (pGroupDef == 0)
500,501c349,350
<             printf("\n\nERROR: init_make_groupdef(): Could not allocate memory for new GROUPDEF structure\n\n");
<             exit(1);
---
>             cerr << endl << endl << "ERROR: init_make_groupdef(): Could not allocate new GroupDefStruct structure" << endl << endl;
>             throw bad_alloc();
503,511d351
<         memset(gd->zone, '\0', sizeof(gd->zone));
<         sprintf(gd->zone, "%s", zone);
<         memset(gd->au, '\0', sizeof(gd->au));
<         sprintf(gd->au, "%s", au);
<         memset(gd->block, '\0', sizeof(gd->block));
<         sprintf(gd->block, "%s", block);
<         gd->low_age = low_age;
<         gd->high_age = high_age;
<         gd->class_type = ctype;
513c353,356
<         group->groupdefs = (LIST_PTR *)List::insert(group->groupdefs, gd, 0);
---
> #ifdef _TSB_FIND_DEBUG
>         cout << endl << "init_make_groupdef: inserted groupdef with zone/au/block: "
>              << zone << "/" << au << "/" << block << endl;
> #endif
515c358,359
<         return(gd);
---
>         pGroup->groupdefs.push_back(pGroupDef);
>         return pGroupDef;
518,519c362
<     GROUP
<     *init_make_group(char *label, int grouptype, int id)
---
>     GroupStruct* init_make_group(const char* label, const int groupType, const int id)
521,522c364
<         GROUP	*group;
<         int	i;
---
>         GroupStruct* pGroup = 0;
524,527c366
< 
<         /* check to see if group already exists */
<         group = (GROUP *)func_find_group(label);
<         if (group != 0)
---
>         if (-1 == id) // reading ascii input files, not binary
529c368,369
<             if (group->grouptype != grouptype)
---
>             // check to see if group already exists
>             try
531,532c371,376
<                 printf("\n\nERROR: init_make_group(): Group(%s) type inconsistency\n\n", label);
<                 exit(1);
---
>                 pGroup = GroupStruct::find(label);
>                 if (pGroup->grouptype != groupType)
>                 {
>                     throw InvalidDataException(label, "init_make_group(): Group type inconsistency");
>                 }
>                 return pGroup; // group already exists
534c378,381
<             return(group);
---
>             catch(DataNotFoundException& e) // if group doesn't exist yet, keep going and create it
>             {
>                 // no problem, keep going and create group
>             }
536,539c383,385
< 
<         /* create new group and add to pApp->m_groupList */
<         group = new GROUP;
<         if (group == 0)
---
>         // create new group and add to pApp->m_groupList (now done inside constructor)
>         pGroup = new GroupStruct(id, label, static_cast<GroupDefStruct::GroupType>(groupType));
>         if (pGroup == 0)
541,542c387,388
<             printf("\n\nERROR: init_make_group(): Could not allocate memory for new GROUP structure\n\n");
<             exit(1);
---
>             cerr << endl << endl << "ERROR: init_make_group(): Could not allocate new GroupStruct structure" << endl << endl;
>             throw bad_alloc();
544,585c390
< 
<         FssimApp* pApp = FssimApp::getApp();
<         if (-1 == id)
<         {
<             group->id = pApp->m_lastGroupID++;
<         }
<         else
<         {
<             group->id = id;
<         }
<         memset(group->label, '\0', sizeof(group->label));
<         sprintf(group->label, "%s", label);
<         group->grouptype = grouptype;
<         group->area = (double)0.0;
<         group->groupdefs = 0;
<         group->axslist = 0;
<         group->transferlist = 0;
<         group->target = 0;
<         group->reportFlags = 0;
<         // dynamically allocate array
<         group->priority = new int[pApp->m_planHorizon+1];
<         if (group->priority == 0)
<         {
<             printf("\n\nERROR: init_make_group(): Could not allocate new priority array\n\n");
<             exit(1);
<         }
<         for(i=0;i<=pApp->m_planHorizon;i++)
<         {
<             group->priority[i] = FssimApp::DEFAULT_PRIORITY;
<         }
<         group->achieved = new ACHIEVED;
<         if (group->achieved == 0)
<         {
<             printf("\n\nERROR: init_make_group(): Could not allocate new ACHIEVED structure\n\n");
<             exit(1);
<         }
<         group->achieved->volume = 0.0;
<         group->achieved->area = 0.0;
<         group->achieved->AgeDist = 0;
<         group->inventoryReport = 0;
<         pApp->m_groupList = (LIST_PTR *)List::insert(pApp->m_groupList, group, group->id);
<         return(group);
---
>         return pGroup;
588,589c393
<     AU
<     *init_make_au(ZONE *zone, char *label, const char *fname, int id)
---
>     AUStruct* init_make_au(ZoneStruct* pZone, const char* label, const int id, const int labelIndex)
591,593c395
<         AU	*au;
<         TABLE	*table;
<         int	i;
---
>         TableStruct* pTable = TableStruct::find(label); // verify that corresponding tables exists
595,602c397,399
<         /*
<         // check to see if au already exists
<         au = static_cast<AU*>(func_find_au(zone, label));
<         if (au != 0)
<         {
<             return(au);
<         }
<         */
---
> #ifdef _TSB_AU_TABLE_DEBUG
>         cout << "au: " << pAU->id << " associated to table: " << pTable->id << endl;
> #endif
604,606c401,403
<         // verify that corresponding tables exists
<         table = (TABLE *)func_find_table(label);
<         if (table == 0)
---
>         // create new au and add to zone->aulist
>         AUStruct* pAU = new AUStruct(id, label, pTable, pZone, labelIndex);
>         if (pAU == 0)
608,610c405,406
<             printf("\n\nERROR: init_make_au(): Could not find table corresponding to AU (%s)\n\n", label);
<             printf("\nIn file: %s", fname);
<             exit(1);
---
>             cerr << endl << endl << "ERROR: init_make_au(): Could not allocate new AUStruct structure" << endl << endl;
>             throw bad_alloc();
613,637c409,410
<         /* create new au and add to zone->aulist */
<         au = new AU;
<         if (au == 0)
<         {
<             printf("\n\nERROR: init_make_au(): Could not allocate memory for new AU structure\n\n");
<             exit(1);
<         }
<         FssimApp* pApp = FssimApp::getApp();
<         if (-1 == id)
<         {
<             au->id = zone->LastAUID++;
<         }
<         else
<         {
<             au->id = id;
<         }
<         memset(au->label, '\0', sizeof(au->label));
<         sprintf(au->label, "%s", label);
<         au->table = table;
<         au->landoaf = 1.0;
<         au->classlist = 0;
<         au->regenlist = 0;
<         au->EligibleGroupList = 0;
<         au->parent_zone = zone;
<         au->RoadRec = 0;
---
>         pZone->m_auLabelIndexMap[pAU->m_labelIndex] = pAU; // insert initialized label index into zone's map
>         pZone->aulist.push_back(pAU); // zones are sorted by zone->id incrementally (low to high)
639,654c412,414
<         // dynamically allocate array
<         au->priority = new int[pApp->m_planHorizon+1];
<         if (au->priority == 0)
<         {
<             printf("\n\nERROR: init_make_au(): Could not allocate new priority array\n\n");
<             exit(1);
<         }
<         for(i=0;i<=pApp->m_planHorizon;i++)
<         {
<             au->priority[i] = FssimApp::DEFAULT_PRIORITY;
<         }
<         zone->aulist = (LIST_PTR *)List::insert(zone->aulist, au, au->id);
< /*
< #ifdef _TSB_DEBUG
<         cout << "inserting au: " << au->id << " at address: " << au
<              << " into aulist of zone: " << zone->id << endl;
---
> #ifdef _TSB_MEMORY_DEBUG
>         cout << "inserting au: " << id << " at address: " << pAU
>              << " into aulist of zone: " << pZone->id << endl;
656,657c416,417
< */
<         return au;
---
> 
>         return pAU;
660,661c420
<     ZONE
<     *init_make_zone(char *label, int id)
---
>     ZoneStruct* init_make_zone(const char* label, const int id)
663,670c422,424
<         ZONE	*zone;
<         TABLE	*table;
<         int	i;
< 
<         /*
<         // check to see if zone already exists
<         zone = (ZONE *)func_find_zone(label);
<         if (zone != 0)
---
>         // create new zone and add to pApp->m_zoneList
>         ZoneStruct* pZone = new ZoneStruct(id, label);
>         if (pZone == 0)
672c426,427
<             return(zone);
---
>             cerr << endl << endl << "ERROR: init_make_zone(): Could not allocate new ZoneStruct structure" << endl << endl;
>             throw bad_alloc();
674d428
<         */
676,686d429
<         /* create new zone and add to pApp->m_zoneList */
<         zone = new ZONE;
<         if (zone == 0)
<         {
<             printf("\n\nERROR: init_make_zone(): Could not allocate memory for new ZONE structure\n\n");
<             exit(1);
<         }
< 
<         memset(zone->label, '\0', sizeof(zone->label));
<         sprintf(zone->label, "%s", label);
< 
688,692c431
< 
<         zone->LastAUID = 0;
<         zone->aulist = 0;
< 
<         if (-1 == id || 0 == id) // we are reading ascii input, writing binary file
---
>         if (-1 == id || 0 == id) // we are reading ascii input, not binary file
694c433
<             zone->id = pApp->m_lastZoneID++;
---
>             pZone->id = pApp->m_zoneCount++; // assign new zone id
696,699c435,437
<             // create an AU record for every existing table
<             pApp->m_tableList = (LIST_PTR *)List::reset(pApp->m_tableList);
<             table = (TABLE *)List::next(pApp->m_tableList);
<             while (table!= 0)
---
>             // create an AUStruct record for every existing table
>             typedef map<int, TableStruct*>::iterator TI;
>             for (TI tableIter = pApp->m_tableList.begin(); tableIter != pApp->m_tableList.end(); ++tableIter)
701,702c439
<                 AU* au = static_cast<AU*>(func_find_au(zone, table->label));
<                 if (au == 0)
---
>                 try
704c441
<                     init_make_au(zone, table->label, "init_make_zone()", -1);
---
>                     pZone->findAU(tableIter->second->label);
706c443,446
<                 table = (TABLE *)List::next(pApp->m_tableList);
---
>                 catch(DataNotFoundException& e) // if not found, create
>                 {
>                     init_make_au(pZone, tableIter->second->label, -1);
>                 }
711,713c451,454
<             zone->id = id;
< #ifdef _TSB_DEBUG
<             cout << "read zone: " << zone->id << " from binary file" << endl;
---
>             pZone->id = id;
> 
> #ifdef _TSB_SERIALIZER_DEBUG
>             cout << "read zone: " << pZone->id << " from binary file" << endl;
715,716d455
<             pApp->m_lastZoneID++;
<         }
718,727c457
<         zone->area = (double)0.0;
<         zone->axslist = 0;
<         zone->target = 0;
<         zone->reportFlags = 0;
<         // dynamically allocate array
<         zone->priority = new int[pApp->m_planHorizon+1];
<         if (zone->priority == 0)
<         {
<             printf("\n\nERROR: init_make_zone(): Could not allocate new priority array\n\n");
<             exit(1);
---
>             pApp->m_zoneCount++; // increment counter for consistency with ascii input
729,759c459
<         for(i=0;i<=pApp->m_planHorizon;i++)
<         {
<             zone->priority[i] = FssimApp::DEFAULT_PRIORITY;
<         }
<         zone->achieved = new ACHIEVED;
<         if (zone->achieved == 0)
<         {
<             printf("\n\nERROR: init_make_zone(): Could not allocate new ACHIEVED structure\n\n");
<             exit(1);
<         }
<         zone->achieved->volume = 0.0;
<         zone->achieved->area = 0.0;
<         zone->achieved->AgeDist = 0;
< 
<         // create an AU record for every existing table
<         /*
<         pApp->m_tableList = (LIST_PTR *)List::reset(pApp->m_tableList);
<         table = (TABLE *)List::next(pApp->m_tableList);
<         while (table!= 0)
<         {
<             AU* au = static_cast<AU*>(func_find_au(zone, table->label));
<             if (au == 0)
<             {
<                 init_make_au(zone, table->label, "init_make_zone()", -1);
<             }
<             table = (TABLE *)List::next(pApp->m_tableList);
<         }
<         */
< 
<         pApp->m_zoneList = (LIST_PTR *)List::insert(pApp->m_zoneList, zone, zone->id);
<         return(zone);
---
>         return pZone;
762,763c462,467
<     TIMBER_CLASS
<     *init_make_class(ZONE *zone, AU *au, BLOCK *block, int age, int width, double area, int class_type, int reversion_age, int ReEntryLag, LIST_PTR *float_group_list, LIST_PTR *static_group_list, int roaded, int RandValue)
---
>     TimberClassStruct* init_make_class(ZoneStruct* pZone, AUStruct* pAU, BlockStruct* pBlock, const int age,
>                                        const int width, const double area, const int classType,
>                                        const int reversionAge, const int reEntryLag,
>                                        list<GroupStruct*>* pFloatGroupList,
>                                        list<GroupStruct*>* pStaticGroupList,
>                                        const bool roaded, const int randValue)
765,767d468
<         TIMBER_CLASS		*timber_class;
<         GROUP		*group;
<         //char		label[20]; // unreferenced!
769,770c470,475
<         /* verify input parameters */
<         if (area<0.0)
---
> #ifdef _TSB_RAND_VALUE_DEBUG
>         cout << "init_make_class: RandValue: " << RandValue << endl;
> #endif
> 
>         // verify input parameters
>         if (area < 0)
772,773c477
<             printf("\n\nERROR: init_make_class(): Invalid area(%.2f)\n\n", area);
<             exit(1);
---
>             throw InvalidDataException(area, "init_make_class(): Invalid area");
775,777c479
< 
<         // check to see if zone already exists; if not, create
<         if (0 == zone)
---
>         if (0 == pZone)
779,788c481
<             zone = (ZONE *)func_find_zone(zone->label);
<             if (zone == 0)
<             {
<                 zone = (ZONE *)init_make_zone(zone->label, -1);
<             }
<             if (zone== 0)
<             {
<                 printf("\n\nERROR: init_make_class(): Call to init_make_zone() returned 0\n\n");
<                 exit(1);
<             }
---
>             throw InvalidDataException(0, "Cannot make class with null parent zone");
790,791c483
< 
<         if (0 == au)
---
>         if (0 == pAU)
793,803c485
<             au = static_cast<AU*>(func_find_au(zone, au->label));
<             if (0 == au)
<             {
<                 au = static_cast<AU*>(init_make_au(zone, au->label, "init_make_class()", -1));
<                 cout << "couldn't find au: " << au->label<< ", had to make a new one!" << endl;
<             }
<             if (0 == au)
<             {
<                 printf("\n\nERROR: init_make_class(): Call to init_make_au() returned 0\n\n");
<                 exit(1);
<             }
---
>             throw InvalidDataException(0, "Cannot make class with null parent au");
806,809c488,492
< 
< 
<         /* create new timber_class and add to au->classlist */
<         timber_class = new TIMBER_CLASS;
---
>         // create new timber class and add to au->classlist
>         TimberClassStruct* pTimberClass = new TimberClassStruct(age, width,
>                                                                 static_cast<GroupDefStruct::TimberClassType>(classType),
>                                                                 reversionAge, area, 0.0, roaded, false, randValue, reEntryLag,
>                                                                 pZone, pAU, pBlock);
811c494
<             cout << "creating timber_class at address: " << hex << (timber_class) << endl;
---
>             cout << endl << "Creating timber_class at address: " << hex << pTimberClass << dec << endl;
813c496,497
<         if (timber_class == 0)
---
> 
>         if (pTimberClass == 0)
815,816c499,500
<             printf("\n\nERROR: init_make_class(): Could not allocate memory for new TIMBER_CLASS structure\n\n");
<             exit(1);
---
>             cerr << endl << endl << "ERROR: init_make_class(): Could not allocate memory for new TimberClassStruct structure" << endl << endl;
>             throw bad_alloc();
818,834c502,504
<         timber_class->parent_zone = zone;
<         timber_class->parent_au = au;
<         timber_class->parent_block = block;
<         timber_class->age = age;
<         timber_class->width = width;
<         timber_class->ReEntryLag = ReEntryLag;
< #ifdef _TSB_REENTRY_DEBUG
<         cout << endl << "created timber_class with reentrylag: " << ReEntryLag << endl;
< #endif
<         timber_class->area = area;
<         timber_class->MerchArea = 0.0;
<         timber_class->class_type = class_type;
<         timber_class->reversion_age = reversion_age;
<         timber_class->roaded = roaded;
<         timber_class->transferred = false;
<         timber_class->float_group_list = 0;
<         if (float_group_list== 0)
---
> 
>         // copy float & static group lists
>         if (0 != pFloatGroupList)
836,844c506
<             timber_class->float_group_list = 0;
<         } else {
<             float_group_list = (LIST_PTR *)List::reset(float_group_list);
<             group = (GROUP *)List::next(float_group_list);
<             while (group != 0)
<             {
<                 timber_class->float_group_list = (LIST_PTR *)List::insert(timber_class->float_group_list, group, group->id);
<                 group = (GROUP *)List::next(float_group_list);
<             }
---
>             pTimberClass->float_group_list = *pFloatGroupList;
846,847c508
<         timber_class->static_group_list = 0;
<         if (static_group_list== 0)
---
>         if (0 != pStaticGroupList)
849,857c510
<             timber_class->static_group_list = 0;
<         } else {
<             static_group_list = (LIST_PTR *)List::reset(static_group_list);
<             group = (GROUP *)List::next(static_group_list);
<             while (group != 0)
<             {
<                 timber_class->static_group_list = (LIST_PTR *)List::insert(timber_class->static_group_list, group, group->id);
<                 group = (GROUP *)List::next(static_group_list);
<             }
---
>             pTimberClass->static_group_list = *pStaticGroupList;
859,888c512,513
<         if (FssimApp::getApp()->m_enableRandomization==true)
<         {
<             if (-1 == RandValue) // reading from class.dat ascii file (-u)
<             {
<                 timber_class->RandValue = rand();
<             }
<             else // reading binary data (-b)
<             {
<                 timber_class->RandValue = RandValue;
<                 // call rand & discard value in order to reach same point in
<                 // sequence of pseudo-random numbers after serial read &
<                 // recreation of structs (classes are recreated in a different
<                 // order than originally created by read_class
<                 rand();
<             }
<         }
<         else
<         {
<             timber_class->RandValue = 0;
<         }
< #ifdef _TSB_HARVEST_AXS_DEBUG_OFF
<         if (zone->id == 3 && au->id > 15)
<         {
<             cout << endl << "class zone/parent_au/au->id/block/type: "
<              << zone->id << "/" << timber_class->parent_au->id << "/" << au->id << "/"
<              << block->label << "/" << class_type;
<         }
< #endif
<         au->classlist = (LIST_PTR *)List::insert(au->classlist, timber_class, timber_class->age);
<         return(timber_class);
---
>         pAU->classlist.insert( make_pair(pTimberClass->age, pTimberClass) );
>         return pTimberClass;
891,892c516
<     void
<     init_delete_target(TARGET *target)
---
>     void init_delete_target(TargetStruct* target)
894,902c518
<         if (target== 0)  return;
<         delete[] target->max_volume;
<         target->max_volume= 0;
<         delete[] target->min_volume;
<         target->min_volume= 0;
<         delete[] target->max_area;
<         target->max_area= 0;
<         delete[] target->min_area;
<         target->min_area= 0;
---
> 
904c520
<             cout << "deleting target at address: " << hex << (target) << endl;
---
>             cout << "deleting target at address: " << hex << (target) << dec << endl;
905a522
> 
907c524
<         target= 0;
---
>         target = 0;
910,911c527
<     void
<     init_delete_axsdef(AXSDEF *axsdef)
---
>     void init_delete_axsdef(AxsDefStruct* axsdef)
913,915c529,535
<         if (axsdef== 0) return;
<         delete[] axsdef->AgeArea;
<         axsdef->AgeArea = 0;
---
>         if (axsdef == 0)
>         {
>             return;
>         }
>         delete axsdef->pAgeArea;
>         axsdef->pAgeArea = 0;
> 
917c537
<             cout << "deleting axsdef at address: " << hex << (axsdef) << endl;
---
>             cout << "deleting axsdef at address: " << hex << (axsdef) << dec << endl;
918a539
> 
920c541
<         axsdef= 0;
---
>         axsdef = 0;
923,924c544
<     void
<     init_delete_transfer(TRANSFER *transfer)
---
>     void init_delete_transfer(TransferStruct* transfer)
926c546
<         if (transfer== 0) return;
---
> 
928c548
<             cout << "deleting transfer at address: " << hex << (transfer) << endl;
---
>             cout << "deleting transfer at address: " << hex << (transfer) << dec << endl;
929a550
> 
931c552
<         transfer= 0;
---
>         transfer = 0;
934,935c555
<     void
<     init_delete_table(TABLE *table)
---
>     void init_delete_table(TableStruct* table)
937,939c557,559
<         if (table== 0) return;
< #ifdef _TSB_MEMORY_DEBUG
<         cout << "deleting table at address: " << hex << (table) << endl;
---
> 
> #ifdef _TSB_TABLE_DEBUG
>         cout << "deleting table at address: " << hex << (table) << dec << endl;
940a561
> 
942c563
<         table= 0;
---
>         table = 0;
945,946c566
<     void
<     init_delete_groupdef(GROUPDEF *groupdef)
---
>     void init_delete_groupdef(GroupDefStruct* groupdef)
948c568
<         if (groupdef== 0) return;
---
> 
950c570
<             cout << "deleting groupdef at address: " << hex << (groupdef) << endl;
---
>             cout << "deleting groupdef at address: " << hex << (groupdef) << dec << endl;
951a572
> 
953c574
<         groupdef= 0;
---
>         groupdef = 0;
956,957c577
<     void
<     init_delete_block(BLOCK *block)
---
>     void init_delete_block(BlockStruct* block)
959,961c579,580
<         if (block== 0) return;
<         block->Neighbours = (LIST_PTR *)List::done(block->Neighbours);
<         block->Neighbours = 0;
---
>         block->m_neighbourIndices.clear();
> 
963c582
<             cout << "deleting block at address: " << hex << (block) << endl;
---
>             cout << "deleting block at address: " << hex << (block) << dec << endl;
964a584
> 
969,970c589
<     void
<     init_delete_regen(REGEN *regen)
---
>     void init_delete_regen(RegenStruct* regen)
972c591
<         if (regen== 0) return;
---
> 
974c593
<             cout << "deleting regen at address: " << hex << (regen) << endl;
---
>             cout << "deleting regen at address: " << hex << (regen) << dec << endl;
975a595
> 
977c597
<         regen= 0;
---
>         regen = 0;
980,981c600
<     void
<     init_delete_roadrec(ROADREC *road)
---
>     void init_delete_roadrec(RoadRecStruct* road)
983c602
<         if (road== 0) return;
---
> 
985c604
<             cout << "deleting road at address: " << hex << (road) << endl;
---
>             cout << "deleting road at address: " << hex << (road) << dec << endl;
986a606
> 
988c608
<         road= 0;
---
>         road = 0;
991,992c611
<     void
<     init_delete_achieved(ACHIEVED *achieved)
---
>     void init_delete_achieved(AchievedStruct* achieved)
994,996c613,619
<         if (achieved== 0) return;
<         achieved->AgeDist = (LIST_PTR *)List::done(achieved->AgeDist);
<         achieved->AgeDist= 0;
---
>         if (achieved == 0)
>         {
>             return;
>         }
> 
>         achieved->AgeDist.clear();
> 
998c621
<             cout << "deleting achieved at address: " << hex << (achieved) << endl;
---
>             cout << "deleting achieved at address: " << hex << (achieved) << dec << endl;
999a623
> 
1001c625
<         achieved= 0;
---
>         achieved = 0;
1004,1005c628
<     void
<     init_delete_class(TIMBER_CLASS *timber_class)
---
>     void init_delete_class(TimberClassStruct* pTimberClass)
1007,1014c630,633
<         if (timber_class== 0) return;
<         List::done(timber_class->float_group_list);
<         timber_class->float_group_list= 0;
<         List::done(timber_class->static_group_list);
<         timber_class->static_group_list= 0;
< #ifdef _TSB_MEMORY_DEBUG
<             //cout << "deleting timber class at address: " << hex << (timber_class) << endl;
<             cout << "deleting timber class at address: " << hex << timber_class << endl;
---
> 
> #ifdef _TSB_TIMBER_CLASS_DEBUG
>         //cout << "deleting timber class at address: " << hex << (pTimberClass) << dec << endl;
>         cout << "deleting timber class at address: " << hex << pTimberClass << dec << endl;
1016,1017c635,637
<         delete timber_class;
<         timber_class= 0;
---
> 
>         delete pTimberClass;
>         pTimberClass = 0;
1020,1021c640
<     void
<     init_delete_au(AU *au)
---
>     void init_delete_au(AUStruct* pAU)
1023,1025c642,645
<         TIMBER_CLASS	*timber_class;
<         REGEN	*regen;
<         //ROADREC	*road; // unreferenced!
---
>         if (pAU == 0)
>         {
>             return;
>         }
1027,1028d646
<         if (au== 0) return;
< 
1030c648
<             cout << "deleting au->priority at address: " << hex << (au->priority) << endl;
---
>             cout << "deleting au->priority at address: " << hex << (pAU->priority) << dec << endl;
1032,1036c650,655
<         delete[] au->priority;
<         au->priority = 0;
<         au->classlist = (LIST_PTR *)List::reset(au->classlist);
<         timber_class = (TIMBER_CLASS *)List::next(au->classlist);
<         while (timber_class != 0)
---
> 
>         delete[] pAU->priority;
>         pAU->priority = 0;
> 
>         typedef multimap<int, TimberClassStruct*>::iterator CI;
>         for (CI classIter = pAU->classlist.begin(); classIter != pAU->classlist.end(); ++classIter)
1038,1039c657
<             init_delete_class(timber_class);
<             timber_class = (TIMBER_CLASS *)List::next(au->classlist);
---
>             init_delete_class(classIter->second);
1041,1045c659,662
<         List::done(au->classlist);
<         au->classlist = 0;
<         au->regenlist = (LIST_PTR *)List::reset(au->regenlist);
<         regen = (REGEN *)List::next(au->regenlist);
<         while (regen != 0)
---
>         pAU->classlist.clear();
> 
>         vector<RegenStruct*>::iterator regenIter = pAU->regenlist.begin();
>         while (regenIter != pAU->regenlist.end())
1047,1048c664,665
<             init_delete_regen(regen);
<             regen = (REGEN *)List::next(au->regenlist);
---
>             init_delete_regen(*regenIter);
>             regenIter++;
1050,1055c667,673
<         List::done(au->regenlist);
<         au->regenlist = 0;
<         List::done(au->EligibleGroupList);
<         au->EligibleGroupList = 0;
<         init_delete_roadrec(au->RoadRec);
<         au->RoadRec = 0;
---
>         pAU->regenlist.clear();
> 
>         pAU->m_eligibleGroupList.clear();
> 
>         init_delete_roadrec(pAU->RoadRec);
>         pAU->RoadRec = 0;
> 
1057c675
<             cout << "deleting au at address: " << hex << (au) << endl;
---
>         cout << "deleting au at address: " << hex << (pAU) << dec << endl;
1059,1060c677,679
<         delete au;
<         au= 0;
---
> 
>         delete pAU;
>         pAU = 0;
1063,1064c682
<     void
<     init_delete_zone(ZONE *zone)
---
>     void init_delete_zone(ZoneStruct* pZone)
1066,1068c684,688
<         AU	*au;
<         AXSDEF	*axsdef;
<         if (zone == 0) return;
---
>         if (pZone == 0)
>         {
>             return;
>         }
> 
1070c690
<             cout << "deleting zone->priority at address: " << hex << (zone->priority) << endl;
---
>             cout << "deleting zone->priority at address: " << hex << (pZone->priority) << dec << endl;
1072,1073d691
<         delete[] zone->priority;
<         zone->priority = 0;
1075,1079c693,694
<         //if (0 != zone->achieved)
<         //{
<             init_delete_achieved(zone->achieved);
<         //}
<         //zone->achieved = 0;
---
>         delete[] pZone->priority;
>         pZone->priority = 0;
1081,1092c696
<         //if (0 != zone->aulist)
<         //{
<             zone->aulist = (LIST_PTR *)List::reset(zone->aulist);
<             au = static_cast<AU*>(List::next(zone->aulist));
<             while (au != 0)
<             {
<                 init_delete_au(au);
<                 au = static_cast<AU*>(List::next(zone->aulist));
<             }
<             List::done(zone->aulist);
<         //}
<         //zone->aulist = 0;
---
>         init_delete_achieved(pZone->achieved);
1094,1105c698,703
<         //if (0 != zone->axslist)
<         //{
<             zone->axslist = (LIST_PTR *)List::reset(zone->axslist);
<             axsdef = (AXSDEF *)List::next(zone->axslist);
<             while (axsdef != 0)
<             {
<                 init_delete_axsdef(axsdef);
<                 axsdef = (AXSDEF *)List::next(zone->axslist);
<             }
<             List::done(zone->axslist);
<         //}
<         //zone->axslist = 0;
---
>         typedef vector<AUStruct*>::iterator AI;
>         for (AI auIter = pZone->aulist.begin(); auIter != pZone->aulist.end(); ++auIter)
>         {
>             init_delete_au(*auIter);
>         }
>         pZone->aulist.clear();
1107,1111c705,711
<         //if (0 != zone->target)
<         //{
<             init_delete_target(zone->target);
<         //}
<         //zone->target = 0;
---
>         vector<AxsDefStruct*>::iterator axsIter = pZone->axslist.begin();
>         while (axsIter != pZone->axslist.end())
>         {
>             init_delete_axsdef(*axsIter);
>             axsIter++;
>         }
>         pZone->axslist.clear();
1112a713,718
> #ifdef _TSB_AXSLIST_DEBUG
>             cout << "just cleared axslist for zone: " << pZone->label << endl;
> #endif
> 
>         init_delete_target(pZone->target);
> 
1114c720
<             cout << "deleting zone->reportFlags at address: " << hex << (zone->reportFlags) << endl;
---
>             cout << "deleting zone->reportFlags at address: " << hex << (pZone->reportFlags) << dec << endl;
1116,1117c722,725
<         delete zone->reportFlags;
<         zone->reportFlags = 0;
---
> 
>         delete pZone->reportFlags;
>         pZone->reportFlags = 0;
> 
1119c727
<             cout << "deleting zone at address: " << hex << (zone) << endl;
---
>             cout << "deleting zone at address: " << hex << (pZone) << dec << endl;
1121,1122c729,731
<         delete zone;
<         zone = 0;
---
> 
>         delete pZone;
>         pZone = 0;
1125,1126c734
<     void
<     init_delete_group(GROUP *group)
---
>     void init_delete_group(GroupStruct* group)
1128,1130c736,739
<         AXSDEF	*axsdef;
<         GROUPDEF	*groupdef;
<         TRANSFER	*transfer;
---
>         if (group == 0)
>         {
>             return;
>         }
1132d740
<         if (group== 0) return;
1134c742
<             cout << "deleting group->priority at address: " << hex << (group->priority) << endl;
---
>             cout << "deleting group->priority at address: " << hex << (group->priority) << dec << endl;
1135a744
> 
1137c746,747
<         group->priority= 0;
---
>         group->priority = 0;
> 
1139,1141c749,751
<         group->axslist = (LIST_PTR *)List::reset(group->axslist);
<         axsdef = (AXSDEF *)List::next(group->axslist);
<         while (axsdef != 0)
---
> 
>         vector<AxsDefStruct*>::iterator axsIter = group->axslist.begin();
>         while (axsIter != group->axslist.end())
1143,1144c753,754
<             init_delete_axsdef(axsdef);
<             axsdef = (AXSDEF *)List::next(group->axslist);
---
>             init_delete_axsdef(*axsIter);
>             axsIter++;
1146,1149c756,763
<         List::done(group->axslist);
<         group->groupdefs = (LIST_PTR *)List::reset(group->groupdefs);
<         groupdef = (GROUPDEF *)List::next(group->groupdefs);
<         while (groupdef != 0)
---
>         group->axslist.clear();
> 
> #ifdef _TSB_AXSLIST_DEBUG
>             cout << "just cleared axslist for group: " << group->label << endl;
> #endif
> 
>         vector<GroupDefStruct*>::iterator groupDefIter = group->groupdefs.begin();
>         while (groupDefIter != group->groupdefs.end())
1151,1152c765,766
<             init_delete_groupdef(groupdef);
<             groupdef = (GROUPDEF *)List::next(group->groupdefs);
---
>             init_delete_groupdef(*groupDefIter);
>             groupDefIter++;
1154,1157c768,771
<         List::done(group->groupdefs);
<         group->transferlist = (LIST_PTR *)List::reset(group->transferlist);
<         transfer = (TRANSFER *)List::next(group->transferlist);
<         while (transfer!= 0)
---
>         group->groupdefs.clear();
> 
>         vector<TransferStruct*>::iterator transferIter = group->transferlist.begin();
>         while (transferIter != group->transferlist.end())
1159,1160c773,774
<             init_delete_transfer(transfer);
<             transfer = (TRANSFER *)List::next(group->transferlist);
---
>             init_delete_transfer(*transferIter);
>             transferIter++;
1162c776,777
<         List::done(group->transferlist);
---
>         group->transferlist.clear();
> 
1163a779
> 
1165c781
<             cout << "deleting group->reportFlags at address: " << hex << (group->reportFlags) << endl;
---
>             cout << "deleting group->reportFlags at address: " << hex << (group->reportFlags) << dec << endl;
1166a783
> 
1171c788
<             cout << "deleting group at address: " << hex << (group) << endl;
---
>             cout << "deleting group at address: " << hex << (group) << dec << endl;
1172a790
> 
