OpFlex Framework  1.7.0
URI.h
Go to the documentation of this file.
1 /* -*- C++ -*-; c-basic-offset: 4; indent-tabs-mode: nil */
6 /*
7  * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
8  *
9  * This program and the accompanying materials are made available under the
10  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
11  * and is available at http://www.eclipse.org/legal/epl-v10.html
12  */
13 
14 #ifndef MODB_URI_H
15 #define MODB_URI_H
16 
17 #include <boost/any.hpp>
18 #include <boost/functional/hash.hpp>
19 
20 #include <string>
21 #include <vector>
22 
23 #include "opflex/ofcore/OFTypes.h"
24 
25 namespace opflex {
26 namespace modb {
27 
43 class URI {
44 public:
48  explicit URI(const OF_SHARED_PTR<const std::string>& uri);
49 
53  explicit URI(const std::string& uri);
54 
58  URI(const URI& uri);
59 
63  ~URI();
64 
68  const std::string& toString() const;
69 
74  void getElements(/* out */ std::vector<std::string>& elements) const;
75 
79  URI& operator=( const URI& rhs );
80 
84  static const URI ROOT;
85 
86 private:
87  OF_SHARED_PTR<const std::string> uri;
88  size_t hashv;
89 
90  friend bool operator==(const URI& lhs, const URI& rhs);
91  friend bool operator!=(const URI& lhs, const URI& rhs);
92  friend bool operator<(const URI& lhs, const URI& rhs);
93  friend size_t hash_value(URI const& uri);
94 };
95 
99 std::ostream & operator<<(std::ostream &os, const URI& uri);
100 
104 bool operator==(const URI& lhs, const URI& rhs);
108 bool operator!=(const URI& lhs, const URI& rhs);
112 bool operator<(const URI& lhs, const URI& rhs);
117 size_t hash_value(URI const& uri);
118 
119 /* @} modb */
120 /* @} cpp */
121 
122 } /* namespace modb */
123 } /* namespace opflex */
124 
125 #if __cplusplus > 199711L
126 
127 namespace std {
132 template<> struct hash<opflex::modb::URI> {
136  std::size_t operator()(const opflex::modb::URI& u) const;
137 };
138 } /* namespace std */
139 
140 #endif
141 
142 #endif /* MODB_URI_H */
~URI()
Destroy the URI.
std::ostream & operator<<(std::ostream &os, const URI &uri)
URI stream insertion.
bool operator==(const URI &lhs, const URI &rhs)
Check for URI equality.
URI & operator=(const URI &rhs)
Assignment operator.
bool operator<(const URI &lhs, const URI &rhs)
Comparison operator for sorting.
friend size_t hash_value(URI const &uri)
Compute a hash value for the URI, making URI suitable as a key in a boost::unordered_map.
static const URI ROOT
Static root URI.
Definition: URI.h:84
bool operator!=(const URI &lhs, const URI &rhs)
Check for URI inequality.
size_t hash_value(URI const &uri)
Compute a hash value for the URI, making URI suitable as a key in a boost::unordered_map.
Definition: OFLogHandler.h:20
friend bool operator<(const URI &lhs, const URI &rhs)
Comparison operator for sorting.
const std::string & toString() const
Get the URI represented as a string.
A URI is used to identify managed objects in the MODB.
Definition: URI.h:43
friend bool operator!=(const URI &lhs, const URI &rhs)
Check for URI inequality.
URI(const OF_SHARED_PTR< const std::string > &uri)
Construct a URI using the given string representation.
void getElements(std::vector< std::string > &elements) const
Parse the URI and get the unescaped path elements from the URI.
friend bool operator==(const URI &lhs, const URI &rhs)
Check for URI equality.