IChangeable.h
Go to the documentation of this file.
1 #ifndef istd_IChangeable_included
2 #define istd_IChangeable_included
3 
4 
5 // Qt includes
6 #include <QtCore/QString>
7 #include <QtCore/QSet>
8 
9 // ACF includes
10 #include <istd/IPolymorphic.h>
11 
12 
13 namespace istd
14 {
15 
16 
24 class IChangeable: virtual public IPolymorphic
25 {
26 public:
30  class ChangeSet
31  {
32  public:
33  ChangeSet();
34  explicit ChangeSet(const QString& description);
35  explicit ChangeSet(int id1, const QString& description = "");
36  ChangeSet(int id1, int id2, const QString& description = "");
37  ChangeSet(int id1, int id2, int id3, const QString& description = "");
38  ChangeSet(int id1, int id2, int id3, int id4, const QString& description = "");
39  ChangeSet(int id1, int id2, int id3, int id4, int id5, const QString& description = "");
40  ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, const QString& description = "");
41  ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, const QString& description = "");
42  ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, const QString& description = "");
43  ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, int id9, const QString& description = "");
44  ChangeSet(int id1, int id2, int id3, int id4, int id5, int id6, int id7, int id8, int id9, int id10, const QString& description = "");
45 
49  void Reset();
50 
54  bool IsEmpty() const;
58  bool Contains(int changeId) const;
65  bool ContainsExplicit(int changeId, bool singleOnly = false) const;
69  bool ContainsAny(const ChangeSet& changeSet) const;
70 
74  void MaskOut(const ChangeSet& changeSet);
75 
79  const QString& GetDescription() const;
80 
85  QSet<int> GetIds() const;
86 
90  ChangeSet operator+(const ChangeSet& changeSet) const;
91 
95  ChangeSet& operator+=(int changeId);
96 
100  ChangeSet& operator+=(const ChangeSet& changeSet);
101 
102  private:
103  QSet<int> m_ids;
104 
105  QString m_description;
106  };
107 
112  {
118 
123 
128 
133 
138 
143  };
144 
150  {
154  SO_NONE = 0,
155 
159  SO_OBSERVE = 1 << 0,
160 
164  SO_COPY = 1 << 1,
165 
169  SO_CLONE = 1 << 2,
170 
174  SO_COMPARE = 1 << 3,
175 
179  SO_RESET = 1 << 4
180  };
181 
187  {
209  };
210 
215  virtual int GetSupportedOperations() const;
216 
221  virtual bool CopyFrom(const IChangeable& object, CompatibilityMode mode = CM_WITHOUT_REFS);
222 
228  virtual bool IsEqual(const IChangeable& object) const;
229 
234  virtual IChangeable* CloneMe(CompatibilityMode mode = CM_WITHOUT_REFS) const;
235 
241  virtual bool ResetData(CompatibilityMode mode = CM_WITHOUT_REFS);
242 
248  virtual void BeginChanges(const ChangeSet& changeSet);
249 
257  virtual void EndChanges(const ChangeSet& changeSet);
258 
265  virtual void BeginChangeGroup(const ChangeSet& changeSet);
266 
273  virtual void EndChangeGroup(const ChangeSet& changeSet);
274 
275  // static methods
279  static const ChangeSet& GetNoChanges();
280 
284  static const ChangeSet& GetAnyChange();
285 
289  static const ChangeSet& GetAllChanges();
290 
294  static const ChangeSet& GetDelegatedChanges();
295 
296 protected:
301  virtual void OnBeginChanges();
302 
306  virtual void OnEndChanges(const ChangeSet& changeSet);
307 
308 private:
309  // static attributes
310  static const ChangeSet s_emptyChanges;
311  static const ChangeSet s_anyChanges;
312  static const ChangeSet s_allChanges;
313  static const ChangeSet s_delegatedChanges;
314 };
315 
316 
317 // public inline methods
318 
320 {
321  return SO_NONE;
322 }
323 
324 
325 inline bool IChangeable::CopyFrom(const IChangeable& /*object*/, CompatibilityMode /*mode*/)
326 {
327  return false;
328 }
329 
330 
331 inline bool IChangeable::IsEqual(const IChangeable& /*object*/) const
332 {
333  return false;
334 }
335 
336 
338 {
339  return NULL;
340 }
341 
342 
344 {
345  return false;
346 }
347 
348 
349 inline void IChangeable::BeginChanges(const ChangeSet& /*changeSet*/)
350 {
351  OnBeginChanges();
352 }
353 
354 
355 inline void IChangeable::EndChanges(const ChangeSet& changeSet)
356 {
357  OnEndChanges(changeSet);
358 }
359 
360 
361 inline void IChangeable::BeginChangeGroup(const ChangeSet& /*changeSet*/)
362 {
363 }
364 
365 
366 inline void IChangeable::EndChangeGroup(const ChangeSet& /*changeSet*/)
367 {
368 }
369 
370 
371 // public static inline methods
376 {
377  return s_emptyChanges;
378 }
379 
380 
382 {
383  return s_anyChanges;
384 }
385 
386 
388 {
389  return s_allChanges;
390 }
391 
392 
394 {
395  return s_delegatedChanges;
396 }
397 
398 
399 // protected inline methods
400 
402 {
403 }
404 
405 
406 inline void IChangeable::OnEndChanges(const ChangeSet& /*changeSet*/)
407 {
408 }
409 
410 
411 } // namespace istd
412 
413 
414 #endif // !istd_IChangeable_included
415 
virtual IChangeable * CloneMe(CompatibilityMode mode=CM_WITHOUT_REFS) const
Make a copy of this object.
Definition: IChangeable.h:337
virtual void OnEndChanges(const ChangeSet &changeSet)
Callback function for end change event.
Definition: IChangeable.h:406
virtual void EndChangeGroup(const ChangeSet &changeSet)
Ends group of changes.
Definition: IChangeable.h:366
External references are simple ignored.
Definition: IChangeable.h:197
CompatibilityMode
Control how relationship betweeen objects are interpreted.
Definition: IChangeable.h:186
virtual void OnBeginChanges()
Callback function for begin change event.
Definition: IChangeable.h:401
Comparison with another object.
Definition: IChangeable.h:174
virtual bool IsEqual(const IChangeable &object) const
Compare this object with another object.
Definition: IChangeable.h:331
ChangeSet & operator+=(int changeId)
Add some change flag.
Resetting of object state.
Definition: IChangeable.h:179
static const ChangeSet & GetAnyChange()
Get anonymous change set.
Definition: IChangeable.h:381
SupportedOperations
Flags for supported operations.
Definition: IChangeable.h:149
Indicate anonymous change.
Definition: IChangeable.h:127
void Reset()
Remove all IDs.
virtual void EndChanges(const ChangeSet &changeSet)
Ends the change transaction.
Definition: IChangeable.h:355
virtual bool CopyFrom(const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS)
Copy this object from another one.
Definition: IChangeable.h:325
ChangeSet operator+(const ChangeSet &changeSet) const
Get the union of two change sets.
bool ContainsAny(const ChangeSet &changeSet) const
Check if any of IDs is changed.
Data of object are interpreted in context of external references.
Definition: IChangeable.h:208
void MaskOut(const ChangeSet &changeSet)
Remove the IDs from the second set.
If external references are different this object are not compatible and cannot be compared or copied...
Definition: IChangeable.h:192
Change flag indicate that this change was delegated (is indirect) for example from aggregated object...
Definition: IChangeable.h:137
bool IsEmpty() const
Check if there is any change in the set.
Common interface for data model objects, which can be changed.
Definition: IChangeable.h:24
Base interface for all used interfaces and implementations.
Definition: IPolymorphic.h:17
Change flag indicate that model is during destruction.
Definition: IChangeable.h:132
Copying from other object.
Definition: IChangeable.h:164
virtual bool ResetData(CompatibilityMode mode=CM_WITHOUT_REFS)
Reset data to its default state.
Definition: IChangeable.h:343
QSet< int > GetIds() const
Get set of all stored IDs.
virtual void BeginChangeGroup(const ChangeSet &changeSet)
Starts group of changes.
Definition: IChangeable.h:361
All object data are changed.
Definition: IChangeable.h:122
No operations are supported.
Definition: IChangeable.h:154
#define NULL
Definition: istd.h:64
const QString & GetDescription() const
Get textual description of this change set.
Used to avoid adding of changes to undo list.
Definition: IChangeable.h:142
bool ContainsExplicit(int changeId, bool singleOnly=false) const
Check if there is specific change flag in the set explicit set by user.
External references are part of object integrity.
Definition: IChangeable.h:202
static const ChangeSet & GetAllChanges()
Get anonymous change set.
Definition: IChangeable.h:387
bool Contains(int changeId) const
Check if there is specific change flag in the set.
Observing of this object via observer-observable pattern.
Definition: IChangeable.h:159
Set of change flags (its IDs).
Definition: IChangeable.h:30
Creating of copy of this object.
Definition: IChangeable.h:169
ChangeFlags
Data model change notification flags.
Definition: IChangeable.h:111
virtual void BeginChanges(const ChangeSet &changeSet)
Starts the change transaction.
Definition: IChangeable.h:349
static const ChangeSet & GetNoChanges()
Get empty set of changes.
Definition: IChangeable.h:375
virtual int GetSupportedOperations() const
Get set of flags for supported operations.
Definition: IChangeable.h:319
static const ChangeSet & GetDelegatedChanges()
Get delegated change set.
Definition: IChangeable.h:393

© 2007-2017 Witold Gantzke and Kirill Lepskiy