ProteoWizard
Filesystem.hpp
Go to the documentation of this file.
1 //
2 // $Id: Filesystem.hpp 4010 2012-10-17 20:22:16Z chambm $
3 //
4 //
5 // Original author: Matt Chambers <matt.chambers .@. vanderbilt.edu>
6 //
7 // Copyright 2008 Spielberg Family Center for Applied Proteomics
8 // Cedars Sinai Medical Center, Los Angeles, California 90048
9 // Copyright 2008 Vanderbilt University - Nashville, TN 37232
10 //
11 // Licensed under the Apache License, Version 2.0 (the "License");
12 // you may not use this file except in compliance with the License.
13 // You may obtain a copy of the License at
14 //
15 // http://www.apache.org/licenses/LICENSE-2.0
16 //
17 // Unless required by applicable law or agreed to in writing, software
18 // distributed under the License is distributed on an "AS IS" BASIS,
19 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 // See the License for the specific language governing permissions and
21 // limitations under the License.
22 //
23 
24 
25 #ifndef _FILESYSTEM_HPP_
26 #define _FILESYSTEM_HPP_
27 
28 #include "Export.hpp"
29 #include "String.hpp"
30 #include "Container.hpp"
31 #include <boost/filesystem/operations.hpp>
32 #include <boost/filesystem/convenience.hpp>
33 #include <boost/filesystem/fstream.hpp>
34 #include <boost/version.hpp>
36 
37 namespace bfs = boost::filesystem;
38 
39 #ifndef BOOST_FILESYSTEM_VERSION
40 # if (BOOST_VERSION/100) >= 1046
41 # define BOOST_FILESYSTEM_VERSION 3
42 # else
43 # define BOOST_FILESYSTEM_VERSION 2
44 # endif
45 #endif // BOOST_FILESYSTEM_VERSION
46 
47 
48 // boost filesystem v2 support is going away
49 // and v3 breaks the API in surprising ways
50 // see http://www.boost.org/doc/libs/1_47_0/libs/filesystem/v3/doc/deprecated.html
51 #if BOOST_FILESYSTEM_VERSION == 2
52 // in BFS2 p.filename() or p.leaf() or p.extension() returns a string
53 #define BFS_STRING(p) p
54 // in BFS2 complete() is in namespace
55 #define BFS_COMPLETE bfs::complete
56 #else
57 // in BFS3 p.filename() or p.leaf() or p.extension() returns a bfs::path
58 #define BFS_STRING(p) (p).string()
59 // in BFS3 complete() is not in namespace
60 #define BFS_COMPLETE complete
61 #endif
62 
63 namespace pwiz {
64 namespace util {
65 
66 
67 /// expands (aka globs) a pathmask to zero or more matching paths and returns the number of matching paths
68 /// - matching paths can be either files or directories
69 /// - matching paths will be absolute if input pathmask was absolute
70 /// - matching paths will be relative if input pathmask was relative
71 PWIZ_API_DECL int expand_pathmask(const bfs::path& pathmask,
72  vector<bfs::path>& matchingPaths);
73 
74 
76 {
77  /// sizes are treated as multiples of 2;
78  /// abbreviations are: GiB (Gibibyte), MiB (Mebibyte), KiB (Kibibyte), B (byte)
80 
81  /// sizes are treated as multiples of 2;
82  /// abbreviations are: GB (Gigabyte), MB (Megabyte), KB (Kilobyte), B (byte)
84 
85  /// sizes are treated as multiples of 10;
86  /// abbreviations are: GB (Gigabyte), MB (Megabyte), KB (Kilobyte), B (byte)
88 };
89 
90 
91 /// abbreviates a byte size (file or RAM) as a readable string, using the specified notation
93 std::string abbreviate_byte_size(boost::uintmax_t byteSize,
95 
96 
97 PWIZ_API_DECL std::string read_file_header(const std::string& filepath, size_t length = 512);
98 
99 
100 } // util
101 } // pwiz
102 
103 #endif // _FILESYSTEM_HPP_