itom  4.1.0
retVal.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet 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 fuer 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 #ifndef RETVAL_H
29 #define RETVAL_H
30 
31 #ifdef __APPLE__
32 extern "C++" {
33 #endif
34 
35 /* includes */
36 #include "commonGlobal.h"
37 #include "typeDefs.h"
38 #include "byteArray.h"
39 
40 #include <stdarg.h>
41 
42 namespace ito
43 {
44 
45 //----------------------------------------------------------------------------------------------------------------------------------
54 class ITOMCOMMON_EXPORT RetVal
55 {
56  private:
58  int m_retCode;
61  public:
63  inline RetVal() : m_retValue(ito::retOk), m_retCode(0) {}
64 
66  RetVal(tRetValue retValue) : m_retValue(retValue), m_retCode(0) {}
67 
69  RetVal(int retValue) : m_retValue((tRetValue)retValue), m_retCode(0) {}
70 
71  //RetVal(tRetValue retValue, int retCode, char *pRetMessage)
79  RetVal(ito::tRetValue retValue, int retCode, const char *pRetMessage);
80 
82  inline ~RetVal() {}
83 
84  //RetVal & operator = (const RetVal &rhs);
88  RetVal &operator=(const RetVal &rhs);
89 
90 
91  //----------------------------------------------------------------------------------------------------------------------------------
97  RetVal & operator += (const RetVal &rhs);
98 
99  //----------------------------------------------------------------------------------------------------------------------------------
104  RetVal operator + (const RetVal &rhs)
105  {
106  return (*this += rhs);
107  }
108 
109  //----------------------------------------------------------------------------------------------------------------------------------
113  inline char operator == (const RetVal &rhs) //Todo: make this method const
114  {
115  return m_retValue == rhs.m_retValue;
116  }
117 
118  //----------------------------------------------------------------------------------------------------------------------------------
122  inline char operator != (const RetVal &rhs) //Todo: make this method const
123  {
124  return !(m_retValue == rhs.m_retValue);
125  }
126 
127  //----------------------------------------------------------------------------------------------------------------------------------
131  inline char operator == (const tRetValue rhs) //Todo: make this method const
132  {
133  return m_retValue == rhs;
134  }
135 
136  //----------------------------------------------------------------------------------------------------------------------------------
140  inline char operator != (const tRetValue rhs) //Todo: make this method const
141  {
142  return !(m_retValue == rhs);
143  }
144 
145  //----------------------------------------------------------------------------------------------------------------------------------
146  void appendRetMessage(const char *addRetMessage);
147 
148  //----------------------------------------------------------------------------------------------------------------------------------
149  inline int containsWarning() const { return (m_retValue & retWarning); }
150  inline int containsError() const { return (m_retValue & retError); }
151  inline int containsWarningOrError() const { return (m_retValue & (retError | retWarning)); }
153  inline bool hasErrorMessage() const { return m_retMessage.size() > 0; }
155  inline int errorCode() const { return m_retCode; }
157  inline const char *errorMessage() const { return m_retMessage.data(); }
159  //----------------------------------------------------------------------------------------------------------------------------------
161 
168  static RetVal format(ito::tRetValue retValue, int retCode, const char *pRetMessage, ...);
169 
170 };
171 
172 
173 } //end namespace ito
174 
175 #ifdef __APPLE__
176 }
177 #endif
178 
179 #endif
Definition: typeDefs.h:60
Class for managing status values (like errors or warning)
Definition: retVal.h:54
int size() const
Definition: byteArray.h:125
const char * errorMessage() const
Definition: retVal.h:157
bool hasErrorMessage() const
Definition: retVal.h:153
int containsWarning() const
Definition: retVal.h:149
This is a Qt-free class for byte arrays (strings) without specific encoding information.
Definition: byteArray.h:64
Definition: typeDefs.h:58
Definition: typeDefs.h:59
ByteArray m_retMessage
Definition: retVal.h:59
Definition: apiFunctionsGraph.cpp:39
tRetValue m_retValue
Definition: retVal.h:57
bool operator==(const ByteArray &a1, const char *a2)
comparison operator that returns true if the content of a1 is equal to the given zero-terminated stri...
Definition: byteArray.h:185
int containsWarningOrError() const
Definition: retVal.h:151
RetVal(int retValue)
default constructor that creates a RetVal with the status given by retValue, code 0 and no message...
Definition: retVal.h:69
int containsError() const
Definition: retVal.h:150
tRetValue
Definition: typeDefs.h:56
int m_retCode
Definition: retVal.h:58
RetVal()
default constructor that creates a RetVal with status ito::retOk, code 0 and no message.
Definition: retVal.h:63
bool operator!=(const ByteArray &a1, const char *a2)
comparison operator that returns true if the content of a1 is not equal to the given zero-terminated ...
Definition: byteArray.h:197
~RetVal()
destructor
Definition: retVal.h:82
RetVal(tRetValue retValue)
default constructor that creates a RetVal with the status given by retValue, code 0 and no message...
Definition: retVal.h:66
const char * data() const
return the pointer to the internal character array. If it is empty, the returned pointer still points...
Definition: byteArray.h:131
int errorCode() const
Definition: retVal.h:155