Line data Source code
1 :
2 : /* Copyright (c) 2010-2017, Stefan Eilemann <eile@eyescale.ch>
3 : *
4 : * This library is free software; you can redistribute it and/or modify it under
5 : * the terms of the GNU Lesser General Public License version 2.1 as published
6 : * by the Free Software Foundation.
7 : *
8 : * This library is distributed in the hope that it will be useful, but WITHOUT
9 : * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 : * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
11 : * details.
12 : *
13 : * You should have received a copy of the GNU Lesser General Public License
14 : * along with this library; if not, write to the Free Software Foundation, Inc.,
15 : * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 : */
17 :
18 : #include "errorRegistry.h"
19 :
20 : #include "error.h"
21 :
22 : #include <unordered_map>
23 :
24 : namespace eq
25 : {
26 : namespace fabric
27 : {
28 : namespace
29 : {
30 20 : static std::string _empty;
31 : typedef std::unordered_map<uint32_t, std::string> ErrorHash;
32 : }
33 :
34 : namespace detail
35 : {
36 40 : class ErrorRegistry
37 : {
38 : public:
39 : ErrorHash errors;
40 : };
41 : }
42 :
43 20 : ErrorRegistry::ErrorRegistry()
44 20 : : _impl(new detail::ErrorRegistry)
45 : {
46 20 : _impl->errors[ERROR_NONE] = "no error";
47 20 : }
48 :
49 40 : ErrorRegistry::~ErrorRegistry()
50 : {
51 20 : delete _impl;
52 20 : }
53 :
54 0 : const std::string& ErrorRegistry::getString(const uint32_t error) const
55 : {
56 0 : ErrorHash::const_iterator i = _impl->errors.find(error);
57 0 : if (i == _impl->errors.end())
58 0 : return _empty;
59 :
60 0 : return i->second;
61 : }
62 :
63 500 : void ErrorRegistry::setString(const uint32_t error, const std::string& text)
64 : {
65 500 : _impl->errors[error] = text;
66 500 : }
67 :
68 500 : void ErrorRegistry::eraseString(const uint32_t error)
69 : {
70 500 : _impl->errors.erase(error);
71 500 : }
72 :
73 0 : bool ErrorRegistry::isEmpty() const
74 : {
75 0 : return _impl->errors.empty();
76 : }
77 : }
78 60 : }
|