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 
11 
12 #include "record.hpp"
13 
14 namespace Nif
15 {
16 
17 struct File
18 {
19  virtual ~File() = default;
20 
21  virtual void fail(const std::string &msg) const = 0;
22 
23  virtual void warn(const std::string &msg) const = 0;
24 
25  virtual Record *getRecord(size_t index) const = 0;
26 
27  virtual size_t numRecords() const = 0;
28 
29  virtual Record *getRoot(size_t index = 0) const = 0;
30 
31  virtual size_t numRoots() const = 0;
32 
33  virtual void setUseSkinning(bool skinning) = 0;
34 
35  virtual bool getUseSkinning() const = 0;
36 
37  virtual std::string getFilename() const = 0;
38 };
39 
40 class NIFFile final : public File
41 {
42  enum NIFVersion {
43  VER_MW = 0x04000002 // Morrowind NIFs
44  };
45 
47  unsigned int ver;
48 
50  std::string filename;
51 
53  std::vector<Record*> records;
54 
56  std::vector<Record*> roots;
57 
59 
61  void parse(Files::IStreamPtr stream);
62 
65  std::string printVersion(unsigned int version);
66 
68  NIFFile (NIFFile const &);
70  void operator = (NIFFile const &);
71 
72 public:
74  void fail(const std::string &msg) const override
75  {
76  std::string err = " NIFFile Error: " + msg;
77  err += "\nFile: " + filename;
78  throw std::runtime_error(err);
79  }
81  void warn(const std::string &msg) const override
82  {
83  Log(Debug::Warning) << " NIFFile Warning: " << msg << "\nFile: " << filename;
84  }
85 
87  NIFFile(Files::IStreamPtr stream, const std::string &name);
88  ~NIFFile();
89 
91  Record *getRecord(size_t index) const override
92  {
93  Record *res = records.at(index);
94  return res;
95  }
97  size_t numRecords() const override { return records.size(); }
98 
100  Record *getRoot(size_t index=0) const override
101  {
102  Record *res = roots.at(index);
103  return res;
104  }
106  size_t numRoots() const override { return roots.size(); }
107 
110  void setUseSkinning(bool skinning) override;
111 
112  bool getUseSkinning() const override;
113 
115  std::string getFilename() const override { return filename; }
116 };
117 typedef std::shared_ptr<const Nif::NIFFile> NIFFilePtr;
118 
119 
120 
121 } // Namespace
122 #endif
Definition: niffile.hpp:40
void fail(const std::string &msg) const override
Used if file parsing fails.
Definition: niffile.hpp:74
virtual Record * getRecord(size_t index) const =0
std::string printVersion(unsigned int version)
Definition: niffile.cpp:119
std::string getFilename() const override
Get the name of the file.
Definition: niffile.hpp:115
NIFVersion
Definition: niffile.hpp:42
size_t numRecords() const override
Number of records.
Definition: niffile.hpp:97
size_t numRoots() const override
Number of roots.
Definition: niffile.hpp:106
Base class for all records.
Definition: record.hpp:101
Definition: debuglog.hpp:13
std::shared_ptr< std::istream > IStreamPtr
Definition: constrainedfilestream.hpp:21
void setUseSkinning(bool skinning) override
Definition: niffile.cpp:216
Definition: debuglog.hpp:22
Record * getRecord(size_t index) const override
Get a given record.
Definition: niffile.hpp:91
virtual void setUseSkinning(bool skinning)=0
std::shared_ptr< const Nif::NIFFile > NIFFilePtr
Definition: niffile.hpp:117
virtual void fail(const std::string &msg) const =0
virtual Record * getRoot(size_t index=0) const =0
std::vector< Record * > records
Record list.
Definition: niffile.hpp:53
unsigned int ver
Nif file version.
Definition: niffile.hpp:47
bool mUseSkinning
Definition: niffile.hpp:58
Definition: niffile.hpp:17
~NIFFile()
Definition: niffile.cpp:19
std::vector< Record * > roots
Root list. This is a select portion of the pointers from records.
Definition: niffile.hpp:56
virtual ~File()=default
void operator=(NIFFile const &)
virtual size_t numRecords() const =0
virtual bool getUseSkinning() const =0
Record * getRoot(size_t index=0) const override
Get a given root.
Definition: niffile.hpp:100
virtual size_t numRoots() const =0
bool getUseSkinning() const override
Definition: niffile.cpp:221
void parse(Files::IStreamPtr stream)
Parse the file.
Definition: niffile.cpp:137
NIFFile(NIFFile const &)
Private Copy Constructor.
virtual void warn(const std::string &msg) const =0
virtual std::string getFilename() const =0
void warn(const std::string &msg) const override
Used when something goes wrong, but not catastrophically so.
Definition: niffile.hpp:81
Definition: niffile.hpp:43
const char * name
Definition: crashcatcher.cpp:67
std::string filename
File name, used for error messages and opening the file.
Definition: niffile.hpp:50