00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef ARCHIVELOCATIONINFO_HPP_
00029 #define ARCHIVELOCATIONINFO_HPP_
00030
00031 #include <string>
00032 #include <sstream>
00033 #include <cassert>
00034 #include <iostream>
00035
00036 #include "Exception.hpp"
00037 #include "PetscTools.hpp"
00038 #include "OutputFileHandler.hpp"
00039
00054 class ArchiveLocationInfo
00055 {
00056 private:
00057
00059 static std::string mDirPath;
00060
00062 static std::string mMeshFilename;
00063
00064 public:
00070 static void SetMeshPathname(const std::string& rDirectory, const std::string& rFilename)
00071 {
00072 SetArchiveDirectory(rDirectory);
00073 mMeshFilename = rFilename;
00074 }
00075
00080 static void SetMeshFilename(const std::string& rFilename)
00081 {
00082 mMeshFilename = rFilename;
00083 }
00084
00089 static std::string GetMeshFilename()
00090 {
00091 if (mMeshFilename == "")
00092 {
00093 EXCEPTION("ArchiveLocationInfo::mMeshFilename has not been set");
00094 }
00095 return mMeshFilename;
00096 }
00097
00103 static std::string GetArchiveDirectory()
00104 {
00105 if (mDirPath == "")
00106 {
00107 EXCEPTION("ArchiveLocationInfo::mDirPath has not been set");
00108 }
00109 return mDirPath;
00110 }
00111
00122 static std::string GetProcessUniqueFilePath(const std::string& rFileName)
00123 {
00124 std::stringstream filepath;
00125 filepath << GetArchiveDirectory() << rFileName << "." << PetscTools::GetMyRank();
00126 return filepath.str();
00127 }
00128
00134 static void SetArchiveDirectory(const std::string& rDirectory)
00135 {
00136 mDirPath = rDirectory;
00137 if (! ( *(mDirPath.end()-1) == '/'))
00138 {
00139 mDirPath = mDirPath + "/";
00140 }
00141 }
00142
00149 static std::string GetArchiveRelativePath()
00150 {
00151 std::string chaste_output=OutputFileHandler::GetChasteTestOutputDirectory();
00152
00153 std::string::size_type pos=mDirPath.find(chaste_output, 0);
00154 if (pos == std::string::npos)
00155 {
00156 EXCEPTION("Full path doesn't give a directory relative to CHASTE_TEST_OUTPUT");
00157 }
00158 assert(pos == 0);
00159
00160 return mDirPath.substr(chaste_output.length());
00161 }
00162 };
00163
00164 #endif