OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
niffile.hpp
Go to the documentation of this file.
1 
3 #ifndef OPENMW_COMPONENTS_NIF_NIFFILE_HPP
4 #define OPENMW_COMPONENTS_NIF_NIFFILE_HPP
5 
6 #include <stdexcept>
7 #include <vector>
8 #include <iostream>
9 
11 
12 #include "record.hpp"
13 
14 namespace Nif
15 {
16 
17 class NIFFile
18 {
19  enum NIFVersion {
20  VER_MW = 0x04000002 // Morrowind NIFs
21  };
22 
24  unsigned int ver;
25 
27  std::string filename;
28 
30  std::vector<Record*> records;
31 
33  std::vector<Record*> roots;
34 
36 
38  void parse(Files::IStreamPtr stream);
39 
42  std::string printVersion(unsigned int version);
43 
45  NIFFile (NIFFile const &);
47  void operator = (NIFFile const &);
48 
49 public:
51  void fail(const std::string &msg) const
52  {
53  std::string err = " NIFFile Error: " + msg;
54  err += "\nFile: " + filename;
55  throw std::runtime_error(err);
56  }
58  void warn(const std::string &msg) const
59  {
60  std::cerr << " NIFFile Warning: " << msg <<std::endl
61  << "File: " << filename <<std::endl;
62  }
63 
65  NIFFile(Files::IStreamPtr stream, const std::string &name);
66  ~NIFFile();
67 
69  Record *getRecord(size_t index) const
70  {
71  Record *res = records.at(index);
72  return res;
73  }
75  size_t numRecords() const { return records.size(); }
76 
78  Record *getRoot(size_t index=0) const
79  {
80  Record *res = roots.at(index);
81  return res;
82  }
84  size_t numRoots() const { return roots.size(); }
85 
88  void setUseSkinning(bool skinning);
89 
90  bool getUseSkinning() const;
91 
93  std::string getFilename() const { return filename; }
94 };
95 typedef boost::shared_ptr<const Nif::NIFFile> NIFFilePtr;
96 
97 
98 
99 } // Namespace
100 #endif
Definition: niffile.hpp:17
void warn(const std::string &msg) const
Used when something goes wrong, but not catastrophically so.
Definition: niffile.hpp:58
std::string printVersion(unsigned int version)
Definition: niffile.cpp:118
NIFVersion
Definition: niffile.hpp:19
Record * getRoot(size_t index=0) const
Get a given root.
Definition: niffile.hpp:78
Base class for all records.
Definition: record.hpp:100
void setUseSkinning(bool skinning)
Definition: niffile.cpp:215
std::string getFilename() const
Get the name of the file.
Definition: niffile.hpp:93
std::vector< Record * > records
Record list.
Definition: niffile.hpp:30
size_t numRecords() const
Number of records.
Definition: niffile.hpp:75
void fail(const std::string &msg) const
Used if file parsing fails.
Definition: niffile.hpp:51
unsigned int ver
Nif file version.
Definition: niffile.hpp:24
bool mUseSkinning
Definition: niffile.hpp:35
~NIFFile()
Definition: niffile.cpp:19
boost::shared_ptr< std::istream > IStreamPtr
Definition: constrainedfilestream.hpp:20
boost::shared_ptr< const Nif::NIFFile > NIFFilePtr
Definition: niffile.hpp:95
std::vector< Record * > roots
Root list. This is a select portion of the pointers from records.
Definition: niffile.hpp:33
bool getUseSkinning() const
Definition: niffile.cpp:220
void operator=(NIFFile const &)
Record * getRecord(size_t index) const
Get a given record.
Definition: niffile.hpp:69
size_t numRoots() const
Number of roots.
Definition: niffile.hpp:84
void parse(Files::IStreamPtr stream)
Parse the file.
Definition: niffile.cpp:136
NIFFile(NIFFile const &)
Private Copy Constructor.
Definition: niffile.hpp:20
const char * name
Definition: crashcatcher.cpp:59
std::string filename
File name, used for error messages and opening the file.
Definition: niffile.hpp:27