retdec
InputBuffer.h
Go to the documentation of this file.
1 /*
2 * InputBuffer.h - Part of the PeLib library.
3 *
4 * Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5 * All rights reserved.
6 *
7 * This software is licensed under the zlib/libpng License.
8 * For more details see http://www.opensource.org/licenses/zlib-license.php
9 * or the license information file (license.htm) in the root directory
10 * of PeLib.
11 */
12 
13 #ifndef RETDEC_PELIB_INPUTBUFFER_H
14 #define RETDEC_PELIB_INPUTBUFFER_H
15 
16 #include <vector>
17 #include <iterator>
18 #include <cassert>
19 
20 namespace PeLib
21 {
23  {
24  private:
25  std::vector<unsigned char>& m_vBuffer;
26  unsigned long ulIndex;
27 
28  public:
29  InputBuffer(std::vector<unsigned char>& vBuffer);
30 
31  const unsigned char* data() const;
32  unsigned long size();
33 
34  template<typename T>
36  {
37 //jk: temporarily disabled because of fails on 64bit systems
38 // assert(ulIndex + sizeof(value) <= m_vBuffer.size());
39 
40  std::vector<char> data(sizeof(T), 0);
41  std::size_t size = ulIndex + sizeof(T) > m_vBuffer.size() ? m_vBuffer.size() - ulIndex : sizeof(T);
42  read(data.data(), (unsigned long)size);
43  value = *reinterpret_cast<T*>(data.data());
44  return *this;
45  }
46 
47  void read(char* lpBuffer, unsigned long ulSize);
48  void reset();
49  void set(unsigned long ulIndex2);
50  void move(unsigned long shift);
51  unsigned long get();
52  void setBuffer(std::vector<unsigned char>& vBuffer);
53 // void updateData(unsigned long ulIndex,
54  };
55 }
56 
57 #endif
Definition: InputBuffer.h:23
void move(unsigned long shift)
Definition: InputBuffer.cpp:52
void set(unsigned long ulIndex2)
Definition: InputBuffer.cpp:47
InputBuffer(std::vector< unsigned char > &vBuffer)
Definition: InputBuffer.cpp:17
void reset()
Definition: InputBuffer.cpp:42
InputBuffer & operator>>(T &value)
Definition: InputBuffer.h:35
const unsigned char * data() const
Definition: InputBuffer.cpp:21
void read(char *lpBuffer, unsigned long ulSize)
Definition: InputBuffer.cpp:31
unsigned long get()
Definition: InputBuffer.cpp:57
unsigned long size()
Definition: InputBuffer.cpp:26
unsigned long ulIndex
Definition: InputBuffer.h:26
void setBuffer(std::vector< unsigned char > &vBuffer)
Definition: InputBuffer.cpp:62
std::vector< unsigned char > & m_vBuffer
Definition: InputBuffer.h:25
Definition: BoundImportDirectory.h:21