QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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
7  email : [email protected]
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 
31 template<class T>
32 class CORE_EXPORT QgsOptional
33 {
34  public:
39  : mEnabled( false )
40  {
41  }
42 
46  QgsOptional( const T& data )
47  : mEnabled( true )
48  , mData( data )
49  {
50  }
51 
55  QgsOptional( const T& data, bool enabled )
56  : mEnabled( enabled )
57  , mData( data )
58  {
59  }
60 
69  bool operator== ( const QgsOptional<T>& other ) const
70  {
71  return mEnabled == other.mEnabled && mData == other.mData;
72  }
73 
77  operator bool() const
78  {
79  return mEnabled;
80  }
81 
87  bool enabled() const
88  {
89  return mEnabled;
90  }
91 
97  void setEnabled( bool enabled )
98  {
99  mEnabled = enabled;
100  }
101 
107  const T* operator->() const
108  {
109  return &mData;
110  }
111 
117  T data() const
118  {
119  return mData;
120  }
121 
127  void setData( const T& data )
128  {
129  mData = data;
130  }
131 
132  private:
133  bool mEnabled;
134  T mData;
135 };
136 
137 #endif // QGSOPTIONAL_H
QgsOptional()
A QgsOptional is disabled by default if default constructed.
Definition: qgsoptional.h:38
bool enabled() const
Check if this optional is enabled.
Definition: qgsoptional.h:87
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QgsOptional(const T &data, bool enabled)
A QgsOptional constructed with enabled status and data.
Definition: qgsoptional.h:55
void setData(const T &data)
Set the payload data.
Definition: qgsoptional.h:127
QgsOptional(const T &data)
A QgsOptional is enabled by default if constructed with payload.
Definition: qgsoptional.h:46
QgsOptional is a container for other classes and adds an additional enabled/disabled flag...
Definition: qgsoptional.h:32
T data() const
Access the payload data.
Definition: qgsoptional.h:117
void setEnabled(bool enabled)
Set if this optional is enabled.
Definition: qgsoptional.h:97
const T * operator->() const
Access the payload data.
Definition: qgsoptional.h:107