MongoDB C++ Driver  legacy-1.0.5
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
hostandport.h
1 /* Copyright 2009 10gen Inc.
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #pragma once
17 
18 #include <iosfwd>
19 #include <string>
20 
21 #include "mongo/bson/util/builder.h"
22 #include "mongo/platform/hash_namespace.h"
23 
24 namespace mongo {
25  class Status;
26  class StringData;
27  template <typename T> class StatusWith;
28 
36  struct MONGO_CLIENT_API HostAndPort {
37 
42  static StatusWith<HostAndPort> MONGO_CLIENT_FUNC parse(const StringData& text);
43 
47  HostAndPort();
48 
53  explicit HostAndPort(const StringData& text);
54 
60  HostAndPort(const std::string& h, int p);
61 
68  Status initialize(const StringData& s);
69 
70  bool operator<(const HostAndPort& r) const;
71  bool operator==(const HostAndPort& r) const;
72  bool operator!=(const HostAndPort& r) const { return !(*this == r); }
73 
80  bool isLocalHost() const;
81 
85  std::string toString() const;
86 
90  void append( StringBuilder& ss ) const;
91 
95  bool empty() const;
96 
97  const std::string& host() const {
98  return _host;
99  }
100  int port() const;
101 
102  bool hasPort() const {
103  return _port >= 0;
104  }
105 
106  private:
107  std::string _host;
108  int _port; // -1 indicates unspecified
109  };
110 
111  MONGO_CLIENT_API std::ostream& MONGO_CLIENT_FUNC operator<<(std::ostream& os, const HostAndPort& hp);
112 
113 } // namespace mongo
114 
115 MONGO_HASH_NAMESPACE_START
116 
117 template <>
118 struct hash<mongo::HostAndPort> {
119  size_t operator()(const mongo::HostAndPort& host) const;
120 };
121 
122 MONGO_HASH_NAMESPACE_END
std::stringstream deals with locale so this is a lot faster than std::stringstream for UTF8 ...
Definition: builder.h:53
the main MongoDB namespace
Definition: bulk_operation_builder.h:24
Definition: sasl_client_conversation.h:27
Name of a process on the network.
Definition: hostandport.h:36
MONGO_CLIENT_API Status(MONGO_CLIENT_FUNC *saslClientAuthenticate)(DBClientWithCommands *client
Attempts to authenticate "client" using the SASL protocol.