OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimUrl.cpp
Go to the documentation of this file.
1 #include <ossim/base/ossimUrl.h>
2 
4 {
5 
6 }
7 
9 {
10  setFieldsFromUrl(url);
11 }
12 
14  const ossimString& ip,
15  const ossimString& port,
16  const ossimString& path,
17  const ossimString& params)
18 :m_protocol(protocol),
19 m_ip(ip),
20 m_port(port),
21 m_path(path),
22 m_params(params)
23 {
24 
25 }
27 {
28  const std::string& s = ip.string();
29  std::string::size_type pos = s.find_first_of(':');
30  if(pos != std::string::npos)
31  {
32  m_ip = ossimString(s.begin(), s.begin()+pos);
33  m_port = ossimString(s.begin()+pos+1, s.end());
34  }
35  else
36  {
37  m_ip = ip;
38  }
39 }
40 
42 {
43  m_params = "";
44  const ossimKeywordlist::KeywordMap& map = kwl.getMap();
45  ossimKeywordlist::KeywordMap::const_iterator iter = map.begin();
46  while(iter!=map.end())
47  {
48  if(m_params.empty())
49  {
50  m_params = iter->first + "=" + iter->second;
51  }
52  else
53  {
54  m_params+=("&"+iter->first + "=" + iter->second);
55  }
56  ++iter;
57  }
58 }
59 
61 {
62  m_protocol = m_ip = m_port = m_path = m_params = "";
63 
64  // look for something of the form <protocol>://
65  const std::string& s = url.string();
66  std::string::size_type pos = s.find_first_of(":");
67 
68  if(pos == std::string::npos) return;
69 
70  m_protocol = ossimString(s.begin(), s.begin()+pos);
71 
72  // now find the ip and then extract port if embedded in IP
73  //
74  pos = s.find_first_not_of('/', pos+1);
75 
76  if(pos == std::string::npos) return;
77 
78  std::string::size_type nextPos = s.find_first_of('/', pos+1);
79 
80  if(nextPos == std::string::npos)
81  {
82  setIp(ossimString(s.begin()+pos, s.end()));
83  return;
84  }
85  else
86  {
87  setIp(ossimString(s.begin()+pos, s.begin()+nextPos));
88  }
89  // now find the path portion
90  //
91  pos = s.find_first_of('?', nextPos);
92  if(pos == std::string::npos)
93  {
94  m_path = ossimString(s.begin()+nextPos+1, s.end());
95  return;
96  }
97  else
98  {
99  m_path = ossimString(s.begin()+nextPos+1, s.begin()+pos);
100  }
101 
102  m_params = ossimString(s.begin()+pos+1, s.end());
103 
104 }
105 
107 {
108  return (m_protocol+"://"+m_ip + (m_port.empty()?"":":"+m_port) +"/"+m_path + (m_params.empty()?"":("?"+m_params)));
109 }
void setFieldsFromUrl(const ossimString &url)
Definition: ossimUrl.cpp:60
ossimString m_port
Definition: ossimUrl.h:37
Represents serializable keyword/value map.
ossimString m_protocol
Definition: ossimUrl.h:35
ossimString m_ip
Definition: ossimUrl.h:36
void setIp(const ossimString &ip)
Definition: ossimUrl.cpp:26
std::string::iterator end()
Definition: ossimString.h:423
std::string::size_type find_first_of(char c, std::string::size_type pos=0) const
Equivalent to find(c, pos).
Definition: ossimString.h:801
ossimString toString() const
Definition: ossimUrl.cpp:106
std::map< std::string, std::string > KeywordMap
std::string::size_type find_first_not_of(char c, std::string::size_type pos=0) const
Returns the smallest character position N such that pos <= N < size(), and such that (*this)[N] does ...
Definition: ossimString.h:813
std::string::iterator begin()
Definition: ossimString.h:420
ossimString m_params
Definition: ossimUrl.h:39
ossimUrl()
Definition: ossimUrl.cpp:3
const ossimKeywordlist::KeywordMap & getMap() const
ossimString m_path
Definition: ossimUrl.h:38
bool empty() const
Definition: ossimString.h:411
void setParams(const ossimString &params)
Definition: ossimUrl.h:27
const std::string & string() const
Definition: ossimString.h:414