Simbody  3.4 (development)
Pathname.h
Go to the documentation of this file.
00001 #ifndef SimTK_SimTKCOMMON_PATHNAME_H_
00002 #define SimTK_SimTKCOMMON_PATHNAME_H_
00003 
00004 /* -------------------------------------------------------------------------- *
00005  *                       Simbody(tm): SimTKcommon                             *
00006  * -------------------------------------------------------------------------- *
00007  * This is part of the SimTK biosimulation toolkit originating from           *
00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
00010  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody.  *
00011  *                                                                            *
00012  * Portions copyright (c) 2009-12 Stanford University and the Authors.        *
00013  * Authors: Michael Sherman                                                   *
00014  * Contributors:                                                              *
00015  *                                                                            *
00016  * Licensed under the Apache License, Version 2.0 (the "License"); you may    *
00017  * not use this file except in compliance with the License. You may obtain a  *
00018  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0.         *
00019  *                                                                            *
00020  * Unless required by applicable law or agreed to in writing, software        *
00021  * distributed under the License is distributed on an "AS IS" BASIS,          *
00022  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   *
00023  * See the License for the specific language governing permissions and        *
00024  * limitations under the License.                                             *
00025  * -------------------------------------------------------------------------- */
00026 
00031 #include "SimTKcommon/internal/common.h"
00032 #include "SimTKcommon/internal/Array.h"
00033 #include <string>
00034 #include <stdexcept>
00035 
00036 namespace SimTK {
00037 
00088 class SimTK_SimTKCOMMON_EXPORT Pathname {
00089 public:
00128     static void deconstructPathname(    const std::string& name,
00129                                         bool&        isAbsolutePath,
00130                                         std::string& directory,
00131                                         std::string& fileName,
00132                                         std::string& extension);
00133 
00151     static std::string getAbsolutePathname(const std::string& pathname) {
00152         bool isAbsolutePath;
00153         std::string directory, fileName, extension;
00154         deconstructPathname(pathname, isAbsolutePath, directory, fileName, extension);
00155         if (!isAbsolutePath)
00156             directory = getCurrentWorkingDirectory() + directory;
00157         return directory + fileName + extension;
00158     }
00159 
00163     static std::string getAbsoluteDirectoryPathname(const std::string& dirPathname) {
00164         std::string absPath = getAbsolutePathname(dirPathname);
00165         if (!absPath.empty() && absPath[absPath.size()-1] != getPathSeparatorChar())
00166             absPath += getPathSeparatorChar();
00167         return absPath;
00168     }
00169 
00172     static bool fileExists(const std::string& fileName);
00173 
00177     static std::string getDefaultInstallDir();
00178 
00181     static std::string addDirectoryOffset(const std::string& base, const std::string& offset);
00182 
00186     static std::string getInstallDir(const std::string& envInstallDir,
00187                                      const std::string& offsetFromDefaultInstallDir);
00188 
00190     static std::string getThisExecutablePath();
00193     static std::string getThisExecutableDirectory();
00201     static std::string getCurrentWorkingDirectory(const std::string& drive="");
00205     static std::string getRootDirectory(const std::string& drive="");
00208     static std::string getCurrentDriveLetter();
00211     static std::string getCurrentDrive();
00214     static bool environmentVariableExists(const std::string& name);
00220     static std::string getEnvironmentVariable(const std::string& name);
00224     static std::string getPathSeparator();
00228     static char getPathSeparatorChar();
00230     static bool isPathSeparator(char c) {
00231         return c=='/' || c=='\\';
00232     }
00233 };
00234 
00235 } // namespace SimTK
00236 
00237 #endif // SimTK_SimTKCOMMON_PATHNAME_H_
00238 
00239 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines