1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-16 05:19:55 +00:00
openmw-tes3mp/apps/opencs/model/doc/documentmanager.cpp

49 lines
1.3 KiB
C++
Raw Normal View History

2012-11-21 16:31:18 +00:00
#include "documentmanager.hpp"
#include <algorithm>
#include <stdexcept>
#include <boost/filesystem.hpp>
2012-11-21 16:31:18 +00:00
#include "document.hpp"
CSMDoc::DocumentManager::DocumentManager (const boost::filesystem::path& projectPath)
: mProjectPath (projectPath)
{
if (!boost::filesystem::is_directory (mProjectPath))
boost::filesystem::create_directories (mProjectPath);
}
2012-11-21 16:31:18 +00:00
CSMDoc::DocumentManager::~DocumentManager()
{
for (std::vector<Document *>::iterator iter (mDocuments.begin()); iter!=mDocuments.end(); ++iter)
delete *iter;
}
2013-09-10 14:45:01 +00:00
CSMDoc::Document *CSMDoc::DocumentManager::addDocument (const std::vector<boost::filesystem::path>& files, const boost::filesystem::path& savePath,
bool new_)
2012-11-21 16:31:18 +00:00
{
boost::filesystem::path projectFile (mProjectPath);
projectFile /= savePath.filename().string() + ".project";
Document *document = new Document (files, savePath, new_, projectFile);
2012-11-21 16:31:18 +00:00
mDocuments.push_back (document);
return document;
}
bool CSMDoc::DocumentManager::removeDocument (Document *document)
{
std::vector<Document *>::iterator iter = std::find (mDocuments.begin(), mDocuments.end(), document);
if (iter==mDocuments.end())
throw std::runtime_error ("removing invalid document");
mDocuments.erase (iter);
delete document;
return mDocuments.empty();
}