1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-11 00:39:59 +00:00
OpenMW/components/nif/niffile.hpp

83 lines
1.8 KiB
C++
Raw Normal View History

///Main header for reading .nif files
#ifndef OPENMW_COMPONENTS_NIF_NIFFILE_HPP
#define OPENMW_COMPONENTS_NIF_NIFFILE_HPP
#include <stdexcept>
#include <vector>
#include <iostream>
#include "record.hpp"
2010-01-04 18:35:11 +00:00
2010-01-06 11:28:37 +00:00
namespace Nif
{
class NIFFile
{
enum NIFVersion {
VER_MW = 0x04000002 // Morrowind NIFs
};
/// Nif file version
int ver;
/// File name, used for error messages and opening the file
std::string filename;
/// Record list
std::vector<Record*> records;
/// Root list. This is a select portion of the pointers from records
std::vector<Record*> roots;
/// Parse the file
void parse();
2010-01-07 18:11:03 +00:00
///Private Copy Constructor
NIFFile (NIFFile const &);
///\overload
void operator = (NIFFile const &);
public:
/// Used if file parsing fails
void fail(const std::string &msg)
{
std::string err = "NIFFile Error: " + msg;
err += "\nFile: " + filename;
throw std::runtime_error(err);
}
/// Used when something goes wrong, but not catastrophically so
void warn(const std::string &msg)
{
std::cerr << "NIFFile Warning: " << msg <<std::endl
<< "File: " << filename <<std::endl;
}
/// Open a NIF stream. The name is used for error messages and opening the file.
NIFFile(const std::string &name);
~NIFFile();
/// Get a given record
2014-06-05 14:53:12 +00:00
Record *getRecord(size_t index) const
{
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(); }
/// Get a given root
2014-06-05 14:53:12 +00:00
Record *getRoot(size_t index=0) const
{
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-06 11:28:37 +00:00
2010-01-06 11:28:37 +00:00
} // Namespace
#endif