OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
nifstream.hpp
Go to the documentation of this file.
1 
3 #ifndef OPENMW_COMPONENTS_NIF_NIFSTREAM_HPP
4 #define OPENMW_COMPONENTS_NIF_NIFSTREAM_HPP
5 
6 #include <stdint.h>
7 #include <stdexcept>
8 #include <vector>
9 
11 
12 #include <osg/Vec3f>
13 #include <osg/Vec4f>
14 #include <osg/Quat>
15 #include <osg/Array>
16 #include <osg/PrimitiveSet>
17 
18 #include "niftypes.hpp"
19 
20 
21 namespace Nif
22 {
23 
24 class NIFFile;
25 
26 class NIFStream {
27 
30 
31  uint8_t read_byte();
32  uint16_t read_le16();
33  uint32_t read_le32();
34  float read_le32f();
35 
36 public:
37 
38  NIFFile * const file;
39 
40  NIFStream (NIFFile * file, Files::IStreamPtr inp): inp (inp), file (file) {}
41 
42  void skip(size_t size) { inp->ignore(size); }
43 
44  char getChar() { return read_byte(); }
45  short getShort() { return read_le16(); }
46  unsigned short getUShort() { return read_le16(); }
47  int getInt() { return read_le32(); }
48  unsigned int getUInt() { return read_le32(); }
49  float getFloat() { return read_le32f(); }
50 
51  osg::Vec2f getVector2();
52  osg::Vec3f getVector3();
53  osg::Vec4f getVector4();
55  osg::Quat getQuaternion();
57 
59  std::string getString(size_t length);
61  std::string getString();
63  std::string getVersionString();
64 
65  void getUShorts(osg::VectorGLushort* vec, size_t size);
66  void getFloats(std::vector<float> &vec, size_t size);
67  void getVector2s(osg::Vec2Array* vec, size_t size);
68  void getVector3s(osg::Vec3Array* vec, size_t size);
69  void getVector4s(osg::Vec4Array* vec, size_t size);
70  void getQuaternions(std::vector<osg::Quat> &quat, size_t size);
71 };
72 
73 }
74 
75 #endif
Definition: niffile.hpp:17
int getInt()
Definition: nifstream.hpp:47
uint16_t read_le16()
Definition: nifstream.cpp:15
osg::Vec4f getVector4()
Definition: nifstream.cpp:51
osg::Quat getQuaternion()
Definition: nifstream.cpp:68
void getVector2s(osg::Vec2Array *vec, size_t size)
Definition: nifstream.cpp:118
NIFFile *const file
Definition: nifstream.hpp:38
void skip(size_t size)
Definition: nifstream.hpp:42
Matrix3 getMatrix3()
Definition: nifstream.cpp:58
std::string getVersionString()
This is special since the version string doesn't start with a number, and ends with "\n"...
Definition: nifstream.cpp:99
unsigned short getUShort()
Definition: nifstream.hpp:46
Transformation getTrafo()
Definition: nifstream.cpp:77
void getVector4s(osg::Vec4Array *vec, size_t size)
Definition: nifstream.cpp:130
void getQuaternions(std::vector< osg::Quat > &quat, size_t size)
Definition: nifstream.cpp:136
NIFStream(NIFFile *file, Files::IStreamPtr inp)
Definition: nifstream.hpp:40
Definition: niftypes.hpp:56
boost::shared_ptr< std::istream > IStreamPtr
Definition: constrainedfilestream.hpp:20
uint8_t read_byte()
Definition: nifstream.cpp:9
osg::Vec2f getVector2()
Definition: nifstream.cpp:37
osg::Vec3f getVector3()
Definition: nifstream.cpp:44
char getChar()
Definition: nifstream.hpp:44
float getFloat()
Definition: nifstream.hpp:49
Files::IStreamPtr inp
Input stream.
Definition: nifstream.hpp:29
Definition: niftypes.hpp:35
std::string getString()
Read in a string of the length specified in the file.
Definition: nifstream.cpp:94
void getFloats(std::vector< float > &vec, size_t size)
Definition: nifstream.cpp:112
Definition: nifstream.hpp:26
unsigned int getUInt()
Definition: nifstream.hpp:48
float read_le32f()
Definition: nifstream.cpp:27
short getShort()
Definition: nifstream.hpp:45
uint32_t read_le32()
Definition: nifstream.cpp:21
void getVector3s(osg::Vec3Array *vec, size_t size)
Definition: nifstream.cpp:124
void getUShorts(osg::VectorGLushort *vec, size_t size)
Definition: nifstream.cpp:106