diff --git a/code/io/itk/rttbFileDispatch.cpp b/code/io/itk/rttbFileDispatch.cpp index 1f6f83d..b06e21b 100644 --- a/code/io/itk/rttbFileDispatch.cpp +++ b/code/io/itk/rttbFileDispatch.cpp @@ -1,168 +1,127 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL: https://svn/sbr/Sources/SBR-Projects/MatchPoint/trunk/Code/Core/source/mapFileDispatch.cpp $ */ #include "rttbFileDispatch.h" #include "itksys/SystemTools.hxx" namespace rttb { namespace core { FileNameString FileDispatch:: getName(const FileNameString& sFilePath) { FileNameString result = itksys::SystemTools::GetFilenameWithoutLastExtension(sFilePath); return result; }; FileNameString FileDispatch:: getExtension(const FileNameString& sFilePath) { FileNameString result = itksys::SystemTools::GetFilenameLastExtension(sFilePath); return result; }; FileNameString FileDispatch:: getFullName(const FileNameString& sFilePath) { FileNameString result = itksys::SystemTools::GetFilenameName(sFilePath); return result; }; FileNameString FileDispatch:: getPath(const FileNameString& sFilePath) { FileNameString result = itksys::SystemTools::GetFilenamePath(sFilePath); return ensureCorrectOSPathSeparator(result); }; FileNameString FileDispatch:: getName() { return getName(_fileName); }; FileNameString FileDispatch:: getExtension() { return getExtension(_fileName); }; FileNameString FileDispatch:: getFullName() { return getFullName(_fileName); }; FileNameString FileDispatch:: getPath() { return getPath(_fileName); }; FileDispatch:: FileDispatch(const FileNameString& filePath) { _fileName = filePath; }; - /** - * A file scope helper function to concat path and file into - * a full path - */ - FileNameString - FileDispatch:: - createFullPath(const char* path, const char* file) - { - FileNameString ret; - - #ifdef _WIN32 - const char sep = '\\'; - #else - const char sep = '/'; - #endif - /** - * make sure the end of path is a separator - */ - ret = path; - ret = ensureCorrectOSPathSeparator(ret); - - if (ret.size()) - { - if (ret[ret.size() - 1] != sep) - { - ret.append(1, sep); - } - } - - ret.append(file); - return ret; - } - - FileNameString - FileDispatch:: - createFullPath(const FileNameString& path, const FileNameString& file) - { - FileNameString ret = createFullPath(path.c_str(), file.c_str()); - return ret; - } - /** Convertes all path seperators in the seperators used in the current OS.*/ FileNameString FileDispatch:: ensureCorrectOSPathSeparator(const FileNameString& path) { FileNameString ret = path; #ifdef _WIN32 const FileNameString curSep = "\\"; const char wrongSep = '/'; #else const FileNameString curSep = "/"; const char wrongSep = '\\'; #endif FileNameString::size_type pos = ret.find_first_of(wrongSep); while (pos != FileNameString::npos) { ret.replace(pos, 1, curSep); pos = ret.find_first_of(wrongSep); } return ret; } } } \ No newline at end of file diff --git a/code/io/itk/rttbFileDispatch.h b/code/io/itk/rttbFileDispatch.h index 4f86e24..58d66d5 100644 --- a/code/io/itk/rttbFileDispatch.h +++ b/code/io/itk/rttbFileDispatch.h @@ -1,76 +1,70 @@ // ----------------------------------------------------------------------- // MatchPoint - DKFZ translational registration framework // // Copyright (c) German Cancer Research Center (DKFZ), // Software development for Integrated Diagnostics and Therapy (SIDT). // ALL RIGHTS RESERVED. // See mapCopyright.txt or // http://www.dkfz.de/en/sidt/projects/MatchPoint/copyright.html // // This software is distributed WITHOUT ANY WARRANTY; without even // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // PURPOSE. See the above copyright notices for more information. // //------------------------------------------------------------------------ /*! // @file // @version $Revision$ (last changed revision) // @date $Date$ (last change date) // @author $Author$ (last changed by) // Subversion HeadURL: $HeadURL: https://svn/sbr/Sources/SBR-Projects/MatchPoint/trunk/Code/Core/include/mapFileDispatch.h $ */ #ifndef __RTTB_FILE_DISPATCH_H #define __RTTB_FILE_DISPATCH_H #include #include "rttbBaseType.h" namespace rttb { namespace core { /*! @class FileDispatch @brief Convenience functions for working with files and path @note code copied from MatchPoint, see documentation (http://sourceforge.net/projects/matchpoint/) */ class FileDispatch { public: - /** Returns the name of the file (without extension).*/ static FileNameString getName(const FileNameString& sFilePath); /** Returns the extansion of the file (dot included).*/ static FileNameString getExtension(const FileNameString& sFilePath); /** Returns name of the file plus extension.*/ static FileNameString getFullName(const FileNameString& sFilePath); /** Returns the directory the file is located in (without trailing slash). * @remark this function always removes the last element of the path. Thus * if you pass a path without a file, it will return the parent directory.*/ static FileNameString getPath(const FileNameString& sFilePath); - /** Helper function to concat path and file into - * a full path */ - static FileNameString createFullPath(const char* path, const char* file); - static FileNameString createFullPath(const FileNameString& path, const FileNameString& file); - /** Convertes all path seperators in the seperators used in the current OS.*/ static FileNameString ensureCorrectOSPathSeparator(const FileNameString& path); FileNameString getName(); FileNameString getExtension(); FileNameString getFullName(); FileNameString getPath(); FileDispatch(const FileNameString& filePath); private: FileNameString _fileName; }; }//end namespace core }//end namespace rttb #endif