2,3d1
< //
< ////////////////////////////////////
6d3
< //#include <fstream>
8a6
> #include <cassert>
11c9,10
< #include "Serializer.h"
---
> 
> #include "Group.h"
13d11
< #include "Regen.h"
14a13,14
> #include "ArchiveException.h"
> 
16d15
< #include "func.h"
21,23d19
< ////////////////////////////////////
< // Construction/Destruction
< ////////////////////////////////////
25,43d20
< /* inlined for speed
< Au::Au(AU* pAUStruct, ZONE* pParentZone) : m_pStruct(pAUStruct), m_pParentZone(pParentZone)
< {
<     if(0 != m_pStruct)
<     {
<         // initialize null members from struct
<         if(0 != m_pStruct->parent_zone && 0 == m_pParentZone)
<         {
<             m_pParentZone = m_pStruct->parent_zone;
<         }
<     }
< }
< */
< 
< Au::~Au()
< {
<     // do nothing yet, but may need to clean up m_pStruct
< }
< 
45c22
< void Au::serialize( Serializer& binaryArchive ) //throw (FileException)
---
> void Au::serialize( Serializer& binaryArchive )
49c26
<         // write AU index
---
>         // write AUStruct index
52c29,32
<         // write AU label length & text
---
>         // write AUStruct label index
>         binaryArchive.write( &m_pStruct->m_labelIndex, sizeof(m_pStruct->m_labelIndex) ); // data, size
> 
>         // write AUStruct label length & text
58c38
<         // write AU landoaf
---
>         // write AUStruct landoaf
61,70c41,43
<         // write AU parent_zone ID
<         int parentZoneID = m_pParentZone->getStruct()->id;
<         binaryArchive.write( &(parentZoneID), sizeof(parentZoneID) ); // data, size
< 
<         // ROADREC struct is 0 until re-set on serial read of road.dat
< 
<         if (this->hasEligibleGroups()) // populate list of eligible group indices
<         {
<             this->createEligibleGroupIndexList();
<         }
---
>         // write AUStruct parent_zone ID
>         //int parentZoneID = m_pParentZone->getStruct()->id;
>         //binaryArchive.write( &(parentZoneID), sizeof(parentZoneID) ); // data, size
74,83c47
<         /*char nullString[FssimApp::MAX_LABEL_LENGTH];
<         for(int i = 0; i < FssimApp::MAX_LABEL_LENGTH ; ++i)
<         {
<             nullString[i] = '\0';
<         }
<         // allocate space to read in values
<         AU tempStruct = { 0, nullString, 0, 0, 0, 0, 0, 0, 0, 0 };
<         m_pStruct = &tempStruct;*/
< 
<         // read AU index
---
>         // read AUStruct index
87c51,55
<         // read AU label length & text
---
>         int labelIndex = 0;
>         // read AUStruct label index
>         binaryArchive.read( &labelIndex, sizeof(labelIndex) ); // data, size
> 
>         // read AUStruct label length & text
93,94c61,62
<         // read AU landoaf
<         double landoaf = 0;
---
>         // read AUStruct landoaf
>         double landoaf = 0.0;
97,99c65,67
<         // read AU parent_zone ID
<         int parentZoneID = 0;
<         binaryArchive.read( &(parentZoneID), sizeof(parentZoneID) ); // data, size
---
>         // read AUStruct parent_zone ID
>         //int parentZoneID = 0;
>         //binaryArchive.read( &(parentZoneID), sizeof(parentZoneID) ); // data, size
101,116c69,72
<         // lookup parent zone
<         m_pParentZone = Zone::lookupZoneAddress(parentZoneID);
<         if (0 != m_pParentZone)
<         {
<             // re-create & insert the C-struct into the hashed FssimApp::m_AUList
<             this->recreateStruct(m_pParentZone, label, id);
<             delete[] label;
<             label = 0;
<         }
<         else
<         {
<             delete[] label;
<             label = 0;
<             string message = "Au::serialize, parent zone not found";
<             throw (message);
<         }
---
>         // re-create & insert the C-struct into the hashed list
>         this->recreateStruct(m_pParentZone, label, id, labelIndex);
>         delete[] label;
>         label = 0;
118c74
<         // set struct with values read before call to init_make_au
---
>         // reset struct with values read before call to init_make_au
120,121d75
< 
<         // ROADREC struct is 0 until re-set on serial read of road.dat
125,126c79
< 
<     this->serializeIDList(binaryArchive, m_eligibleGroupIndices);
---
>     this->serializeIDList(binaryArchive, m_pStruct->m_eligibleGroupList);
131a85,105
> 
> void Au::recreateStruct(Zone *pZone, const char *label, const int id, const int labelIndex)
> {
>     AUStruct* pAU = init_make_au(pZone->getStruct(), label, id, labelIndex);
>     if (0 == pAU)
>     {
>         string message = "ERROR: init_make_au() failed in Au::serialize.\n";
>         throw ArchiveException(message);
>     }
>     else
>     {
>         m_pStruct = pAU;
> 
> #ifdef _TSB_MEMORY_DEBUG
>         cout << "recreated au struct at address: " << m_pStruct << endl;
> #endif
> 
>     }
> }
> 
> 
138c112
<         // write number of AU's associated items
---
>         // write number of AUStruct's associated items
139a114
> 
141c116
<         if (0 != numberOfItems) // does the AU have AUs?
---
>         if (0 != numberOfItems) // does the AUStruct have AUs?
146c121,122
< #endif // _TSB_SERIALIZER_DEBUG
---
> #endif
> 
149c125
<             // write AU's associated items
---
>             // write AUStruct's associated items
164c140
<         // read number of AU's items
---
>         // read number of AUStruct's items
166a143
> 
168c145
<         if (0 != numberOfItems) // does the AU have eligible groups?
---
>         if (0 != numberOfItems) // does the AUStruct have eligible groups?
173,174c150,152
< #endif // _TSB_SERIALIZER_DEBUG
<         // read AU's associated items' indices
---
> #endif
> 
>         // read AUStruct's associated items' indices
181d158
<         this->recreateEligibleGroupList();
185,205d161
< void Au::recreateStruct(Zone *pZone, char *label, int id)
< {
<     /*if (0 != m_pStruct) // clean up memory if overwriting existing struct
<     {
<         init_delete_au(m_pStruct);
<     }*/
<     AU* pAU = init_make_au(pZone->getStruct(), label, "Au::recreateStruct", id);
<     if (0 == pAU)
<     {
<         string message = "ERROR: init_make_au() failed in Au::serialize.\n";
<         throw (message);
<     }
<     else
<     {
<         m_pStruct = pAU;
< #ifdef _TSB_MEMORY_DEBUG
<         cout << "recreated au struct at address: " << m_pStruct << endl;
< #endif
<         pZone->appendAUAddressToVector(m_pStruct);
<     }
< }
207,220d162
< /*int Au::lookupAUID(const string& label)
< {
<     // lookup AU's index in map by label
<     AConstIndexIterator item = m_labelIndex.find(label);
<     if ( item != m_labelIndex.end() )
<     {
<         return ( (item->second) );
<     }
<     else
<     {
<         throw ("AU not found in labelIndex map");
<     }
< }*/
< 
223d164
<     //FssimApp* pApp = FssimApp::getApp();
227a169
> 
230c172
<                  << dec << m_pStruct->classlist->size << " timber classes" << endl;
---
>                  << dec << m_pStruct->classlist.size() << " timber classes" << endl;
231a174
> 
233c176
<             int numberOfClasses = m_pStruct->classlist->size;
---
>             int numberOfClasses = m_pStruct->classlist.size();
236,241c179,183
<             m_pStruct->classlist = (LIST_PTR *)List::reset(m_pStruct->classlist);
<             TIMBER_CLASS* pTimberClass = 0;
<             do
<             {   // m_timberClassList is not a hashed list
<                 pTimberClass = static_cast<TIMBER_CLASS*>(List::next(m_pStruct->classlist));
<                 if (0 != pTimberClass)
---
>             typedef multimap<int, TimberClassStruct*>::iterator CI;
>             for (CI classIter = m_pStruct->classlist.begin(); classIter != m_pStruct->classlist.end(); ++classIter)
>             {
>                 assert(classIter->second->parent_au != 0);
>                 if (0 != (classIter->second))
243c185
<                     TimberClass newTimberClassObject( pTimberClass, this->m_pParentZone, 0, this->m_pStruct);
---
>                     TimberClass newTimberClassObject( this->m_pParentZone, this->m_pStruct, (classIter->second), 0 );
246c188
<             } while (0 != pTimberClass);
---
>             }
249a192
> 
252a196
> 
266c210
<             // populate list of TIMBER_CLASSsr
---
>             // populate list of timber classes
269c213
<                 // insert into list of TIMBER_CLASSes
---
>                 // insert into list of timber classes
271,272c215
<                 TimberClass newTimberClassObject(0/*m_pStruct*/, this->m_pParentZone,
<                                                  0/*BLOCK*/, this->m_pStruct/*, this->m_pParentZone*/);
---
>                 TimberClass newTimberClassObject( this->m_pParentZone, this->m_pStruct);
275,277d217
<                 //m_pStruct->classlist =
<                         //static_cast<LIST_PTR*>(List::insert(m_pStruct->classlist,
<                         //                                    newTimberClassObject.getStruct(), 0));
278a219
> 
283c224
<                  << dec << m_pStruct->classlist->size << " timber classes" << endl;
---
>                  << dec << m_pStruct->classlist.size() << " timber classes" << endl;
285a227
> 
292d233
<     //FssimApp* pApp = FssimApp::getApp();
296a238
> 
298c240
<             cout << "Au " << m_pStruct->id
---
>             cout << "AU " << m_pStruct->id
300c242
<                  << m_pStruct->regenlist->size << " REGENs" << endl;
---
>                  << m_pStruct->regenlist.size() << " REGENs" << endl;
301a244
> 
303c246
<             int numberOfRegens = m_pStruct->regenlist->size;
---
>             int numberOfRegens = m_pStruct->regenlist.size();
306,308c249,250
<             m_pStruct->regenlist = (LIST_PTR *)List::reset(m_pStruct->regenlist);
<             REGEN* pRegen = 0;
<             do
---
>             vector<RegenStruct*>::iterator regenIter = m_pStruct->regenlist.begin();
>             while (regenIter != m_pStruct->regenlist.end())
310c252
<                 pRegen = static_cast<REGEN*>(List::next(m_pStruct->regenlist));
---
>                 RegenStruct* pRegen = *regenIter;
313c255,261
<                     Regen newRegenObject( pRegen, 0, this->m_pStruct); // m_regenList is not a hashed list
---
> 
> #ifdef _TSB_SERIALIZER_DEBUG
>                     cout << "serial writing regen parent_auID/regen_auID: "
>                          << this->m_pStruct->id << "/" << pRegen->m_auID << endl;
> #endif
> 
>                     Regen newRegenObject( this->m_pStruct, pRegen ); // m_regenList is not a hashed list
316c264,265
<             } while (0 != pRegen);
---
>                 regenIter++;
>             }
328c277
<         if (0 != m_pStruct) // does the AU exist?
---
>         if (0 != m_pStruct) // does the AUStruct exist?
338c287
<                 Regen newRegenObject(0, 0, this->m_pStruct, this->m_pParentZone); // create Regen object, initialize parent au to this
---
>                 Regen newRegenObject( this->m_pStruct ); // create Regen object, initialize parent au to this
342c291
<                 m_regens.push_back(newRegenObject); // do shallow copy into list
---
>                 //m_regens.push_back(newRegenObject); // do shallow copy into list
344,346c293,298
<                 //m_pStruct->regenlist =
<                 //       static_cast<LIST_PTR*>( List::insert(m_pStruct->regenlist,
<                 //                                            newRegenObject.getStruct(), 0) );
---
> 
> #ifdef _TSB_SERIALIZER_DEBUG
>                 cout << "serial reading regen parent_auID/regen_auID: "
>                      << this->m_pStruct->id << "/" << newRegenObject.getStruct()->m_auID << endl;
> #endif
> 
347a300
> 
353c306
<                  << m_pStruct->regenlist->size << " REGENs" << endl;
---
>                  << m_pStruct->regenlist.size() << " REGENs" << endl;
355a309
> 
365a320
> 
369,370c324,327
<             // write AU's ROADREC flag
<             int hasRoadRec = 1;
---
> 
>             // write AUStruct's RoadRecStruct flag
>             //int hasRoadRec = 1;
>             bool hasRoadRec = true;
373c330,333
<             // write AU's ROADREC age
---
>             // write AUStruct's RoadRecStruct au label index
>             binaryArchive.write( &m_pStruct->RoadRec->m_auLabelIndex, sizeof(m_pStruct->RoadRec->m_auLabelIndex) ); // data, size
> 
>             // write AUStruct's RoadRecStruct age
376c336
<             // write AU's ROADREC percent
---
>             // write AUStruct's RoadRecStruct percent
379c339
<             // write AU's ROADREC ToAge
---
>             // write AUStruct's RoadRecStruct ToAge
382c342
<             // write AU's ROADREC Offset
---
>             // write AUStruct's RoadRecStruct Offset
385c345
<             // write AU's ROADREC reentry
---
>             // write AUStruct's RoadRecStruct reentry
387,392d346
< 
<             // write AU's ROADREC label length & text
<             size_t labelLength = 0;
<             labelLength = strlen( m_pStruct->RoadRec->au ) + 1; // write with terminating null
<             binaryArchive.write( &labelLength, sizeof(labelLength) ); // data, size
<             binaryArchive.write( &(m_pStruct->RoadRec->au), labelLength ); // data, size
396c350,351
<             int hasRoadRec = 0;
---
>             //int hasRoadRec = 0;
>             bool hasRoadRec = false;
402,403c357,359
<         // read AU's ROADREC flag
<         int hasRoadRec = 0;
---
>         // read AUStruct's RoadRecStruct flag
>         //int hasRoadRec = 0;
>         bool hasRoadRec = false;
406c362,363
<         if (0 != hasRoadRec)
---
>         //if (0 != hasRoadRec)
>         if (hasRoadRec)
407a365
> 
410a369
> 
412,413c371,372
<             //ROADREC tempStruct;
<             m_pStruct->RoadRec = new ROADREC;
---
>             //RoadRecStruct tempStruct;
>             m_pStruct->RoadRec = new RoadRecStruct;
415c374,377
<             // read AU's ROADREC age
---
>             // read AUStruct's RoadRecStruct au label index
>             binaryArchive.read( &m_pStruct->RoadRec->m_auLabelIndex, sizeof(m_pStruct->RoadRec->m_auLabelIndex) ); // data, size
> 
>             // read AUStruct's RoadRecStruct age
418c380
<             // read AU's ROADREC percent
---
>             // read AUStruct's RoadRecStruct percent
421c383
<             // read AU's ROADREC ToAge
---
>             // read AUStruct's RoadRecStruct ToAge
424c386
<             // read AU's ROADREC Offset
---
>             // read AUStruct's RoadRecStruct Offset
427c389
<             // read AU's ROADREC reentry
---
>             // read AUStruct's RoadRecStruct reentry
429,446d390
< 
<             // read AU's ROADREC label length & text
<             size_t labelLength = 0; // already includes terminating null
<             binaryArchive.read( &labelLength, sizeof(labelLength) ); // data, size
<             char* label = new char[labelLength];
<             binaryArchive.read( label, labelLength ); // data, size
< 
<             // copy label from binary file to struct
<             strcpy(m_pStruct->RoadRec->au, label);
< 
<             /*
<             tsb::init_make_roadrec(m_pParentZone->getStruct(), m_pStruct, m_pStruct->RoadRec->age,
<                                    m_pStruct->RoadRec->percent, m_pStruct->RoadRec->ToAge,
<                                    m_pStruct->RoadRec->au, m_pStruct->RoadRec->Offset,
<                                    m_pStruct->RoadRec->reentry);
<             */
<             delete[] label;
<             label = 0;
450,474d393
< 
< 
< /* inlined for speed
< void Au::createEligibleGroupIndexList() // called before binary write
< {
< #ifdef _TSB_SERIALIZER_DEBUG
<     cout << "AU " << m_pStruct->id << " has "
<          << m_pStruct->EligibleGroupList->size << " eligibe groups" << endl;
< #endif
<     m_pStruct->EligibleGroupList = (LIST_PTR *)List::reset(m_pStruct->EligibleGroupList);
<     GROUP* pEligibleGroup = 0;
<     do
<     {
<         pEligibleGroup = static_cast<GROUP*>(List::next(m_pStruct->EligibleGroupList));
<         if (0 != pEligibleGroup)
<         {
<             m_eligibleGroupIndices.push_back(pEligibleGroup->id);
<         }
< 
<     } while (0 != pEligibleGroup);
< }
< */
< 
< 
< 
