ArchiveLocationInfo.cpp

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 
00029 #include "ArchiveLocationInfo.hpp"
00030 
00031 #include <sstream>
00032 
00033 #include "Exception.hpp"
00034 #include "OutputFileHandler.hpp"
00035 
00036 
00037 std::string ArchiveLocationInfo::mDirAbsPath = "";
00038 std::string ArchiveLocationInfo::mMeshFilename = "mesh";
00039 
00040 void ArchiveLocationInfo::SetMeshPathname(const FileFinder& rDirectory, const std::string& rFilename)
00041 {
00042     SetArchiveDirectory(rDirectory);
00043     mMeshFilename = rFilename;
00044 }
00045 
00046 void ArchiveLocationInfo::SetMeshPathname(const std::string& rDirectory, const std::string& rFilename)
00047 {
00048     bool is_absolute = FileFinder::IsAbsolutePath(rDirectory);
00049     RelativeTo::Value relative_to;
00050     if (!is_absolute)
00051     {
00052         relative_to = RelativeTo::ChasteTestOutput;
00053     }
00054     else
00055     {
00056         relative_to = RelativeTo::Absolute;
00057     }
00058     FileFinder dir(rDirectory, relative_to);
00059     SetArchiveDirectory(dir);
00060     mMeshFilename = rFilename;
00061 }
00062 
00063 void ArchiveLocationInfo::SetMeshFilename(const std::string& rFilename)
00064 {
00065     mMeshFilename = rFilename;
00066 }
00067 
00068 std::string ArchiveLocationInfo::GetMeshFilename()
00069 {
00070     if (mMeshFilename == "")
00071     {
00072         EXCEPTION("ArchiveLocationInfo::mMeshFilename has not been set");
00073     }
00074     return mMeshFilename;
00075 }
00076 
00077 std::string ArchiveLocationInfo::GetArchiveDirectory()
00078 {
00079     if (mDirAbsPath == "")
00080     {
00081         EXCEPTION("ArchiveLocationInfo::mDirAbsPath has not been set");
00082     }
00083     return mDirAbsPath;
00084 }
00085 
00086 std::string ArchiveLocationInfo::GetProcessUniqueFilePath(
00087         const std::string& rFileName,
00088         unsigned procId)
00089 {
00090     std::stringstream filepath;
00091     filepath << GetArchiveDirectory() << rFileName << "." << procId;
00092     return filepath.str();
00093 }
00094 
00095 void ArchiveLocationInfo::SetArchiveDirectory(const FileFinder& rDirectory)
00096 {
00097     mDirAbsPath = rDirectory.GetAbsolutePath();
00098     if (! ( *(mDirAbsPath.end()-1) == '/'))
00099     {
00100         mDirAbsPath = mDirAbsPath + "/";
00101     }
00102 }
00103 
00104 std::string ArchiveLocationInfo::GetArchiveRelativePath()
00105 {
00106     std::string chaste_output = OutputFileHandler::GetChasteTestOutputDirectory();
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 }
00125 

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5