DABC (Data Acquisition Backbone Core)  2.9.9
Url.h
Go to the documentation of this file.
1 // $Id: Url.h 4421 2019-10-10 19:23:30Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #ifndef DABC_Url
17 #define DABC_Url
18 
19 #ifndef DABC_string
20 #include "dabc/string.h"
21 #endif
22 
23 namespace dabc {
24 
33  class Url {
34  protected:
35  std::string fUrl;
36  bool fValid;
37  std::string fProtocol;
38  std::string fHostName;
39  int fPort;
40  std::string fFileName;
41  std::string fOptions;
42 
43  bool GetOption(const std::string &optname, int optionnumber = -1, std::string *value = nullptr) const;
44 
45  public:
46  Url();
47  Url(const char* url);
48  Url(const std::string &url);
49  virtual ~Url();
50 
51  void Reset();
52  bool SetUrl(const std::string &url, bool showerr = true);
53 
54  std::string GetUrl() const { return fUrl; }
55  bool IsValid() const { return fValid; }
56 
57  std::string GetProtocol() const { return fProtocol; }
58  std::string GetHostName() const { return fHostName; }
59  int GetPort() const { return fPort; }
60  std::string GetPortStr() const;
61  std::string GetHostNameWithPort(int dfltport = 0) const;
62  std::string GetFileName() const { return fFileName; }
63  std::string GetOptions() const { return fOptions; }
64  std::string GetFullName() const;
65 
67  void SetOptions(const std::string &opt);
68 
69  std::string GetOptionsPart(int number = 0) const;
70  bool HasOption(const std::string &optname) const { return GetOption(optname); }
71  std::string GetOptionStr(const std::string &optname, const std::string &dflt = "") const;
72  int GetOptionInt(const std::string &optname, int dflt = 0) const;
73  double GetOptionDouble(const std::string &optname, double dflt = 0.) const;
74  bool GetOptionBool(const std::string &optname, bool dflt = false) const;
75 
77  static std::string ComposeItemName(int nodeid, const std::string &itemname = "");
78 
83  static std::string ComposePortName(int nodeid, const std::string &fullportname, int portid = -1);
84 
86  static bool DecomposeItemName(const std::string &url, int& nodeid, std::string& itemtname);
87 
89  static void ReplaceSpecialSymbols(std::string& opt);
90  };
91 }
92 
93 #endif
Uniform Resource Locator interpreter.
Definition: Url.h:33
std::string fFileName
file name
Definition: Url.h:40
std::string fUrl
Full URL.
Definition: Url.h:35
std::string GetOptionsPart(int number=0) const
Definition: Url.cxx:195
std::string fHostName
host name
Definition: Url.h:38
std::string GetOptionStr(const std::string &optname, const std::string &dflt="") const
Definition: Url.cxx:281
bool SetUrl(const std::string &url, bool showerr=true)
Definition: Url.cxx:46
std::string GetFullName() const
Definition: Url.cxx:124
bool GetOptionBool(const std::string &optname, bool dflt=false) const
Definition: Url.cxx:314
std::string GetFileName() const
Definition: Url.h:62
bool HasOption(const std::string &optname) const
Definition: Url.h:70
int GetOptionInt(const std::string &optname, int dflt=0) const
Definition: Url.cxx:290
std::string fOptions
list of options
Definition: Url.h:41
std::string GetHostName() const
Definition: Url.h:58
std::string GetProtocol() const
Definition: Url.h:57
Url()
Definition: Url.cxx:21
std::string GetPortStr() const
Definition: Url.cxx:132
void Reset()
Definition: Url.cxx:40
std::string fProtocol
protocol
Definition: Url.h:37
static void ReplaceSpecialSymbols(std::string &opt)
!
Definition: Url.cxx:109
bool fValid
Is URL valid.
Definition: Url.h:36
std::string GetHostNameWithPort(int dfltport=0) const
Definition: Url.cxx:139
static bool DecomposeItemName(const std::string &url, int &nodeid, std::string &itemtname)
Method decompose from url nodeid and full item name, which includes all parents.
Definition: Url.cxx:167
virtual ~Url()
Definition: Url.cxx:36
std::string GetOptions() const
Definition: Url.h:63
double GetOptionDouble(const std::string &optname, double dflt=0.) const
Definition: Url.cxx:302
int GetPort() const
Definition: Url.h:59
void SetOptions(const std::string &opt)
Method allows to set URL options directly to be able use all Get methods.
Definition: Url.cxx:102
bool GetOption(const std::string &optname, int optionnumber=-1, std::string *value=nullptr) const
Definition: Url.cxx:203
int fPort
port number
Definition: Url.h:39
std::string GetUrl() const
Definition: Url.h:54
static std::string ComposeItemName(int nodeid, const std::string &itemname="")
!
Definition: Url.cxx:147
bool IsValid() const
Definition: Url.h:55
static std::string ComposePortName(int nodeid, const std::string &fullportname, int portid=-1)
! Method creates url string with port address, which includes nodeid and full portname If optional pa...
Definition: Url.cxx:154
Event manipulation API.
Definition: api.h:23