Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals

DCFsbifstream.h

Go to the documentation of this file.
00001 // DCFsbifstream.h
00002 //////////////////////////////////////////////////////////////////////
00003 //          (c) Copyright 2001-2002 Brown Deer Technology, LLC.
00004 //                        All rights reserved.
00005 //////////////////////////////////////////////////////////////////////
00006 
00007 #ifndef DCFSBIFSTREAM_H
00008 #define DCFSBIFSTREAM_H
00009 
00010 #ifdef USE_STD
00011 #include <iostream>
00012 #include <fstream>
00013 #include <string>
00014 using namespace std;
00015 #else
00016 #include <iostream.h>
00017 #include <fstream.h>
00018 #include <string.h>
00019 #endif
00020 
00021 #include "DCFsbistream.h"
00022 
00023 template < class Data_t >
00024 class DCFsbifstream : public DCFsbistream<Data_t> {
00025    public:
00026       DCFsbifstream( const string& = "_\0" );
00027       ~DCFsbifstream();
00028       void filenamebase( const string& );
00029       bool isopen();
00030       void open();
00031       void close();
00032       void initmfilepos();
00033       void findmpacket( DCFmpacketBase&,  const char, const int );
00034    private:
00035       int _lenfilenamebase;
00036       string _filenamebase;
00037       string _filenamesb;
00038       ifstream* _ifs;
00039       int* _mfilepos;
00040 };
00041 
00042 template < class Data_t >
00043 DCFsbifstream<Data_t>::DCFsbifstream( const string& filenamebase ) 
00044   : DCFsbistream<Data_t>( *( _ifs = new ifstream ) ) 
00045 {
00046     _lenfilenamebase = filenamebase.size();
00047     _filenamebase = filenamebase;
00048     _mfilepos = new int[256];
00049 };
00050 
00051 template < class Data_t >
00052 DCFsbifstream<Data_t>::~DCFsbifstream() 
00053 {
00054    (*_ifs).close();
00055    delete [] _mfilepos; _mfilepos = 0;
00056    delete _ifs; _ifs = 0;
00057 };
00058 
00059 template < class Data_t >
00060 void DCFsbifstream<Data_t>::filenamebase( const string& filenamebase ) 
00061 {
00062     _lenfilenamebase = filenamebase.size();
00063     _filenamebase = filenamebase;
00064 };
00065 
00066 template < class Data_t >
00067 bool DCFsbifstream<Data_t>::isopen() { return (*_ifs).is_open(); }
00068 
00069 template < class Data_t >
00070 void DCFsbifstream<Data_t>::open() 
00071 {
00072    if (isopen()) close();
00073    dcfsbfilename( _blocknum, _filenamebase, _filenamesb );
00074    (*_ifs).open( _filenamesb.c_str() );
00075    DCFsbistream<Data_t>::open();
00076    initmfilepos();
00077 //#ifdef STORM_DEBUG
00078    descr();
00079 //#endif
00080 };
00081 
00082 template < class Data_t >
00083 void DCFsbifstream<Data_t>::close() { (*_ifs).close(); }
00084 
00085 template < class Data_t >
00086 void DCFsbifstream<Data_t>::initmfilepos() 
00087 {
00088    for( int i = 0; i < 256; i++ ) { _mfilepos[i] = (*_is).tellg(); }
00089 #ifdef STORM_DEBUG
00090    cout << " initial seek pos " << _mfilepos[0] << '\n';
00091 #endif
00092 };
00093 
00094 template < class Data_t >
00095 void DCFsbifstream<Data_t>::findmpacket(
00096   DCFmpacketBase& mp,
00097   const char mcode,
00098   const int n
00099 ) 
00100 {
00101    bool found = false;
00102    bool missing = false;
00103    bool eof = false;
00104    int nextfilepos;
00105    bytepack bp;
00106 
00107 #ifdef STORM_DEBUG
00108    cout << "DCFsbifstream.findmpacket(): SEARCHING FOR : mcode "
00109         << int( (unsigned char)(mcode) ) << '\n';
00110 #endif
00111 
00112    mp.clear();
00113    (*_is).seekg( _mfilepos[ int( (unsigned char)(mcode) ) ], ios::beg );
00114    int i0 = (*_is).tellg();
00115 
00116    while ( (*_is).good() & !found & !missing & !eof ) {
00117       nextfilepos = (*_is).tellg();
00118       (*_is) >> mp; 
00119 #ifdef STORM_DEBUG
00120       cout << "DCFsbifstream.findmpacket(): mp.mcode() mp.empty() "
00121            << int( (unsigned char)(mp.mcode()) ) << ' ' << mp.empty() << '\n';
00122 #endif
00123       if ( mp.empty() ) { 
00124          (*_is) >> bp( 0, _bplen_n ); _finalstep = bp;
00125 //       cout << "FINALSTEP " << _finalstep << '\n';
00126          eof = true; 
00127       }
00128       if ( ( mp.mcode() == mcode ) && ( mp.n() == n ) ) {
00129          found=true; 
00130       }
00131       if ( ( mp.mcode() == mcode ) && ( mp.n() > n ) ) {
00132          missing=true; 
00133          mp.reset(); 
00134       }
00135    }
00136 
00137    int i1=(*_is).tellg();
00138    if (found) {
00139       _mfilepos[ int( (unsigned char)(mcode) ) ] = (*_is).tellg();
00140    }
00141    else {
00142       _mfilepos[ int( (unsigned char)(mcode) ) ] = nextfilepos;
00143    }
00144 
00145 #ifdef STORM_DEBUG
00146    cout << "DCFsbifstream.findmpacket(): mcode _result_ _mfilepos[mcode] "
00147         << int( (unsigned char)(mcode) );
00148    if (found)  cout << " FOUND ";
00149    if (missing) cout << " MISSING ";
00150    if (eof) cout << " EOF ";
00151    cout << _mfilepos[ int( (unsigned char)(mcode) ) ] << ' ' << n << '\n';
00152 #endif
00153 };
00154 
00155 #endif
00156 

Generated on Mon May 31 21:38:44 2004 for SR2k4 Assembler by doxygen 1.3.6