2014-08-24 17:27:09 +00:00
|
|
|
///Main header for reading .nif files
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2013-02-24 21:51:56 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_NIF_NIFFILE_HPP
|
|
|
|
#define OPENMW_COMPONENTS_NIF_NIFFILE_HPP
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2010-09-02 20:30:39 +00:00
|
|
|
#include <stdexcept>
|
2010-01-04 13:48:18 +00:00
|
|
|
#include <vector>
|
2014-08-24 17:27:09 +00:00
|
|
|
#include <iostream>
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2010-06-03 18:44:55 +00:00
|
|
|
#include "record.hpp"
|
2010-01-04 18:35:11 +00:00
|
|
|
|
2010-01-06 11:28:37 +00:00
|
|
|
namespace Nif
|
|
|
|
{
|
|
|
|
|
2010-01-04 13:48:18 +00:00
|
|
|
class NIFFile
|
|
|
|
{
|
2012-07-03 04:41:21 +00:00
|
|
|
enum NIFVersion {
|
|
|
|
VER_MW = 0x04000002 // Morrowind NIFs
|
2010-01-04 13:48:18 +00:00
|
|
|
};
|
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
/// Nif file version
|
|
|
|
int ver;
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2014-08-24 17:27:09 +00:00
|
|
|
/// File name, used for error messages and opening the file
|
2012-07-03 04:41:21 +00:00
|
|
|
std::string filename;
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
/// Record list
|
|
|
|
std::vector<Record*> records;
|
2010-01-04 13:48:18 +00:00
|
|
|
|
2014-08-24 17:27:09 +00:00
|
|
|
/// Root list. This is a select portion of the pointers from records
|
2013-04-06 17:17:09 +00:00
|
|
|
std::vector<Record*> roots;
|
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
/// Parse the file
|
|
|
|
void parse();
|
2010-01-07 18:11:03 +00:00
|
|
|
|
2014-08-24 17:27:09 +00:00
|
|
|
///Private Copy Constructor
|
2013-01-05 18:58:50 +00:00
|
|
|
NIFFile (NIFFile const &);
|
2014-08-24 17:27:09 +00:00
|
|
|
///\overload
|
2013-01-05 18:58:50 +00:00
|
|
|
void operator = (NIFFile const &);
|
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
public:
|
2014-08-24 17:27:09 +00:00
|
|
|
/// Used if file parsing fails
|
2012-07-03 04:41:21 +00:00
|
|
|
void fail(const std::string &msg)
|
2010-01-04 13:48:18 +00:00
|
|
|
{
|
2012-07-03 04:41:21 +00:00
|
|
|
std::string err = "NIFFile Error: " + msg;
|
|
|
|
err += "\nFile: " + filename;
|
|
|
|
throw std::runtime_error(err);
|
2010-01-04 13:48:18 +00:00
|
|
|
}
|
2014-08-24 17:27:09 +00:00
|
|
|
/// Used when something goes wrong, but not catastrophically so
|
2012-07-12 13:47:38 +00:00
|
|
|
void warn(const std::string &msg)
|
|
|
|
{
|
2013-01-05 21:03:05 +00:00
|
|
|
std::cerr << "NIFFile Warning: " << msg <<std::endl
|
|
|
|
<< "File: " << filename <<std::endl;
|
2012-07-12 13:47:38 +00:00
|
|
|
}
|
|
|
|
|
2014-08-24 17:27:09 +00:00
|
|
|
/// Open a NIF stream. The name is used for error messages and opening the file.
|
2014-08-23 15:48:11 +00:00
|
|
|
NIFFile(const std::string &name);
|
2013-01-05 18:58:50 +00:00
|
|
|
~NIFFile();
|
|
|
|
|
2012-07-03 04:41:21 +00:00
|
|
|
/// Get a given record
|
2014-06-05 14:53:12 +00:00
|
|
|
Record *getRecord(size_t index) const
|
2012-07-03 04:41:21 +00:00
|
|
|
{
|
|
|
|
Record *res = records.at(index);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
/// Number of records
|
2014-06-05 14:53:12 +00:00
|
|
|
size_t numRecords() const { return records.size(); }
|
2013-04-06 17:17:09 +00:00
|
|
|
|
|
|
|
/// Get a given root
|
2014-06-05 14:53:12 +00:00
|
|
|
Record *getRoot(size_t index=0) const
|
2013-04-06 17:17:09 +00:00
|
|
|
{
|
|
|
|
Record *res = roots.at(index);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
/// Number of roots
|
2014-06-05 14:53:12 +00:00
|
|
|
size_t numRoots() const { return roots.size(); }
|
2010-01-04 13:48:18 +00:00
|
|
|
};
|
2010-01-06 11:28:37 +00:00
|
|
|
|
2012-07-12 13:47:38 +00:00
|
|
|
|
|
|
|
|
2010-01-06 11:28:37 +00:00
|
|
|
} // Namespace
|
2010-01-04 13:48:18 +00:00
|
|
|
#endif
|