00001 #ifndef INCLUDE_PARTIALPTRS_H 00002 #define INCLUDE_PARTIALPTRS_H 00003 /* 00004 * This is the Loris C++ Class Library, implementing analysis, 00005 * manipulation, and synthesis of digitized sounds using the Reassigned 00006 * Bandwidth-Enhanced Additive Sound Model. 00007 * 00008 * Loris is Copyright (c) 1999-2010 by Kelly Fitz and Lippold Haken 00009 * 00010 * This program is free software; you can redistribute it and/or modify 00011 * it under the terms of the GNU General Public License as published by 00012 * the Free Software Foundation; either version 2 of the License, or 00013 * (at your option) any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY, without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * You should have received a copy of the GNU General Public License 00021 * along with this program; if not, write to the Free Software 00022 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00023 * 00024 * 00025 * PartialPtrs.h 00026 * 00027 * Type definition of Loris::PartialPtrs. 00028 * 00029 * PartialPtrs is a collection of pointers to Partials that 00030 * can be used (among other things) for algorithms that operate 00031 * on a range of Partials, but don't rely on access to their 00032 * container. 00033 * 00034 * Kelly Fitz, 23 May 2002 00035 * loris@cerlsoundgroup.org 00036 * 00037 * http://www.cerlsoundgroup.org/Loris/ 00038 * 00039 */ 00040 00041 #include "Partial.h" 00042 #include <iterator> 00043 #include <vector> 00044 00045 // begin namespace 00046 namespace Loris { 00047 00048 00049 // --------------------------------------------------------------------------- 00050 // class PartialPtrs 00051 // 00052 // PartialPtrs is a typedef for a std::vectror<> of pointers to Loris 00053 // Partials. The oscciated bidirectional iterators are also defined as 00054 // PartialPtrsIterator and PartialPtrsConstIterator. Since these are 00055 // simply typedefs, they classes have identical interfaces to 00056 // std::vector, std::vector::iterator, and std::vector::const_iterator, 00057 // respectively. 00058 // 00059 // PartialPtrs is a collection of pointers to Partials that can be used 00060 // (among other things) for algorithms that operate on a range of 00061 // Partials, but don't rely on access to their container. A template 00062 // function defined in a header file can convert a range of Partials to a 00063 // PartialPtrs using the template free function fillPartialPtrs() (see 00064 // below), and pass the latter to the algorithm implementation, thereby 00065 // generalizing access to the algorithm across containers without 00066 // exposing the implementation in the header file. 00067 // 00068 typedef std::vector< Partial * > PartialPtrs; 00069 typedef std::vector< Partial * >::iterator PartialPtrsIterator; 00070 typedef std::vector< Partial * >::const_iterator PartialPtrsConstIterator; 00071 00072 typedef std::vector< const Partial * > ConstPartialPtrs; 00073 typedef std::vector< const Partial * >::iterator ConstPartialPtrsIterator; 00074 typedef std::vector< const Partial * >::const_iterator ConstPartialPtrsConstIterator; 00075 00076 00077 // --------------------------------------------------------------------------- 00078 // fillPartialPtrs 00079 // --------------------------------------------------------------------------- 00080 // Fill the specified PartialPtrs with pointers to the Partials n the 00081 // specified half-open (STL-style) range. This is a generally useful 00082 // operation that can be used to adapt algorithms to work with arbitrary 00083 // containers of Partials without exposing the algorithms themselves in 00084 // the header files. 00085 // 00086 template <typename Iter> 00087 void fillPartialPtrs( Iter begin, Iter end, PartialPtrs & fillme ) 00088 { 00089 fillme.reserve( std::distance( begin, end ) ); 00090 fillme.clear(); 00091 while ( begin != end ) 00092 fillme.push_back( &(*begin++) ); 00093 } 00094 00095 template <typename Iter> 00096 void fillPartialPtrs( Iter begin, Iter end, ConstPartialPtrs & fillme ) 00097 { 00098 fillme.reserve( std::distance( begin, end ) ); 00099 fillme.clear(); 00100 while ( begin != end ) 00101 fillme.push_back( &(*begin++) ); 00102 } 00103 00104 } // end of namespace Loris 00105 00106 #endif /* ndef INCLUDE_PARTIALPTRS_H */