OpendTect  6.3
dbdir.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: Sep 2016
9 ________________________________________________________________________
10 
11 -*/
12 
13 
14 #include "generalmod.h"
15 #include "sharedobject.h"
16 #include "monitoriter.h"
17 #include "dbkey.h"
18 #include "objectset.h"
19 #include "od_iosfwd.h"
20 #include "threadlock.h"
21 #include "uistring.h"
22 #include "ioobjctxt.h"
23 #include "ioobj.h"
24 class TranslatorGroup;
25 
26 
27 /*\brief 'Directory' of IOObj objects.
28 
29 The DBDir class is responsible for finding all IOObj's in one of the
30 subdirectories of an OpendTect data tree. A DBDir instance will actually load
31 all IOObj's, provides access to keys and allows searching.
32 
33 */
34 
35 
36 mExpClass(General) DBDir : public SharedObject
38 public:
39 
41  typedef size_type IdxType;
44  typedef DBKey::ObjID ObjID;
45 
46  DBDir(const char* dirname);
47  DBDir(DirID);
50 
51  bool isBad() const;
52  bool isOutdated() const;
53  DirID dirID() const { return dirid_; }
54  const char* dirName() const { return dirname_; }
55  od_int64 readTime() const { return readtime_; }
56  uiString errMsg() const { return errmsg_; }
57 
58  size_type size() const;
59  bool isEmpty() const { return size() < 1; }
60 
61  bool isPresent(ObjID) const;
62  bool isPresent(const DBKey&) const;
63  IdxType indexOf(ObjID) const;
64 
65  IOObj* getEntry(ObjID) const;
66  IOObj* getEntryByName(const char* nm,
67  const char* trgrpnm=0) const;
68  IOObj* getEntryByIdx(IdxType) const;
69 
70  bool commitChanges(const IOObj&);
71  bool permRemove(ObjID);
72  DBKey newKey() const;
73  DBKey newTmpKey() const;
74 
75  static ChangeType cEntryChanged() { return 2; }
76  static ChangeType cEntryAdded() { return 3; }
77  static ChangeType cEntryToBeRemoved() { return 4; }
78  static ChangeType cEntryRemoved() { return 5; }
79 
80 private:
81 
82  bool isok_;
84  const DirID dirid_;
86  od_int64 readtime_ = -1;
87  mutable ObjNrType curnr_ = 0;
88  mutable ObjNrType curtmpnr_ = IOObj::tmpObjNrStart();
89  mutable uiString errmsg_;
90 
91  DBDir();
92  ~DBDir();
93 
94  void fromDirID(DirID,bool);
95  bool readFromFile(bool);
96  bool readOmf(od_istream&,bool);
97  bool writeToFile() const;
98  bool wrOmf(od_ostream&) const;
99  const IOObj* gtObjByName(const char*,const char*) const;
100  IdxType gtIdx(ObjID) const;
101  bool gtIsOutdated() const;
102  bool setObj(IOObj*,bool writeafter);
103  bool addAndWrite(IOObj*);
104 
105  friend class DBMan;
106  friend class DBDirIter;
107 
108  DBKey gtNewKey(const ObjNrType&) const;
109  void setObjDirName(IOObj&);
110 
111 public:
112 
113  // 'Usually not needed' section
114 
115  bool reRead(bool force) const;
116  // Done a lot already
117  bool prepObj(IOObj&) const;
118  // Will be done before storage anyway
119 
120  static void getTmpIOObjs(DirID,ObjectSet<IOObj>&,
121  const IOObjSelConstraints* c=0);
122 
123  mDeprecated bool commitChanges( const IOObj* obj )
124  { return obj ? commitChanges(*obj) : false; }
125 
126 };
127 
128 
129 /*\brief iterates a DBDir */
130 
132 {
133 public:
134 
136 
137  DBDirIter(const DBDir&);
138  DBDirIter(const DBDirIter&);
139 
140  virtual size_type size() const { return dbDir().size(); }
141  const DBDir& dbDir() const;
142 
143  const IOObj& ioObj() const;
144  ObjID objID() const;
145  DBKey key() const;
146 
148 
149 };
150 
151 
156 {
157 public:
158 
160  typedef size_type IdxType;
161 
162  DBDirEntryList(const IOObjContext&,bool dofill=true);
163  DBDirEntryList(const TranslatorGroup&,
164  const char* translator_globexpr=0);
165  ~DBDirEntryList();
166  const char* name() const { return name_; }
167  size_type size() const { return entries_.size(); }
168  bool isEmpty() const { return entries_.isEmpty(); }
169 
170  void fill(const char* nmfiltglobexpr=0);
171  IdxType indexOf(const char*) const;
172 
173  const IOObj& ioobj( IdxType idx ) const { return *entries_[idx]; }
174  DBKey key(IdxType) const;
175  BufferString name(IdxType) const;
176  BufferString dispName(IdxType) const;
177  BufferString iconName(IdxType) const;
178 
179 protected:
180 
184 
185  void sort();
186 
187 };
#define mExpClass(module)
Definition: commondefs.h:157
bool isEmpty() const
Definition: dbdir.h:59
const char * name() const
Definition: dbdir.h:166
size_type size() const
Definition: dbdir.h:167
const DirID dirid_
Definition: dbdir.h:84
BufferString name_
Definition: dbdir.h:183
DBKey::ObjNrType ObjNrType
Definition: dbdir.h:42
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:25
Definition: ioobj.h:57
Definition: dbdir.h:36
int ChangeType
Definition: monitorable.h:80
Definition: dbdir.h:131
#define mODTextTranslationClass(clss)
Definition: uistring.h:37
DBKey::ObjID ObjID
Definition: dbdir.h:44
#define od_int64
Definition: plftypes.h:34
Definition: sharedobject.h:18
virtual size_type size() const
Definition: dbdir.h:140
ObjectSet< IOObj >::size_type size_type
Definition: dbdir.h:159
size_type size() const
od_int64 readTime() const
Definition: dbdir.h:55
ObjectSet< IOObj >::size_type size_type
Definition: dbdir.h:40
GroupID DirID
Definition: dbkey.h:40
Definition: uistring.h:88
ObjectSet< T >::size_type indexOf(const ObjectSet< T > &os, const S &val)
Locate object in set.
Definition: objectset.h:173
int ObjNrType
Definition: groupedid.h:39
#define mDeclMonitorableAssignment(clss)
like mDeclAbstractMonitorableAssignment but for non-abstract subclasses. Implements the clone() metho...
Definition: monitor.h:111
OD class for stream read.
Definition: od_istream.h:23
size_type IdxType
Definition: dbdir.h:41
Holds constraints on IOObj selection.
Definition: ioobjctxt.h:27
Set of pointers to objects.
Definition: commontypes.h:28
ObjID objID() const
Group of Translators. Has a static factory.
Definition: transl.h:54
static ChangeType cEntryChanged()
Definition: dbdir.h:75
StdSelType
Definition: ioobjctxt.h:66
ObjectSet< IOObj > objs_
Definition: dbdir.h:83
const IOObj & ioobj(IdxType idx) const
Definition: dbdir.h:173
IdxType size_type
Definition: monitoriter.h:36
const char * dirName() const
Definition: dbdir.h:54
DBKey::DirID DirID
Definition: dbdir.h:43
manages the &#39;Meta-&#39;data store for the IOObj&#39;s. This info is read from the .omf files. The &#39;workhorse is the DBDir object.
Definition: dbman.h:32
#define mDefNoAssignmentOper(clss)
Definition: commondefs.h:131
DBDir::ObjID ObjID
Definition: dbdir.h:135
DirID dirID() const
Definition: dbdir.h:53
static ObjNrType tmpObjNrStart()
Definition: ioobj.h:127
const BufferString dirname_
Definition: dbdir.h:85
static ChangeType cEntryAdded()
Definition: dbdir.h:76
uiString errmsg_
Definition: dbdir.h:89
const DBDir & dbDir() const
#define mDeprecated
Definition: plfdefs.h:213
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:38
void sort(ObjectSet< T > &os)
Sort ObjectSet. Must have operator > defined for elements.
Definition: objectset.h:224
mDeprecated bool commitChanges(const IOObj *obj)
Definition: dbdir.h:123
static ChangeType cEntryRemoved()
Definition: dbdir.h:78
BufferString errmsg_
Definition: horizontracker.h:117
const IOObj & ioObj() const
bool isEmpty() const
Definition: dbdir.h:168
ObjectSet< IOObj > entries_
Definition: dbdir.h:181
Full key to any object in the OpendTect data store.
Definition: dbkey.h:36
uiString errMsg() const
Definition: dbdir.h:56
DBKey key() const
base class for Monitorable iterators. Inherit from one of its subclasses.
Definition: monitoriter.h:31
size_type IdxType
Definition: dbdir.h:160
list of DBDir entries, sorted by name, conforming to a context. Can be Filtered using GlobExpr...
Definition: dbdir.h:155
bool isok_
Definition: dbdir.h:82
static ChangeType cEntryToBeRemoved()
Definition: dbdir.h:77
IOObjContext & ctxt_
Definition: dbdir.h:182
DBDirIter(const DBDir &)
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