Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

gnFileSource.cpp

Go to the documentation of this file.
00001 /////////////////////////////////////////////////////////////////////////////
00002 // File:            gnFileSource.h
00003 // Purpose:         Implements generic gnBaseSource methods
00004 // Description:     Provides a general implementation for accessing DNA
00005 //                  sequence contig data files.
00006 // Changes:        
00007 // Version:         libGenome 0.5.1 
00008 // Author:          Aaron Darling 
00009 // Modified by:     
00010 // Copyright:       (c) Aaron Darling 
00011 // Licenses:        See COPYING file for details
00012 /////////////////////////////////////////////////////////////////////////////
00013 #include "gn/gnFileSource.h"
00014 #include <fstream>
00015 #include "gn/gnFilter.h"
00016 
00017 //copy constructor
00018 gnFileSource::gnFileSource(const gnFileSource& gnfs){
00019         m_openString = gnfs.m_openString;
00020         m_pFilter = gnfs.m_pFilter;
00021         m_newlineType = gnfs.m_newlineType;
00022         m_newlineSize = gnfs.m_newlineSize;
00023         m_ifstream.open( m_openString.c_str(), ios::in | ios::binary );
00024         if( !m_ifstream.is_open() )
00025                 m_ifstream.clear();
00026 }
00027 
00028 // Open, Close  
00029 void gnFileSource::Open( string openString )
00030 {
00031         m_ifstream.open(openString.c_str(), ios::in | ios::binary );
00032         if( m_ifstream.is_open() )
00033         {
00034                 m_openString = openString;
00035                 if( ParseStream(m_ifstream) )
00036                 {
00037                         ;
00038                 }
00039                 else{
00040                         m_ifstream.clear();
00041                         m_ifstream.close();
00042                 }
00043         }else{
00044                 m_ifstream.clear();
00045                 Throw_gnEx(FileNotOpened());
00046         }
00047 }
00048 void gnFileSource::Open( )
00049 {
00050         m_ifstream.open( m_openString.c_str(), ios::in | ios::binary );
00051         if( !m_ifstream.is_open() ){
00052                 m_ifstream.clear();
00053                 Throw_gnEx(FileNotOpened());
00054         }
00055 }
00056 void gnFileSource::Close()
00057 {
00058         m_ifstream.close();
00059         if( m_ifstream.is_open() )
00060                 Throw_gnEx(IOStreamFailed());
00061 }
00062 
00063 boolean gnFileSource::Read( const uint64 pos, char* buf, uint32& bufLen) 
00064 {
00065         m_ifstream.seekg(pos, ios::beg);
00066         m_ifstream.read(buf, bufLen);
00067         if(m_ifstream.fail()){
00068                 m_ifstream.clear();
00069                 return false;
00070         }
00071         return true;
00072 }
00073 
00074 void gnFileSource::DetermineNewlineType()
00075 {
00076         // set default values
00077         m_newlineType = gnNewlineUnix;
00078         m_newlineSize = 1;
00079 
00080         //decide what type of newlines we have
00081         char buf[ BUFFER_SIZE ];
00082         m_ifstream.getline( buf, BUFFER_SIZE);
00083         m_ifstream.seekg(-2, ios::cur);
00084         m_ifstream.read( buf, 2);
00085         m_ifstream.seekg(0);
00086         if(buf[1] == '\n'){
00087                 if(buf[0] == '\r'){
00088                         m_newlineType = gnNewlineWindows;
00089                         m_newlineSize = 2;
00090                 }else{ 
00091                         if(buf[1] == '\r')
00092                                 m_newlineType = gnNewlineMac;
00093                         else
00094                                 m_newlineType = gnNewlineUnix;
00095                 }
00096         }
00097 }

Generated on Mon Feb 3 02:34:39 2003 for libGenome by doxygen1.3-rc3