Simbody  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Pathname.h
Go to the documentation of this file.
1 #ifndef SimTK_SimTKCOMMON_PATHNAME_H_
2 #define SimTK_SimTKCOMMON_PATHNAME_H_
3 
4 /* -------------------------------------------------------------------------- *
5  * Simbody(tm): SimTKcommon *
6  * -------------------------------------------------------------------------- *
7  * This is part of the SimTK biosimulation toolkit originating from *
8  * Simbios, the NIH National Center for Physics-Based Simulation of *
9  * Biological Structures at Stanford, funded under the NIH Roadmap for *
10  * Medical Research, grant U54 GM072970. See https://simtk.org/home/simbody. *
11  * *
12  * Portions copyright (c) 2009-12 Stanford University and the Authors. *
13  * Authors: Michael Sherman *
14  * Contributors: *
15  * *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may *
17  * not use this file except in compliance with the License. You may obtain a *
18  * copy of the License at http://www.apache.org/licenses/LICENSE-2.0. *
19  * *
20  * Unless required by applicable law or agreed to in writing, software *
21  * distributed under the License is distributed on an "AS IS" BASIS, *
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
23  * See the License for the specific language governing permissions and *
24  * limitations under the License. *
25  * -------------------------------------------------------------------------- */
26 
33 #include <string>
34 #include <stdexcept>
35 
36 namespace SimTK {
37 
89 public:
128  static void deconstructPathname( const std::string& name,
129  bool& isAbsolutePath,
130  std::string& directory,
131  std::string& fileName,
132  std::string& extension);
133 
151  static std::string getAbsolutePathname(const std::string& pathname) {
152  bool isAbsolutePath;
153  std::string directory, fileName, extension;
154  deconstructPathname(pathname, isAbsolutePath, directory, fileName, extension);
155  if (!isAbsolutePath)
156  directory = getCurrentWorkingDirectory() + directory;
157  return directory + fileName + extension;
158  }
159 
163  static std::string getAbsoluteDirectoryPathname(const std::string& dirPathname) {
164  std::string absPath = getAbsolutePathname(dirPathname);
165  if (!absPath.empty() && absPath[absPath.size()-1] != getPathSeparatorChar())
166  absPath += getPathSeparatorChar();
167  return absPath;
168  }
169 
172  static bool fileExists(const std::string& fileName);
173 
177  static std::string getDefaultInstallDir();
178 
181  static std::string addDirectoryOffset(const std::string& base, const std::string& offset);
182 
186  static std::string getInstallDir(const std::string& envInstallDir,
187  const std::string& offsetFromDefaultInstallDir);
188 
190  static std::string getThisExecutablePath();
193  static std::string getThisExecutableDirectory();
201  static std::string getCurrentWorkingDirectory(const std::string& drive="");
205  static std::string getRootDirectory(const std::string& drive="");
208  static std::string getCurrentDriveLetter();
211  static std::string getCurrentDrive();
214  static bool environmentVariableExists(const std::string& name);
220  static std::string getEnvironmentVariable(const std::string& name);
224  static std::string getPathSeparator();
228  static char getPathSeparatorChar();
230  static bool isPathSeparator(char c) {
231  return c=='/' || c=='\\';
232  }
233 };
234 
235 } // namespace SimTK
236 
237 #endif // SimTK_SimTKCOMMON_PATHNAME_H_
238 
239 
#define SimTK_SimTKCOMMON_EXPORT
Definition: SimTKcommon/include/SimTKcommon/internal/common.h:202
static std::string getAbsoluteDirectoryPathname(const std::string &dirPathname)
This is the same as getAbsolutePathname() except that the final segment is interpreted as a directory...
Definition: Pathname.h:163
This class encapsulates the handling of file and directory pathnames in a platform-independent manner...
Definition: Pathname.h:88
This file defines the Array_<T,X> class and related support classes including base classes ArrayViewC...
static std::string getAbsolutePathname(const std::string &pathname)
Get canonicalized absolute pathname from a given pathname which can be relative or absolute...
Definition: Pathname.h:151
static bool isPathSeparator(char c)
Returns true if the character is slash or backslash.
Definition: Pathname.h:230
Mandatory first inclusion for any Simbody source or header file.