ExceptionContext.hpp
Go to the documentation of this file.
1 /*
2 
3  This file is part of OpenFLUID software
4  Copyright(c) 2007, INRA - Montpellier SupAgro
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 /**
35  @file ExceptionContext.hpp
36 
37  @author Jean-Christophe FABRE <jean-christophe.fabre@supagro.inra.fr>
38 */
39 
40 
41 #ifndef __OPENFLUID_BASE_EXCEPTIONCONTEXT_HPP__
42 #define __OPENFLUID_BASE_EXCEPTIONCONTEXT_HPP__
43 
44 
45 #include <string>
46 #include <map>
47 #include <sstream>
48 
49 
50 namespace openfluid { namespace base {
51 
52 
53 class 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  ExceptionContext& addInfos(const std::map<std::string, std::string>& Infos)
70  {
71  for (auto& it : Infos)
72  insert(std::pair<std::string,std::string>(it.first,it.second));
73 
74  return (*this);
75  }
76 
77 
78  // =====================================================================
79  // =====================================================================
80 
81 
82  ExceptionContext& addTimeIndex(const unsigned long long& TimeIndex)
83  {
84  std::ostringstream iss;
85  iss << TimeIndex;
86  insert(std::pair<std::string,std::string>("timeindex",iss.str()));
87 
88  return (*this);
89  }
90 
91 
92  // =====================================================================
93  // =====================================================================
94 
95 
96  ExceptionContext& addSpatialUnit(const std::string& SpatialUnitStr)
97  {
98  insert(std::pair<std::string,std::string>("spatialunit",SpatialUnitStr));
99 
100  return (*this);
101  }
102 
103 
104  // =====================================================================
105  // =====================================================================
106 
107 
108  ExceptionContext& addSpatialConnection(const std::string& SpatialUnitStr1,const std::string& SpatialUnitStr2)
109  {
110  insert(std::pair<std::string,std::string>("spatialconnection",SpatialUnitStr1+"->"+SpatialUnitStr2));
111 
112  return (*this);
113  }
114 
115 
116  // =====================================================================
117  // =====================================================================
118 
119 
120  ExceptionContext& addStage(const std::string& StageStr)
121  {
122  if (!StageStr.empty())
123  insert(std::pair<std::string,std::string>("stage",StageStr));
124 
125  return (*this);
126  }
127 
128 
129  // =====================================================================
130  // =====================================================================
131 
132 
133  std::string toString() const
134  {
135  std::string Str;
136 
137  auto itb = begin();
138  auto ite = end();
139 
140  for (auto it = itb; it!= ite; ++it)
141  {
142  if (it!=itb)
143  Str += ",";
144 
145  Str += (*it).first + "=" + (*it).second;
146  }
147 
148  return Str;
149  }
150 
151 };
152 
153 
154 } } // namespace
155 
156 
157 #endif /* __OPENFLUID_BASE_EXCEPTIONCONTEXT_HPP__ */
ExceptionContext & addCodeLocation(const std::string &CodeLocStr)
Definition: ExceptionContext.hpp:58
ExceptionContext & addSpatialUnit(const std::string &SpatialUnitStr)
Definition: ExceptionContext.hpp:96
std::string toString() const
Definition: ExceptionContext.hpp:133
ExceptionContext & addInfos(const std::map< std::string, std::string > &Infos)
Definition: ExceptionContext.hpp:69
ExceptionContext & addStage(const std::string &StageStr)
Definition: ExceptionContext.hpp:120
Definition: ApplicationException.hpp:47
Definition: ExceptionContext.hpp:53
ExceptionContext & addTimeIndex(const unsigned long long &TimeIndex)
Definition: ExceptionContext.hpp:82
ExceptionContext & addSpatialConnection(const std::string &SpatialUnitStr1, const std::string &SpatialUnitStr2)
Definition: ExceptionContext.hpp:108