URI.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
3 
4  This file is part of the TerraLib - a Framework for building GIS enabled applications.
5 
6  TerraLib is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Lesser General Public License as published by
8  the Free Software Foundation, either version 3 of the License,
9  or (at your option) any later version.
10 
11  TerraLib is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public License
17  along with TerraLib. See COPYING. If not, write to
18  TerraLib Team at <terralib-team@terralib.org>.
19  */
20 
21 /*!
22  \file terralib/core/uri/URI.h
23 
24  \brief A class for representing an Uniform Resource Identifier (URI).
25 
26  \author Vinicius Campanha
27  \author Gilberto Ribeiro de Queiroz
28  */
29 
30 #ifndef __TERRALIB_CORE_URI_URI_H__
31 #define __TERRALIB_CORE_URI_URI_H__
32 
33 // TerraLib
34 #include "Config.h"
35 
36 // STL
37 #include <string>
38 #include <memory>
39 
40 namespace te
41 {
42  namespace core
43  {
44  /*!
45  \class URI
46 
47  \brief A class for representing an Uniform Resource Identifier (URI).
48  */
50  {
51  public:
52 
53  /*! \brief Default constructor. */
54  URI();
55 
56  /*!
57  \brief A constructor from a string.
58 
59  This constructor check the URI enconding,
60  then parse it and validate.
61 
62  \param uri A string with the URI to be parsed.
63 
64  \exception URIException when the given URI isn't valid.
65  */
66  explicit URI(const std::string& uri);
67 
68  /*! \brief Copy constructor. */
69  URI(const URI& other);
70 
71  /*! Default destructor. */
72  ~URI();
73 
74  /*! \brief Assingment operator. */
75  URI& operator=(const URI& other);
76 
77  /*!
78  \brief Retrieving the full URI
79 
80  \return Returns the complete URI.
81  */
82  const std::string& uri() const;
83 
84  /*!
85  \brief Retrieving the scheme
86 
87  \return Returns the URI scheme.
88  */
89  std::string scheme() const;
90 
91  /*!
92  \brief Retrieving the user information
93 
94  \return Returns the URI user information.
95  */
96  std::string user() const;
97 
98  /*!
99  \brief Retrieving the password information
100 
101  \return Returns the URI password information.
102  */
103  std::string password() const;
104 
105  /*!
106  \brief Retrieving the host
107 
108  \return Returns the URI host.
109  */
110  std::string host() const;
111 
112  /*!
113  \brief Retrieving the port
114 
115  \return Returns the URI port.
116  */
117  std::string port() const;
118 
119  /*!
120  \brief Retrieving the path
121 
122  \return Returns the URI path.
123  */
124  std::string path() const;
125 
126  /*!
127  \brief Retrieving the query
128 
129  \return Returns the URI query.
130  */
131  std::string query() const;
132 
133  /*!
134  \brief Retrieving the fragment
135 
136  \return Returns the URI fragment.
137  */
138  std::string fragment() const;
139 
140  /*!
141  \brief Return if the given URI is valid or not.
142 
143  \return Returns true if the given URI is valid.
144  */
145  bool isValid() const;
146 
147  private:
148 
149  /*! \brief Swap operation. */
150  void swap(URI& other);
151 
152  /*!
153  \brief Parse the URI stored in uri_ member.
154 
155  It uses regex to validate and parse the given URI.
156 
157  After this, if the given URI is valid, the match_ member
158  will have the references to all parts of the URI.
159 
160  The regex split the URI by using named groups in
161  regex, "(?<name>...)", so knowing the group name,
162  you can require the corresponding group, from match_.
163 
164  \exception URIException when the given URI isn't valid.
165  */
166  void parse();
167 
168  /*!
169  \brief Check if the uri_ contains any invalid character and parse
170  it to his hexadecimal value
171  */
172  void encode();
173 
174  std::string hexToLetter(int i);
175 
176  private:
177 
178  struct Impl;
179 
180  std::unique_ptr<Impl> m_pimpl;
181  };
182 
183  } // end namespace core
184 } // end namespace te
185 
186 #endif // __TERRALIB_CORE_URI_URI_H__
Configuration flags for URI support.
bool TECOMMONEXPORT parse(std::string::const_iterator &first, std::string::const_iterator last, authority &v)
Parse URI authority, returning whether found or not and advancing first and setting authority if foun...
std::string TECOMMONEXPORT encode(const traits &ts, const std::string &comp)
Encode the URI (sub) component.
#define TECOREEXPORT
Definition: Config.h:40
URI C++ Library.
A class for representing an Uniform Resource Identifier (URI).
Definition: URI.h:49
std::unique_ptr< Impl > m_pimpl
Definition: URI.h:178