itom
Loading...
Searching...
No Matches
retVal.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom and its software development toolkit (SDK).
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 In addition, as a special exception, the Institut für Technische
15 Optik (ITO) gives you certain additional rights.
16 These rights are described in the ITO LGPL Exception version 1.0,
17 which can be found in the file LGPL_EXCEPTION.txt in this package.
18
19 itom is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22 General Public Licence for more details.
23
24 You should have received a copy of the GNU Library General Public License
25 along with itom. If not, see <http://www.gnu.org/licenses/>.
26*********************************************************************** */
27
28#pragma once
29
30#ifdef __APPLE__
31extern "C++"
32{
33#endif
34
35/* includes */
36#include "byteArray.h"
37#include "commonGlobal.h"
38#include "typeDefs.h"
39
40#include <stdarg.h>
41
42namespace ito {
43
44//----------------------------------------------------------------------------------------------------------------------------------
53class ITOMCOMMON_EXPORT RetVal
54{
55private:
58
61
63 ByteArray m_retMessage;
64
65public:
67 inline RetVal() : m_retValue(ito::retOk), m_retCode(0)
68 {
69 }
70
73 RetVal(tRetValue retValue) : m_retValue(retValue), m_retCode(0)
74 {
75 }
76
79 RetVal(int retValue) : m_retValue((tRetValue)retValue), m_retCode(0)
80 {
81 }
82
83 // RetVal(tRetValue retValue, int retCode, char *pRetMessage)
91 RetVal(ito::tRetValue retValue, int retCode, const char* pRetMessage);
92
94 inline ~RetVal()
95 {
96 }
97
98 // RetVal & operator = (const RetVal &rhs);
103 RetVal& operator=(const RetVal& rhs);
104
110 RetVal& operator+=(const RetVal& rhs);
111
117 {
118 return (*this += rhs);
119 }
120
125 inline char operator==(const RetVal& rhs) const
126 {
127 return m_retValue == rhs.m_retValue;
128 }
129
134 inline char operator!=(const RetVal& rhs) const
135 {
136 return !(m_retValue == rhs.m_retValue);
137 }
138
143 inline char operator==(const tRetValue rhs) const
144 {
145 return m_retValue == rhs;
146 }
147
152 inline char operator!=(const tRetValue rhs) const
153 {
154 return !(m_retValue == rhs);
155 }
156
157 void appendRetMessage(const char* addRetMessage);
158
160 inline int containsWarning() const
161 {
162 return (m_retValue & retWarning);
163 }
164
166 inline int containsError() const
167 {
168 return (m_retValue & retError);
169 }
170
172 inline int containsWarningOrError() const
173 {
174 return (m_retValue & (retError | retWarning));
175 }
176
178 inline bool hasErrorMessage() const
179 {
180 return m_retMessage.size() > 0;
181 }
182
184 inline int errorCode() const
185 {
186 return m_retCode;
187 }
188
191 inline const char* errorMessage() const
192 {
193 return m_retMessage.data();
194 }
195
198
205 static RetVal format(ito::tRetValue retValue, int retCode, const char* pRetMessage, ...);
206};
207
208
209} // end namespace ito
210
211#ifdef __APPLE__
212}
213#endif
This is a Qt-free class for byte arrays (strings) without specific encoding information.
Definition byteArray.h:65
int size() const
Definition byteArray.h:138
const char * data() const
return the pointer to the internal character array. If it is empty, the returned pointer still points...
Definition byteArray.h:144
Class for managing status values (like errors or warning)
Definition retVal.h:54
RetVal operator+(const RetVal &rhs)
Definition retVal.h:116
char operator==(const tRetValue rhs) const
Definition retVal.h:143
int m_retCode
Definition retVal.h:60
RetVal(int retValue)
Definition retVal.h:79
int containsError() const
Definition retVal.h:166
char operator==(const RetVal &rhs) const
Definition retVal.h:125
bool hasErrorMessage() const
Definition retVal.h:178
char operator!=(const RetVal &rhs) const
Definition retVal.h:134
tRetValue m_retValue
Definition retVal.h:57
int errorCode() const
Definition retVal.h:184
RetVal()
default constructor that creates a RetVal with status ito::retOk, code 0 and no message.
Definition retVal.h:67
int containsWarning() const
Definition retVal.h:160
~RetVal()
destructor
Definition retVal.h:94
int containsWarningOrError() const
Definition retVal.h:172
RetVal(tRetValue retValue)
Definition retVal.h:73
char operator!=(const tRetValue rhs) const
Definition retVal.h:152
Definition apiFunctionsGraph.cpp:40
tRetValue
Definition typeDefs.h:57
@ retError
Definition typeDefs.h:60
@ retOk
Definition typeDefs.h:58
@ retWarning
Definition typeDefs.h:59