https://mooseframework.inl.gov
Loading...
Searching...
No Matches
FileLineInfo.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
3//*
4//* All rights reserved, see COPYRIGHT for full restrictions
5//* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6//*
7//* Licensed under LGPL 2.1, please see LICENSE for details
8//* https://www.gnu.org/licenses/lgpl-2.1.html
9
10#include "FileLineInfo.h"
11
13
14FileLineInfo::FileLineInfo(const std::string & f, int l) : _line(l), _file(f) {}
15
16bool
18{
19 return !_file.empty() && _line >= 0;
20}
21
22int
24{
25 return _line;
26}
27
28std::string
30{
31 return _file;
32}
33
34void
35FileLineInfoMap::addInfo(const std::string & key0, const std::string & file, int line)
36{
37 FileLineInfo f(file, line);
38 if (f.isValid())
39 _map[key0] = f;
40}
41
42void
43FileLineInfoMap::addInfo(const std::string & key0,
44 const std::string & key1,
45 const std::string & file,
46 int line)
47{
48 addInfo(makeKey(key0, key1), file, line);
49}
50
51void
52FileLineInfoMap::addInfo(const std::string & key0,
53 const std::string & key1,
54 const std::string & key2,
55 const std::string & file,
56 int line)
57{
58 addInfo(makeKey(key0, key1, key2), file, line);
59}
60
61std::string
62FileLineInfoMap::makeKey(const std::string & key0, const std::string & key1) const
63{
64 return key0 + "%" + key1;
65}
66
67std::string
68FileLineInfoMap::makeKey(const std::string & key0,
69 const std::string & key1,
70 const std::string & key2) const
71{
72 return key0 + "%" + key1 + "%" + key2;
73}
74
76FileLineInfoMap::getInfo(const std::string & key0) const
77{
78 auto it = _map.find(key0);
79 if (it == _map.end())
80 return FileLineInfo();
81 return it->second;
82}
83
85FileLineInfoMap::getInfo(const std::string & key0, const std::string & key1) const
86{
87 return getInfo(makeKey(key0, key1));
88}
89
91FileLineInfoMap::getInfo(const std::string & key0,
92 const std::string & key1,
93 const std::string & key2) const
94{
95 return getInfo(makeKey(key0, key1, key2));
96}
void addInfo(const std::string &key0, const std::string &file, int line)
Associate a key with file/line info.
std::map< std::string, FileLineInfo > _map
FileLineInfo getInfo(const std::string &key0) const
Get file/line info for a key.
std::string makeKey(const std::string &key0, const std::string &key1) const
Makes a unique key for the map given two strings.
Holds file and line information.
bool isValid() const
int line() const
std::string _file
std::string file() const