libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/sound/dynamic_buffer_range.hpp
Go to the documentation of this file.
00001 
00011 /*
00012  *  Copyright (C) 2010 Juan Pedro Bolivar Puente
00013  *
00014  *  This file is part of Psychosynth.
00015  *   
00016  *  Psychosynth is free software: you can redistribute it and/or modify
00017  *  it under the terms of the GNU General Public License as published by
00018  *  the Free Software Foundation, either version 3 of the License, or
00019  *  (at your option) any later version.
00020  *
00021  *  Psychosynth is distributed in the hope that it will be useful,
00022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  *  GNU General Public License for more details.
00025  *
00026  *  You should have received a copy of the GNU General Public License
00027  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00028  *
00029  */
00030 
00031 /*
00032  *  Copyright 2005-2007 Adobe Systems Incorporated
00033  * 
00034  *  Use, modification and distribution are subject to the Boost
00035  *  Software License, Version 1.0. (See accompanying file
00036  *  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
00037  */
00038 
00039 #ifndef PSYNTH_SOUND_DYNAMIC_BUFFER_RANGE_HPP
00040 #define PSYNTH_SOUND_DYNAMIC_BUFFER_RANGE_HPP
00041 
00042 #include <psynth/sound/buffer_range.hpp>
00043 #include <psynth/sound/variant.hpp>
00044 #include <psynth/sound/buffer.hpp>
00045 
00046 namespace psynth
00047 {
00048 
00049 namespace mpl = boost::mpl;
00050 
00051 namespace sound
00052 {
00053 
00054 namespace detail
00055 {
00056 
00057 template <typename Range>
00058 struct get_const_type
00059 {
00060     typedef typename Range::const_type type;
00061 };
00062 
00063 template <typename Ranges>
00064 struct ranges_get_const_type :
00065         public mpl::transform<Ranges,
00066                               mpl::quote1<get_const_type> > {};
00067 
00068 } /* namespace detail */
00069 
00070 template <typename Range>
00071 struct dynamic_step_type;
00072 
00073 namespace detail
00074 {
00075 
00076 struct dynamic_type_get_num_samples
00077 {   // works for both buffer_range and buffer
00078     typedef int result_type;
00079     template <typename T>
00080     result_type operator () (const T& v) const
00081     { return num_samples<T>::value; }
00082 };
00083 
00084 struct dynamic_type_get_size
00085 {   // works for both buffer_range and buffer
00086     typedef std::ptrdiff_t result_type;
00087     template <typename T>
00088     result_type operator () (const T& v) const
00089     { return v.size (); }
00090 };
00091 
00092 } /* namespace detail */
00093 
00121 template <typename BufferRangeTypes>
00122 class dynamic_buffer_range : public variant<BufferRangeTypes>
00123 {
00124     typedef variant<BufferRangeTypes> parent_type;
00125 
00126 public:
00127     typedef dynamic_buffer_range<
00128     typename detail::ranges_get_const_type<BufferRangeTypes>::type>
00129     const_range;
00130     
00131     typedef std::size_t    size_type;
00132     typedef std::ptrdiff_t difference_type;
00133 
00134     dynamic_buffer_range ()
00135         : parent_type () {}
00136     
00137     template <typename T>
00138     explicit dynamic_buffer_range (const T& obj) throw ()
00139         : parent_type (obj) {}
00140     
00141     dynamic_buffer_range (const dynamic_buffer_range& v) 
00142         : parent_type ((const parent_type&) v)
00143     {}
00144 
00145     template <typename T>
00146     dynamic_buffer_range& operator= (const T& obj)
00147     {
00148         parent_type::operator= (obj);
00149         return *this;
00150     }
00151     
00152     dynamic_buffer_range& operator= (const dynamic_buffer_range& v)
00153     {
00154         parent_type::operator= ((const parent_type&) v);
00155         return *this;
00156     }
00157 
00158     std::size_t num_samples () const
00159     {
00160         return apply_operation (*this, detail::dynamic_type_get_num_samples ());
00161     }
00162     
00163     size_type size () const
00164     {
00165         return apply_operation (*this, detail::dynamic_type_get_size ());
00166     }
00167 };
00168 
00169 /*
00170  *
00171  *     HasDynamicStepTypeConcept
00172  *
00173  */
00174 template <typename IVTypes>
00175 struct dynamic_step_type<dynamic_buffer_range<IVTypes> >
00176 {
00177     typedef dynamic_buffer_range<
00178         typename boost::mpl::transform<
00179             IVTypes, mpl::quote1<dynamic_step_type> >::type> type;
00180 };
00181 
00182 } /* namespace sound */
00183 } /* namespace psynth */
00184 
00185 #endif /* PSYNTH_SOUND_DYNAMIC_BUFFER_RANGE */