Documentation for OpenFLUID 2.2.2
Loading...
Searching...
No Matches
ExceptionContext.hpp
Go to the documentation of this file.
1/*
2
3 This file is part of OpenFLUID software
4 Copyright(c) 2021-2026, INRAE
5
6
7 == GNU General Public License Usage ==
8
9 OpenFLUID is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 OpenFLUID is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with OpenFLUID. If not, see <http://www.gnu.org/licenses/>.
21
22
23 == Other Usage ==
24
25 Other Usage means a use of OpenFLUID that is inconsistent with the GPL
26 license, and requires a written agreement between You and INRA.
27 Licensees for Other Usage of OpenFLUID may use this file in accordance
28 with the terms contained in the written agreement between You and INRA.
29
30*/
31
32
33/**
34 @file ExceptionContext.hpp
35
36 @author Jean-Christophe FABRE <jean-christophe.fabre@inra.fr>
37*/
38
39
40#ifndef __OPENFLUID_BASE_EXCEPTIONCONTEXT_HPP__
41#define __OPENFLUID_BASE_EXCEPTIONCONTEXT_HPP__
42
43
44#include <string>
45#include <map>
46#include <sstream>
47#include <cstdint>
48
49
50namespace openfluid { namespace base {
51
52
53class ExceptionContext : public std::map<std::string, std::string>
54{
55 public:
56
57
58 ExceptionContext& addCodeLocation(const std::string& CodeLocStr)
59 {
60 insert(std::pair<std::string,std::string>("codeloc",CodeLocStr));
61
62 return (*this);
63 }
64
65
66 // =====================================================================
67 // =====================================================================
68
69
70 ExceptionContext& addInfos(const std::map<std::string, std::string>& Infos)
71 {
72 for (auto& it : Infos)
73 {
74 insert(std::pair<std::string,std::string>(it.first,it.second));
75 }
76
77 return (*this);
78 }
79
80
81 // =====================================================================
82 // =====================================================================
83
84
85 ExceptionContext& addTimeIndex(const std::uint64_t& TimeIndex)
86 {
87 std::ostringstream iss;
88 iss << TimeIndex;
89 insert(std::pair<std::string,std::string>("timeindex",iss.str()));
90
91 return (*this);
92 }
93
94
95 // =====================================================================
96 // =====================================================================
97
98
99 ExceptionContext& addSpatialUnit(const std::string& SpatialUnitStr)
100 {
101 insert(std::pair<std::string,std::string>("spatialunit",SpatialUnitStr));
102
103 return (*this);
104 }
105
106
107 // =====================================================================
108 // =====================================================================
109
110
111 ExceptionContext& addSpatialConnection(const std::string& SpatialUnitStr1,const std::string& SpatialUnitStr2)
112 {
113 insert(std::pair<std::string,std::string>("spatialconnection",SpatialUnitStr1+"->"+SpatialUnitStr2));
114
115 return (*this);
116 }
117
118
119 // =====================================================================
120 // =====================================================================
121
122
123 ExceptionContext& addStage(const std::string& StageStr)
124 {
125 if (!StageStr.empty())
126 {
127 insert(std::pair<std::string,std::string>("stage",StageStr));
128 }
129
130 return (*this);
131 }
132
133
134 // =====================================================================
135 // =====================================================================
136
137
138 std::string toString() const
139 {
140 std::string Str;
141
142 auto itb = begin();
143 auto ite = end();
144
145 for (auto it = itb; it!= ite; ++it)
146 {
147 if (it!=itb)
148 {
149 Str += ",";
150 }
151
152 Str += (*it).first + "=" + (*it).second;
153 }
154
155 return Str;
156 }
157
158};
159
160
161} } // namespace
162
163
164#endif /* __OPENFLUID_BASE_EXCEPTIONCONTEXT_HPP__ */
Definition ExceptionContext.hpp:54
ExceptionContext & addSpatialUnit(const std::string &SpatialUnitStr)
Definition ExceptionContext.hpp:99
std::string toString() const
Definition ExceptionContext.hpp:138
ExceptionContext & addStage(const std::string &StageStr)
Definition ExceptionContext.hpp:123
ExceptionContext & addInfos(const std::map< std::string, std::string > &Infos)
Definition ExceptionContext.hpp:70
ExceptionContext & addTimeIndex(const std::uint64_t &TimeIndex)
Definition ExceptionContext.hpp:85
ExceptionContext & addCodeLocation(const std::string &CodeLocStr)
Definition ExceptionContext.hpp:58
ExceptionContext & addSpatialConnection(const std::string &SpatialUnitStr1, const std::string &SpatialUnitStr2)
Definition ExceptionContext.hpp:111
Definition ApplicationException.hpp:47