VISR  0.11.7
Versatile Interactive Scene Renderer
fft_wrapper_factory.hpp
Go to the documentation of this file.
1 /* Copyright Institute of Sound and Vibration Research - All rights reserved */
2 
3 #ifndef VISR_LIBRBBL_FFT_WRAPPER_FACTORY_HPP_INCLUDED
4 #define VISR_LIBRBBL_FFT_WRAPPER_FACTORY_HPP_INCLUDED
5 
6 #include "export_symbols.hpp"
7 
8 #include <map>
9 #include <memory>
10 #include <string>
11 
12 #include <boost/algorithm/string.hpp> // for string conversion to lowercase
13 #include <boost/function.hpp>
14 
15 namespace visr
16 {
17 namespace rbbl
18 {
19 
20 // forward declaration
21 template<typename SampleType>
22 class FftWrapperBase;
23 
29 template<typename SampleType>
30 class VISR_RBBL_LIBRARY_SYMBOL FftWrapperFactory
31 {
32 public:
40  static std::unique_ptr<FftWrapperBase<SampleType> >
41  create( std::string const & wrapperName, std::size_t fftSize, std::size_t alignElements );
42 
46  template< class FftWrapper >
47  static void registerWrapper( std::string const & wrapperName );
48 
53  static std::string listImplementations();
54 
55 private:
56  struct Creator
57  {
58  using CreateFunction = boost::function< FftWrapperBase<SampleType>* ( std::size_t, std::size_t ) >;
59 
60  explicit Creator( CreateFunction fcn );
61 
62  std::unique_ptr< FftWrapperBase<SampleType> > create( std::size_t fftSize,
63  std::size_t alignElements) const;
64  private:
65  CreateFunction mCreateFunction;
66  };
67 
68  template< class WrapperType >
69  class TCreator: public Creator
70  {
71  public:
72  TCreator( )
73  : Creator( &TCreator<WrapperType>::construct )
74  {
75  }
76 
77  static WrapperType* construct( std::size_t fftSize, std::size_t alignmentElement )
78  {
79  return new WrapperType( fftSize, alignmentElement );
80  }
81  };
82 
83  using CreatorTable = std::map<std::string, Creator >;
84 
85  static CreatorTable & creatorTable();
86 
91 };
92 
93 template< typename SampleType >
94 template< class WrapperType >
95 void FftWrapperFactory<SampleType>::registerWrapper( std::string const & wrapperName )
96 {
97  std::string lowerName(wrapperName); // convert the name to lower case.
98  boost::algorithm::to_lower(lowerName);
99  creatorTable().insert( std::make_pair( lowerName,
100  TCreator<WrapperType>() ) );
101 }
102 
103 } // namespace rbbl
104 } // namespace visr
105 
106 #endif // #ifndef VISR_LIBRBBL_FFT_WRAPPER_FACTORY_HPP_INCLUDED
Definition: fft_wrapper_factory.hpp:30
Definition: options.cpp:10
static void registerWrapper(std::string const &wrapperName)
Definition: fft_wrapper_factory.hpp:95