LibreOffice Module comphelper (master) 1
errcode.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19#pragma once
20
21#include <rtl/ustring.hxx>
23#include <ostream>
24
25/*
26
2701234567012345670123456701234567
28|| || || || |
29Warning || || |
30 | || || || |
31 Dynamic || || |
32 | || || |
33 Subsystemarea| || |
34 | || |
35 | || |
36 | || |
37 Class| |
38 | |
39 | |
40 | |
41 Code
42*/
43
44#define ERRCODE_ERROR_MASK 0x3fffffffUL
45#define ERRCODE_WARNING_MASK 0x80000000UL
46
47#define ERRCODE_CLASS_SHIFT 8
48#define ERRCODE_AREA_SHIFT 13
49#define ERRCODE_DYNAMIC_SHIFT 26
50
51#define ERRCODE_CLASS_MASK (31UL << ERRCODE_CLASS_SHIFT)
52
53#define ERRCODE_DYNAMIC_COUNT 31UL
54#define ERRCODE_DYNAMIC_MASK (31UL << ERRCODE_DYNAMIC_SHIFT)
55
56enum class ErrCodeArea;
57enum class ErrCodeClass;
58
59enum class WarningFlag { Yes };
60
62{
63public:
64 explicit constexpr ErrCode(WarningFlag, ErrCodeArea nArea, ErrCodeClass nClass, sal_uInt16 nCode)
65 : m_value(ERRCODE_WARNING_MASK | (sal_uInt32(nArea) << ERRCODE_AREA_SHIFT) | (sal_uInt32(nClass) << ERRCODE_CLASS_SHIFT) | nCode)
66 {
67 assert(nCode <= 0xff && "code out of range");
68 }
69 explicit constexpr ErrCode(ErrCodeArea nArea, ErrCodeClass nClass, sal_uInt16 nCode)
70 : m_value((sal_uInt32(nArea) << ERRCODE_AREA_SHIFT) | (sal_uInt32(nClass) << ERRCODE_CLASS_SHIFT) | nCode)
71 {
72 assert(nCode <= 0xff && "code out of range");
73 }
74 explicit constexpr ErrCode(ErrCodeArea nArea, sal_uInt16 nClassAndCode)
75 : m_value((sal_uInt32(nArea) << ERRCODE_AREA_SHIFT) | nClassAndCode) {}
76 explicit constexpr ErrCode(sal_uInt32 nValue)
77 : m_value(nValue) {}
78 constexpr ErrCode()
79 : m_value(0) {}
80
81 explicit operator sal_uInt32() const { return m_value; }
82 explicit operator bool() const { return m_value != 0; }
83
84 bool operator<(ErrCode const & other) const { return m_value < other.m_value; }
85 bool operator<=(ErrCode const & other) const { return m_value <= other.m_value; }
86 bool operator>(ErrCode const & other) const { return m_value > other.m_value; }
87 bool operator>=(ErrCode const & other) const { return m_value >= other.m_value; }
88 bool operator==(ErrCode const & other) const { return m_value == other.m_value; }
89 bool operator!=(ErrCode const & other) const { return m_value != other.m_value; }
90
94 ? ErrCode(0)
95 : ErrCode(static_cast<sal_uInt32>(m_value & ERRCODE_ERROR_MASK));
96 }
97
98 bool IsWarning() const {
100 }
101
104 }
105
106 bool IsError() const {
107 return m_value && !IsWarning();
108 }
109
110 bool IsDynamic() const {
112 }
113
114 sal_uInt32 GetDynamic() const {
116 }
117
120 }
121
122 constexpr ErrCode StripWarningAndDynamic() const {
124 }
125
126 constexpr ErrCodeArea GetArea() const {
127 return static_cast<ErrCodeArea>((m_value >> ERRCODE_AREA_SHIFT) & 0x01fff);
128 }
129
130 constexpr ErrCodeClass GetClass() const {
131 return static_cast<ErrCodeClass>((m_value >> ERRCODE_CLASS_SHIFT) & 0x1f);
132 }
133
134 constexpr sal_uInt8 GetCode() const {
135 return static_cast<sal_uInt8>(m_value & 0xff);
136 }
137
138 OUString toHexString() const {
139 return "0x" + OUString::number(m_value, 16);
140 }
141
143 COMPHELPER_DLLPUBLIC OUString toString() const;
144
145 template <typename... Args> bool anyOf(Args... args) const
146 {
147 static_assert(sizeof...(args) > 0);
148 return (... || (*this == args));
149 }
150
151private:
152 sal_uInt32 m_value;
153};
154
155COMPHELPER_DLLPUBLIC std::ostream& operator<<(std::ostream& os, const ErrCode& err);
156
157enum class ErrCodeArea {
158 Io = 0 ,
159 Sfx = 2 ,
160 Inet = 3 ,
161 Vcl = 4 ,
162 Svx = 8 ,
163 So = 9 ,
164 Sbx = 10,
165 Uui = 13,
166 Sc = 32,
167 Sd = 40,
168 Sw = 56,
169};
170
171enum class ErrCodeClass {
172 NONE = 0,
173 Abort = 1,
174 General = 2,
175 NotExists = 3,
176 AlreadyExists = 4,
177 Access = 5,
178 Path = 6,
179 Locking = 7,
180 Parameter = 8,
181 Space = 9,
182 NotSupported = 10,
183 Read = 11,
184 Write = 12,
185 Unknown = 13,
186 Version = 14,
187 Format = 15,
188 Create = 16,
189 Import = 17,
190 Export = 18,
191 So = 20,
192 Sbx = 21,
193 Runtime = 22,
194 Compiler = 23
195};
196
197#define ERRCODE_NONE ErrCode(0)
198
199#define ERRCODE_IO_MISPLACEDCHAR ErrCode( ErrCodeArea::Io, ErrCodeClass::Parameter, 1 )
200#define ERRCODE_IO_NOTEXISTS ErrCode( ErrCodeArea::Io, ErrCodeClass::NotExists, 2 )
201#define ERRCODE_IO_ALREADYEXISTS ErrCode( ErrCodeArea::Io, ErrCodeClass::AlreadyExists, 3 )
202#define ERRCODE_IO_NOTADIRECTORY ErrCode( ErrCodeArea::Io, ErrCodeClass::Parameter, 4 )
203#define ERRCODE_IO_NOTAFILE ErrCode( ErrCodeArea::Io, ErrCodeClass::Parameter, 5 )
204#define ERRCODE_IO_INVALIDDEVICE ErrCode( ErrCodeArea::Io, ErrCodeClass::Path, 6 )
205#define ERRCODE_IO_ACCESSDENIED ErrCode( ErrCodeArea::Io, ErrCodeClass::Access, 7 )
206#define ERRCODE_IO_LOCKVIOLATION ErrCode( ErrCodeArea::Io, ErrCodeClass::Locking, 8 )
207#define ERRCODE_IO_OUTOFSPACE ErrCode( ErrCodeArea::Io, ErrCodeClass::Space, 9 )
208#define ERRCODE_IO_ISWILDCARD ErrCode( ErrCodeArea::Io, ErrCodeClass::Parameter, 11 )
209#define ERRCODE_IO_NOTSUPPORTED ErrCode( ErrCodeArea::Io, ErrCodeClass::NotSupported, 12 )
210#define ERRCODE_IO_GENERAL ErrCode( ErrCodeArea::Io, ErrCodeClass::General, 13 )
211#define ERRCODE_IO_TOOMANYOPENFILES ErrCode( ErrCodeArea::Io, ErrCodeClass::Space, 14 )
212#define ERRCODE_IO_CANTREAD ErrCode( ErrCodeArea::Io, ErrCodeClass::Read, 15 )
213#define ERRCODE_IO_CANTWRITE ErrCode( ErrCodeArea::Io, ErrCodeClass::Write, 16 )
214#define ERRCODE_IO_OUTOFMEMORY ErrCode( ErrCodeArea::Io, ErrCodeClass::Space, 17 )
215#define ERRCODE_IO_CANTSEEK ErrCode( ErrCodeArea::Io, ErrCodeClass::General, 18 )
216#define ERRCODE_IO_CANTTELL ErrCode( ErrCodeArea::Io, ErrCodeClass::General, 19 )
217#define ERRCODE_IO_WRONGVERSION ErrCode( ErrCodeArea::Io, ErrCodeClass::Version, 20 )
218#define ERRCODE_IO_WRONGFORMAT ErrCode( ErrCodeArea::Io, ErrCodeClass::Format, 21 )
219#define ERRCODE_IO_INVALIDCHAR ErrCode( ErrCodeArea::Io, ErrCodeClass::Parameter, 22 )
220#define ERRCODE_IO_UNKNOWN ErrCode( ErrCodeArea::Io, ErrCodeClass::Unknown, 23 )
221#define ERRCODE_IO_INVALIDACCESS ErrCode( ErrCodeArea::Io, ErrCodeClass::Access, 24 )
222#define ERRCODE_IO_CANTCREATE ErrCode( ErrCodeArea::Io, ErrCodeClass::Create, 25 )
223#define ERRCODE_IO_INVALIDPARAMETER ErrCode( ErrCodeArea::Io, ErrCodeClass::Parameter, 26 )
224#define ERRCODE_IO_ABORT ErrCode( ErrCodeArea::Io, ErrCodeClass::Abort, 27 )
225#define ERRCODE_IO_NOTEXISTSPATH ErrCode( ErrCodeArea::Io, ErrCodeClass::NotExists, 28 )
226#define ERRCODE_IO_PENDING ErrCode( ErrCodeArea::Io, ErrCodeClass::NotExists, 29 )
227#define ERRCODE_IO_RECURSIVE ErrCode( ErrCodeArea::Io, ErrCodeClass::Parameter, 30 )
228#define ERRCODE_IO_NAMETOOLONG ErrCode( ErrCodeArea::Io, ErrCodeClass::Parameter, 31 )
229#define ERRCODE_IO_INVALIDLENGTH ErrCode( ErrCodeArea::Io, ErrCodeClass::Parameter, 32 )
230#define ERRCODE_IO_CURRENTDIR ErrCode( ErrCodeArea::Io, ErrCodeClass::Parameter, 33 )
231#define ERRCODE_IO_NOTSAMEDEVICE ErrCode( ErrCodeArea::Io, ErrCodeClass::Parameter, 34 )
232#define ERRCODE_IO_DEVICENOTREADY ErrCode( ErrCodeArea::Io, ErrCodeClass::Read, 35 )
233#define ERRCODE_IO_BADCRC ErrCode( ErrCodeArea::Io, ErrCodeClass::Read, 36 )
234#define ERRCODE_IO_WRITEPROTECTED ErrCode( ErrCodeArea::Io, ErrCodeClass::Access, 37 )
235#define ERRCODE_IO_BROKENPACKAGE ErrCode( ErrCodeArea::Io, ErrCodeClass::Format, 38 )
236#define ERRCODE_IO_NOTSTORABLEINBINARYFORMAT ErrCode( ErrCodeArea::Io, ErrCodeClass::Format, 39 )
237#define ERRCODE_IO_FILTERDISABLED ErrCode( ErrCodeArea::Io, ErrCodeClass::Format, 40 )
238
239// StreamErrorCodes
240
241#define SVSTREAM_GENERALERROR ERRCODE_IO_GENERAL
242#define SVSTREAM_FILE_NOT_FOUND ERRCODE_IO_NOTEXISTS
243#define SVSTREAM_PATH_NOT_FOUND ERRCODE_IO_NOTEXISTSPATH
244#define SVSTREAM_TOO_MANY_OPEN_FILES ERRCODE_IO_TOOMANYOPENFILES
245#define SVSTREAM_ACCESS_DENIED ERRCODE_IO_ACCESSDENIED
246#define SVSTREAM_SHARING_VIOLATION ERRCODE_IO_LOCKVIOLATION
247#define SVSTREAM_LOCKING_VIOLATION ERRCODE_IO_LOCKVIOLATION
248#define SVSTREAM_SHARE_BUFF_EXCEEDED ERRCODE_IO_LOCKVIOLATION
249
250#define SVSTREAM_INVALID_ACCESS ERRCODE_IO_INVALIDACCESS
251#define SVSTREAM_INVALID_HANDLE ERRCODE_IO_GENERAL
252#define SVSTREAM_CANNOT_MAKE ERRCODE_IO_CANTCREATE
253#define SVSTREAM_INVALID_PARAMETER ERRCODE_IO_INVALIDPARAMETER
254
255#define SVSTREAM_READ_ERROR ERRCODE_IO_CANTREAD
256#define SVSTREAM_WRITE_ERROR ERRCODE_IO_CANTWRITE
257#define SVSTREAM_SEEK_ERROR ERRCODE_IO_CANTSEEK
258
259#define SVSTREAM_OUTOFMEMORY ERRCODE_IO_OUTOFMEMORY
260
261#define SVSTREAM_FILEFORMAT_ERROR ERRCODE_IO_WRONGFORMAT
262#define SVSTREAM_WRONGVERSION ERRCODE_IO_WRONGVERSION
263
264#define SVSTREAM_DISK_FULL ERRCODE_IO_OUTOFSPACE
265
266#define PRINTER_ABORT ERRCODE_IO_ABORT
267#define PRINTER_GENERALERROR ERRCODE_IO_GENERAL
268
269#define ERRCODE_ABORT ERRCODE_IO_ABORT
270
271#define ERRCODE_INET_NAME_RESOLVE ErrCode(ErrCodeArea::Inet, ErrCodeClass::Read, 1)
272#define ERRCODE_INET_CONNECT ErrCode(ErrCodeArea::Inet, ErrCodeClass::Read, 2)
273#define ERRCODE_INET_READ ErrCode(ErrCodeArea::Inet, ErrCodeClass::Read, 3)
274#define ERRCODE_INET_WRITE ErrCode(ErrCodeArea::Inet, ErrCodeClass::Write, 4)
275#define ERRCODE_INET_GENERAL ErrCode(ErrCodeArea::Inet, ErrCodeClass::Write, 5)
276#define ERRCODE_INET_OFFLINE ErrCode(ErrCodeArea::Inet, ErrCodeClass::Read, 6)
277
278/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr ErrCode()
Definition: errcode.hxx:78
constexpr sal_uInt8 GetCode() const
Definition: errcode.hxx:134
bool operator<(ErrCode const &other) const
Definition: errcode.hxx:84
ErrCode StripDynamic() const
Definition: errcode.hxx:118
OUString toHexString() const
Definition: errcode.hxx:138
bool IsError() const
Definition: errcode.hxx:106
sal_uInt32 m_value
Definition: errcode.hxx:152
bool IsWarning() const
Definition: errcode.hxx:98
bool IsDynamic() const
Definition: errcode.hxx:110
bool operator==(ErrCode const &other) const
Definition: errcode.hxx:88
constexpr ErrCode(ErrCodeArea nArea, sal_uInt16 nClassAndCode)
Definition: errcode.hxx:74
constexpr ErrCodeArea GetArea() const
Definition: errcode.hxx:126
constexpr ErrCodeClass GetClass() const
Definition: errcode.hxx:130
sal_uInt32 GetDynamic() const
Definition: errcode.hxx:114
constexpr ErrCode(WarningFlag, ErrCodeArea nArea, ErrCodeClass nClass, sal_uInt16 nCode)
Definition: errcode.hxx:64
bool operator<=(ErrCode const &other) const
Definition: errcode.hxx:85
constexpr ErrCode(sal_uInt32 nValue)
Definition: errcode.hxx:76
constexpr ErrCode(ErrCodeArea nArea, ErrCodeClass nClass, sal_uInt16 nCode)
Definition: errcode.hxx:69
ErrCode IgnoreWarning() const
convert to ERRCODE_NONE if it's a warning, else return the error
Definition: errcode.hxx:92
bool anyOf(Args... args) const
Definition: errcode.hxx:145
constexpr ErrCode StripWarningAndDynamic() const
Definition: errcode.hxx:122
bool operator>(ErrCode const &other) const
Definition: errcode.hxx:86
bool operator>=(ErrCode const &other) const
Definition: errcode.hxx:87
bool operator!=(ErrCode const &other) const
Definition: errcode.hxx:89
ErrCode MakeWarning() const
Definition: errcode.hxx:102
#define COMPHELPER_DLLPUBLIC
COMPHELPER_DLLPUBLIC std::ostream & operator<<(std::ostream &os, const ErrCode &err)
Definition: errcode.cxx:153
#define ERRCODE_AREA_SHIFT
Definition: errcode.hxx:48
#define ERRCODE_DYNAMIC_SHIFT
Definition: errcode.hxx:49
WarningFlag
Definition: errcode.hxx:59
ErrCodeClass
Definition: errcode.hxx:171
#define ERRCODE_DYNAMIC_MASK
Definition: errcode.hxx:54
#define ERRCODE_ERROR_MASK
Definition: errcode.hxx:44
#define ERRCODE_WARNING_MASK
Definition: errcode.hxx:45
ErrCodeArea
Definition: errcode.hxx:157
#define ERRCODE_CLASS_SHIFT
Definition: errcode.hxx:47
sal_Int16 nValue
T m_value
Yes
NONE
Unknown
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
args
OUString toString(OptionInfo const *info)
unsigned char sal_uInt8
#define SAL_WARN_UNUSED