1,153c1,87
< // GroupDef.cpp: implementation of the GroupDef class.
< //
< ////////////////////////////////////
< 
< #include <iostream>
< //#include <fstream>
< #include <cstring> // strcpy
< #include <string>
< 
< #include "GroupDef.h"
< 
< #include "Serializer.h"
< #include "init.h"
< 
< using namespace std;
< using namespace tsb; // timber supply branch namespace
< 
< ////////////////////////////////////
< // Construction/Destruction
< ////////////////////////////////////
< 
< /* inlined
< GroupDef::GroupDef(GROUPDEF* pGROUPDEFStruct, GROUP* pGroup)
<     : m_pStruct(pGROUPDEFStruct), m_pGroup(pGroup)
< {
< }
< */
< 
< GroupDef::~GroupDef()
< {
<     // do nothing yet, but may need to clean up m_pStruct
< }
< 
< // write contents to binary file
< void GroupDef::serialize( Serializer& binaryArchive ) //throw (FileException)
< {
<     if (binaryArchive.isWriting())
<     {
<         size_t labelLength = 0;
< 
<         // write GROUPDEF zone label length & text
<         labelLength = strlen( m_pStruct->zone ) + 1; // write with terminating null
<         binaryArchive.write( &labelLength, sizeof(labelLength) ); // data, size
<         binaryArchive.write( &(m_pStruct->zone), labelLength ); // data, size
< 
<         // write GROUPDEF au label length & text
<         labelLength = strlen( m_pStruct->au ) + 1; // write with terminating null
<         binaryArchive.write( &labelLength, sizeof(labelLength) ); // data, size
<         binaryArchive.write( &(m_pStruct->au), labelLength ); // data, size
< 
<         // write GROUPDEF block label length & text
<         labelLength = strlen( m_pStruct->block ) + 1; // write with terminating null
<         binaryArchive.write( &labelLength, sizeof(labelLength) ); // data, size
<         binaryArchive.write( &(m_pStruct->block), labelLength ); // data, size
< 
<         // write GROUPDEF low_age
<         binaryArchive.write( &(m_pStruct->low_age), sizeof(m_pStruct->low_age) ); // data, size
< 
<         // write GROUPDEF high_age
<         binaryArchive.write( &(m_pStruct->high_age), sizeof(m_pStruct->high_age) ); // data, size
< 
<         // write GROUPDEF class_type
<         binaryArchive.write( &(m_pStruct->class_type), sizeof(m_pStruct->class_type) ); // data, size
<     }
<     else // reading archive
<     {
<         /*// allocate space to read in values
<         GROUPDEF tempStruct = { 0, 0, 0, 0, 0, 0 };
<         m_pStruct = &tempStruct;*/
< 
<         size_t labelLength = 0; // already includes terminating null
< 
<         // read GROUPDEF zone label length & text
<         binaryArchive.read( &labelLength, sizeof(labelLength) ); // data, size
<         char* zoneLabel = new char[labelLength];
<         binaryArchive.read( zoneLabel, labelLength ); // data, size
< 
<         // read GROUPDEF au label length & text
<         binaryArchive.read( &labelLength, sizeof(labelLength) ); // data, size
<         char* auLabel = new char[labelLength];
<         binaryArchive.read( auLabel, labelLength ); // data, size
< 
<         // read GROUPDEF block label length & text
<         binaryArchive.read( &labelLength, sizeof(labelLength) ); // data, size
<         char* blockLabel = new char[labelLength];
<         binaryArchive.read( blockLabel, labelLength ); // data, size
< 
<         // read GROUPDEF low_age
<         int low_age = 0;
<         binaryArchive.read( &(low_age), sizeof(low_age) ); // data, size
< 
<         // read GROUPDEF Age
<         int high_age = 0;
<         binaryArchive.read( &(high_age), sizeof(high_age) ); // data, size
< 
<         // read GROUPDEF class_type
<         int class_type = 0;
<         binaryArchive.read( &(class_type), sizeof(class_type) ); // data, size
< 
<         this->recreateStruct(zoneLabel, auLabel, blockLabel,
<                              low_age, high_age, class_type);
<         delete[] zoneLabel;
<         zoneLabel = 0;
<         delete[] auLabel;
<         auLabel = 0;
<         delete[] blockLabel;
<         blockLabel = 0;
< 
<         // set struct with values read before call to init_make_groupdef
<         //m_pStruct->low_age = low_age; // done by init_make_groupdef
<         //m_pStruct->high_age = high_age; // done by init_make_groupdef
<         //m_pStruct->class_type = class_type; // done by init_make_groupdef
<     }
< }
< 
< 
< void GroupDef::recreateStruct(char *zone, char *au, char *block, int low_age, int high_age, int ctype)
< {
<     /*if (0 != m_pStruct) // clean up memory if overwriting existing struct
<     {
<         tsb::init_delete_groupdef(m_pStruct);
<     }*/
<     GROUPDEF* pGroupDef = 0;
<     if (0 != m_pGroup) // if groupdef has an owner
<     {
<         pGroupDef = tsb::init_make_groupdef(m_pGroup, zone, au, block, low_age, high_age, ctype);
<     }
<     if (0 == pGroupDef)
<     {
<         string message = "ERROR: init_make_groupdef() failed in GroupDef::serialize.\n";
<         throw (message);
<     }
<     else
<     {
<         m_pStruct = pGroupDef;
<     }
< }
< 
< /*int GroupDef::lookupGROUPDEFID(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");
<     }
< }*/
< 
< 
---
> // GroupDef.cpp: implementation of the GroupDef class.
> 
> #include <string>
> 
> #include <cstring> // strcpy
> 
> #include "GroupDef.h"
> 
> #include "ArchiveException.h"
> 
> #include "init.h"
> 
> using namespace std;
> using namespace tsb; // timber supply branch namespace
> 
> 
> // write contents to binary file
> void GroupDef::serialize( Serializer& binaryArchive ) //throw (FileException)
> {
>     if (binaryArchive.isWriting())
>     {
>         // write GroupDefStruct m_zoneID
>         binaryArchive.write( &(m_pStruct->m_zoneID), sizeof(m_pStruct->m_zoneID) ); // data, size
> 
>         // write GroupDefStruct m_auLabelIndex
>         binaryArchive.write( &(m_pStruct->m_auLabelIndex), sizeof(m_pStruct->m_auLabelIndex) ); // data, size
> 
>         // write GroupDefStruct m_blockID
>         binaryArchive.write( &(m_pStruct->m_blockID), sizeof(m_pStruct->m_blockID) ); // data, size
> 
>         // write GroupDefStruct low_age
>         binaryArchive.write( &(m_pStruct->low_age), sizeof(m_pStruct->low_age) ); // data, size
> 
>         // write GroupDefStruct high_age
>         binaryArchive.write( &(m_pStruct->high_age), sizeof(m_pStruct->high_age) ); // data, size
> 
>         // write GroupDefStruct class_type
>         binaryArchive.write( &(m_pStruct->class_type), sizeof(m_pStruct->class_type) ); // data, size
>     }
>     else // reading archive
>     {
>         // read GroupDefStruct m_zoneID
>         int zoneID = 0;
>         binaryArchive.read( &(zoneID), sizeof(zoneID) ); // data, size
> 
>         // read GroupDefStruct auID
>         int auLabelIndex = 0;
>         binaryArchive.read( &(auLabelIndex), sizeof(auLabelIndex) ); // data, size
> 
>         // read GroupDefStruct blockID
>         int blockID = 0;
>         binaryArchive.read( &(blockID), sizeof(blockID) ); // data, size
> 
>         // read GroupDefStruct low_age
>         int low_age = 0;
>         binaryArchive.read( &(low_age), sizeof(low_age) ); // data, size
> 
>         // read GroupDefStruct Age
>         int high_age = 0;
>         binaryArchive.read( &(high_age), sizeof(high_age) ); // data, size
> 
>         // read GroupDefStruct class_type
>         int class_type = 0;
>         binaryArchive.read( &(class_type), sizeof(class_type) ); // data, size
> 
>         this->recreateStruct(zoneID, auLabelIndex, blockID, low_age, high_age, class_type);
>     }
> }
> 
> 
> void GroupDef::recreateStruct(int zone, int au, int block, int low_age, int high_age, int ctype)
> {
>     GroupDefStruct* pGroupDef = 0;
>     if (0 != m_pGroup) // if groupdef has an owner
>     {
>         pGroupDef = tsb::init_make_groupdef(m_pGroup, zone, au, block, low_age, high_age, ctype);
>     }
>     if (0 == pGroupDef)
>     {
>         string message = "ERROR: init_make_groupdef() failed in GroupDef::serialize.\n";
>         throw ArchiveException(message);
>     }
>     else
>     {
>         m_pStruct = pGroupDef;
>     }
> }
