ArchiveLocationInfo.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2009
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 
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         //Find occurrence of CHASTE_TEST_OUTPUT in string
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); //Expect this as a prefix, not in the middle of the string
00159 
00160         return mDirPath.substr(chaste_output.length());
00161     }
00162 };
00163 
00164 #endif /*ARCHIVELOCATIONINFO_HPP_*/

Generated on Tue Aug 4 16:10:21 2009 for Chaste by  doxygen 1.5.5