• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

src/hpp/dds/topic/AnyTopicDescription.hpp

Go to the documentation of this file.
00001 #ifndef OMG_DDS_TOPIC_ANY_TOPIC_DESCRIPTION_HPP_
00002 #define OMG_DDS_TOPIC_ANY_TOPIC_DESCRIPTION_HPP_
00003 
00004 /* Copyright 2010, Object Management Group, Inc.
00005  * Copyright 2010, PrismTech, Corp.
00006  * Copyright 2010, Real-Time Innovations, Inc.
00007  * All rights reserved.
00008  *
00009  * Licensed under the Apache License, Version 2.0 (the "License");
00010  * you may not use this file except in compliance with the License.
00011  * You may obtain a copy of the License at
00012  *
00013  *     http://www.apache.org/licenses/LICENSE-2.0
00014  *
00015  * Unless required by applicable law or agreed to in writing, software
00016  * distributed under the License is distributed on an "AS IS" BASIS,
00017  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00018  * See the License for the specific language governing permissions and
00019  * limitations under the License.
00020  */
00021 
00022 #include <dds/core/Exception.hpp>
00023 #include <dds/topic/topicfwd.hpp>
00024 #include <dds/topic/detail/AnyTopicDescription.hpp>
00025 
00026 
00027 namespace dds { namespace topic {
00028 
00029 class AnyTopicDescription {
00030 public:
00031     template <typename T>
00032     inline AnyTopicDescription(const T& t)
00033     : holder_(new detail::TDHolder<T>(t)) { }
00034 
00035     const detail::TDHolderBase* operator->() const {
00036         return holder_;
00037     }
00038 
00039     detail::TDHolderBase* operator->() {
00040         return holder_;
00041     }
00042 
00043     inline ~AnyTopicDescription() {
00044         delete holder_;
00045     }
00046 
00047 protected:
00048     inline AnyTopicDescription(detail::TDHolderBase* holder)
00049     : holder_(holder) { }
00050 
00051 public:
00052     inline AnyTopicDescription& swap(AnyTopicDescription& rhs) {
00053         std::swap(holder_, rhs.holder_);
00054         return *this;
00055     }
00056 
00057     template <typename TOPIC>
00058     AnyTopicDescription& operator =(const TOPIC& rhs) {
00059         AnyTopicDescription(rhs).swap(*this);
00060         return *this;
00061     }
00062 
00063     inline AnyTopicDescription& operator =(AnyTopicDescription rhs) {
00064         rhs.swap(*this);
00065         return *this;
00066     }
00067 
00068 public:
00069     template <typename T>
00070     const T& get() {
00071         detail::TDHolder<T>* h = dynamic_cast<detail::TDHolder<T>* >(holder_);
00072         if (h == 0) {
00073             throw dds::core::InvalidDowncastError("invalid type");
00074         }
00075         return h->get();
00076     }
00077 
00078 protected:
00079     detail::TDHolderBase* holder_;
00080 };
00081 
00082 }}
00083 
00084 #endif /* OMG_DDS_TOPIC_ANY_TOPIC_DESCRIPTION_HPP_ */

Generated on Tue Nov 9 2010 02:16:21 for dds-psm-cxx-doc by  doxygen 1.7.1