ICF 3.1.1.10
Technical documentation of ICF Libraries
IChangeable.h
Go to the documentation of this file.
1/********************************************************************************
2** This file is part of the ICF Framework. Copyright (C) Witold Gantzke & Kirill Lepskiy
3** ICF Framework may be used under the terms of the LGPL License v. 2.1 by the Free Software Foundation.
4********************************************************************************/
5
6#pragma once
7
8
9// Qt includes
10#include <QtCore/QString>
11#include <QtCore/QSet>
12#include <QtCore/QVariant>
13#include <QtCore/QMap>
14#include <QtCore/QMutex>
15
16// ICF includes
17#include <istd/IPolymorphic.h>
18
19
20namespace istd
21{
22
23
31class IChangeable: virtual public IPolymorphic
32{
33public:
38 {
39 public:
41 ChangeSet(const ChangeSet& changeSet);
42 ChangeSet(ChangeSet&& changeSet);
43 explicit ChangeSet(const QString& description);
44 explicit ChangeSet(int id1, const QString& description = "");
45 ChangeSet(int id1, int id2, const QString& description = "");
46 ChangeSet(int id1, int id2, int id3, const QString& description = "");
47 ChangeSet(int id1, int id2, int id3, int id4, const QString& description = "");
48 ChangeSet(int id1, int id2, int id3, int id4, int id5, const QString& description = "");
49 ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, const QString& description = "");
50 ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, const QString& description = "");
51 ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, const QString& description = "");
52 ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, int id9, const QString& description = "");
53 ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, int id9, int id10, const QString& description = "");
54
58 void Reset();
59
63 bool IsEmpty() const;
67 bool Contains(int changeId) const;
74 bool ContainsExplicit(int changeId, bool singleOnly = false) const;
78 bool ContainsAny(const ChangeSet& changeSet) const;
79
83 void MaskOut(const ChangeSet& changeSet);
84
88 const QString& GetDescription() const;
89
94 QSet<int> GetIds() const;
95
96 // Copy operators
97 ChangeSet& operator=(const ChangeSet& changeSet);
99
103 ChangeSet& operator+=(int changeId);
104
108 ChangeSet& operator+=(const ChangeSet& changeSet);
109
110 private:
111 QSet<int> m_ids;
112 mutable QMutex m_idsLock;
113
114 QString m_description;
115 };
116
153
159 {
164
168 SO_OBSERVE = 1 << 0,
169
173 SO_COPY = 1 << 1,
174
178 SO_CLONE = 1 << 2,
179
183 SO_COMPARE = 1 << 3,
184
188 SO_RESET = 1 << 4,
189
193 SO_CHANGE_LOCK = 1 << 5
194 };
195
224
229 virtual int GetSupportedOperations() const;
230
236 virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS);
237
244 virtual bool IsEqual(const IChangeable& object) const;
245
251 virtual std::unique_ptr<IChangeable> CloneMe(CompatibilityMode mode = CM_WITHOUT_REFS) const;
252
259 virtual bool ResetData(CompatibilityMode mode = CM_WITHOUT_REFS);
260
267 virtual QMutex* GetChangesLock() const;
268
274 virtual void BeginChanges(const ChangeSet& changeSet);
275
283 virtual void EndChanges(const ChangeSet& changeSet);
284
291 virtual void BeginChangeGroup(const ChangeSet& changeSet);
292
299 virtual void EndChangeGroup(const ChangeSet& changeSet);
300
301 // static methods
305 static const ChangeSet& GetNoChanges();
306
310 static const ChangeSet& GetAnyChange();
311
315 static const ChangeSet& GetAllChanges();
316
320 static const ChangeSet& GetDelegatedChanges();
321
322protected:
327 virtual void OnBeginChanges();
328
332 virtual void OnEndChanges(const ChangeSet& changeSet);
333
334private:
335 // static attributes
336 static const ChangeSet s_emptyChanges;
337 static const ChangeSet s_anyChanges;
338 static const ChangeSet s_allChanges;
339 static const ChangeSet s_delegatedChanges;
340};
341
342
343// public inline methods
344
346{
347 return SO_NONE;
348}
349
350
351inline bool IChangeable::CopyFrom(const IChangeable& /*object*/, CompatibilityMode /*mode*/)
352{
353 return false;
354}
355
356
357inline bool IChangeable::IsEqual(const IChangeable& /*object*/) const
358{
359 return false;
360}
361
362
363inline std::unique_ptr<IChangeable> IChangeable::CloneMe(CompatibilityMode /*mode*/) const
364{
365 return nullptr;
366}
367
368
370{
371 return false;
372}
373
374
375inline QMutex* IChangeable::GetChangesLock() const
376{
377 return nullptr;
378}
379
380
381inline void IChangeable::BeginChanges(const ChangeSet& /*changeSet*/)
382{
384}
385
386
387inline void IChangeable::EndChanges(const ChangeSet& changeSet)
388{
389 OnEndChanges(changeSet);
390}
391
392
393inline void IChangeable::BeginChangeGroup(const ChangeSet& /*changeSet*/)
394{
395}
396
397
398inline void IChangeable::EndChangeGroup(const ChangeSet& /*changeSet*/)
399{
400}
401
402
403// public static inline methods
408{
409 return s_emptyChanges;
410}
411
412
414{
415 return s_anyChanges;
416}
417
418
420{
421 return s_allChanges;
422}
423
424
426{
427 return s_delegatedChanges;
428}
429
430
431// protected inline methods
432
434{
435}
436
437
438inline void IChangeable::OnEndChanges(const ChangeSet& /*changeSet*/)
439{
440}
441
442
443} // namespace istd
444
445
Set of change flags (its IDs).
Definition IChangeable.h:38
ChangeSet(int id1, int id2, int id3, int id4, const QString &description="")
QSet< int > GetIds() const
Get set of all stored IDs.
ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, const QString &description="")
ChangeSet(ChangeSet &&changeSet)
bool IsEmpty() const
Check if there is any change in the set.
ChangeSet(const ChangeSet &changeSet)
ChangeSet(const QString &description)
ChangeSet & operator+=(int changeId)
Add some change flag.
ChangeSet(int id1, int id2, const QString &description="")
void MaskOut(const ChangeSet &changeSet)
Remove the IDs from the second set.
ChangeSet & operator=(const ChangeSet &changeSet)
ChangeSet(int id1, const QString &description="")
ChangeSet & operator=(ChangeSet &&changeSet)
ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, const QString &description="")
bool ContainsExplicit(int changeId, bool singleOnly=false) const
Check if there is specific change flag in the set explicit set by user.
ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, int id9, const QString &description="")
void Reset()
Remove all IDs.
ChangeSet & operator+=(const ChangeSet &changeSet)
Add some change set.
bool Contains(int changeId) const
Check if there is specific change flag in the set.
ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, int id9, int id10, const QString &description="")
bool ContainsAny(const ChangeSet &changeSet) const
Check if any of IDs is changed.
ChangeSet(int id1, int id2, int id3, int id4, int id5, const QString &description="")
ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, const QString &description="")
ChangeSet(int id1, int id2, int id3, const QString &description="")
const QString & GetDescription() const
Get textual description of this change set.
Common interface for data model objects, which can be changed.
Definition IChangeable.h:32
static const ChangeSet & GetAllChanges()
Get anonymous change set.
virtual void BeginChanges(const ChangeSet &changeSet)
Starts the change transaction.
virtual bool ResetData(CompatibilityMode mode=CM_WITHOUT_REFS)
Reset data to its default state.
virtual bool IsEqual(const IChangeable &object) const
Compare this object with another object.
static const ChangeSet & GetNoChanges()
Get empty set of changes.
virtual void EndChangeGroup(const ChangeSet &changeSet)
Ends group of changes.
virtual void BeginChangeGroup(const ChangeSet &changeSet)
Starts group of changes.
virtual void EndChanges(const ChangeSet &changeSet)
Ends the change transaction.
CompatibilityMode
Control how relationship betweeen objects are interpreted.
@ CM_WITHOUT_REFS
External references are simple ignored.
@ CM_WITH_REFS
External references are part of object integrity.
@ CM_STRICT
If external references are different this object are not compatible and cannot be compared or copied.
@ CM_CONVERT
Data of object are interpreted in context of external references.
static const ChangeSet & GetDelegatedChanges()
Get delegated change set.
virtual bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS)
Copy this object from another one.
virtual int GetSupportedOperations() const
Get set of flags for supported operations.
virtual QMutex * GetChangesLock() const
Get mutex beeing locked during changes, if available.
virtual std::unique_ptr< IChangeable > CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const
Make a copy of this object.
virtual void OnBeginChanges()
Callback function for begin change event.
ChangeFlags
Data model change notification flags.
@ CF_ALL_DATA
All object data are changed.
@ CF_NO_UNDO
Used to avoid adding of changes to undo list.
@ CF_ANY
Indicate anonymous change.
@ CF_DESTROYING
Change flag indicate that model is during destruction.
@ CF_ICF_INTERNAL
Internal ICF flag.
@ CF_DELEGATED
Change flag indicate that this change was delegated (is indirect) for example from aggregated object.
SupportedOperations
Flags for supported operations.
@ SO_COPY
Copying from other object.
@ SO_RESET
Resetting of object state.
@ SO_NONE
No operations are supported.
@ SO_CHANGE_LOCK
Locking of object during changes with mutex.
@ SO_CLONE
Creating of copy of this object.
@ SO_COMPARE
Comparison with another object.
@ SO_OBSERVE
Observing of this object via observer-observable pattern.
virtual void OnEndChanges(const ChangeSet &changeSet)
Callback function for end change event.
static const ChangeSet & GetAnyChange()
Get anonymous change set.
Standard library.
Definition IComponent.h:17

© Witold Gantzke and Kirill Lepskiy