1,223c1,219
< // Table.cpp: implementation of the Table class.
< //
< ////////////////////////////////////
< 
< #include <iostream>
< //#include <fstream>
< #include <string>
< #include <cstring> // strcpy
< 
< #include "Table.h"
< #include "Serializer.h"
< #include "init.h"
< 
< using namespace std;
< using namespace tsb; // timber supply branch namespace
< 
< ////////////////////////////////////
< // Construction/Destruction
< ////////////////////////////////////
< 
< /* inlined
< Table::Table(TABLE* pTableStruct)
<     : m_pStruct(pTableStruct)
< {
< }
< */
< 
< Table::~Table()
< {
<     // do nothing yet, but may need to clean up m_pStruct
< }
< 
< // write contents to binary file
< void Table::serialize( Serializer& binaryArchive ) //throw (FileException)
< {
<     if (binaryArchive.isWriting())
<     {
<         // write table index
<         binaryArchive.write( &m_pStruct->id, sizeof(m_pStruct->id) ); // data, size
< 
<         // write table label length & text
<         size_t labelLength = 0;
<         labelLength = strlen( m_pStruct->label ) + 1; // write with terminating null
<         binaryArchive.write( &labelLength, sizeof(labelLength) ); // data, size
<         binaryArchive.write( &(m_pStruct->label), labelLength ); // data, size
< 
<         // write table mha
<         binaryArchive.write( &(m_pStruct->mha), sizeof(m_pStruct->mha) ); // data, size
< 
<         // write table AdjacencyAge
<         binaryArchive.write( &(m_pStruct->AdjacencyAge), sizeof(m_pStruct->AdjacencyAge) ); // data, size
< 
<         // write table voaf1
<         binaryArchive.write( &(m_pStruct->voaf1), sizeof(m_pStruct->voaf1) ); // data, size
< 
<         // write table voaf2
<         binaryArchive.write( &(m_pStruct->voaf2), sizeof(m_pStruct->voaf2) ); // data, size
< 
<         // write table RefAge
<         binaryArchive.write( &(m_pStruct->RefAge), sizeof(m_pStruct->RefAge) ); // data, size
< 
<         // write table Volume array
<         for( int i = 0; i < FssimApp::MAX_NUM_TABLE_VERTICES; ++i )
<         {
<             binaryArchive.write( &(m_pStruct->Volume[i]), sizeof(m_pStruct->Volume[i]) ); // data, size
<         }
<     }
<     else // reading archive
<     {
<         /*// allocate space to read in values
<         TABLE tempStruct = { 0, 0, 0, 0, 0, 0, 0, 0 };
<         m_pStruct = &tempStruct;*/
< 
<         // read table index
<         int id = 0;
<         binaryArchive.read( &id, sizeof(id) ); // data, size
< 
<         // read table 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
< 
<         // re-create & insert the C-struct into the hashed FssimApp::m_tableList
<         this->recreateStruct(label, id);
< 
<         //m_labelIndex[m_pStruct->label] = m_pStruct->id; // create & insert key-value pair
<         delete[] label;
<         label = 0;
< 
<         // read table mha
<         binaryArchive.read( &(m_pStruct->mha), sizeof(m_pStruct->mha) ); // data, size
< 
<         // read table AdjacencyAge
<         binaryArchive.read( &(m_pStruct->AdjacencyAge), sizeof(m_pStruct->AdjacencyAge) ); // data, size
< 
<         // read table voaf1
<         binaryArchive.read( &(m_pStruct->voaf1), sizeof(m_pStruct->voaf1) ); // data, size
< 
<         // read table voaf2
<         binaryArchive.read( &(m_pStruct->voaf2), sizeof(m_pStruct->voaf2) ); // data, size
< 
<         // read table RefAge
<         binaryArchive.read( &(m_pStruct->RefAge), sizeof(m_pStruct->RefAge) ); // data, size
< 
<         // read table Volume array
<         for( int i = 0; i < FssimApp::MAX_NUM_TABLE_VERTICES; ++i )
<         {
<             binaryArchive.read( &(m_pStruct->Volume[i]), sizeof(m_pStruct->Volume[i]) ); // data, size
<         }
<     }
< }
< 
< 
< void Table::recreateStruct(char* label, int id)
< {
<     /*if (0 != m_pStruct) // clean up memory if overwriting existing struct
<     {
<         init_delete_table(m_pStruct);
<     }*/
<     TABLE* pTable = init_make_table(label, "Table::recreateStruct", id);
<     if (0 == pTable)
<     {
<         string message = "ERROR: init_make_table() failed in Table::serialize.\n";
<         throw (message);
<     }
<     else
<     {
<         m_pStruct = pTable;
<     }
< }
< 
< /*int Table::lookupTableID(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");
<     }
< }*/
< 
< 
< void Table::serializeTableList(Serializer& binaryArchive)
< {
<     FssimApp* pApp = FssimApp::getApp();
<     if (binaryArchive.isWriting())
<     {
<         // write size of m_tableList
<         int tableListLength = pApp->m_tableList->size;
<         binaryArchive.write( &tableListLength, sizeof(tableListLength) ); // data, size
< #ifdef _TSB_SERIALIZER_DEBUG
<             cout << endl << "Writing " << tableListLength << " Tables to binary file..." << endl;
< #endif
<         TABLE* pTable;
<         pApp->m_tableList = static_cast<LIST_PTR*>(List::reset(pApp->m_tableList));
<         do
<         {
<             pTable = static_cast<TABLE*>(List::next(pApp->m_tableList));
<             if (0 != pTable)
<             {
<                 Table newTableObject( pTable ); // m_tableList is not a hashed list
<                 newTableObject.serialize(binaryArchive); // serialize table
<             }
<         } while (pTable != 0);
<     }
<     else // we are reading from binary file
<     {
<         // read size of m_tableList
<         int tableListLength = 0;
<         binaryArchive.read( &tableListLength, sizeof(tableListLength) ); // data, size
< #ifdef _TSB_SERIALIZER_DEBUG
<             cout << endl << "Reading " << tableListLength
<                  << " tables from binary file..." << endl;
< #endif
<         // populate m_tableList
<         for( int i = 0; i < tableListLength; ++i )
<         {
<             Table newTableObject; // create default Table object
<             try
<             {
<                 newTableObject.serialize(binaryArchive);
<                 // new table is added to m_tableList by init_make_table
<                 //pApp->m_tableList =
<                 //       static_cast<LIST_PTR*>( List::insert(pApp->m_tableList,
<                 //                                            newTableObject.getStruct(), 0) );
<             }
<             catch(FileException& e)
<             {
< #ifdef _TSB_SERIALIZER_DEBUG
<                 cout << "File exception: " << e.what() << endl;
< #endif
<                 if (e.isEndOfFile())
<                 {
<                     //endOfFile = true;
<                     break;
<                 }
<                 else
<                 {
<                     throw e;
<                 }
<             }
<             catch(exception& e)
<             {
<                 cout << "Binary read exception: " << e.what() << endl;
<                 throw e;
<             }
<         }
< #ifdef _TSB_SERIALIZER_DEBUG
<         if (0 != pApp->m_tableList) // does the Table list have tables?
<         {
<             cout << "m_tableList " << " has "
<              << tableListLength << " Tables" << endl;
<         }
< #endif
<     }
< }
< 
< 
---
> // Table.cpp: implementation of the Table class.
> //
> ////////////////////////////////////
> 
> #include <iostream>
> //#include <fstream>
> #include <string>
> #include <cstring> // strcpy
> 
> #include "Table.h"
> 
> //#include "Serializer.h"
> 
> #include "FileException.h"
> 
> #include "init.h"
> 
> using namespace std;
> using namespace tsb; // timber supply branch namespace
> 
> ////////////////////////////////////
> // Construction/Destruction
> ////////////////////////////////////
> 
> /* inlined
> Table::Table(TableStruct* pTableStruct)
>     : m_pStruct(pTableStruct)
> {
> }
> */
> 
> Table::~Table()
> {
>     // do nothing yet, but may need to clean up m_pStruct
> }
> 
> // write contents to binary file
> void Table::serialize( Serializer& binaryArchive ) //throw (FileException)
> {
>     if (binaryArchive.isWriting())
>     {
>         // write table index
>         binaryArchive.write( &m_pStruct->id, sizeof(m_pStruct->id) ); // data, size
> 
>         // write table label length & text
>         size_t labelLength = 0;
>         labelLength = strlen( m_pStruct->label ) + 1; // write with terminating null
>         binaryArchive.write( &labelLength, sizeof(labelLength) ); // data, size
>         binaryArchive.write( &(m_pStruct->label), labelLength ); // data, size
> 
>         // write table mha
>         binaryArchive.write( &(m_pStruct->mha), sizeof(m_pStruct->mha) ); // data, size
> 
>         // write table AdjacencyAge
>         binaryArchive.write( &(m_pStruct->AdjacencyAge), sizeof(m_pStruct->AdjacencyAge) ); // data, size
> 
>         // write table voaf1
>         binaryArchive.write( &(m_pStruct->voaf1), sizeof(m_pStruct->voaf1) ); // data, size
> 
>         // write table voaf2
>         binaryArchive.write( &(m_pStruct->voaf2), sizeof(m_pStruct->voaf2) ); // data, size
> 
>         // write table RefAge
>         binaryArchive.write( &(m_pStruct->RefAge), sizeof(m_pStruct->RefAge) ); // data, size
> 
>         // write table Volume array
>         for( int i = 0; i < FssimUtil::MAX_NUM_TABLE_VERTICES; ++i )
>         {
>             binaryArchive.write( &(m_pStruct->Volume[i]), sizeof(m_pStruct->Volume[i]) ); // data, size
>         }
>     }
>     else // reading archive
>     {
>         // read table index
>         int id = 0;
>         binaryArchive.read( &id, sizeof(id) ); // data, size
> 
>         // read table 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
> 
>         // re-create & insert the C-struct into the hashed FssimApp::m_tableList
>         this->recreateStruct(label, id);
> 
>         //m_labelIndex[m_pStruct->label] = m_pStruct->id; // create & insert key-value pair
>         delete[] label;
>         label = 0;
> 
>         // read table mha
>         binaryArchive.read( &(m_pStruct->mha), sizeof(m_pStruct->mha) ); // data, size
> 
>         // read table AdjacencyAge
>         binaryArchive.read( &(m_pStruct->AdjacencyAge), sizeof(m_pStruct->AdjacencyAge) ); // data, size
> 
>         // read table voaf1
>         binaryArchive.read( &(m_pStruct->voaf1), sizeof(m_pStruct->voaf1) ); // data, size
> 
>         // read table voaf2
>         binaryArchive.read( &(m_pStruct->voaf2), sizeof(m_pStruct->voaf2) ); // data, size
> 
>         // read table RefAge
>         binaryArchive.read( &(m_pStruct->RefAge), sizeof(m_pStruct->RefAge) ); // data, size
> 
>         // read table Volume array
>         for( int i = 0; i < FssimUtil::MAX_NUM_TABLE_VERTICES; ++i )
>         {
>             binaryArchive.read( &(m_pStruct->Volume[i]), sizeof(m_pStruct->Volume[i]) ); // data, size
>         }
>     }
> }
> 
> 
> void Table::recreateStruct(char* label, int id)
> {
>     /*if (0 != m_pStruct) // clean up memory if overwriting existing struct
>     {
>         init_delete_table(m_pStruct);
>     }*/
>     TableStruct* pTable = init_make_table(label, id);
>     if (0 == pTable)
>     {
>         string message = "ERROR: init_make_table() failed in Table::serialize.\n";
>         throw (message);
>     }
>     else
>     {
>         m_pStruct = pTable;
>     }
> }
> 
> /*int Table::lookupTableID(const string& label)
> {
>     // lookup AUStruct's index in map by label
>     AConstIndexIterator item = m_labelIndex.find(label);
>     if ( item != m_labelIndex.end() )
>     {
>         return ( (item->second) );
>     }
>     else
>     {
>         throw ("AUStruct not found in labelIndex map");
>     }
> }*/
> 
> 
> void Table::serializeTableList(Serializer& binaryArchive)
> {
>     FssimApp* pApp = FssimApp::getApp();
>     if (binaryArchive.isWriting())
>     {
>         // write size of m_tableList
>         int tableListLength = pApp->m_tableList.size();
>         binaryArchive.write( &tableListLength, sizeof(tableListLength) ); // data, size
> #ifdef _TSB_SERIALIZER_DEBUG
>             cout << endl << "Writing " << tableListLength << " Tables to binary file..." << endl;
> #endif
>         typedef map<int, TableStruct*>::iterator TI;
>         for (TI tableIter = pApp->m_tableList.begin(); tableIter != pApp->m_tableList.end(); ++tableIter)
>         {
>             if (0 != tableIter->second)
>             {
>                 Table newTableObject( tableIter->second ); // m_tableList is not a hashed list
>                 newTableObject.serialize(binaryArchive); // serialize table
>             }
> 
>         }
>     }
>     else // we are reading from binary file
>     {
>         // read size of m_tableList
>         int tableListLength = 0;
>         binaryArchive.read( &tableListLength, sizeof(tableListLength) ); // data, size
> #ifdef _TSB_SERIALIZER_DEBUG
>             cout << endl << "Reading " << tableListLength
>                  << " tables from binary file..." << endl;
> #endif
>         // populate m_tableList
>         for( int i = 0; i < tableListLength; ++i )
>         {
>             Table newTableObject; // create default Table object
>             try
>             {
>                 newTableObject.serialize(binaryArchive);
>                 // new table is added to m_tableList by init_make_table
>             }
>             catch(FileException& e)
>             {
> #ifdef _TSB_DEBUG
>                 cerr << "File exception: " << e.what() << endl;
> #endif
>                 if (e.isEndOfFile())
>                 {
>                     //endOfFile = true;
>                     break;
>                 }
>                 else
>                 {
>                     throw e;
>                 }
>             }
>             catch(exception& e)
>             {
>                 cerr << "Binary read exception: " << e.what() << endl;
>                 throw e;
>             }
>         }
> #ifdef _TSB_DEBUG
>         if ( !pApp->m_tableList.empty() ) // does the Table list have tables?
>         {
>             cout << "m_tableList " << " has "
>              << tableListLength << " Tables" << endl;
>         }
> #endif
>     }
> }
> 
> 
