Apache Qpid - AMQP Messaging for Java JMS, C++, Python, Ruby, and .NET | Apache Qpid Documentation |
00001 #ifndef QPID_ADDRESS_H 00002 #define QPID_ADDRESS_H 00003 00004 /* 00005 * 00006 * Copyright (c) 2006 The Apache Software Foundation 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); 00009 * you may not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * 00012 * http://www.apache.org/licenses/LICENSE-2.0 00013 * 00014 * Unless required by applicable law or agreed to in writing, software 00015 * distributed under the License is distributed on an "AS IS" BASIS, 00016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00017 * See the License for the specific language governing permissions and 00018 * limitations under the License. 00019 * 00020 */ 00021 00022 #include "qpid/sys/IntegerTypes.h" 00023 #include "qpid/CommonImportExport.h" 00024 #include <boost/variant.hpp> 00025 #include <iosfwd> 00026 #include <string> 00027 #include <vector> 00028 00029 namespace qpid { 00030 00032 struct TcpAddress { 00033 static const uint16_t DEFAULT_PORT=5672; 00034 QPID_COMMON_EXTERN explicit TcpAddress(const std::string& host_=std::string(),uint16_t port_=DEFAULT_PORT); 00035 std::string host; 00036 uint16_t port; 00037 }; 00038 bool operator==(const TcpAddress& x, const TcpAddress& y); 00039 QPID_COMMON_EXTERN std::ostream& operator<<(std::ostream& os, const TcpAddress& a); 00040 00045 struct ExampleAddress { 00046 explicit ExampleAddress(char data); 00047 char data; 00048 }; 00049 bool operator==(const ExampleAddress& x, const ExampleAddress& y); 00050 std::ostream& operator<<(std::ostream& os, const ExampleAddress& a); 00051 00056 struct Address { 00057 public: 00058 Address(const Address& a) : value(a.value) {} 00059 Address(const TcpAddress& tcp) : value(tcp) {} 00060 Address(const ExampleAddress& eg) : value(eg) {} 00061 00062 template <class AddressType> Address& operator=(const AddressType& t) { value=t; return *this; } 00063 00068 template <class AddressType> AddressType* get() { return boost::get<AddressType>(&value); } 00069 00074 template <class AddressType> const AddressType* get() const { return boost::get<AddressType>(&value); } 00075 00076 private: 00077 boost::variant<TcpAddress,ExampleAddress> value; 00078 friend std::ostream& operator<<(std::ostream& os, const Address& addr); 00079 }; 00080 00081 00082 00083 } // namespace qpid 00084 00085 #endif