SAGA Adaptor CPI v.1.0
adaptor_data.hpp
Go to the documentation of this file.
00001 //  Copyright (c) 2005-2009 Hartmut Kaiser
00002 //  Copyright (c) 2005 Stephan Hirmer (stephan.hirmer@gmail.com)
00003 // 
00004 //  Distributed under the Boost Software License, Version 1.0. (See accompanying 
00005 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
00006 
00007 #ifndef SAGA_SAGA_ADAPTORS_ADAPTOR_DATA_HPP
00008 #define SAGA_SAGA_ADAPTORS_ADAPTOR_DATA_HPP
00009 
00010 #include <boost/noncopyable.hpp>
00011 
00012 #include <saga/saga/adaptors/config.hpp>
00013 #include <saga/impl/engine/cpi.hpp>
00014 
00016 namespace saga { namespace adaptors {
00017  
00027     template <typename Adaptor>
00028     class adaptor_data
00029     :   public boost::noncopyable
00030     {
00031     private:
00032         typedef saga::impl::v1_0::cpi cpi;
00033 
00034         // this holds the locked data
00035         TR1::shared_ptr <Adaptor> adaptor_;
00036         
00037     public:
00038         typedef Adaptor adaptor_type;
00039 
00047         template <typename Cpi>
00048         adaptor_data(Cpi *cpi_instance)
00049             : adaptor_ (TR1::static_pointer_cast<Adaptor>(
00050                 cpi_instance->get_adaptor())) 
00051         {
00052             adaptor_->lock_data();
00053         }
00054         
00058         ~adaptor_data (void)
00059         {
00060             if (adaptor_) 
00061                 adaptor_->unlock_data();
00062         }
00063 
00064         // automatic conversion to the actual adaptor data type is provided
00065         Adaptor * operator->() const
00066         {
00067             return boost::get_pointer(adaptor_);
00068         }
00069     };
00070 
00071 }} // namespace saga::adaptors
00073 
00074 #endif  // SAGA_SAGA_ADAPTORS_ADAPTOR_DATA_HPP
00075 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines