QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsoptional.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsoptional.h - QgsOptional
3
4 ---------------------
5 begin : 7.9.2016
6 copyright : (C) 2016 by Matthias Kuhn
8 ***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16#ifndef QGSOPTIONAL_H
17#define QGSOPTIONAL_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21
34template<typename T>
35class CORE_EXPORT QgsOptional
36{
37 public:
38
42 QgsOptional() = default;
43
47 QgsOptional( const T &data )
48 : mEnabled( true )
49 , mData( data )
50 {
51 }
52
56 QgsOptional( const T &data, bool enabled )
57 : mEnabled( enabled )
58 , mData( data )
59 {
60 }
61
69 bool operator== ( const QgsOptional<T> &other ) const
70 {
71 return mEnabled == other.mEnabled && mData == other.mData;
72 }
73
77 explicit operator bool() const SIP_SKIP
78 {
79 return mEnabled;
80 }
81
86 bool enabled() const
87 {
88 return mEnabled;
89 }
90
95 void setEnabled( bool enabled )
96 {
97 mEnabled = enabled;
98 }
99
104 const T *operator->() const
105 {
106 return &mData;
107 }
108
113 T data() const
114 {
115 return mData;
116 }
117
122 void setData( const T &data )
123 {
124 mData = data;
125 }
126
127 private:
128 bool mEnabled = false;
129 T mData;
130};
131
132#endif // QGSOPTIONAL_H
QgsOptional is a container for other classes and adds an additional enabled/disabled flag.
Definition qgsoptional.h:36
bool enabled() const
Check if this optional is enabled.
Definition qgsoptional.h:86
QgsOptional(const T &data, bool enabled)
A QgsOptional constructed with enabled status and data.
Definition qgsoptional.h:56
void setData(const T &data)
Set the payload data.
void setEnabled(bool enabled)
Set if this optional is enabled.
Definition qgsoptional.h:95
T data() const
Access the payload data.
const T * operator->() const
Access the payload data.
QgsOptional(const T &data)
A QgsOptional is enabled by default if constructed with payload.
Definition qgsoptional.h:47
QgsOptional()=default
A QgsOptional is disabled by default if default constructed.
#define SIP_SKIP
Definition qgis_sip.h:126
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)