GDAL
cpl_error_internal.h
1/**********************************************************************
2 *
3 * Name: cpl_error_internal.h
4 * Project: CPL - Common Portability Library
5 * Purpose: CPL Error handling
6 * Author: Even Rouault, <even.rouault at spatialys.com>
7 *
8 **********************************************************************
9 * Copyright (c) 2019, Even Rouault, <even.rouault at spatialys.com>
10 *
11 * SPDX-License-Identifier: MIT
12 ****************************************************************************/
13
14#ifndef CPL_ERROR_INTERNAL_H_INCLUDED
15#define CPL_ERROR_INTERNAL_H_INCLUDED
16
17#if defined(GDAL_COMPILATION) || defined(DOXYGEN_SKIP)
18// internal only
19
20#include "cpl_error.h"
21#include "cpl_string.h"
22
23#include <mutex>
24#include <vector>
25
26/************************************************************************/
27/* CPLErrorHandlerAccumulatorStruct */
28/************************************************************************/
29
37{
38 public:
41
44
46 CPLString msg{};
47
52
55 const char *msgIn)
56 : type(eErrIn), no(noIn), msg(msgIn)
57 {
58 }
59};
60
61/************************************************************************/
62/* CPLErrorAccumulator */
63/************************************************************************/
64
76{
77 public:
80
84 struct CPL_DLL Context
85 {
87 ~Context();
88
89 Context(const Context &) = delete;
90 Context &operator=(const Context &) = delete;
91 Context(Context &&) = delete;
92 Context &operator=(Context &&) = delete;
93
94 private:
95 friend class CPLErrorAccumulator;
96 explicit Context(CPLErrorAccumulator &sAccumulator);
98 };
99
103
105 const std::vector<CPLErrorHandlerAccumulatorStruct> &GetErrors() const
106 {
107 return errors;
108 }
109
112
113 private:
114 std::mutex mutex{};
115 std::vector<CPLErrorHandlerAccumulatorStruct> errors{};
116
117 static void CPL_STDCALL Accumulator(CPLErr eErr, CPLErrorNum no,
118 const char *msg);
119};
120
121#endif
122
123#endif // CPL_ERROR_INTERNAL_H_INCLUDED
Class typically used by a worker thread to store errors emitted by their worker functions,...
Definition cpl_error_internal.h:76
void ReplayErrors()
Replay stored errors.
CPLErrorAccumulator()=default
Constructor.
Context InstallForCurrentScope()
Install a temporary error handler that will store errors and warnings.
Class that stores details about an emitted error.
Definition cpl_error_internal.h:37
CPLErrorHandlerAccumulatorStruct(CPLErr eErrIn, CPLErrorNum noIn, const char *msgIn)
Constructor.
Definition cpl_error_internal.h:54
CPLErrorNum no
Error number.
Definition cpl_error_internal.h:43
CPLErrorHandlerAccumulatorStruct()
Default constructor.
Definition cpl_error_internal.h:49
CPLErr type
Error level.
Definition cpl_error_internal.h:40
Convenient string class based on std::string.
Definition cpl_string.h:338
CPL error handling services.
#define CPLE_None
No error.
Definition cpl_error.h:106
CPLErr
Error category / error level.
Definition cpl_error.h:45
@ CE_None
No error.
Definition cpl_error.h:47
int CPLErrorNum
Error number.
Definition cpl_error.h:103
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:1035
Various convenience functions for working with strings and string lists.
Object returned by InstallForCurrentScope() during life-time of which, errors are redirected to the C...
Definition cpl_error_internal.h:85