IBamIODevice.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef IBAMIODEVICE_H
00019 #define IBAMIODEVICE_H
00020
00021 #include "api/api_global.h"
00022 #include <cstdio>
00023 #include <string>
00024
00025 namespace BamTools {
00026
00027 class API_EXPORT IBamIODevice {
00028
00029
00030 public: enum OpenMode { NotOpen = 0x0000
00031 , ReadOnly = 0x0001
00032 , WriteOnly = 0x0002
00033 , ReadWrite = ReadOnly | WriteOnly
00034 };
00035
00036
00037 public:
00038 virtual ~IBamIODevice(void) { }
00039
00040
00041 public:
00042
00043
00044
00045
00046 virtual void Close(void) =0;
00047 virtual bool IsRandomAccess(void) const =0;
00048 virtual bool Open(const OpenMode mode) =0;
00049 virtual int64_t Read(char* data, const unsigned int numBytes) =0;
00050 virtual bool Seek(const int64_t& position, const int origin = SEEK_SET) =0;
00051 virtual int64_t Tell(void) const =0;
00052 virtual int64_t Write(const char* data, const unsigned int numBytes) =0;
00053
00054
00055 virtual std::string GetErrorString(void);
00056 virtual bool IsOpen(void) const;
00057 virtual OpenMode Mode(void) const;
00058
00059
00060 protected:
00061 IBamIODevice(void);
00062 void SetErrorString(const std::string& where, const std::string& what);
00063
00064
00065 protected:
00066 OpenMode m_mode;
00067 std::string m_errorString;
00068 };
00069
00070 inline
00071 IBamIODevice::IBamIODevice(void)
00072 : m_mode(IBamIODevice::NotOpen)
00073 { }
00074
00075 inline
00076 std::string IBamIODevice::GetErrorString(void) {
00077 return m_errorString;
00078 }
00079
00080 inline
00081 bool IBamIODevice::IsOpen(void) const {
00082 return ( m_mode != IBamIODevice::NotOpen );
00083 }
00084
00085 inline
00086 IBamIODevice::OpenMode IBamIODevice::Mode(void) const {
00087 return m_mode;
00088 }
00089
00090 inline
00091 void IBamIODevice::SetErrorString(const std::string& where, const std::string& what) {
00092 static const std::string SEPARATOR = ": ";
00093 m_errorString = where + SEPARATOR + what;
00094 }
00095
00096 }
00097
00098 #endif // IBAMIODEVICE_H