OpendTect-6_4  6.4
transl.h
Go to the documentation of this file.
1 #ifndef transl_h
2 #define transl_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H.Bril
9  Date: 21-10-1995
10  Contents: Translators
11 RCS: $Id$
12 ________________________________________________________________________
13 
14 A translator is an object specific for a certain storage mechanism coupled with
15 specific details about how to interpret/write a certain format.
16 
17 A Translator is member of a group, e.g. the Wavelet Translator group.
18 Translator groups have a description of IOObj context needed to select an
19 object of that type.
20 
21 */
22 
23 #include "generalmod.h"
24 #include "refcount.h"
25 #include "objectset.h"
26 #include "callback.h"
27 #include "bufstring.h"
28 #include "streamconn.h"
29 #include "ctxtioobj.h"
30 #include "uistring.h"
31 class Translator;
32 
33 #define mDGBKey "dGB"
34 #define mdTectKey "dTect"
35 
36 #define mObjSelUnrelated 0
37 #define mObjSelRelated 1
38 #define mObjSelMatch 2
39 mGlobal(General) int defaultSelector(const char*,const char*);
40 
41 
57 { mRefCountImpl(TranslatorGroup);
58 public:
59 
60  TranslatorGroup( const char* clssnm );
61 
62  virtual FixedString groupName() const = 0;
63  virtual uiString typeName(int num=1) const = 0;
64  virtual Translator* make(const char*,bool usrnm) const;
65  const Translator* getTemplate(const char*,bool usrnm) const;
66 
67  const ObjectSet<const Translator>& templates() const { return templs_; }
68 
69  virtual const IOObjContext& ioCtxt() const = 0;
70  virtual int objSelector(const char*) const = 0;
72 
73  bool hasConnType(const char*) const;
74  virtual const char* defExtension() const { return 0; }
75  IOPar& selHist();
76  void clearSelHist();
77 
78  static const ObjectSet<TranslatorGroup>& groups() { return getGroups(); }
79  static TranslatorGroup& getGroup(const char* nm);
80  static bool hasGroup(const char* nm);
81  static void clearSelHists();
82 
83  // Called from macros
84  bool add(Translator*);
85  static TranslatorGroup& addGroup(TranslatorGroup*);
86 
87  int defTranslIdx() const { return deftridx_; }
88  void setDefTranslIdx( int i ) { deftridx_ = i; }
89 
90  virtual const char* getSurveyDefaultKey(const IOObj* = 0) const;
91 
92  virtual const char* translationApplication() const;
93 
94 protected:
95 
96  const OD::String& clssName() const { return clssname_; }
97 
102 
103  static ObjectSet<TranslatorGroup>& getGroups();
104 
105 };
106 
107 
123 mExpClass(General) Translator : public CallBacker
125 public:
126  Translator(const char* nm,const char* usr_nm);
127  virtual ~Translator() {}
128 
129  const OD::String& typeName() const { return typname_; }
130  const OD::String& userName() const { return usrname_; }
131  const TranslatorGroup* group() const { return group_; }
132 
133  virtual Translator* getNew() const = 0;
134 
135  virtual bool implExists(const IOObj*,bool forread) const;
136  virtual bool implReadOnly(const IOObj*) const;
137  virtual bool implRename(const IOObj*,const char*,
138  const CallBack* cb=0) const;
139  virtual bool implManagesObjects(const IOObj*) const;
140  virtual bool implRemove(const IOObj*) const;
141  virtual bool implSetReadOnly(const IOObj*,bool) const;
142 
143  virtual const char* connType() const;
144  virtual void usePar(const IOPar&) {}
145  virtual const char* defExtension() const
146  { return group_ ? group_->defExtension() : 0; }
147 
148  void setGroup( TranslatorGroup* g ) { group_ = g; }
149 
150  virtual bool isUserSelectable( bool forread=true ) const
151  { return true; }
152  virtual IOObj* createWriteIOObj(const IOObjContext&,
153  const MultiID&) const;
154  virtual const char* iconName() const { return "od"; }
155  const char* getDisplayName() const;
156  static const Translator* getTemplateInstance(const char* displayname);
157 
158 protected:
159 
163 
164 public:
165  static uiString sNoIoobjMsg();
166  static uiString sBadConnection();
168 };
169 
170 
171 
172 
173 // Essential macros for implementing the concept
174 #define mImplTranslatorInitClass( spec, clss, usrnm ) \
175 { \
176  spec##clss##Translator* tr = new spec##clss##Translator( #spec, usrnm ); \
177  clss##TranslatorGroup::theInst().add( tr ); \
178 }
179 
180 #define mImplTranslatorGroupTheInst( clss ) \
181 { \
182  mDefineStaticLocalObject(RefMan<TranslatorGroup>, inst, \
183  = &TranslatorGroup::addGroup( new clss##TranslatorGroup ));\
184  return *inst; \
185 }
186 
187 
189 #define isTranslatorGroupBody(clss) \
190 protected: \
191  ~clss##TranslatorGroup() {} \
192 public: \
193  static int selector(const char*); \
194  static void initClass() { theInst(); } \
195  static const IOObjContext& ioContext(); \
196  static FixedString sGroupName(); \
197  static uiString sTypeName(int num=1); \
198  virtual FixedString groupName() const { return sGroupName(); } \
199  virtual uiString typeName(int num=1) const \
200  { return sTypeName(num); } \
201  virtual const IOObjContext& ioCtxt() const { return ioContext(); } \
202  virtual int objSelector( const char* s ) const { return selector(s); } \
203  static TranslatorGroup& theInst()
204 
205 
206 #define isTranslatorGroup( clss ) \
207 mTextTranslationClass( clss##TranslatorGroup, \
208  clss##TranslatorGroup::theInst().translationApplication() ) \
209 isTranslatorGroupBody(clss);
210 
211 #define isTranslatorGroupWithInst( clss ) \
212 isTranslatorGroupBody( clss ) \
213 mImplTranslatorGroupTheInst( clss )
214 
215 
217 #define isTranslatorBody(spec,clss) \
218 public: \
219  Translator* getNew() const \
220  { \
221  Translator* trans = new spec##clss##Translator(typeName().buf(), \
222  userName().buf()); \
223  trans->setGroup( group_ ); return trans; \
224  } \
225  static spec##clss##Translator* getInstance(); \
226  static const char* translKey(); \
227  static void initClass()
228 
229 
230 #define isTranslator( spec, clss ) \
231 isTranslatorBody( spec, clss );
232 
233 #define mIsTranslatorWithInitClass( spec, clss, usrnm ) \
234 isTranslatorBody(spec, clss) \
235 mImplTranslatorInitClass(spec, clss, usrnm )
236 
238 #define defineTranslatorGroup(clss,groupname) \
239 FixedString clss##TranslatorGroup::sGroupName() \
240 { return groupname; } \
241 TranslatorGroup& clss##TranslatorGroup::theInst() \
242 mImplTranslatorGroupTheInst( clss )
243 
245 #define defineTranslator(spec,clss,usrnm) \
246 spec##clss##Translator* spec##clss##Translator::getInstance() \
247 { return new spec##clss##Translator(#clss,usrnm); } \
248 const char* spec##clss##Translator::translKey() { return usrnm; } \
249 void spec##clss##Translator::initClass() \
250 mImplTranslatorInitClass( spec, clss, usrnm )
251 
252 
255 #define mDefEmptyTranslatorGroupConstructor(clss) \
256  clss##TranslatorGroup() \
257  : TranslatorGroup(#clss) {}
258 
261 #define mDefEmptyTranslatorBaseConstructor(clss) \
262  clss##Translator( const char* nm, const char* unm ) \
263  : Translator(nm,unm) {}
264 
267 #define mDefEmptyTranslatorConstructor(spec,clss) \
268  spec##clss##Translator( const char* nm, const char* unm ) \
269  : clss##Translator(nm,unm) {}
270 
274 #define mDeclEmptyTranslatorBundle(mod,clss,fmt,defext) \
275 mExpClass(mod) clss##TranslatorGroup : public TranslatorGroup \
276 { isTranslatorGroup(clss) \
277  mDefEmptyTranslatorGroupConstructor(clss) \
278  const char* defExtension() const { return defext; } \
279 }; \
280  \
281 mExpClass(mod) clss##Translator : public Translator \
282 { public: \
283  mDefEmptyTranslatorBaseConstructor(clss) \
284 }; \
285  \
286 mExpClass(mod) fmt##clss##Translator : public clss##Translator \
287 { isTranslator(fmt,clss) \
288  mDefEmptyTranslatorConstructor(fmt,clss) \
289 };
290 
294 #define mDefSimpleTranslatorInstances(clss,usrnm,fmt) \
295 defineTranslatorGroup(clss,usrnm) \
296 uiString clss##TranslatorGroup::sTypeName(int) { return toUiString(usrnm); } \
297 defineTranslator(fmt,clss,#fmt)
298 
301 #define mDefSimpleTranslatorSelector(clss) \
302 int clss##TranslatorGroup::selector( const char* s ) \
303 { return defaultSelector(clss##TranslatorGroup::sGroupName(),s); }
304 
308 #define mDefSimpleTranslatorioContextWithExtra(clss,stdtyp,extra) \
309 const IOObjContext& clss##TranslatorGroup::ioContext() \
310 { \
311  mDefineStaticLocalObject( PtrMan<IOObjContext>, ctxt, = nullptr ); \
312  if ( !ctxt ) \
313  { \
314  ctxt = new IOObjContext( nullptr ); \
315  ctxt->stdseltype_ = IOObjContext::stdtyp; \
316  extra; \
317  } \
318  ctxt->trgroup_ = &theInst(); \
319  return *ctxt; \
320 }
321 
324 #define mDefSimpleTranslatorioContext(clss,stdtyp) \
325  mDefSimpleTranslatorioContextWithExtra(clss,stdtyp,)
326 
330 #define mDefSimpleTranslators(clss,usrnm,fmt,stdtyp) \
331 mDefSimpleTranslatorSelector(clss)\
332 mDefSimpleTranslatorInstances(clss,usrnm,fmt) \
333 mDefSimpleTranslatorioContext(clss,stdtyp)
334 
338 #define mDefSimpleTranslatorsWithCtioExtra(clss,usrnm,fmt,stdtyp,extra) \
339 mDefSimpleTranslatorInstances(clss,usrnm,fmt) \
340 mDefSimpleTranslatorSelector(clss) \
341 mDefSimpleTranslatorioContextWithExtra(clss,stdtyp,extra)
342 
347 #define mDefSimpleTranslatorsWithSelKey(clss,usrnm,fmt,stdtyp,selky) \
348  mDefSimpleTranslatorsWithCtioExtra(clss,usrnm,fmt,stdtyp, \
349  ctxt->selkey_ = selky)
350 
351 
352 // Convenience macros when using Translator(Group)-related classes
353 
354 #define mIOObjContext(trgrp) \
355  trgrp##TranslatorGroup::ioContext()
356 
357 #define mTranslGroupName(trgrp) \
358  trgrp##TranslatorGroup::sGroupName()
359 
360 #define mTranslTemplInstance(trgrp,tr) \
361  (*trgrp##TranslatorGroup::theInst() \
362  .getTemplate(tr##trgrp##Translator::translKey(),true))
363 
364 #define mTranslCreate(trgrp,tr) \
365  (trgrp##Translator*)trgrp##TranslatorGroup::theInst().make(tr)
366 
367 #define mTranslKey(trgrp,tr) \
368  tr##trgrp##Translator::translKey()
369 
370 #define mMkCtxtIOObj(trgrp) \
371  new CtxtIOObj(trgrp##TranslatorGroup::ioContext())
372 
373 #define mSelHist(trgrp) \
374  trgrp##TranslatorGroup::theInst().selHist()
375 
376 
377 #endif
#define mRefCountImpl(ClassName)
Macro to setup a class with destructor for reference counting.
Definition: refcount.h:163
#define mExpClass(module)
Definition: commondefs.h:160
virtual bool isUserSelectable(bool forread=true) const
Definition: transl.h:150
To be able to send and/or receive CallBacks, inherit from this class.
Definition: callback.h:272
virtual const char * connType() const
Definition: ioobj.h:58
virtual const char * iconName() const
Definition: transl.h:154
static uiString sNoIoobjMsg()
#define mODTextTranslationClass(clss)
Definition: uistring.h:38
#define mGlobal(module)
Definition: commondefs.h:163
OD::String that holds an existing text string.
Definition: fixedstring.h:29
virtual bool implExists(const IOObj *, bool forread) const
virtual void usePar(const IOPar &)
Definition: transl.h:144
virtual Translator * getNew() const =0
const OD::String & typeName() const
Definition: transl.h:129
const OD::String & clssName() const
Definition: transl.h:96
static const ObjectSet< TranslatorGroup > & groups()
Definition: transl.h:78
BufferString clssname_
Definition: transl.h:98
Definition: uistring.h:89
const TranslatorGroup * group() const
Definition: transl.h:131
const OD::String & userName() const
Definition: transl.h:130
BufferString usrname_
Definition: transl.h:161
virtual bool implManagesObjects(const IOObj *) const
ObjectSet< const Translator > templs_
Definition: transl.h:99
Group of Translators. Has a static factory.
Definition: transl.h:56
virtual bool implRemove(const IOObj *) const
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:47
virtual const char * defExtension() const
Definition: transl.h:74
static uiString sBadConnection()
virtual const char * defExtension() const
Definition: transl.h:145
encapsulates the read-access-only part of strings in OD.
Definition: odstring.h:31
TranslatorGroup * group_
Definition: transl.h:162
BufferString typname_
Definition: transl.h:160
virtual bool implSetReadOnly(const IOObj *, bool) const
void setDefTranslIdx(int i)
Definition: transl.h:88
int deftridx_
Definition: transl.h:100
I/O Interpreter class for a certain object type.
Definition: transl.h:123
virtual IOObj * createWriteIOObj(const IOObjContext &, const MultiID &) const
uiString sSelObjectIsWrongType()
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
void setGroup(TranslatorGroup *g)
Definition: transl.h:148
static const Translator * getTemplateInstance(const char *displayname)
int defTranslIdx() const
Definition: transl.h:87
virtual bool implRename(const IOObj *, const char *, const CallBack *cb=0) const
int defaultSelector(const char *, const char *)
const ObjectSet< const Translator > & templates() const
Definition: transl.h:67
CallBacks object-oriented (object + method).
Definition: callback.h:57
IOPar * selhist_
Definition: transl.h:101
virtual mODTextTranslationClass(Translator) public ~Translator()
Definition: transl.h:127
const char * getDisplayName() const
"username [group]"
Compound key consisting of ints.
Definition: multiid.h:25
virtual bool implReadOnly(const IOObj *) const
Holds the context for selecting and/or creating IOObjs.
Definition: ctxtioobj.h:62

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