QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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> class CORE_EXPORT QgsOptional
35{
36 public:
40 QgsOptional() = default;
41
45 QgsOptional( const T &data )
46 : mEnabled( true )
47 , mData( data )
48 {}
49
53 QgsOptional( const T &data, bool enabled )
54 : mEnabled( enabled )
55 , mData( data )
56 {}
57
65 bool operator==( const QgsOptional<T> &other ) const { return mEnabled == other.mEnabled && mData == other.mData; }
66
70 explicit operator bool() const SIP_SKIP { return mEnabled; }
71
76 bool enabled() const { return mEnabled; }
77
82 void setEnabled( bool enabled ) { mEnabled = enabled; }
83
88 const T *operator->() const { return &mData; }
89
94 T data() const { return mData; }
95
100 void setData( const T &data ) { mData = data; }
101
102 private:
103 bool mEnabled = false;
104 T mData;
105};
106
107// These typedefs are in place to work around a SIP bug:
108// https://github.com/Python-SIP/sip/issues/66
109#ifndef SIP_RUN
110#include "qgsexpression.h"
112#endif
113
114#endif // QGSOPTIONAL_H
A container for other classes and adds an additional enabled/disabled flag.
Definition qgsoptional.h:35
QgsOptional(const T &data, bool enabled)
A QgsOptional constructed with enabled status and data.
Definition qgsoptional.h:53
void setData(const T &data)
Set the payload data.
void setEnabled(bool enabled)
Set if this optional is enabled.
Definition qgsoptional.h:82
QgsExpression data() const
Definition qgsoptional.h:94
bool operator==(const QgsOptional< T > &other) const
Compare this QgsOptional to another one.
Definition qgsoptional.h:65
const T * operator->() const
Access the payload data.
Definition qgsoptional.h:88
QgsOptional(const T &data)
A QgsOptional is enabled by default if constructed with payload.
Definition qgsoptional.h:45
QgsOptional()=default
A QgsOptional is disabled by default if default constructed.
#define SIP_SKIP
Definition qgis_sip.h:133
QgsOptional< QgsExpression > QgsOptionalQgsExpressionBase