GDAL
commonutils.h
1/******************************************************************************
2 *
3 * Project: GDAL Utilities
4 * Purpose: Common utility routines
5 * Author: Even Rouault, <even dot rouault at spatialys.com>
6 *
7 ******************************************************************************
8 * Copyright (c) 2011-2012, Even Rouault <even dot rouault at spatialys.com>
9 *
10 * SPDX-License-Identifier: MIT
11 ****************************************************************************/
12
13#ifndef COMMONUTILS_H_INCLUDED
14#define COMMONUTILS_H_INCLUDED
15
16#include "cpl_port.h"
17
18#ifdef __cplusplus
19
20#if defined(_WIN32) && (defined(_MSC_VER) || defined(SUPPORTS_WMAIN))
21
22#include <wchar.h>
23#include <stdlib.h>
24#include "cpl_conv.h"
25#include "cpl_string.h"
26
27class ARGVDestroyer
28{
29 char **m_papszList = nullptr;
30 ARGVDestroyer(const ARGVDestroyer &) = delete;
31 ARGVDestroyer &operator=(const ARGVDestroyer &) = delete;
32
33 public:
34 explicit ARGVDestroyer(char **papszList) : m_papszList(papszList)
35 {
36 }
37
38 ~ARGVDestroyer()
39 {
40 CSLDestroy(m_papszList);
41 }
42};
43
44extern "C" int wmain(int argc, wchar_t **argv_w, wchar_t ** /* envp */);
45
46#define MAIN_START(argc, argv) \
47 extern "C" int wmain(int argc, wchar_t **argv_w, wchar_t ** /* envp */) \
48 { \
49 char **argv = \
50 static_cast<char **>(CPLCalloc(argc + 1, sizeof(char *))); \
51 for (int i = 0; i < argc; i++) \
52 { \
53 argv[i] = \
54 CPLRecodeFromWChar(argv_w[i], CPL_ENC_UCS2, CPL_ENC_UTF8); \
55 } \
56 ARGVDestroyer argvDestroyer(argv); \
57 try \
58 {
59
60#else // defined(_WIN32)
61
62#define MAIN_START(argc, argv) \
63 int main(int argc, char **argv) \
64 { \
65 try \
66 {
67
68#endif // defined(_WIN32)
69
70#define MAIN_END \
71 } \
72 catch (const std::exception &e) \
73 { \
74 fprintf(stderr, "Unexpected exception: %s", e.what()); \
75 return -1; \
76 } \
77 }
78
79#endif // defined(__cplusplus)
80
82
83void CPL_DLL EarlySetConfigOptions(int argc, char **argv);
84
86
87#ifdef __cplusplus
88
89#include "cpl_string.h"
90#include <vector>
91
92std::vector<std::string> CPL_DLL
93GetOutputDriversFor(const char *pszDestFilename, int nFlagRasterVector);
94CPLString CPL_DLL GetOutputDriverForRaster(const char *pszDestFilename);
95void GDALRemoveBOM(GByte *pabyData);
96
97int ArgIsNumeric(const char *pszArg);
98
99bool GDALPatternMatch(const char *input, const char *pattern);
100
101// those values shouldn't be changed, because overview levels >= 0 are meant
102// to be overview indices, and ovr_level < OVR_LEVEL_AUTO mean overview level
103// automatically selected minus (OVR_LEVEL_AUTO - ovr_level)
104constexpr int OVR_LEVEL_AUTO = -2;
105constexpr int OVR_LEVEL_NONE = -1;
106
107#endif /* __cplusplus */
108
109#endif /* COMMONUTILS_H_INCLUDED */
Convenient string class based on std::string.
Definition cpl_string.h:320
Various convenience functions for CPL.
Core portability definitions for CPL.
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:289
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:285
unsigned char GByte
Unsigned byte type.
Definition cpl_port.h:175
Various convenience functions for working with strings and string lists.