OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
BlockStreamBuffer.h
Go to the documentation of this file.
1 #ifndef ossimBlockStreamBuffer_HEADER
2 #define ossimBlockStreamBuffer_HEADER 1
5 #include <iostream>
6 #include <vector>
7 
8 namespace ossim{
19  public:
21  m_startByte(0),
22  m_blockSize(0),
23  m_validSize(0),
24  m_blockBufferPtr(0),
25  m_blockLoaded(false){
26 
27  }
28 
37  ossim_int64 result = -1;
38  if(m_blockSize&&m_blockBufferPtr&&(pos>=0))
39  {
40  result = pos/m_blockSize;
41  }
42 
43  return result;
44  }
45 
54  bool isWithinWindow(ossim_int64 pos)const{
55  return (m_blockLoaded&&
56  (pos>=m_startByte)&&
57  (pos<(m_startByte+m_blockSize)));
58  }
59 
69  return (m_blockLoaded&&
70  (pos>=m_startByte)&&
71  (pos<getEndByte()));
72  }
73 
81  if(m_validSize>=0) return m_startByte+(m_validSize);
82  return m_startByte;
83  }
84 
91  const char* getBufferStart(ossim_int64 absolutePosition)const{
92  if(isWithinValidWindow(absolutePosition))
93  {
94  return m_blockBufferPtr+(absolutePosition-m_startByte);
95  }
96 
97  return 0;
98  }
99 
103  const char* getBuffer()const{
104  return m_blockBufferPtr;
105  }
106 
110  char* getBuffer(){
111  return m_blockBufferPtr;
112  }
113 
118  bool isLoaded()const{return m_blockLoaded;}
119 
127  void setBuffer(char* bufPtr, ossim_uint32 blockSize)
128  {
129  m_blockBufferPtr = bufPtr;
130  m_blockSize = blockSize;
131  m_blockLoaded = false;
132  }
133 
138 
143 
150 
156 
161  };
162 
168  class OSSIM_DLL BlockStreamBuffer : public std::streambuf{
169  public:
170  BlockStreamBuffer(ossim::istream* adaptStream=0, ossim_uint64 blockSize=0);
172  m_adaptStream=0;
173  }
174  protected:
178  std::vector<char> m_blockBuffer;
179 
184 
191 
196 
205  virtual std::streambuf* setbuf (char* s, std::streamsize n);
206 
213  void setgPtrs();
214 
220  void loadBlock();
221 
228  virtual pos_type seekoff(off_type offset, std::ios_base::seekdir dir,
229  std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out);
230 
242  virtual pos_type seekpos(pos_type pos,
243  std::ios_base::openmode mode = std::ios_base::in | std::ios_base::out);
244 
257  virtual std::streamsize xsgetn(char_type* s, std::streamsize n);
258 
267  virtual int underflow();
268 
279  void syncCurrentPosition();
280  };
281 }
282 #endif
std::vector< char > m_blockBuffer
The block buffer that we set the buf pointers to.
ossim_int64 m_blockSize
Is the size of the buffer.
ossim_int64 m_startByte
Is the starting absolute byte offset for the buffer.
bool m_blockLoaded
Variable used to invalidate a block or specify whether the block is loaded.
char * m_blockBufferPtr
Starting address of the block.
This code was derived from https://gist.github.com/mshockwave.
Definition: Barrier.h:8
ossim_int64 m_currentPosValue
holds the current absolute byte position
ossim_int64 m_validSize
is the valid size of the buffer.
bool isWithinWindow(ossim_int64 pos) const
This just tests if the given abolute position is within a block window.
ossim_int64 getBlockIndex(ossim_int64 pos)
Returns the index of a block.
This is a utility class used by the BlockStreamBuffer.
os2<< "> n<< " > nendobj n
ossim_int64 getEndByte() const
Convenient method to get the absolute byte position of the end byte.
unsigned long long ossim_uint64
unsigned int ossim_uint32
const char * getBuffer() const
bool isWithinValidWindow(ossim_int64 pos) const
This just tests if the given abolute position is within a valid window.
const char * getBufferStart(ossim_int64 absolutePosition) const
Get the starting address in the buffer of the absolute position.
std::basic_istream< char > istream
Base class for char input streams.
Definition: ossimIosFwd.h:20
#define OSSIM_DLL
void setBuffer(char *bufPtr, ossim_uint32 blockSize)
Will set the buffer and then reset the loaded flag to be false.
ossim::istream * m_adaptStream
The stream we are adapting.
long long ossim_int64
This is the BlockStreamBuffer class and derives from stream buf.
BlockBufInfo m_blockInfo
Holds the information about the block.