Multiscale Universal Interface  2.0
A Concurrent Framework for Coupling Heterogeneous Solvers
lib_uri.h
Go to the documentation of this file.
1 /*****************************************************************************
2 * Multiscale Universal Interface Code Coupling Library *
3 * *
4 * Copyright (C) 2019 Y. H. Tang, S. Kudo, X. Bian, Z. Li, G. E. Karniadakis *
5 * *
6 * This software is jointly licensed under the Apache License, Version 2.0 *
7 * and the GNU General Public License version 3, you may use it according *
8 * to either. *
9 * *
10 * ** Apache License, version 2.0 ** *
11 * *
12 * Licensed under the Apache License, Version 2.0 (the "License"); *
13 * you may not use this file except in compliance with the License. *
14 * You may obtain a copy of the License at *
15 * *
16 * http://www.apache.org/licenses/LICENSE-2.0 *
17 * *
18 * Unless required by applicable law or agreed to in writing, software *
19 * distributed under the License is distributed on an "AS IS" BASIS, *
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
21 * See the License for the specific language governing permissions and *
22 * limitations under the License. *
23 * *
24 * ** GNU General Public License, version 3 ** *
25 * *
26 * This program is free software: you can redistribute it and/or modify *
27 * it under the terms of the GNU General Public License as published by *
28 * the Free Software Foundation, either version 3 of the License, or *
29 * (at your option) any later version. *
30 * *
31 * This program is distributed in the hope that it will be useful, *
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
34 * GNU General Public License for more details. *
35 * *
36 * You should have received a copy of the GNU General Public License *
37 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
38 *****************************************************************************/
39 
48 #ifndef LIB_URI_H_
49 #define LIB_URI_H_
50 
51 #include "../general/util.h"
52 
53 namespace mui {
54 
55 class uri {
56 public:
57  uri(const std::string& url_s) {
58  parse(url_s);
59  }
60  uri(const char url_c[]) {
61  parse(url_c);
62  }
63  const std::string& protocol() const { return protocol_; }
64  const std::string& host() const { return host_; }
65  const std::string& path() const { return path_; }
66 
67  uri( const uri &another ) = delete;
68  uri& operator = ( const uri &another ) = delete;
69 private:
70  void parse(const std::string& url_s) {
71  // "__protocol__://__host__/__path__"
72  std::size_t prot_end = url_s.find("://");
73  protocol_ = url_s.substr(0,prot_end);
74  std::size_t host_end = url_s.find("/",prot_end+3);
75  host_ = url_s.substr(prot_end+3,host_end-prot_end-3);
76  path_ = url_s.substr(host_end+1);
77 
78  std::transform(protocol_.begin(), protocol_.end(), protocol_.begin(), ::tolower);
79  std::transform(host_.begin(), host_.end(), host_.begin(), ::tolower);
80  }
81 
82  std::string protocol_, host_, path_;
83 };
84 
85 }
86 
87 #endif /* LIB_URI_H_ */
Definition: lib_uri.h:55
uri(const uri &another)=delete
uri(const char url_c[])
Definition: lib_uri.h:60
const std::string & protocol() const
Definition: lib_uri.h:63
uri(const std::string &url_s)
Definition: lib_uri.h:57
const std::string & host() const
Definition: lib_uri.h:64
const std::string & path() const
Definition: lib_uri.h:65
uri & operator=(const uri &another)=delete
Definition: comm.h:54