ToPS
SequenceFormat.hpp
00001 /*
00002  *       SequenceFormat.hpp
00003  *
00004  *       Copyright 2011 Andre Yoshiaki Kashiwabara <akashiwabara@usp.br>
00005  *                      Ígor Bonádio <ibonadio@ime.usp.br>
00006  *                      Vitor Onuchic <vitoronuchic@gmail.com>
00007  *                      Alan Mitchell Durham <aland@usp.br>
00008  *
00009  *       This program is free software; you can redistribute it and/or modify
00010  *       it under the terms of the GNU  General Public License as published by
00011  *       the Free Software Foundation; either version 3 of the License, or
00012  *       (at your option) any later version.
00013  *
00014  *       This program is distributed in the hope that it will be useful,
00015  *       but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017  *       GNU General Public License for more details.
00018  *
00019  *       You should have received a copy of the GNU General Public License
00020  *       along with this program; if not, write to the Free Software
00021  *       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00022  *       MA 02110-1301, USA.
00023  */
00024 
00025 #ifndef SEQUENCE_FORMAT_HPP
00026 #define SEQUENCE_FORMAT_HPP
00027 
00028 #include "crossplatform.hpp"
00029 
00030 #include <istream>
00031 #include <ostream>
00032 #include <boost/shared_ptr.hpp>
00033 
00034 
00035 namespace tops {
00036   class DLLEXPORT SequenceEntry;
00038   class DLLEXPORT SequenceFormat {
00039   public:
00040     SequenceFormat(){};
00041     virtual ~SequenceFormat(){}
00042     virtual std::ostream & saveSequence (std::ostream & stream, SequenceEntry & out);
00043     virtual std::istream & readSequence (std::istream & stream, SequenceEntry & in) ;
00044   };
00045   typedef boost::shared_ptr<SequenceFormat> SequenceFormatPtr;
00046 
00048   class DLLEXPORT FastaSequenceFormat : public SequenceFormat {
00049   private:
00050     std::string _nextFastaHeader;
00051     std::string _currentFastaHeader;
00052     std::string _currentSequence;
00053   public:
00054     FastaSequenceFormat(){};
00055     virtual ~FastaSequenceFormat(){}
00056     virtual std::ostream & saveSequence (std::ostream & stream, SequenceEntry & out);
00057     virtual std::istream & readSequence (std::istream & stream, SequenceEntry & in) ;
00058   };
00059   typedef boost::shared_ptr <FastaSequenceFormat> FastaSequenceFormatPtr;
00060 
00061   class DLLEXPORT SequenceFormatManager;
00062   typedef boost::shared_ptr <SequenceFormatManager> SequenceFormatManagerPtr;
00064   class DLLEXPORT SequenceFormatManager {
00065   public:
00066     static SequenceFormatManagerPtr instance();
00067     virtual ~SequenceFormatManager(){};
00068     virtual void setFormat(SequenceFormatPtr format) {
00069       _format = format;
00070     }
00071     virtual SequenceFormatPtr getFormat(){
00072       return _format;
00073     }
00074   protected:
00075     SequenceFormatManager() {
00076       _format = SequenceFormatPtr(new SequenceFormat());
00077     };
00078   private:
00079     static SequenceFormatManagerPtr _inst;
00080     SequenceFormatPtr _format;
00081   };
00082 
00083 };
00084 
00085 #endif