OpendTect  6.3
saveablemanager.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: Bert
8  Date: July 2016
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "saveable.h"
14 #include "objectset.h"
15 class ChangeRecorder;
16 class IOObjContext;
17 
18 
43 public:
44 
45  typedef ::DBKey ObjID;
47  typedef size_type IdxType;
48 
49  ~SaveableManager();
50 
51  bool nameExists(const char*) const;
52  bool canSave(const ObjID&) const;
53  uiRetVal save(const ObjID&) const;
54  uiRetVal saveAs(const ObjID& curid,const ObjID& newid) const;
55  bool needsSave(const ObjID&) const;
56  void setJustSaved(const ObjID&) const;
57 
58  bool isValidID(const ObjID&) const;
59  bool isLoaded(const char*) const;
60  bool isLoaded(const ObjID&) const;
61  void getAllLoaded(DBKeySet&) const;
62  ObjID getIDByName(const char*) const;
63  IOPar getIOObjPars(const ObjID&) const;
64  BufferString nameOf(const ObjID&) const;
65 
66  // Use MonitorLock when iterating
67  IdxType size() const;
68  ObjID getIDByIndex(IdxType) const;
69  IOPar getIOObjParsByIndex(IdxType) const;
70 
76 
81  void clearChangeRecords(const ObjID&);
82  void getChangeInfo(const ObjID&,
83  uiString& undotxt,uiString& redotxt) const;
84  bool useChangeRecord(const ObjID&,bool forundo);
85 
86  enum DispOpt { Show, Hide, Vanish };
87  void displayRequest(const DBKey&,DispOpt=Show);
88 
89 protected:
90 
91  SaveableManager(const IOObjContext&,bool autosv,
92  bool tempobjsonly=false);
93 
94  virtual Saveable* getSaver(const SharedObject&) const = 0;
96  { return 0; }
97  virtual void addCBsToObj(const SharedObject&);
98  virtual void setAuxOnAdd() {}
99 
103  const bool autosaveable_;
104  const bool tempobjsonly_;
105 
106  // to be called from public obj-type specific ones
107  ObjID getID(const SharedObject&) const;
108  uiRetVal store(const SharedObject&,const IOPar*) const;
109  uiRetVal store(const SharedObject&,const ObjID&,
110  const IOPar*) const;
111  uiRetVal save(const SharedObject&) const;
112  bool needsSave(const SharedObject&) const;
113  IOObj* getIOObj(const DBKey&) const;
114  IOObj* getIOObjByName(const char*) const;
115 
116  // Tools for locked state
117  void setEmpty();
118  IdxType gtIdx(const char*) const;
119  IdxType gtIdx(const ObjID&) const;
120  IdxType gtIdx(const SharedObject&) const;
121  SharedObject* gtObj(IdxType) const;
122  const Saveable* saverFor(const ObjID&) const;
123  uiRetVal doSave(const ObjID&) const;
124  void add(const SharedObject&,const ObjID&,AccessLocker&,
125  const IOPar*,bool) const;
126 
127  void dbmEntryRemovedCB(CallBacker*);
128  void survChgCB(CallBacker*);
129  void appExitCB(CallBacker*);
130  void objDelCB(CallBacker*);
131  void objChgCB(CallBacker*);
132 
133 public:
134 
135  SaveableManager* clone() const { return 0; }
136  void handleUnsavedLastCall();
137 
138  // intended only for dedicated loaders
139  void addNew(const SharedObject&,const ObjID&,
140  const IOPar*,bool) const;
141 
142 };
143 
144 
145 #define mDeclareSaveableManagerInstance(typ) \
146  static typ& getInstance(); \
147  typ* clone() const { return 0; } \
148  mDeclInstanceCreatedNotifierAccess(typ)
149 
150 #define mDefineSaveableManagerInstance(typ) \
151 mDefineInstanceCreatedNotifierAccess(typ) \
152  \
153 static typ* theinst_ = 0; \
154 static Threads::Lock theinstcreatelock_(true); \
155  \
156 typ& typ::getInstance() \
157 { \
158  if ( !theinst_ ) \
159  { \
160  Threads::Locker locker( theinstcreatelock_ ); \
161  if ( !theinst_ ) \
162  theinst_ = new typ; \
163  } \
164  return *theinst_; \
165 }
166 
167 
168 #define mDefineStdFns(typ) \
169  ObjID getID( const char* nm ) const \
170  { return SaveableManager::getID(nm); } \
171  ObjID getID( const SharedObject& obj ) const \
172  { return SaveableManager::getID(obj); } \
173  ObjID getID(const typ&) const; \
174  uiRetVal store(const typ&,const IOPar* ioobjpars=0) const; \
175  uiRetVal store(const typ&,const ObjID&,const IOPar* p=0) const; \
176  uiRetVal save(const typ&) const; \
177  bool needsSave(const typ&) const
virtual void setAuxOnAdd()
Definition: saveablemanager.h:98
#define mExpClass(module)
Definition: commondefs.h:157
size_type IdxType
Definition: saveablemanager.h:47
CNotifier< SaveableManager, ObjID > HideRequested
Definition: saveablemanager.h:74
Inherit from this class to be able to send and/or receive CallBacks.
Definition: callback.h:182
Definition: ioobj.h:57
const bool autosaveable_
Definition: saveablemanager.h:103
CNotifier< SaveableManager, ObjID > ShowRequested
Definition: saveablemanager.h:73
Monitorable object with a name. All but name() are MT-safe.
Definition: namedmonitorable.h:20
#define mODTextTranslationClass(clss)
Definition: uistring.h:37
Definition: sharedobject.h:18
Definition: dbkey.h:98
CNotifier< SaveableManager, ObjID > UnsavedObjLastCall
Definition: saveablemanager.h:72
DispOpt
Definition: saveablemanager.h:86
Definition: uistring.h:88
ObjectSet< ChangeRecorder > chgrecs_
Definition: saveablemanager.h:101
Definition: odpresentationmgr.h:32
Object that can be saved at any time.
Definition: saveable.h:23
CNotifier< SaveableManager, ObjID > ObjOrphaned
Definition: saveablemanager.h:71
virtual ChangeRecorder * getChangeRecorder(const SharedObject &) const
Definition: saveablemanager.h:95
mODTextTranslationClass(SaveableManager) public typedef ObjectSet< Saveable >::size_type size_type
Definition: saveablemanager.h:42
Set of pointers to objects.
Definition: commontypes.h:28
base class for recorder of changes in a Monitorable
Definition: monitorchangerecorder.h:20
Base class for managers of Saveable objects: loading and storing.
Definition: saveablemanager.h:41
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:53
SaveableManager * clone() const
Definition: saveablemanager.h:135
CNotifier< SaveableManager, ObjID > VanishRequested
Definition: saveablemanager.h:75
CNotifier< SaveableManager, ObjID > ObjAdded
Definition: saveablemanager.h:77
Definition: odpresentationmgr.h:32
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:38
Definition: odpresentationmgr.h:32
Definition: uistring.h:299
ObjectSet< Saveable > savers_
Definition: saveablemanager.h:100
Definition: monitorable.h:155
Full key to any object in the OpendTect data store.
Definition: dbkey.h:36
const char * nameOf(ButtonState)
const bool tempobjsonly_
Definition: saveablemanager.h:104
const IOObjContext & ctxt_
Definition: saveablemanager.h:102
Holds the context for selecting and/or creating IOObjs.
Definition: ioobjctxt.h:59

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2017