37 #include <boost/archive/text_oarchive.hpp>
38 #include <boost/archive/text_iarchive.hpp>
43 #include "ArchiveOpener.hpp"
44 #include "ArchiveLocationInfo.hpp"
45 #include "ProcessSpecificArchive.hpp"
47 #include "OutputFileHandler.hpp"
58 const std::string& rFileNameBase,
60 : mpCommonStream(NULL),
61 mpPrivateStream(NULL),
62 mpCommonArchive(NULL),
63 mpPrivateArchive(NULL)
68 std::stringstream common_path;
72 mpCommonStream =
new std::ifstream(common_path.str().c_str(), std::ios::binary);
76 EXCEPTION(
"Cannot load main archive file: " + common_path.str());
83 catch (boost::archive::archive_exception& boost_exception)
85 if (boost_exception.code == boost::archive::archive_exception::unsupported_version)
90 EXCEPTION(
"Could not open Boost archive '" + common_path.str() +
"' because it was written by a more recent Boost. Check process-specific archives too");
95 #define COVERAGE_IGNORE
96 throw boost_exception;
97 #undef COVERAGE_IGNORE
102 mpPrivateStream =
new std::ifstream(private_path.c_str(), std::ios::binary);
108 EXCEPTION(
"Cannot load secondary archive file: " + private_path);
118 delete mpPrivateArchive;
119 delete mpPrivateStream;
120 delete mpCommonArchive;
121 delete mpCommonStream;
133 const std::string& rFileNameBase,
135 : mpCommonStream(NULL),
136 mpPrivateStream(NULL),
137 mpCommonArchive(NULL),
138 mpPrivateArchive(NULL)
143 EXCEPTION(
"Specifying the secondary archive file ID doesn't make sense when writing.");
154 std::stringstream common_path;
160 mpCommonStream =
new std::ofstream(common_path.str().c_str(), std::ios::binary | std::ios::trunc);
164 EXCEPTION(
"Failed to open main archive file for writing: " + common_path.str());
171 mpCommonStream =
new std::ofstream(
"NUL", std::ios::binary | std::ios::trunc);
173 mpCommonStream =
new std::ofstream(
"/dev/null", std::ios::binary | std::ios::trunc);
175 #define COVERAGE_IGNORE
179 EXCEPTION(
"Failed to open dummy archive file '/dev/null' for writing");
181 #undef COVERAGE_IGNORE
186 mpPrivateStream =
new std::ofstream(private_path.c_str(), std::ios::binary | std::ios::trunc);
192 EXCEPTION(
"Failed to open secondary archive file for writing: " + private_path);
202 delete mpPrivateArchive;
203 delete mpPrivateStream;
204 delete mpCommonArchive;
205 delete mpCommonStream;
static std::string GetProcessUniqueFilePath(const std::string &rFileName, unsigned procId=PetscTools::GetMyRank())
ArchiveOpener(const FileFinder &rDirectory, const std::string &rFileNameBase, unsigned procId=PetscTools::GetMyRank())
static bool GetIsDirRelativeToChasteTestOutput()
#define EXCEPTION(message)
Archive * mpPrivateArchive
static std::string GetArchiveDirectory()
static std::string GetArchiveRelativePath()
static void SetArchiveDirectory(const FileFinder &rDirectory)
Archive * mpCommonArchive
static void Set(Archive *pArchive)