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

src/hpp/dds/pub/AnyDataWriter.hpp

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

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