OpendTect  6.6
serverprogtool.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: May 2019
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "generalmod.h"
14 
15 #include "commandlineparser.h"
16 #include "genc.h"
17 #include "iopar.h"
18 #include "odruncontext.h"
19 #include "od_iosfwd.h"
20 class CommandLineParser;
21 class Timer;
22 class uiRetVal;
23 namespace OD { namespace JSON { class Array; class Object; } }
24 
26 {
27 public:
28 
31  mUseType( TypeSet<int>, size_type );
32 
33  virtual ~ServerProgTool();
34 
35  void exitWithUsage() const;
36  void exitProgram(bool success) const;
37 
38 # define mDeclServerProgToolSetFn( typ ) \
39  void set(const char* keyw,typ,JSONObject* jobj=0)
40 # define mDeclServerProgToolSetArrFn( typ ) \
41  void set(const char* keyw,const typ*,size_type, \
42  JSONObject* jobj=0)
43 
44 # define mDeclServerProgToolSetFns( typ ) \
45  mDeclServerProgToolSetFn(typ); \
46  mDeclServerProgToolSetFn(const TypeSet<typ>&); \
47  mDeclServerProgToolSetArrFn(typ)
48 
55  void set(const char*,const bool*,size_type,JSONObject* o=0);
63 
64  // only in jsonmode_:
65  void set(const char* keyw,JSONObject*);
66  void set(const char* keyw,JSONArray*);
67 
68  void respondInfo(bool success,bool exit=true) const;
69  void respondError(const char*) const;
70  void respondError(const uiRetVal&) const;
71 
72  CommandLineParser& clp() { return *clp_; }
73  const CommandLineParser& clp() const { return *clp_; }
74  od_istream& inStream() const;
76 
77  static const char* sListUsrCmd() { return "list"; }
78  static const char* sExistsUsrCmd() { return "exists"; }
79  static const char* sInfoUsrCmd() { return "info"; }
80  static const char* sAllUsrCmd() { return "all"; }
81  static const char* sKeyTransGrp(int n=1)
82  { return n<2 ? "TranslatorGroup"
83  : "TranslatorGroups"; }
84 
86 
87 protected:
88 
89  ServerProgTool(int,char**,const char* moddep);
90  void initParsing(int protocolnr,bool setdatasrc=true);
91 
93  bool jsonmode_;
96  int protocolnr_ = 0;
98  int retval_ = -1;
99 
100  virtual BufferString getSpecificUsage() const = 0;
101 
102  BufferString getKeyedArgStr(const char* ky,
103  bool mandatory=true) const;
104  DBKey getDBKey(const char* ky,bool mandatory=true) const;
105 
106  static void addToUsageStr(BufferString&,const char* flg,
107  const char* args,bool isextra=false);
108  void setStatus(bool) const;
110  void exitProgram(bool success);
111 
112  template <class T>
113  void setSingle(const char*,T,JSONObject*);
114  template <class T>
115  void setArr(const char*,const T&,JSONObject*);
116  template <class T>
117  void setArr(const char*,const T*,size_type,JSONObject*);
118 
119 };
ServerProgTool::sKeyTransGrp
static const char * sKeyTransGrp(int n=1)
Definition: serverprogtool.h:81
ServerProgTool
Definition: serverprogtool.h:26
ServerProgTool::sAllUsrCmd
static const char * sAllUsrCmd()
Definition: serverprogtool.h:80
ServerProgTool::exitProgram
void exitProgram(bool success) const
ServerProgTool::respondInfo
void respondInfo(bool success, bool exit=true) const
BufferStringSet
Set of BufferString objects.
Definition: bufstringset.h:26
od_int64
#define od_int64
Definition: plftypes.h:35
ServerProgTool::JSONArray
OD::JSON::Array JSONArray
Definition: serverprogtool.h:30
OD
OpendTect.
Definition: commontypes.h:28
mExpClass
#define mExpClass(module)
Definition: commondefs.h:177
od_istream
OD class for stream read common access to the std::cin.
Definition: od_istream.h:24
ServerProgTool::addToUsageStr
static void addToUsageStr(BufferString &, const char *flg, const char *args, bool isextra=false)
ServerProgTool::set
void set(const char *, const bool *, size_type, JSONObject *o=0)
ServerProgTool::sExistsUsrCmd
static const char * sExistsUsrCmd()
Definition: serverprogtool.h:78
ServerProgTool::sInfoUsrCmd
static const char * sInfoUsrCmd()
Definition: serverprogtool.h:79
genc.h
uiRetVal
Definition: uistringset.h:105
commandlineparser.h
CallBacker
Inherit from this class to be able to send and/or receive CallBacks.
Definition: callback.h:185
ServerProgTool::respondError
void respondError(const uiRetVal &) const
CommandLineParser
Definition: commandlineparser.h:53
mDeclServerProgToolSetFn
#define mDeclServerProgToolSetFn(typ)
Definition: serverprogtool.h:38
ServerProgTool::getKeyedArgStr
BufferString getKeyedArgStr(const char *ky, bool mandatory=true) const
ServerProgTool::exitProgram
void exitProgram(bool success)
ServerProgTool::jsonmode_
bool jsonmode_
Definition: serverprogtool.h:93
ServerProgTool::initParsing
void initParsing(int protocolnr, bool setdatasrc=true)
Timer
Timer class.
Definition: timer.h:25
ServerProgTool::respondError
void respondError(const char *) const
ServerProgTool::clp
CommandLineParser & clp()
Definition: serverprogtool.h:72
ServerProgTool::JSONObject
OD::JSON::Object JSONObject
Definition: serverprogtool.h:29
ServerProgTool::exitWithUsage
void exitWithUsage() const
sKey::Object
FixedString Object()
Definition: keystrs.h:112
ServerProgTool::clp_
CommandLineParser * clp_
Definition: serverprogtool.h:92
ServerProgTool::set
void set(const char *keyw, JSONArray *)
odruncontext.h
DBKey
Definition: dbkey.h:21
ServerProgTool::clp
const CommandLineParser & clp() const
Definition: serverprogtool.h:73
od_int16
#define od_int16
Definition: plftypes.h:26
ServerProgTool::setSingle
void setSingle(const char *, T, JSONObject *)
ServerProgTool::timer_
Timer & timer_
Definition: serverprogtool.h:97
OD::JSON::Array
ValueSet where the values and subsets have no key.
Definition: odjson.h:187
ServerProgTool::sListUsrCmd
static const char * sListUsrCmd()
Definition: serverprogtool.h:77
od_uint16
#define od_uint16
Definition: plftypes.h:27
ServerProgTool::jsonroot_
JSONObject & jsonroot_
Definition: serverprogtool.h:94
ServerProgTool::getSpecificUsage
virtual BufferString getSpecificUsage() const =0
BufferString
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size.
Definition: bufstring.h:40
od_int32
#define od_int32
Definition: plftypes.h:30
od_iosfwd.h
DBKeySet
Definition: dbkey.h:58
ServerProgTool::iop_
IOPar iop_
Definition: serverprogtool.h:95
ServerProgTool::set
void set(const char *keyw, JSONObject *)
iopar.h
ServerProgTool::ServerProgTool
ServerProgTool(int, char **, const char *moddep)
ServerProgTool::setArr
void setArr(const char *, const T *, size_type, JSONObject *)
ServerProgTool::setArr
void setArr(const char *, const T &, JSONObject *)
ServerProgTool::getDBKey
DBKey getDBKey(const char *ky, bool mandatory=true) const
od_uint32
#define od_uint32
Definition: plftypes.h:31
ServerProgTool::inStream
od_istream & inStream() const
ServerProgTool::mUseType
mUseType(TypeSet< int >, size_type)
od_ostream
OD class for stream write common access to the user log file, or std::cout in other than od_main.
Definition: od_ostream.h:26
ServerProgTool::setDBMDataSource
void setDBMDataSource()
ServerProgTool::setStatus
void setStatus(bool) const
ServerProgTool::timerTickCB
void timerTickCB(CallBacker *)
IOPar
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:55
ServerProgTool::~ServerProgTool
virtual ~ServerProgTool()
OD::JSON::Object
ValueSet where the values and subsets have a key.
Definition: odjson.h:283
ServerProgTool::outStream
od_ostream & outStream() const
mDeclServerProgToolSetFns
#define mDeclServerProgToolSetFns(typ)
Definition: serverprogtool.h:44
TypeSet< int >

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