~ubuntu-branches/ubuntu/wily/openms/wily

« back to all changes in this revision

Viewing changes to include/OpenMS/SYSTEM/File.h

  • Committer: Package Import Robot
  • Author(s): Filippo Rusconi
  • Date: 2012-11-12 15:58:12 UTC
  • Revision ID: package-import@ubuntu.com-20121112155812-vr15wtg9b50cuesg
Tags: upstream-1.9.0
ImportĀ upstreamĀ versionĀ 1.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- mode: C++; tab-width: 2; -*-
 
2
// vi: set ts=2:
 
3
//
 
4
// --------------------------------------------------------------------------
 
5
//                   OpenMS Mass Spectrometry Framework 
 
6
// --------------------------------------------------------------------------
 
7
//  Copyright (C) 2003-2011 -- Oliver Kohlbacher, Knut Reinert
 
8
//
 
9
//  This library is free software; you can redistribute it and/or
 
10
//  modify it under the terms of the GNU Lesser General Public
 
11
//  License as published by the Free Software Foundation; either
 
12
//  version 2.1 of the License, or (at your option) any later version.
 
13
//
 
14
//  This library is distributed in the hope that it will be useful,
 
15
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
//  Lesser General Public License for more details.
 
18
//
 
19
//  You should have received a copy of the GNU Lesser General Public
 
20
//  License along with this library; if not, write to the Free Software
 
21
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
//
 
23
// --------------------------------------------------------------------------
 
24
// $Maintainer: Chris Bielow $
 
25
// $Authors: Andreas Bertsch, Chris Bielow, Marc Sturm $
 
26
// --------------------------------------------------------------------------
 
27
 
 
28
 
 
29
#ifndef OPENMS_SYSTEM_FILE_H
 
30
#define OPENMS_SYSTEM_FILE_H
 
31
 
 
32
#include <OpenMS/DATASTRUCTURES/StringList.h>
 
33
#include <OpenMS/DATASTRUCTURES/Param.h>
 
34
#include <OpenMS/config.h>
 
35
 
 
36
 
 
37
namespace OpenMS
 
38
{
 
39
        
 
40
  class TOPPBase;
 
41
 
 
42
        /**
 
43
                @brief Basic file handling operations.
 
44
                
 
45
                @ingroup System
 
46
        */
 
47
        class OPENMS_DLLAPI File
 
48
        {
 
49
                public:
 
50
        
 
51
      friend class TOPPBase;
 
52
 
 
53
      /// Retrieve path of current executable (useful to find other TOPP tools)
 
54
      /// The returned path is either just an EMPTY string if the call to system subroutines failed
 
55
      /// or the complete path including a trailing "/", to enable usage of this function as 
 
56
      ///  File::getExecutablePath() + "mytool"
 
57
      static String getExecutablePath();
 
58
 
 
59
                        /// Method used to test if a @p file exists.
 
60
                        static bool exists(const String& file);
 
61
                
 
62
                        /// Return true if the file does not exist or the file is empty
 
63
                        static bool empty(const String& file);
 
64
                
 
65
                        /**
 
66
                                @brief Removes a file (if it exists). 
 
67
                        
 
68
                                @return Returns true if the file was successfully deleted (or if it did not exist).
 
69
                        */
 
70
                        static bool remove(const String& file);
 
71
 
 
72
                        /// Removes the specified directory (absolute path). Returns true if successful.
 
73
                        static bool removeDirRecursively(const String& dir_name);
 
74
 
 
75
                        /// Replaces the relative path in the argument with the absolute path.
 
76
                        static String absolutePath(const String& file);
 
77
 
 
78
                        /// Returns the basename of the file (without the path).
 
79
                        static String basename(const String& file);
 
80
 
 
81
                        /// Returns the path of the file (without the file name).
 
82
                        static String path(const String& file);
 
83
 
 
84
                        /**
 
85
                                Returns the file name without the extension
 
86
                                
 
87
                                The extension is the suffix of the string upto and including the last dot.
 
88
                                
 
89
                                If no extension is found, the whole file name is returned
 
90
                        */
 
91
                        static String removeExtension(const String& file);
 
92
                        
 
93
                        /// Return true if the file exists and is readable
 
94
                        static bool readable(const String& file);
 
95
 
 
96
                        /// Return true if the file is writable
 
97
                        static bool writable(const String& file);
 
98
 
 
99
                        /// Return true if the given path specifies a directory
 
100
                        static bool isDirectory(const String& path);
 
101
 
 
102
                        /**
 
103
                                @brief Looks up the location of the file @p filename
 
104
                                
 
105
                                The following locations are checked in this order:
 
106
                                - the directories in @p directories
 
107
                                - the directory contained in the environment variable $OPENMS_DATA_PATH
 
108
                                - the 'share/OpenMS/' directory of the OpenMS install directory
 
109
                                
 
110
                                @exception FileNotFound is thrown, if the file is not found
 
111
                        */
 
112
                        static String find(const String& filename, StringList directories = StringList());
 
113
                        
 
114
                        /**
 
115
                                @brief Retrieves a list of files matching @p file_pattern in directory @p dir (returns filenames without paths unless @p full_path is true)
 
116
                                
 
117
                                @return true => there are matching files
 
118
                        */
 
119
                        static bool fileList(const String& dir, const String& file_pattern, StringList& output, bool full_path = false);
 
120
 
 
121
                        /// Returns a string, consisting of date, time, hostname, process id, and a incrementing number.  This can be used for temporary files.
 
122
                        static String getUniqueName();
 
123
                        
 
124
                        /// Returns the OpenMS data path (environment variable overwrites the default installation path)
 
125
                        static String getOpenMSDataPath();
 
126
 
 
127
      /// The current OpenMS temporary data path (for temporary files)
 
128
      static String getTempDirectory();
 
129
 
 
130
      /// The current OpenMS user data path (for result files)
 
131
      static String getUserDirectory();
 
132
 
 
133
      /// get the system's default OpenMS.ini file in the users home directory (&lt;home&gt;/OpenMS/OpenMS.ini)
 
134
      /// or create/repair it if required
 
135
      static Param getSystemParameters();
 
136
 
 
137
      /// uses File::find() to search for a file names @p db_name
 
138
      /// in the 'id_db_dir' param of the OpenMS system parameters
 
139
      /// @exception FileNotFound is thrown, if the file is not found
 
140
      static String findDatabase(const String& db_name);
 
141
 
 
142
  private:
 
143
      
 
144
      /// get defaults for the system's Temp-path, user home directory etc
 
145
      static Param getSystemParameterDefaults_();
 
146
        };
 
147
 
 
148
}
 
149
 
 
150
#endif // OPENMS_SYSTEM_FILE_H