-
Notifications
You must be signed in to change notification settings - Fork 0
/
Job.hh
112 lines (99 loc) · 2.87 KB
/
Job.hh
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#ifndef JOB_HH
#define JOB_HH
/*!
* \file Job.hh
* \brief Definition of the Job class
*/
#include <map>
#include <util.hh>
#include "io/JobIStream.hh"
#include "Geometry.hh"
/*!
* \brief Class for Quill jobs
*
* Class Job holds the parameters that tell Quill what to compute, such as the
* type of calculation, the basis set, and the geometry of the system. The
* parameters are stored as key,value pairs of strings, where the key is
* case-insensitive. Extraction of values to other types is supported, the
* conversion from string is done on the fly.
*/
class Job
{
public:
//! Local typedef for the parameter map
typedef std::map<std::string, std::string> ParamMap;
/*!
* \brief Constructor
*
* Create a new and empty job
*/
Job(): _params() {}
/*!
* \brief Constructor
*
* Create a new job and read the parameters from input stream \a is.
* \param is The job input stream to read this job from
*/
Job(JobIStream& is): _params() { scan(is); }
//! Clear the job, removing all parameters
void clear() { _params.clear(); }
/*!
* \brief Read a job
*
* Read a job from input stream \a is, and store the parameters found.
* Parameters currently stored in the job are preserved, but will be
* overwritten if a parameter with the same name is found in the input.
* \param is The job input stream to read this job from
* \return The updated input stream
*/
JobIStream& scan(JobIStream& is);
/*!
* \brief Extract a string value
*
* Extract the value for parameter \a key from the job. If it is not
* found, an InvalidIndex exception is thrown.
*/
const std::string get(const std::string& key) const;
/*!
* \brief Extract a string value
*
* Extract the value for parameter \a key from the job. If it is not
* found, return \a defval.
*/
const std::string get(const std::string& key, const std::string& defval) const;
/*!
* \brief Extract avalue
*
* Extract the value for parameter \a key from the job and convert it to
* type \a T. If the key is not found, an InvalidIndex exception is
* thrown. If the conversion cannot be made. a Li::InvalidConversion
* exception is thrown.
*/
template <typename T>
const T get(const std::string& key) const
{
return Li::fromString<T>(get(key));
}
private:
//! The parameters themselves
ParamMap _params;
};
template <>
const Geometry Job::get<Geometry>(const std::string& key) const;
namespace {
/*!
* \brief Read a job
*
* Read a job from input stream \a is, and store the parameters found in \a job.
* Parameters currently stored in the job are preserved, but will be overwritten
* if a parameter with the same name is found in the input.
* \param is The input stream to read from
* \param job The job in which to store the parameters
* \return The updated input stream
*/
JobIStream& operator>>(JobIStream& is, Job& job)
{
return job.scan(is);
}
} // namespace
#endif // JOB_HH