Remove gmx::File (except for File::exists())
[alexxy/gromacs.git] / src / gromacs / utility / path.h
index 4fa5dc1a11a54f1309918da8fcdc2d739022cbe7..8dba41e84c0f1947cb21c62b907eb601e4ad911e 100644 (file)
@@ -1,32 +1,36 @@
 /*
+ * This file is part of the GROMACS molecular simulation package.
  *
- *                This source code is part of
+ * Copyright (c) 2011,2012,2013,2014,2015, by the GROMACS development team, led by
+ * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
+ * and including many others, as listed in the AUTHORS file in the
+ * top-level source directory and at http://www.gromacs.org.
  *
- *                 G   R   O   M   A   C   S
- *
- *          GROningen MAchine for Chemical Simulations
+ * GROMACS is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; either version 2.1
+ * of the License, or (at your option) any later version.
  *
- * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2009, The GROMACS development team,
- * check out http://www.gromacs.org for more information.
+ * GROMACS is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with GROMACS; if not, see
+ * http://www.gnu.org/licenses, or write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
  *
- * If you want to redistribute modifications, please consider that
- * scientific software is very special. Version control is crucial -
- * bugs must be traceable. We will be happy to consider code for
- * inclusion in the official distribution, but derived work must not
- * be called official GROMACS. Details are found in the README & COPYING
- * files - if they are missing, get the official version at www.gromacs.org.
+ * If you want to redistribute modifications to GROMACS, please
+ * consider that scientific software is very special. Version
+ * control is crucial - bugs must be traceable. We will be happy to
+ * consider code for inclusion in the official distribution, but
+ * derived work must not be called official GROMACS. Details are found
+ * in the README & COPYING files - if they are missing, get the
+ * official version at http://www.gromacs.org.
  *
  * To help us fund GROMACS development, we humbly ask that you cite
- * the papers on the package - you can find them in the top README file.
- *
- * For more info, check our website at http://www.gromacs.org
+ * the research papers on the package. Check out http://www.gromacs.org.
  */
 /*! \libinternal \file
  * \brief
  *
  * \author Teemu Murtola <teemu.murtola@gmail.com>
  * \inlibraryapi
+ * \ingroup module_utility
  */
 #ifndef GMX_UTILITY_PATH_H
 #define GMX_UTILITY_PATH_H
 
 #include <string>
 #include <utility>
+#include <vector>
 
 namespace gmx
 {
@@ -47,19 +53,57 @@ namespace gmx
 class Path
 {
     public:
+        static bool containsDirectory(const std::string &path);
+        static bool isAbsolute(const char *path);
+        static bool isAbsolute(const std::string &path);
+        static bool isEquivalent(const std::string &path1,
+                                 const std::string &path2);
+
         static std::string join(const std::string &path1,
                                 const std::string &path2);
         static std::string join(const std::string &path1,
                                 const std::string &path2,
                                 const std::string &path3);
-        static std::pair<std::string, std::string>
-        splitToPathAndFilename(const std::string &path);
+        static std::string normalize(const std::string &path);
+        static std::string getParentPath(const std::string &path);
+        static std::string getFilename(const std::string &path);
+        static bool hasExtension(const std::string &path);
+        static std::string stripExtension(const std::string &path);
+
+        static bool exists(const char *path);
+        static bool exists(const std::string &path);
+        static std::string getWorkingDirectory();
+
+        static void splitPathEnvironment(const std::string        &pathEnv,
+                                         std::vector<std::string> *result);
+        static std::vector<std::string> getExecutablePaths();
+
+        static std::string resolveSymlinks(const std::string &path);
 
     private:
         // Disallow instantiation.
         Path();
 };
 
+class File
+{
+    public:
+        /*! \brief
+         * Checks whether a file exists and is a regular file.
+         *
+         * \param[in] filename  Path to the file to check.
+         * \returns   `true` if \p filename exists and is accessible.
+         *
+         * Does not throw.
+         */
+        static bool exists(const char *filename);
+        //! \copydoc exists(const char *)
+        static bool exists(const std::string &filename);
+
+    private:
+        // Disallow instantiation.
+        File();
+};
 
 class Directory
 {