[go: up one dir, main page]

Menu

[r999]: / mia2 / mia / core / filetools.hh  Maximize  Restore  History

Download this file

97 lines (79 with data), 3.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* -*- mona-c++ -*-
*
* Copyright (c) Leipzig, Madrid 2004 - 2009
* Max-Planck-Institute for Human Cognitive and Brain Science
* Max-Planck-Institute for Evolutionary Anthropology
* BIT, ETSI Telecomunicacion, UPM
*
* 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.
*
* This program 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 PUcRPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef MIA_FILETOOLS_HH
#define MIA_FILETOOLS_HH
#include <string>
#include <vector>
#include <mia/core/defines.hh>
NS_MIA_BEGIN
/**
Based on an input pattern get a vector of all files that follow the same numbering pattern and
are all numberd consecutive. Only the part of a numbering scheme is taken into account that
is directly followed by the last "." in the filename.
\param in_filename a file name pattern, e.g. file0000.png
\returns a vector of filenames that follow above pattern
*/
EXPORT_CORE std::vector<std::string> get_consecutive_numbered_files(std::string const& in_filename);
/**
Based on an input pattern get a vector of all files that follow the same numbering pattern and
are all numberd consecutive. Also obtain the begin and end numbers as well as the width of the
number pattern
\param in_filename a file name pattern, e.g. file0000.png
\retval min minimum file number
\retval max maximum file number
\retval format_width with of the numbering part (here 4)
\returns a vector of filenames that follow above pattern
*/
EXPORT_CORE const std::string get_filename_pattern_and_range(std::string const& in_filename, size_t& min, size_t& max, size_t& format_width);
/**
Based on an input pattern obtain a vector of file names that follow the same numbering pattern and
are all numberd consecutive and are within the given range.
\param in_filename a file name pattern, e.g. file0000.png
\param start minimum file number
\param end maximum file number
\returns a vector of filenames that follow above pattern
*/
EXPORT_CORE std::vector<std::string> get_consecutive_numbered_files_from_pattern(std::string const& in_filename, int start, int end);
/**
split a filname with a number part into a c-format string or a wildcard string
\param fname input file name
\retval base the resulting format string
\param wildcard true to generate a wildcard string, false to generate a c-format string
\returns the width of the numbering pattern
\example fname = file000.png -> wildcard ? file???.png : file%03d.png
*/
EXPORT_CORE size_t fname_to_cformat(const char *fname, std::string& base, bool wildcard);
/**
split a file name into directoyr and file
\remark obsolate - use BOOST functions
*/
EXPORT_CORE void split_dir_fname(const char *in_name, std::string& dir, std::string& sname);
/**
create a file name from a pattern and a number
\param cformat format pattern string
\param num number
\returns an according string
*/
EXPORT_CORE std::string create_filename(const char *cformat, size_t num);
NS_MIA_END
#endif