Lunchbox  1.9.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
uri.h
1 
2 /* Copyright (c) 2013-2014, ahmet.bilgili@epfl.ch
3  * 2014, Stefan.Eilemann@epfl.ch
4  *
5  * This file is part of Lunchbox <https://github.com/Eyescale/Lunchbox>
6  *
7  * This library is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU Lesser General Public License version 2.1 as published
9  * by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  * details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef LUNCHBOX_URI_H
22 #define LUNCHBOX_URI_H
23 
24 #include <lunchbox/api.h>
25 #include <lunchbox/types.h>
26 #include <boost/unordered_map.hpp> // iterator typedefs
27 
28 namespace lunchbox
29 {
30 namespace detail { class URI; }
31 
55 class URI
56 {
57 public:
58  typedef boost::unordered_map< std::string, std::string > KVMap;
59  typedef KVMap::const_iterator ConstKVIter;
60 
67  LUNCHBOX_API URI( const std::string& uri );
68 
70  LUNCHBOX_API URI( const URI& from );
71 
72  LUNCHBOX_API ~URI();
73 
75  LUNCHBOX_API URI& operator = ( const URI& rhs );
76 
79  LUNCHBOX_API const std::string& getScheme() const;
80  LUNCHBOX_API const std::string& getUserinfo() const;
81  LUNCHBOX_API uint16_t getPort() const;
82  LUNCHBOX_API const std::string& getHost() const;
83  LUNCHBOX_API const std::string& getPath() const;
84  LUNCHBOX_API const std::string& getQuery() const;
85  LUNCHBOX_API const std::string& getFragment() const;
87 
94  LUNCHBOX_API ConstKVIter queryBegin() const;
95 
100  LUNCHBOX_API ConstKVIter queryEnd() const;
101 
106  LUNCHBOX_API ConstKVIter findQuery( const std::string& key ) const;
108 
109 private:
110  detail::URI* const _impl;
111 };
112 
113 inline std::ostream& operator << ( std::ostream& os, const URI& uri )
114 {
115  os << uri.getScheme() << "://";
116  if( !uri.getUserinfo().empty( ))
117  os << uri.getUserinfo() << "@";
118  os << uri.getHost();
119  if( uri.getPort( ))
120  os << ':' << uri.getPort();
121  os << uri.getPath() << '?' << uri.getQuery();
122  if( !uri.getFragment().empty( ))
123  os << '#' << uri.getFragment();
124  return os;
125 }
126 
127 }
128 #endif // LUNCHBOX_URI_H
Defines export visibility macros for Lunchbox.
Basic type definitions not provided by the operating system.
LUNCHBOX_API URI & operator=(const URI &rhs)
Assign the data from another URI.
LUNCHBOX_API URI(const std::string &uri)
LUNCHBOX_API ConstKVIter queryBegin() const
The URI class parses the given uri string according to the regex given in RFC3986.
Definition: uri.h:55
LUNCHBOX_API ConstKVIter queryEnd() const
LUNCHBOX_API ConstKVIter findQuery(const std::string &key) const
std::ostream & operator<<(std::ostream &os, const Array< T > &array)
Pretty-print all members of the array.
Definition: array.h:47