Alex Bikfalvi
SimStream Documentation
DataSession.cpp
00001 #include "Headers.h" 00002 #include "DataSession.h" 00003 00004 CDataSession::CDataSession( 00005 __uint32 size, 00006 char* fileName 00007 ) 00008 { 00009 // Open the file 00010 if(FILE_OPEN(this->file, fileName, "w")) 00011 { 00012 printf("\nCannot write to file %s.", fileName); 00013 this->file = NULL; 00014 } 00015 00016 // Create the pool 00017 this->size = size; 00018 this->index = 0; 00019 this->count = 0; 00020 00021 this->pool = new CDataSessionRecord[this->size]; 00022 } 00023 00024 CDataSession::~CDataSession() 00025 { 00026 // Write last data to the file 00027 this->Write(); 00028 00029 // Close the file 00030 if(this->file) fclose(this->file); 00031 00032 // Delete the pool 00033 delete[] this->pool; 00034 } 00035 00036 CDataSessionRecord* CDataSession::Add() 00037 { 00038 // If the pool is full, write values to file 00039 if(this->index == this->size) this->Write(); 00040 00041 assert(this->index < this->size); 00042 00043 // Add value to pool 00044 this->pool[this->index].Index(this->count++); 00045 return &this->pool[this->index++]; 00046 } 00047 00048 void CDataSession::Write() 00049 { 00050 // Write the pool values to the file 00051 for(__uint32 idx = 0; idx < this->index; idx++) this->pool[idx].Write(this->file); 00052 00053 // Reset the pool index 00054 this->index = 0; 00055 }
Last updated: February 8, 2011