summaryrefslogtreecommitdiff
path: root/include/vcl/errcode.hxx
blob: 1ea3b304e8c94dfcc1a6bb70a02ece32ba9d3638 (plain)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */

#ifndef INCLUDED_VCL_ERRCODE_HXX
#define INCLUDED_VCL_ERRCODE_HXX

#ifndef __RSC
#include <rtl/ustring.hxx>
#include <tools/solar.h>
#include <tools/toolsdllapi.h>
#include <ostream>
#endif


/*

01234567012345670123456701234567
||   ||          |||   ||      |
Warning           ||   ||      |
 |   ||           ||   ||      |
 Dynamic          ||   ||      |
      |           ||   ||      |
      Subsystemarea|   ||      |
                   |   ||      |
                   |   ||      |
                   |   ||      |
                   Class|      |
                        |      |
                        |      |
                        |      |
                        Code
*/

#define ERRCODE_ERROR_MASK               0x3fffffffUL
#define ERRCODE_WARNING_MASK             0x80000000UL
#define ERRCODE_RES_MASK                 0x7fff

#define ERRCODE_CLASS_SHIFT              8
#define ERRCODE_AREA_SHIFT               13
#define ERRCODE_DYNAMIC_SHIFT            26

#define ERRCODE_CLASS_MASK               (31UL << ERRCODE_CLASS_SHIFT)

#define ERRCODE_DYNAMIC_START            ( 1UL << ERRCODE_DYNAMIC_SHIFT)
#define ERRCODE_DYNAMIC_COUNT            31UL
#define ERRCODE_DYNAMIC_MASK             (31UL << ERRCODE_DYNAMIC_SHIFT)

/** we get included in contexts that don't have access to config_typesizes.h or C++11 */
#ifndef __RSC

class ErrCode final
{
public:
    explicit constexpr ErrCode(sal_uInt32 value) : m_value(value) {}
    constexpr ErrCode() : m_value(0) {}

    explicit operator sal_uInt32() const { return m_value; }
    explicit operator bool() const { return m_value != 0; }

    bool operator<(ErrCode const & other) const { return m_value < other.m_value; }
    bool operator<=(ErrCode const & other) const { return m_value <= other.m_value; }
    bool operator>(ErrCode const & other) const { return m_value > other.m_value; }
    bool operator>=(ErrCode const & other) const { return m_value >= other.m_value; }
    bool operator==(ErrCode const & other) const { return m_value == other.m_value; }
    bool operator!=(ErrCode const & other) const { return m_value != other.m_value; }

    /** convert to ERRCODE_NONE if it's a warning, else return the error */
    ErrCode IgnoreWarning() const {
        return (m_value & ERRCODE_WARNING_MASK)
              ? ErrCode(0UL)
              : ErrCode(static_cast<sal_uInt32>(m_value & ERRCODE_ERROR_MASK));
    }

    bool IsWarning() const {
        return m_value & ERRCODE_WARNING_MASK;
    }

    ErrCode MakeWarning() const {
        return ErrCode(m_value & ERRCODE_WARNING_MASK);
    }

    bool IsError() {
        return m_value && !IsWarning();
    }

    bool IsDynamic() const {
        return m_value & ERRCODE_DYNAMIC_MASK;
    }

    sal_uInt32 GetDynamic() const {
        return (m_value & ERRCODE_DYNAMIC_MASK) >> ERRCODE_DYNAMIC_SHIFT;
    }

    ErrCode StripDynamic() const {
        return ErrCode(m_value & ~ERRCODE_DYNAMIC_MASK);
    }

    sal_uInt16 GetRest() const {
        return m_value & ERRCODE_RES_MASK;
    }

    sal_uInt32 GetClass() const {
        return m_value & ERRCODE_CLASS_MASK;
    }

    OUString toHexString() const {
        return "0x" + OUString::number(m_value, 16);
    }

    bool anyOf(ErrCode v) const {
      return *this == v;
    }

    template<typename... Args>
    bool anyOf(ErrCode first, Args... args) const {
      return *this == first || anyOf(args...);
    }
private:
    sal_uInt32 m_value;
};

inline std::ostream& operator<<(std::ostream& os, const ErrCode& err)
{
    os << sal_uInt32(err); return os;
}

#else
#define ErrCode(X) (X)
#endif

#define ERRCODE_AREA_TOOLS               (0   << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_SV                  (1   << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_SFX                 (2   << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_INET                (3   << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_IO                  ERRCODE_AREA_TOOLS
#define ERRCODE_AREA_VCL                 (4   << ERRCODE_AREA_SHIFT)

#define ERRCODE_AREA_LIB1                (8   << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_SVX                 ERRCODE_AREA_LIB1
#define ERRCODE_AREA_SVX_END             (ERRCODE_AREA_SO-1)
#define ERRCODE_AREA_SO                  (9   << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_SO_END              (ERRCODE_AREA_SBX-1)
#define ERRCODE_AREA_SBX                 (10   << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_SBX_END             ((11  << ERRCODE_AREA_SHIFT) - 1)
#define ERRCODE_AREA_DB                  (11   << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_DB_END              ((12  << ERRCODE_AREA_SHIFT) - 1)
#define ERRCODE_AREA_JAVA                (12  << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_JAVA_END            ((13  << ERRCODE_AREA_SHIFT) - 1)
#define ERRCODE_AREA_UUI                 (13  << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_UUI_END             ((14  << ERRCODE_AREA_SHIFT) - 1)
#define ERRCODE_AREA_LIB2                (14  << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_LIB2_END            ((15  << ERRCODE_AREA_SHIFT) - 1)
#define ERRCODE_AREA_CHAOS               (15  << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_CHAOS_END           ((16  << ERRCODE_AREA_SHIFT) - 1)

#define ERRCODE_AREA_APP1                (32 << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_APP2                (40 << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_APP3                (48 << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_APP4                (56 << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_APP5                (64 << ERRCODE_AREA_SHIFT)
#define ERRCODE_AREA_APP6                (72 << ERRCODE_AREA_SHIFT)

#define ERRCODE_AREA_SC                  ERRCODE_AREA_APP1
#define ERRCODE_AREA_SC_END              (ERRCODE_AREA_APP2-1)

#define ERRCODE_AREA_SD                  ERRCODE_AREA_APP2
#define ERRCODE_AREA_SD_END              (ERRCODE_AREA_APP3-1)

#define ERRCODE_AREA_SW                  ERRCODE_AREA_APP4
#define ERRCODE_AREA_SW_END              (ERRCODE_AREA_APP5-1)

#define ERRCODE_AREA_OFA_END             (ERRCODE_AREA_APP6-1)

#define ERRCODE_CLASS_NONE               ( 0  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_ABORT              ( 1  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_GENERAL            ( 2  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_NOTEXISTS          ( 3  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_ALREADYEXISTS      ( 4  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_ACCESS             ( 5  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_PATH               ( 6  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_LOCKING            ( 7  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_PARAMETER          ( 8  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_SPACE              ( 9  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_NOTSUPPORTED       (10  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_READ               (11  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_WRITE              (12  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_UNKNOWN            (13  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_VERSION            (14  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_FORMAT             (15  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_CREATE             (16  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_IMPORT             (17  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_EXPORT             (18  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_SO                 (20  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_SBX                (21  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_RUNTIME            (22  << ERRCODE_CLASS_SHIFT)
#define ERRCODE_CLASS_COMPILER           (23  << ERRCODE_CLASS_SHIFT)

#define ERRCODE_NONE                     ErrCode(0UL)

#define ERRCODE_IO_MISPLACEDCHAR         ErrCode(1UL  | ERRCODE_CLASS_PARAMETER | ERRCODE_AREA_IO)
#define ERRCODE_IO_NOTEXISTS             ErrCode(2UL  | ERRCODE_CLASS_NOTEXISTS | ERRCODE_AREA_IO)
#define ERRCODE_IO_ALREADYEXISTS         ErrCode(3UL  | ERRCODE_CLASS_ALREADYEXISTS | ERRCODE_AREA_IO)
#define ERRCODE_IO_NOTADIRECTORY         ErrCode(4UL  | ERRCODE_CLASS_PARAMETER | ERRCODE_AREA_IO)
#define ERRCODE_IO_NOTAFILE              ErrCode(5UL  | ERRCODE_CLASS_PARAMETER | ERRCODE_AREA_IO)
#define ERRCODE_IO_INVALIDDEVICE         ErrCode(6UL  | ERRCODE_CLASS_PATH | ERRCODE_AREA_IO)
#define ERRCODE_IO_ACCESSDENIED          ErrCode(7UL  | ERRCODE_CLASS_ACCESS | ERRCODE_AREA_IO)
#define ERRCODE_IO_LOCKVIOLATION         ErrCode(8UL  | ERRCODE_CLASS_LOCKING | ERRCODE_AREA_IO)
#define ERRCODE_IO_OUTOFSPACE            ErrCode(9UL  | ERRCODE_CLASS_SPACE | ERRCODE_AREA_IO)
#define ERRCODE_IO_ISWILDCARD            ErrCode(11UL | ERRCODE_CLASS_PARAMETER | ERRCODE_AREA_IO)
#define ERRCODE_IO_NOTSUPPORTED          ErrCode(12UL | ERRCODE_CLASS_NOTSUPPORTED | ERRCODE_AREA_IO)
#define ERRCODE_IO_GENERAL               ErrCode(13UL | ERRCODE_CLASS_GENERAL | ERRCODE_AREA_IO)
#define ERRCODE_IO_TOOMANYOPENFILES      ErrCode(14UL | ERRCODE_CLASS_SPACE | ERRCODE_AREA_IO)
#define ERRCODE_IO_CANTREAD              ErrCode(15UL | ERRCODE_CLASS_READ | ERRCODE_AREA_IO)
#define ERRCODE_IO_CANTWRITE             ErrCode(16UL | ERRCODE_CLASS_WRITE | ERRCODE_AREA_IO)
#define ERRCODE_IO_OUTOFMEMORY           ErrCode(17UL | ERRCODE_CLASS_SPACE | ERRCODE_AREA_IO)
#define ERRCODE_IO_CANTSEEK              ErrCode(18UL | ERRCODE_CLASS_GENERAL | ERRCODE_AREA_IO)
#define ERRCODE_IO_CANTTELL              ErrCode(19UL | ERRCODE_CLASS_GENERAL | ERRCODE_AREA_IO)
#define ERRCODE_IO_WRONGVERSION          ErrCode(20UL | ERRCODE_CLASS_VERSION | ERRCODE_AREA_IO)
#define ERRCODE_IO_WRONGFORMAT           ErrCode(21UL | ERRCODE_CLASS_FORMAT | ERRCODE_AREA_IO)
#define ERRCODE_IO_INVALIDCHAR           ErrCode(22UL | ERRCODE_CLASS_PARAMETER | ERRCODE_AREA_IO)
#define ERRCODE_IO_UNKNOWN               ErrCode(23UL | ERRCODE_CLASS_UNKNOWN | ERRCODE_AREA_IO)
#define ERRCODE_IO_INVALIDACCESS         ErrCode(24UL | ERRCODE_CLASS_ACCESS | ERRCODE_AREA_IO)
#define ERRCODE_IO_CANTCREATE            ErrCode(25UL | ERRCODE_CLASS_CREATE | ERRCODE_AREA_IO)
#define ERRCODE_IO_INVALIDPARAMETER      ErrCode(26UL | ERRCODE_CLASS_PARAMETER | ERRCODE_AREA_IO)
#define ERRCODE_IO_ABORT                 ErrCode(27UL | ERRCODE_CLASS_ABORT | ERRCODE_AREA_IO)
#define ERRCODE_IO_NOTEXISTSPATH         ErrCode(28UL | ERRCODE_CLASS_NOTEXISTS | ERRCODE_AREA_IO)
#define ERRCODE_IO_PENDING               ErrCode(29UL | ERRCODE_CLASS_NOTEXISTS | ERRCODE_AREA_IO)
#define ERRCODE_IO_RECURSIVE             ErrCode(30UL | ERRCODE_CLASS_PARAMETER | ERRCODE_AREA_IO)
#define ERRCODE_IO_NAMETOOLONG           ErrCode(31UL | ERRCODE_CLASS_PARAMETER | ERRCODE_AREA_IO)
#define ERRCODE_IO_INVALIDLENGTH         ErrCode(32UL | ERRCODE_CLASS_PARAMETER | ERRCODE_AREA_IO)
#define ERRCODE_IO_CURRENTDIR            ErrCode(33UL | ERRCODE_CLASS_PARAMETER | ERRCODE_AREA_IO)
#define ERRCODE_IO_NOTSAMEDEVICE         ErrCode(34UL | ERRCODE_CLASS_PARAMETER | ERRCODE_AREA_IO)
#define ERRCODE_IO_DEVICENOTREADY        ErrCode(35UL | ERRCODE_CLASS_READ | ERRCODE_AREA_IO)
#define ERRCODE_IO_BADCRC                ErrCode(36UL | ERRCODE_CLASS_READ | ERRCODE_AREA_IO)
#define ERRCODE_IO_WRITEPROTECTED        ErrCode(37UL | ERRCODE_CLASS_ACCESS | ERRCODE_AREA_IO)
#define ERRCODE_IO_BROKENPACKAGE         ErrCode(38UL | ERRCODE_CLASS_FORMAT | ERRCODE_AREA_IO)
#define ERRCODE_IO_NOTSTORABLEINBINARYFORMAT ErrCode(39UL | ERRCODE_CLASS_FORMAT | ERRCODE_AREA_IO)

// StreamErrorCodes

#define SVSTREAM_GENERALERROR            ERRCODE_IO_GENERAL
#define SVSTREAM_FILE_NOT_FOUND          ERRCODE_IO_NOTEXISTS
#define SVSTREAM_PATH_NOT_FOUND          ERRCODE_IO_NOTEXISTSPATH
#define SVSTREAM_TOO_MANY_OPEN_FILES     ERRCODE_IO_TOOMANYOPENFILES
#define SVSTREAM_ACCESS_DENIED           ERRCODE_IO_ACCESSDENIED
#define SVSTREAM_SHARING_VIOLATION       ERRCODE_IO_LOCKVIOLATION
#define SVSTREAM_LOCKING_VIOLATION       ERRCODE_IO_LOCKVIOLATION
#define SVSTREAM_SHARE_BUFF_EXCEEDED     ERRCODE_IO_LOCKVIOLATION

#define SVSTREAM_INVALID_ACCESS          ERRCODE_IO_INVALIDACCESS
#define SVSTREAM_INVALID_HANDLE          ERRCODE_IO_GENERAL
#define SVSTREAM_CANNOT_MAKE             ERRCODE_IO_CANTCREATE
#define SVSTREAM_INVALID_PARAMETER       ERRCODE_IO_INVALIDPARAMETER

#define SVSTREAM_READ_ERROR              ERRCODE_IO_CANTREAD
#define SVSTREAM_WRITE_ERROR             ERRCODE_IO_CANTWRITE
#define SVSTREAM_SEEK_ERROR              ERRCODE_IO_CANTSEEK

#define SVSTREAM_OUTOFMEMORY             ERRCODE_IO_OUTOFMEMORY

#define SVSTREAM_FILEFORMAT_ERROR        ERRCODE_IO_WRONGFORMAT
#define SVSTREAM_WRONGVERSION            ERRCODE_IO_WRONGVERSION

#define SVSTREAM_DISK_FULL               ERRCODE_IO_OUTOFSPACE

// For the EditEngine:
#define SVSTREAM_ERRBASE_USER            ERRCODE_AREA_LIB1

#define PRINTER_ABORT                    ERRCODE_IO_ABORT
#define PRINTER_GENERALERROR             ERRCODE_IO_GENERAL

#define ERRCODE_ABORT                    ERRCODE_IO_ABORT

#define ERRCODE_INET_NAME_RESOLVE        ErrCode(ERRCODE_AREA_INET | ERRCODE_CLASS_READ | 1)
#define ERRCODE_INET_CONNECT             ErrCode(ERRCODE_AREA_INET | ERRCODE_CLASS_READ | 2)
#define ERRCODE_INET_READ                ErrCode(ERRCODE_AREA_INET | ERRCODE_CLASS_READ | 3)
#define ERRCODE_INET_WRITE               ErrCode(ERRCODE_AREA_INET | ERRCODE_CLASS_WRITE| 4)
#define ERRCODE_INET_GENERAL             ErrCode(ERRCODE_AREA_INET | ERRCODE_CLASS_WRITE| 5)
#define ERRCODE_INET_OFFLINE             ErrCode(ERRCODE_AREA_INET | ERRCODE_CLASS_READ | 6)

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */