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#ifdef GDAL_COMPILATION
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
30class CPL_DLL CPLErrorHandlerAccumulatorStruct
31{
32 public:
33 CPLErr type;
34 CPLErrorNum no;
35 CPLString msg{};
36
37 CPLErrorHandlerAccumulatorStruct() : type(CE_None), no(CPLE_None)
38 {
39 }
40
41 CPLErrorHandlerAccumulatorStruct(CPLErr eErrIn, CPLErrorNum noIn,
42 const char *msgIn)
43 : type(eErrIn), no(noIn), msg(msgIn)
44 {
45 }
46};
47
48/************************************************************************/
49/* CPLErrorAccumulator */
50/************************************************************************/
51
62class CPL_DLL CPLErrorAccumulator
63{
64 public:
66 CPLErrorAccumulator() = default;
67
68 struct CPL_DLL Context
69 {
71 ~Context();
72
73 Context(const Context &) = delete;
74 Context &operator=(const Context &) = delete;
75 Context(Context &&) = delete;
76 Context &operator=(Context &&) = delete;
77
78 private:
79 friend class CPLErrorAccumulator;
80 explicit Context(CPLErrorAccumulator &sAccumulator);
82 };
83
86 Context InstallForCurrentScope() CPL_WARN_UNUSED_RESULT;
87
89 const std::vector<CPLErrorHandlerAccumulatorStruct> &GetErrors() const
90 {
91 return errors;
92 }
93
95 void ReplayErrors();
96
97 private:
98 std::mutex mutex{};
99 std::vector<CPLErrorHandlerAccumulatorStruct> errors{};
100
101 static void CPL_STDCALL Accumulator(CPLErr eErr, CPLErrorNum no,
102 const char *msg);
103};
104
105#endif
106
107#endif // CPL_ERROR_INTERNAL_H_INCLUDED
CPL error handling services.
#define CPLE_None
No error.
Definition cpl_error.h:83
CPLErr
Error category.
Definition cpl_error.h:37
int CPLErrorNum
Error number.
Definition cpl_error.h:80
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:870
Various convenience functions for working with strings and string lists.