ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
uri.cpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_ocm_libdaqif_suppport
4  * @copyright 2022 ESO - European Southern Observatory
5  *
6  * @brief Contains definitions for daqif/uri.hpp
7  */
8 #include <stdexcept>
9 #include <daqif/uri.hpp>
10 
11 namespace daqif {
12 
13 network::uri MakeServerUri(std::string uri) {
14  uri.erase(uri.find_last_not_of('/') + 1u);
15  uri.append(1u, '/');
16  return network::uri(uri);
17 }
18 
19 network::uri MakeServiceUri(std::string base_uri, std::string_view service_path) {
20  // Strip any trailing slashes
21  base_uri.erase(base_uri.find_last_not_of('/') + 1u);
22  // Strip leading slashes from service_path
23  service_path.remove_prefix(std::min(service_path.find_first_not_of('/'),
24  service_path.size()));
25  if (base_uri.empty()) {
26  throw std::invalid_argument("base_uri argument is empty after stripping trailing slashes");
27  }
28  if (service_path.empty()) {
29  throw std::invalid_argument("service_path argument is empty after stripping leading "
30  "slashes");
31  }
32 
33  base_uri.append(1u, '/');
34  base_uri.append(service_path);
35  return network::uri(base_uri);
36 }
37 
38 } // namespace daqif
network::uri MakeServerUri(std::string uri)
Creates a server URI.
Definition: uri.cpp:13
network::uri MakeServiceUri(std::string base_uri, std::string_view service_path)
Creates a service URI of the form <baseuri>/<service>.
Definition: uri.cpp:19
Contains URI support functions for daqif.