ufe  4.2
Universal Front End is a DCC-agnostic component that will allow a DCC to browse and edit data in multiple data models
subject.h
Go to the documentation of this file.
1 #line 1 "S:/jenkins/workspace/ECP/ufe/ufe-full-python3.10-windows/ufe/include/subject.h"
2 #ifndef _ufeSubject
3 #define _ufeSubject
4 // ===========================================================================
5 // Copyright 2018 Autodesk, Inc. All rights reserved.
6 //
7 // Use of this software is subject to the terms of the Autodesk license
8 // agreement provided at the time of installation or download, or which
9 // otherwise accompanies this software in either electronic or hard copy form.
10 // ===========================================================================
11 
12 #include "observer.h"
13 
14 #include <set>
15 
16 UFE_NS_DEF {
17 
18 class Notification;
19 class NotificationGuard;
20 
22 
41 {
42 public:
43 
45  Subject();
46 
48  Subject(const Subject&);
49 
51  Subject(Subject&&);
52 
54  virtual ~Subject();
55 
57  Subject& operator=(const Subject&);
58 
60  Subject& operator=(Subject&&);
61 
68  bool addObserver(const Observer::Ptr& obs);
69 
76  bool removeObserver(const Observer::Ptr& obs);
77 
79  bool hasObserver(const Observer::Ptr& obs) const;
80 
82  std::size_t nbObservers() const;
83 
86  virtual void notify(const Notification& notification);
87 
91  virtual bool inCompositeNotification() const;
92 
93 protected:
95  virtual void beginNotificationGuard();
97  virtual void endNotificationGuard();
99 
100 private:
101  friend class NotificationGuard;
102 
103  // Weak pointers cannot be ordered by default, as they can expire at any
104  // time. However, they can be ordered by the address of the control block,
105  // which stores the number of shared_ptr AND weak_ptr, and is deleted only
106  // when the last weak_ptr expires.
107  typedef std::set<Observer::WeakPtr, std::owner_less<Observer::WeakPtr> >
109 
112  void cleanObservers(const Observers& dead);
113 
115 };
116 
118 
129 public:
130 
131  NotificationGuard(Subject& subject);
133 
135  NotificationGuard(const NotificationGuard&) = delete;
137  const NotificationGuard& operator&(const NotificationGuard&) = delete;
139 
140 private:
142 };
143 
144 }
145 
146 #endif /* _ufeSubject */
std::shared_ptr< Observer > Ptr
Definition: observer.h:36
Subject *const fSubject
Definition: subject.h:141
std::set< Observer::WeakPtr, std::owner_less< Observer::WeakPtr > > Observers
Definition: subject.h:108
Observer pattern Subject class.
Definition: subject.h:40
Notification guard for Subject.
Definition: subject.h:128
#define UFE_NS_DEF
Definition: ufe.h:35
Base class for all notifications.
Definition: notification.h:28
#define UFE_SDK_DECL
Definition: ufeExport.h:36
Observers fObservers
Definition: subject.h:114