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
30 class 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
62 class CPL_DLL CPLErrorAccumulator
63{
64 public:
66 CPLErrorAccumulator() = default;
67
68 struct CPL_DLL Context
69 {
70 ~Context();
71 };
72
75 Context InstallForCurrentScope() CPL_WARN_UNUSED_RESULT;
76
78 const std::vector<CPLErrorHandlerAccumulatorStruct> &GetErrors() const
79 {
80 return errors;
81 }
82
84 void ReplayErrors();
85
86 private:
87 std::mutex mutex{};
88 std::vector<CPLErrorHandlerAccumulatorStruct> errors{};
89
90 static void CPL_STDCALL Accumulator(CPLErr eErr, CPLErrorNum no,
91 const char *msg);
92};
93
94#endif
95
96#endif // CPL_ERROR_INTERNAL_H_INCLUDED
CPLString
Convenient string class based on std::string.
Definition cpl_string.h:320
cpl_error.h
CPL error handling services.
CPLE_None
#define CPLE_None
No error.
Definition cpl_error.h:83
CPLErr
CPLErr
Error category.
Definition cpl_error.h:37
CPLErrorNum
int CPLErrorNum
Error number.
Definition cpl_error.h:80
CPL_WARN_UNUSED_RESULT
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:870
cpl_string.h
Various convenience functions for working with strings and string lists.