File: commonutils.h

package info (click to toggle)
gdal 3.6.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 89,664 kB
  • sloc: cpp: 1,136,033; ansic: 197,355; python: 35,910; java: 5,511; xml: 4,011; sh: 3,950; cs: 2,443; yacc: 1,047; makefile: 288
file content (102 lines) | stat: -rw-r--r-- 3,681 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/******************************************************************************
 * $Id$
 *
 * Project:  GDAL Utilities
 * Purpose:  Common utility routines
 * Author:   Even Rouault, <even dot rouault at spatialys.com>
 *
 ******************************************************************************
 * Copyright (c) 2011-2012, Even Rouault <even dot rouault at spatialys.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 ****************************************************************************/

#ifndef COMMONUTILS_H_INCLUDED
#define COMMONUTILS_H_INCLUDED

#include "cpl_port.h"

#ifdef __cplusplus

#if defined(WIN32) && (defined(_MSC_VER) || defined(SUPPORTS_WMAIN))

#include <wchar.h>
#include <stdlib.h>
#include "cpl_conv.h"
#include "cpl_string.h"

class ARGVDestroyer
{
    char **m_papszList = nullptr;
    ARGVDestroyer(const ARGVDestroyer &) = delete;
    ARGVDestroyer &operator=(const ARGVDestroyer &) = delete;

  public:
    explicit ARGVDestroyer(char **papszList) : m_papszList(papszList)
    {
    }
    ~ARGVDestroyer()
    {
        CSLDestroy(m_papszList);
    }
};

extern "C" int wmain(int argc, wchar_t **argv_w, wchar_t ** /* envp */);

#define MAIN_START(argc, argv)                                                 \
    extern "C" int wmain(int argc, wchar_t **argv_w, wchar_t ** /* envp */)    \
    {                                                                          \
        char **argv =                                                          \
            static_cast<char **>(CPLCalloc(argc + 1, sizeof(char *)));         \
        for (int i = 0; i < argc; i++)                                         \
        {                                                                      \
            argv[i] =                                                          \
                CPLRecodeFromWChar(argv_w[i], CPL_ENC_UCS2, CPL_ENC_UTF8);     \
        }                                                                      \
        ARGVDestroyer argvDestroyer(argv);

#define MAIN_END }

#else  // defined(WIN32)

#define MAIN_START(argc, argv) int main(int argc, char **argv)

#define MAIN_END

#endif  // defined(WIN32)
#endif  // defined(__cplusplus)

CPL_C_START

void CPL_DLL EarlySetConfigOptions(int argc, char **argv);

CPL_C_END

#ifdef __cplusplus

#include "cpl_string.h"
#include <vector>

std::vector<CPLString> CPL_DLL GetOutputDriversFor(const char *pszDestFilename,
                                                   int nFlagRasterVector);
CPLString CPL_DLL GetOutputDriverForRaster(const char *pszDestFilename);

#endif /* __cplusplus */

#endif /* COMMONUTILS_H_INCLUDED */