Flow123d
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
flow123d
src
system
file_path.cc
Go to the documentation of this file.
1
/*
2
* file_name.cc
3
*
4
* Created on: May 23, 2012
5
* Author: jb
6
*/
7
8
#include "
file_path.hh
"
9
#include "
system.hh
"
10
11
12
// static data members
13
map<string,string>
FilePath::placeholder
;
14
string
FilePath::output_dir
=
""
;
15
string
FilePath::root_dir
=
""
;
16
17
FilePath::FilePath
(
const
string
file_path,
const
FileType
ft) {
18
if
(
output_dir
==
""
) {
19
xprintf
(
Warn
,
"Creating FileName object before set_io_dirs is called. No file path resolving.\n"
);
20
abs_file_path
= file_path;
21
return
;
22
}
23
24
if
(ft ==
input_file
) {
25
abs_file_path
=
root_dir
+
DIR_DELIMITER
+ file_path;
26
substitute_value
();
27
}
else
if
(ft ==
output_file
) {
28
if
(file_path[0] ==
DIR_DELIMITER
) {
29
THROW
( ExcAbsOutputPath() << EI_Path( file_path ) );
30
}
31
abs_file_path
=
output_dir
+
DIR_DELIMITER
+ file_path;
32
substitute_value
();
33
}
34
}
35
36
37
38
void
FilePath::set_io_dirs
(
const
string
working_dir,
const
string
root_input_dir,
const
string
input,
const
string
output) {
39
// root directory
40
root_dir
= root_input_dir;
41
42
// relative output dir is relative to working directory
43
// this is possibly independent of position of the main input file
44
if
(output[0] ==
DIR_DELIMITER
)
output_dir
= output;
45
else
output_dir
= working_dir +
DIR_DELIMITER
+ output;
46
47
// the relative input is relative to the directory of the main input file
48
add_placeholder
(
"${INPUT}"
, input);
49
}
50
51
52
53
void
FilePath::add_placeholder
(
string
key,
string
value) {
54
placeholder
[key] = value;
55
}
56
57
58
void
FilePath::substitute_value
() {
59
for
(
std::map<std::string,std::string>::const_iterator
it = this->
placeholder
.begin(); it != this->
placeholder
.end(); ++it) {
60
size_t
i =
abs_file_path
.find(it->first,0);
61
if
(i != std::string::npos) {
62
if
(it->second ==
""
)
xprintf
(
Warn
,
"Substituting placeholder %s with empty value.\n"
, it->first.c_str());
63
abs_file_path
.replace(i, it->first.size(), it->second);
64
}
65
}
66
}
Generated on Thu May 29 2014 23:14:49 for Flow123d by
1.8.4