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

src/hpp/dds/sub/AnyDataReader.hpp

Go to the documentation of this file.
00001 #ifndef OMG_DDS_SUB_ANY_DATA_READER_HPP_
00002 #define OMG_DDS_SUB_ANY_DATA_READER_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/sub/subfwd.hpp>
00024 #include <dds/sub/detail/AnyDataReader.hpp>
00025 
00026 namespace dds { namespace sub {
00027 class AnyDataReader {
00028 public:
00029     template <typename DR>
00030     AnyDataReader(const DR& dr)  {
00031         holder_ = new detail::DRHolder<DR>(dr);
00032     }
00033 
00034     inline const detail::DRHolderBase* operator->() const {
00035         return holder_;
00036     }
00037 
00038     inline detail::DRHolderBase* operator->() {
00039         return holder_;
00040     }
00041 
00042     inline ~AnyDataReader() {
00043         delete holder_;
00044     }
00045 
00046 public:
00047     inline AnyDataReader& swap(AnyDataReader& rhs) {
00048         std::swap(holder_, rhs.holder_);
00049         return *this;
00050     }
00051 
00052     template <typename TOPIC>
00053     AnyDataReader& operator =(const TOPIC& rhs) {
00054         AnyDataReader(rhs).swap(*this);
00055         return *this;
00056     }
00057 
00058     inline AnyDataReader& operator =(AnyDataReader rhs) {
00059         rhs.swap(*this);
00060         return *this;
00061     }
00062 
00063 public:
00064     template <typename DR>
00065     const DR& get() {
00066         detail::DRHolder<DR>* h = dynamic_cast<detail::DRHolder<DR>* >(holder_);
00067         if (h == 0) {
00068             throw dds::core::InvalidDowncastError("invalid type");
00069         }
00070         return h->get();
00071     }
00072 private:
00073     detail::DRHolderBase* holder_;
00074 };
00075 
00076 }}
00077 
00078 #endif /* OMG_DDS_SUB_ANY_DATA_READER_HPP_ */

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