ArchiveLocationInfo.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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 
00064     static bool mDirIsRelativeToChasteTestOutput;
00065 
00067     static std::string mMeshFilename;
00068 
00069 
00070 public:
00076     static void SetMeshPathname(const std::string& rDirectory, const std::string& rFilename)
00077     {
00078         SetArchiveDirectory(rDirectory);
00079         mMeshFilename = rFilename;
00080     }
00081 
00086     static void SetMeshFilename(const std::string& rFilename)
00087     {
00088         mMeshFilename = rFilename;
00089     }
00090 
00095     static std::string GetMeshFilename()
00096     {
00097         if (mMeshFilename == "")
00098         {
00099             EXCEPTION("ArchiveLocationInfo::mMeshFilename has not been set");
00100         }
00101         return mMeshFilename;
00102     }
00103 
00109     static std::string GetArchiveDirectory()
00110     {
00111         if (mDirPath == "")
00112         {
00113             EXCEPTION("ArchiveLocationInfo::mDirPath has not been set");
00114         }
00115         return mDirPath;
00116     }
00117 
00129     static std::string GetProcessUniqueFilePath(const std::string& rFileName,
00130                                                 unsigned procId=PetscTools::GetMyRank())
00131     {
00132         std::stringstream filepath;
00133         filepath << GetArchiveDirectory() << rFileName << "." << procId;
00134         return filepath.str();
00135     }
00136 
00144     static void SetArchiveDirectory(const std::string& rDirectory, bool relativeToChasteTestOutput=true)
00145     {
00146         mDirPath = rDirectory;
00147         if (! ( *(mDirPath.end()-1) == '/'))
00148         {
00149             mDirPath = mDirPath + "/";
00150         }
00151 
00152         mDirIsRelativeToChasteTestOutput = relativeToChasteTestOutput;
00153     }
00154 
00161     static std::string GetArchiveRelativePath()
00162     {
00163         if (mDirIsRelativeToChasteTestOutput)
00164         {
00165             std::string chaste_output=OutputFileHandler::GetChasteTestOutputDirectory();
00166             //Find occurrence of CHASTE_TEST_OUTPUT in string
00167             std::string::size_type pos=mDirPath.find(chaste_output, 0);
00168             if (pos == std::string::npos)
00169             {
00170                 EXCEPTION("Full path doesn't give a directory relative to CHASTE_TEST_OUTPUT");
00171             }
00172             assert(pos == 0); //Expect this as a prefix, not in the middle of the string
00173 
00174             return mDirPath.substr(chaste_output.length());
00175         }
00176         else
00177         {
00178             return mDirPath;
00179         }
00180     }
00181 
00186     static bool GetIsDirRelativeToChasteTestOutput()
00187     {
00188         return mDirIsRelativeToChasteTestOutput;
00189     }
00190 };
00191 
00192 #endif /*ARCHIVELOCATIONINFO_HPP_*/

Generated by  doxygen 1.6.2