File: fobject.h

package info (click to toggle)
finalcut 0.9.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,832 kB
  • sloc: cpp: 90,264; makefile: 546; sh: 412
file content (293 lines) | stat: -rw-r--r-- 10,784 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/***********************************************************************
* fobject.h - Object container base class of all widget objects        *
*                                                                      *
* This file is part of the FINAL CUT widget toolkit                    *
*                                                                      *
* Copyright 2015-2023 Markus Gans                                      *
*                                                                      *
* FINAL CUT is free software; you can redistribute it and/or modify    *
* it under the terms of the GNU Lesser General Public License as       *
* published by the Free Software Foundation; either version 3 of       *
* the License, or (at your option) any later version.                  *
*                                                                      *
* FINAL CUT is distributed in the hope that it will be useful, but     *
* WITHOUT ANY WARRANTY; without even the implied warranty of           *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        *
* GNU Lesser General Public License for more details.                  *
*                                                                      *
* You should have received a copy of the GNU Lesser General Public     *
* License along with this program.  If not, see                        *
* <http://www.gnu.org/licenses/>.                                      *
***********************************************************************/

/*  Inheritance diagram
 *  ═══════════════════
 *
 *      ▕▔▔▔▔▔▔▔▔▏
 *      ▕ FTimer ▏
 *      ▕▁▁▁▁▁▁▁▁▏
 *           ▲
 *           │
 *      ▕▔▔▔▔▔▔▔▔▔▏
 *      ▕ FObject ▏
 *      ▕▁▁▁▁▁▁▁▁▁▏
 */

#ifndef FOBJECT_H
#define FOBJECT_H

#if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT)
  #error "Only <final/final.h> can be included directly."
#endif

#if !defined (__cplusplus)
  #error "You need a C++ compiler like g++ or clang++"
#elif __cplusplus > 1 && __cplusplus < 201402L
  #error "Your C++ compiler does not support the C++14 standard!"
#endif

#include <sys/time.h>  // need for gettimeofday
#include <cstdlib>
#include <cstring>
#include <memory>
#include <vector>

#include "final/ftimer.h"
#include "final/ftypes.h"
#include "final/util/fstring.h"

namespace finalcut
{

// class forward declaration
class FEvent;
class FKeyEvent;
class FMouseEvent;
class FWheelEvent;
class FFocusEvent;
class FAccelEvent;
class FShowEvent;
class FHideEvent;
class FCloseEvent;
class FTimerEvent;
class FUserEvent;

//----------------------------------------------------------------------
// class FObject
//----------------------------------------------------------------------

class FObject : public FObjectTimer
{
  public:
    // Using-declarations
    using FObjectList            = std::vector<FObject*>;
    using iterator               = FObjectList::iterator;
    using reverse_iterator       = FObjectList::reverse_iterator;
    using const_iterator         = FObjectList::const_iterator;
    using const_reverse_iterator = FObjectList::const_reverse_iterator;
    using reference              = FObjectList::reference;
    using const_reference        = FObjectList::const_reference;

    // Constants
    static constexpr auto UNLIMITED = static_cast<std::size_t>(-1);

    // Constructor
    explicit FObject (FObject* = nullptr);

    // Disable copy constructor
    FObject (const FObject&) = delete;

    // Disable move constructor
    FObject (FObject&&) noexcept = delete;

    // Destructor
    ~FObject() override;

    // Disable copy assignment operator (=)
    auto operator = (const FObject&) -> FObject& = delete;

    // Disable move assignment operator (=)
    auto operator = (FObject&&) noexcept -> FObject& = delete;

    // Accessors
    auto  getClassName() const -> FString override;
    auto  getParent() const & -> FObject*;
    auto  getChild (int) const & -> FObject*;
    auto  getChildren() & -> FObjectList&;
    auto  getChildren() const & -> const FObjectList&;
    auto  getMaxChildren() const & noexcept -> std::size_t;
    auto  numOfChildren() const & -> std::size_t;
    auto  begin() -> iterator;
    auto  end() -> iterator;
    auto  begin() const -> const_iterator;
    auto  end() const -> const_iterator;
    auto  cbegin() const noexcept -> const_iterator;
    auto  cend() const noexcept -> const_iterator;
    auto  rbegin() -> reverse_iterator;
    auto  rend() -> reverse_iterator;
    auto  rbegin() const -> const_reverse_iterator;
    auto  rend() const -> const_reverse_iterator;
    auto  crbegin() const noexcept -> const_reverse_iterator;
    auto  crend() const noexcept -> const_reverse_iterator;
    auto  front() -> reference;
    auto  back() -> reference;
    auto  front() const -> const_reference;
    auto  back() const -> const_reference;

    // Mutator
    void  setMaxChildren (std::size_t) noexcept;

    // Inquiries
    auto  hasParent() const & noexcept -> bool;
    auto  hasChildren() const & -> bool;
    auto  isChild (const FObject*) const & -> bool;
    auto  isDirectChild (const FObject*) const & -> bool;
    auto  isWidget() const noexcept -> bool;
    auto  isInstanceOf (const FString&) const -> bool;

    // Methods
    void  removeParent() &;
    void  addChild (FObject*) &;
    void  delChild (FObject*) &;
    void  setParent (FObject*) &;

    // Event handler
    virtual auto event (FEvent*) -> bool;

  protected:
    // Mutator
    void  setWidgetProperty (bool = true);

    // Event handler
    virtual void onTimer (FTimerEvent*);
    virtual void onUserEvent (FUserEvent*);

  private:
    // Data members
    FObject*     parent_obj{nullptr};
    FObjectList  children_list{};  // no children yet
    std::size_t  max_children{UNLIMITED};
    bool         has_parent{false};
    bool         widget_object{false};
};

// FObject inline functions
//----------------------------------------------------------------------
inline auto FObject::getClassName() const -> FString
{ return "FObject"; }

//----------------------------------------------------------------------
inline auto FObject::getParent() const & -> FObject*
{ return parent_obj; }

//----------------------------------------------------------------------
inline auto FObject::getChildren() & -> FObjectList&
{ return children_list; }

//----------------------------------------------------------------------
inline auto FObject::getChildren() const & -> const FObjectList&
{ return children_list; }

//----------------------------------------------------------------------
inline auto FObject::getMaxChildren() const & noexcept -> std::size_t
{ return max_children; }

//----------------------------------------------------------------------
inline auto FObject::numOfChildren() const & -> std::size_t
{ return children_list.size(); }

//----------------------------------------------------------------------
inline auto FObject::begin() -> iterator
{ return children_list.begin(); }

//----------------------------------------------------------------------
inline auto FObject::end() -> iterator
{ return children_list.end(); }

//----------------------------------------------------------------------
inline auto FObject::begin() const -> const_iterator
{ return children_list.begin(); }

//----------------------------------------------------------------------
inline auto FObject::end() const -> const_iterator
{ return children_list.end(); }

//----------------------------------------------------------------------
inline auto FObject::cbegin() const noexcept -> const_iterator
{ return children_list.cbegin(); }

//----------------------------------------------------------------------
inline auto FObject::cend() const noexcept -> const_iterator
{ return children_list.cend(); }

//----------------------------------------------------------------------
inline auto FObject::rbegin() -> reverse_iterator
{ return children_list.rbegin(); }

//----------------------------------------------------------------------
inline auto FObject::rend() -> reverse_iterator
{ return children_list.rend(); }

//----------------------------------------------------------------------
inline auto FObject::rbegin() const -> const_reverse_iterator
{ return children_list.rbegin(); }

//----------------------------------------------------------------------
inline auto FObject::rend() const -> const_reverse_iterator
{ return children_list.rend(); }

//----------------------------------------------------------------------
inline auto FObject::crbegin() const noexcept -> const_reverse_iterator
{ return children_list.crbegin(); }

//----------------------------------------------------------------------
inline auto FObject::crend() const noexcept -> const_reverse_iterator
{ return children_list.crend(); }

//----------------------------------------------------------------------
inline auto FObject::front() -> reference
{ return children_list.front(); }

//----------------------------------------------------------------------
inline auto FObject::back() -> reference
{ return children_list.back(); }

//----------------------------------------------------------------------
inline auto FObject::front() const -> const_reference
{ return children_list.front(); }

//----------------------------------------------------------------------
inline auto FObject::back() const -> const_reference
{ return children_list.back(); }

//----------------------------------------------------------------------
inline void FObject::setMaxChildren (std::size_t max) noexcept
{ max_children = max; }

//----------------------------------------------------------------------
inline auto FObject::hasParent() const & noexcept -> bool
{ return has_parent; }

//----------------------------------------------------------------------
inline auto FObject::hasChildren() const & -> bool
{ return ! children_list.empty(); }

//----------------------------------------------------------------------
inline auto FObject::isDirectChild (const FObject* obj) const & -> bool
{ return obj->getParent() == this; }

//----------------------------------------------------------------------
inline auto FObject::isWidget() const noexcept -> bool
{ return widget_object; }

//----------------------------------------------------------------------
inline auto FObject::isInstanceOf (const FString& classname) const -> bool
{ return classname == getClassName(); }

//----------------------------------------------------------------------
inline void FObject::setWidgetProperty (bool property)
{ widget_object = property; }

}  // namespace finalcut

#endif  // FOBJECT_H