www.mooseframework.org
FileLineInfo.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "FileLineInfo.h"
16 
18 
19 FileLineInfo::FileLineInfo(const std::string & f, int l) : _line(l), _file(f) {}
20 
21 bool
23 {
24  return !_file.empty() && _line >= 0;
25 }
26 
27 int
29 {
30  return _line;
31 }
32 
33 std::string
35 {
36  return _file;
37 }
38 
39 void
40 FileLineInfoMap::addInfo(const std::string & key0, const std::string & file, int line)
41 {
42  FileLineInfo f(file, line);
43  if (f.isValid())
44  _map[key0] = f;
45 }
46 
47 void
48 FileLineInfoMap::addInfo(const std::string & key0,
49  const std::string & key1,
50  const std::string & file,
51  int line)
52 {
53  addInfo(makeKey(key0, key1), file, line);
54 }
55 
56 void
57 FileLineInfoMap::addInfo(const std::string & key0,
58  const std::string & key1,
59  const std::string & key2,
60  const std::string & file,
61  int line)
62 {
63  addInfo(makeKey(key0, key1, key2), file, line);
64 }
65 
66 std::string
67 FileLineInfoMap::makeKey(const std::string & key0, const std::string & key1) const
68 {
69  return key0 + "%" + key1;
70 }
71 
72 std::string
73 FileLineInfoMap::makeKey(const std::string & key0,
74  const std::string & key1,
75  const std::string & key2) const
76 {
77  return key0 + "%" + key1 + "%" + key2;
78 }
79 
81 FileLineInfoMap::getInfo(const std::string & key0) const
82 {
83  auto it = _map.find(key0);
84  if (it == _map.end())
85  return FileLineInfo();
86  return it->second;
87 }
88 
90 FileLineInfoMap::getInfo(const std::string & key0, const std::string & key1) const
91 {
92  return getInfo(makeKey(key0, key1));
93 }
94 
96 FileLineInfoMap::getInfo(const std::string & key0,
97  const std::string & key1,
98  const std::string & key2) const
99 {
100  return getInfo(makeKey(key0, key1, key2));
101 }
std::string makeKey(const std::string &key0, const std::string &key1) const
Makes a unique key for the map given two strings.
Definition: FileLineInfo.C:67
int line() const
Definition: FileLineInfo.C:28
void addInfo(const std::string &key0, const std::string &file, int line)
Associate a key with file/line info.
Definition: FileLineInfo.C:40
bool isValid() const
Definition: FileLineInfo.C:22
std::string _file
Definition: FileLineInfo.h:38
Holds file and line information.
Definition: FileLineInfo.h:24
std::string file() const
Definition: FileLineInfo.C:34
FileLineInfo getInfo(const std::string &key0) const
Get file/line info for a key.
Definition: FileLineInfo.C:81