ArchiveLocationInfo.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 
00029 #include "ArchiveLocationInfo.hpp"
00030 
00031 #include <sstream>
00032 
00033 #include "Exception.hpp"
00034 #include "OutputFileHandler.hpp"
00035 
00036 std::string ArchiveLocationInfo::mDirAbsPath = "";
00037 std::string ArchiveLocationInfo::mMeshFilename = "mesh";
00038 
00039 void ArchiveLocationInfo::SetMeshPathname(const FileFinder& rDirectory, const std::string& rFilename)
00040 {
00041     SetArchiveDirectory(rDirectory);
00042     mMeshFilename = rFilename;
00043 }
00044 
00045 void ArchiveLocationInfo::SetMeshPathname(const std::string& rDirectory, const std::string& rFilename)
00046 {
00047     bool is_absolute = FileFinder::IsAbsolutePath(rDirectory);
00048     RelativeTo::Value relative_to;
00049     if (!is_absolute)
00050     {
00051         relative_to = RelativeTo::ChasteTestOutput;
00052     }
00053     else
00054     {
00055         relative_to = RelativeTo::Absolute;
00056     }
00057     FileFinder dir(rDirectory, relative_to);
00058     SetArchiveDirectory(dir);
00059     mMeshFilename = rFilename;
00060 }
00061 
00062 void ArchiveLocationInfo::SetMeshFilename(const std::string& rFilename)
00063 {
00064     mMeshFilename = rFilename;
00065 }
00066 
00067 std::string ArchiveLocationInfo::GetMeshFilename()
00068 {
00069     if (mMeshFilename == "")
00070     {
00071         EXCEPTION("ArchiveLocationInfo::mMeshFilename has not been set");
00072     }
00073     return mMeshFilename;
00074 }
00075 
00076 std::string ArchiveLocationInfo::GetArchiveDirectory()
00077 {
00078     if (mDirAbsPath == "")
00079     {
00080         EXCEPTION("ArchiveLocationInfo::mDirAbsPath has not been set");
00081     }
00082     return mDirAbsPath;
00083 }
00084 
00085 std::string ArchiveLocationInfo::GetProcessUniqueFilePath(
00086         const std::string& rFileName,
00087         unsigned procId)
00088 {
00089     std::stringstream filepath;
00090     filepath << GetArchiveDirectory() << rFileName << "." << procId;
00091     return filepath.str();
00092 }
00093 
00094 void ArchiveLocationInfo::SetArchiveDirectory(const FileFinder& rDirectory)
00095 {
00096     mDirAbsPath = rDirectory.GetAbsolutePath();
00097     if (!(*(mDirAbsPath.end()-1) == '/'))
00098     {
00099         mDirAbsPath = mDirAbsPath + "/";
00100     }
00101 }
00102 
00103 std::string ArchiveLocationInfo::GetArchiveRelativePath()
00104 {
00105     std::string chaste_output = OutputFileHandler::GetChasteTestOutputDirectory();
00106 
00107     // Find occurrence of CHASTE_TEST_OUTPUT in string
00108     std::string::size_type pos = mDirAbsPath.find(chaste_output, 0);
00109     if (pos == 0)
00110     {
00111         return mDirAbsPath.substr(chaste_output.length());
00112     }
00113     else
00114     {
00115         return mDirAbsPath;
00116     }
00117 }
00118 
00119 bool ArchiveLocationInfo::GetIsDirRelativeToChasteTestOutput()
00120 {
00121     std::string chaste_output = OutputFileHandler::GetChasteTestOutputDirectory();
00122     std::string::size_type pos = mDirAbsPath.find(chaste_output, 0);
00123     return (pos == 0);
00124 }
Generated on Thu Dec 22 13:00:05 2011 for Chaste by  doxygen 1.6.3