ProteoWizard
Main Page
Namespaces
Classes
Files
File List
File Members
pwiz
utility
misc
Environment.hpp
Go to the documentation of this file.
1
//
2
// $Id: Environment.hpp 2784 2011-06-15 18:46:58Z chambm $
3
//
4
//
5
// Original author: Matt Chambers <matt.chambers .@. vanderbilt.edu>
6
//
7
// Copyright 2011 Vanderbilt University - Nashville, TN 37232
8
//
9
// Licensed under the Apache License, Version 2.0 (the "License");
10
// you may not use this file except in compliance with the License.
11
// You may obtain a copy of the License at
12
//
13
// http://www.apache.org/licenses/LICENSE-2.0
14
//
15
// Unless required by applicable law or agreed to in writing, software
16
// distributed under the License is distributed on an "AS IS" BASIS,
17
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
// See the License for the specific language governing permissions and
19
// limitations under the License.
20
//
21
22
23
#include <stdexcept>
24
#include "
optimized_lexical_cast.hpp
"
25
#include <cstdlib>
26
27
28
namespace
pwiz {
29
namespace
util {
30
namespace
env {
31
32
33
template
<
typename
T>
34
T
get
(
const
char
* name,
const
T&
defaultValue
)
35
{
36
if
(!name)
37
throw
std::runtime_error(
"[env::get()] null variable name"
);
38
39
T
value
(
defaultValue
);
40
char
* result = ::getenv(name);
41
if
(result)
42
value =
boost::lexical_cast
<T>(result);
43
return
value
;
44
}
45
46
47
template
<
typename
T>
48
T
get
(
const
std::string& name,
const
T&
defaultValue
)
49
{
50
if
(name.empty())
51
throw
std::runtime_error(
"[env::get()] empty variable name"
);
52
53
return
get
(name.c_str(),
defaultValue
);
54
}
55
56
57
/// explicit single-argument overload
58
inline
std::string
get
(
const
std::string& name) {
return
get<std::string>(name, std::string());}
59
60
61
}
// namespace env
62
}
// namespace util
63
}
// namespace pwiz
Generated on Mon Nov 26 2012 18:05:49 for ProteoWizard by
1.8.1.1