@@ -5,115 +5,106 @@ namespace data {
55
66void DataModelCollectionBase::OnFrozen () noexcept
77{
8- m_vNotifyTargets.clear ();
8+ m_vNotifyTargets.Clear ();
99}
1010
1111void DataModelCollectionBase::OnModelValueChanged (gsl::index nIndex,
1212 const BoolModelProperty::ChangeArgs& args)
1313{
14- // create a copy of the list of pointers in case it's modified by one of the callbacks
15- NotifyTargetSet vNotifyTargets (m_vNotifyTargets);
16- for (NotifyTarget* target : vNotifyTargets)
14+ if (m_vNotifyTargets.LockIfNotEmpty ())
1715 {
18- Expects (target != nullptr );
19- target->OnDataModelBoolValueChanged (nIndex, args);
16+ for (auto & target : m_vNotifyTargets.Targets ())
17+ target.OnDataModelBoolValueChanged (nIndex, args);
18+
19+ m_vNotifyTargets.Unlock ();
2020 }
2121}
2222
2323void DataModelCollectionBase::OnModelValueChanged (gsl::index nIndex,
2424 const StringModelProperty::ChangeArgs& args)
2525{
26- // create a copy of the list of pointers in case it's modified by one of the callbacks
27- NotifyTargetSet vNotifyTargets (m_vNotifyTargets);
28- for (NotifyTarget* target : vNotifyTargets)
26+ if (m_vNotifyTargets.LockIfNotEmpty ())
2927 {
30- Expects (target != nullptr );
31- target->OnDataModelStringValueChanged (nIndex, args);
28+ for (auto & target : m_vNotifyTargets.Targets ())
29+ target.OnDataModelStringValueChanged (nIndex, args);
30+
31+ m_vNotifyTargets.Unlock ();
3232 }
3333}
3434
3535void DataModelCollectionBase::OnModelValueChanged (gsl::index nIndex,
3636 const IntModelProperty::ChangeArgs& args)
3737{
38- // create a copy of the list of pointers in case it's modified by one of the callbacks
39- NotifyTargetSet vNotifyTargets (m_vNotifyTargets);
40- for (NotifyTarget* target : vNotifyTargets)
38+ if (m_vNotifyTargets.LockIfNotEmpty ())
4139 {
42- Expects (target != nullptr );
43- target->OnDataModelIntValueChanged (nIndex, args);
40+ for (auto & target : m_vNotifyTargets.Targets ())
41+ target.OnDataModelIntValueChanged (nIndex, args);
42+
43+ m_vNotifyTargets.Unlock ();
4444 }
4545}
4646
4747void DataModelCollectionBase::OnBeginUpdate ()
4848{
49- // create a copy of the list of pointers in case it's modified by one of the callbacks
50- NotifyTargetSet vNotifyTargets (m_vNotifyTargets);
51- for (NotifyTarget* target : vNotifyTargets)
49+ if (m_vNotifyTargets.LockIfNotEmpty ())
5250 {
53- Expects (target != nullptr );
54- target->OnBeginDataModelCollectionUpdate ();
51+ for (auto & target : m_vNotifyTargets.Targets ())
52+ target.OnBeginDataModelCollectionUpdate ();
53+
54+ m_vNotifyTargets.Unlock ();
5555 }
5656}
5757
5858void DataModelCollectionBase::OnEndUpdate ()
5959{
60- // create a copy of the list of pointers in case it's modified by one of the callbacks
61- NotifyTargetSet vNotifyTargets (m_vNotifyTargets);
62- for (NotifyTarget* target : vNotifyTargets)
60+ if (m_vNotifyTargets.LockIfNotEmpty ())
6361 {
64- Expects (target != nullptr );
65- target->OnEndDataModelCollectionUpdate ();
62+ for (auto & target : m_vNotifyTargets.Targets ())
63+ target.OnEndDataModelCollectionUpdate ();
64+
65+ m_vNotifyTargets.Unlock ();
6666 }
6767}
6868
6969void DataModelCollectionBase::OnItemsRemoved (const std::vector<gsl::index>& vDeletedIndices)
7070{
71- if (! m_vNotifyTargets.empty ())
71+ if (m_vNotifyTargets.LockIfNotEmpty ())
7272 {
73- // create a copy of the list of pointers in case it's modified by one of the callbacks
74- NotifyTargetSet vNotifyTargets (m_vNotifyTargets);
75- for (auto nDeletedIndex : vDeletedIndices)
73+ for (auto & target : m_vNotifyTargets.Targets ())
7674 {
77- for (NotifyTarget* target : vNotifyTargets)
78- {
79- Expects (target != nullptr );
80- target->OnDataModelRemoved (nDeletedIndex);
81- }
75+ for (auto nDeletedIndex : vDeletedIndices)
76+ target.OnDataModelRemoved (nDeletedIndex);
8277 }
78+
79+ m_vNotifyTargets.Unlock ();
8380 }
8481}
8582
8683void DataModelCollectionBase::OnItemsAdded (const std::vector<gsl::index>& vNewIndices)
8784{
88- if (! m_vNotifyTargets.empty ())
85+ if (m_vNotifyTargets.LockIfNotEmpty ())
8986 {
90- // create a copy of the list of pointers in case it's modified by one of the callbacks
91- NotifyTargetSet vNotifyTargets (m_vNotifyTargets);
92- for (auto vNewIndex : vNewIndices)
87+ for (auto & target : m_vNotifyTargets.Targets ())
9388 {
94- for (NotifyTarget* target : vNotifyTargets)
95- {
96- Expects (target != nullptr );
97- target->OnDataModelAdded (vNewIndex);
98- }
89+ for (auto vNewIndex : vNewIndices)
90+ target.OnDataModelAdded (vNewIndex);
9991 }
92+
93+ m_vNotifyTargets.Unlock ();
10094 }
10195}
10296
10397void DataModelCollectionBase::OnItemsChanged (const std::vector<gsl::index>& vChangedIndices)
10498{
105- if (! m_vNotifyTargets.empty ())
99+ if (m_vNotifyTargets.LockIfNotEmpty ())
106100 {
107- // create a copy of the list of pointers in case it's modified by one of the callbacks
108- NotifyTargetSet vNotifyTargets (m_vNotifyTargets);
109- for (auto vChangedIndex : vChangedIndices)
101+ for (auto & target : m_vNotifyTargets.Targets ())
110102 {
111- for (NotifyTarget* target : vNotifyTargets)
112- {
113- Expects (target != nullptr );
114- target->OnDataModelChanged (vChangedIndex);
115- }
103+ for (auto vChangedIndex : vChangedIndices)
104+ target.OnDataModelChanged (vChangedIndex);
116105 }
106+
107+ m_vNotifyTargets.Unlock ();
117108 }
118109}
119110
0 commit comments