CMS 3D CMS Logo

FWModelChangeManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWModelChangeManager
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Thu Jan 17 19:13:46 EST 2008
11 //
12 
13 // system include files
14 #include <cassert>
15 #include <memory>
16 #include <exception>
17 
18 // user include files
23 
24 //
25 // constants, enums and typedefs
26 //
27 
28 //
29 // static data member definitions
30 //
31 
32 //
33 // constructors and destructor
34 //
36 
37 // FWModelChangeManager::FWModelChangeManager(const FWModelChangeManager& rhs)
38 // {
39 // // do actual copying here;
40 // }
41 
43 
44 //
45 // assignment operators
46 //
47 // const FWModelChangeManager& FWModelChangeManager::operator=(const FWModelChangeManager& rhs)
48 // {
49 // //An exception safe implementation is
50 // FWModelChangeManager temp(rhs);
51 // swap(rhs);
52 //
53 // return *this;
54 // }
55 
56 //
57 // member functions
58 //
60 
62  FWChangeSentry sentry(*this);
63  assert(iID.item());
64  assert(iID.item()->id() < m_changes.size());
65  m_changes[iID.item()->id()].insert(iID);
66 }
67 
69  FWChangeSentry sentry(*this);
70  assert(nullptr != iItem);
71  m_itemChanges.insert(iItem);
72  //remove any pending changes on models owned by this item
73  assert(iItem->id() < m_changes.size());
74  m_changes[iItem->id()].clear();
75 }
76 
78  //since this can cause other changes, we might as well aggregate them
79  FWChangeSentry sentry(*iCM);
80  iCM->changeSignalsAreDone_();
81 }
82 
84  assert(m_depth != 0);
85  //makes sure that 'changeSignalsAreDone is called if changeSignalsAreComing_ is sent
86  bool guard(false);
87  if (0 == --m_depth) {
88  unsigned int index = 0;
89  for (std::set<const FWEventItem*>::iterator itChanges = m_itemChanges.begin(); itChanges != m_itemChanges.end();
90  ++itChanges, ++index) {
91  if (!guard) {
92  // std::shared_ptr<FWModelChangeManager> done(this, &sendChangeSignalsAreDone);
93  guard = true;
95  }
96  try {
97  const FWEventItem* item = (*itChanges);
98  item->itemChanged_.emit(item);
99  } catch (const cms::Exception& iE) {
100  fwLog(fwlog::kError) << (*itChanges)->name() << " had the failure in process FWItemChanged signals\n"
101  << iE.what() << std::endl;
102  } catch (const std::bad_alloc& iE) {
103  std::cerr << "Ran out of memory while processing " << (*itChanges)->name() << std::endl;
104  exit(1);
105  } catch (const std::exception& iE) {
106  fwLog(fwlog::kError) << (*itChanges)->name() << " had the failure in process FWItemChanged signals (2) \n"
107  << iE.what() << std::endl;
108  }
109  }
110  m_itemChanges.clear();
111 
112  for (size_t ci = 0, ce = m_changes.size(), si = 0; ci != ce; ++ci, ++si) {
113  FWModelIds& changes = m_changes[ci];
114  if (not changes.empty()) {
115  if (!guard) {
116  // std::shared_ptr<FWModelChangeManager> done(this, &sendChangeSignalsAreDone);
117  guard = true;
119  try {
120  const FWEventItem* item = changes.begin()->item();
121  item->changed_.emit(changes);
122  } catch (const cms::Exception& iE) {
123  fwLog(fwlog::kError) << changes.begin()->item()->name()
124  << " had the failure in process FWModelChangeSignals\n"
125  << iE.what() << "\n";
126  } catch (const std::bad_alloc& iE) {
127  // GE: if we run out of memory why do we assume that we will be able to print?
128  fwLog(fwlog::kError) << "Ran out of memory while processing " << changes.begin()->item()->name() << "\n";
129  exit(1);
130  } catch (const std::exception& iE) {
131  fwLog(fwlog::kError) << changes.begin()->item()->name()
132  << " had the failure in process FWModelChangeSignals (2)\n"
133  << iE.what() << "\n";
134  }
135  }
136  }
137  changes.clear();
138  }
139  }
140 
141  if (guard)
143 }
144 
146  assert(nullptr != iItem);
147  assert(iItem->id() == m_changes.size());
148  assert(iItem->id() == m_changeSignals.size());
149  m_changes.push_back(FWModelIds());
152  //propagate our signal to the item
153  m_changeSignals.back().connect(iItem->changed_);
154  m_itemChangeSignals.back().connect(iItem->itemChanged_);
155 }
156 
161  m_changes.clear();
162  m_changeSignals.clear();
163 
164  m_itemChangeSignals.clear();
165  m_itemChanges.clear();
166 }
167 
168 //
169 // const member functions
170 //
171 
172 //
173 // static member functions
174 //
std::vector< FWModelChangeSignal > m_changeSignals
unsigned int id() const
Definition: FWEventItem.cc:433
std::vector< FWModelIds > m_changes
static void sendChangeSignalsAreDone(FWModelChangeManager *iCM)
assert(be >=bs)
std::set< const FWEventItem * > m_itemChanges
void newItemSlot(FWEventItem *)
std::set< FWModelId > FWModelIds
sigc::signal< void(const FWModelIds &)> FWModelChangeSignal
FWItemChangeSignal itemChanged_
Definition: FWEventItem.h:181
sigc::signal< void(const FWEventItem *)> FWItemChangeSignal
sigc::signal< void()> changeSignalsAreDone_
const FWEventItem * item() const
Definition: FWModelId.h:39
void changed(const FWModelId &)
#define fwLog(_level_)
Definition: fwLog.h:45
std::vector< FWItemChangeSignal > m_itemChangeSignals
FWModelChangeSignal changed_
Definition: FWEventItem.h:178
sigc::signal< void()> changeSignalsAreComing_
char const * what() const noexcept override
Definition: Exception.cc:107
def exit(msg="")