KeinMitleid

Lump

Dec 25th, 2014
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #ifndef LUMP_H
  2. #define LUMP_H
  3.  
  4. #include <fstream>
  5. #include <memory>
  6. #include <string>
  7.  
  8. class Lump
  9. {
  10. private:
  11.     std::fstream* m_wad;
  12.     int           m_offset;
  13.     int           m_size;
  14.     std::string   m_name;
  15.    
  16. public:
  17.     Lump (std::fstream& wad, int offset) : m_wad (&wad)
  18.     {
  19.         char name[8];
  20.         int current = m_wad->tellg ();
  21.        
  22.         m_wad->seekg (offset);
  23.         m_wad->read  ((char*) &m_offset, 4);
  24.         m_wad->read  ((char*) &m_size, 4);
  25.         m_wad->read  ((char*) &name, 8);
  26.         m_wad->seekg (current);
  27.        
  28.         m_name = std::string (name, 8).c_str ();
  29.     }
  30.    
  31.     std::unique_ptr<char> data () const
  32.     {
  33.         std::unique_ptr<char> result (new char[m_size]);
  34.         int current = m_wad->tellg ();
  35.            
  36.         m_wad->seekg (m_offset);
  37.         m_wad->read  ((char*) result.get (), m_size);
  38.         m_wad->seekg (current);
  39.  
  40.         return result;
  41.     }
  42.    
  43.     const std::string& name () const
  44.     {
  45.         return m_name;
  46.     }
  47. };
  48.  
  49. #endif // LUMP_H
Advertisement
Add Comment
Please, Sign In to add comment