FTransformAgent.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2006 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9#ifndef __FTransformAgent_h_
10#define __FTransformAgent_h_
11
12#include "FTransformPlan.h"
13#include "ThreadContext.h"
14
15namespace FTransform {
16
18 class Agent : public Reference::Able {
19
20 public:
21
22 Agent();
23
24 virtual ~Agent();
25
27 std::string name;
28
31
33 virtual Plan* get_plan (size_t nfft, type call) = 0;
34
36 virtual Plan2* get_plan2 (size_t nx, size_t ny, type call) = 0;
37
39 virtual void clean_plans () = 0;
40
42 static unsigned get_num_libraries ()
43 { return libraries.size(); }
44
46 static std::string get_library_name (unsigned i)
47 { return libraries[i]->name; }
48
50 static void set_library (const std::string& name);
51
54
57
58 protected:
59
61 void add ();
62
63 private:
64
66 static std::vector< Reference::To<Agent> > libraries;
67
68 friend void set_library (const std::string& name);
69 friend void clean_plans();
70
71 };
72
73
75
77
78 template <class Library>
79 class PlanAgent : public Agent {
80
81 public:
82
84 PlanAgent (const std::string& name, normalization norm);
85
87 typename Library::Plan* get_plan (size_t nfft, type call);
88
90 typename Library::Plan2* get_plan2 (size_t nx, size_t ny, type call);
91
93 void clean_plans ();
94
96 static void enlist ();
97
98 protected:
99
101 std::vector< Reference::To<typename Library::Plan> > plans;
102
104 std::vector< Reference::To<typename Library::Plan2> > plans2;
105
106 };
107
109 template<class Library>
111 {
112 plans.resize (0);
113 }
114
115 template<class Library>
116 PlanAgent<Library>::PlanAgent (const std::string& _name, normalization _norm)
117 {
118 name = _name;
119 norm = _norm;
120 }
121
122 template<class Library>
123 typename Library::Plan*
125 {
127
128 for (unsigned iplan=0; iplan<plans.size(); iplan++)
129 if (plans[iplan]->matches (nfft, t))
130 return plans[iplan];
131
132 plans.push_back( new typename Library::Plan (nfft, t) );
133 return plans.back();
134 }
135
136 template<class Library>
137 typename Library::Plan2*
138 PlanAgent<Library>::get_plan2 (size_t nx, size_t ny, type t)
139 {
140 for (unsigned iplan=0; iplan<plans2.size(); iplan++)
141 if (plans2[iplan]->matches (nx, ny, t))
142 return plans2[iplan];
143
144 plans2.push_back( new typename Library::Plan2 (nx, ny, t) );
145 return plans2.back();
146
147 }
148
149 template<class Library>
151 {
152 PlanAgent<Library>* instance = new typename Library::Agent;
153 instance->add();
154 }
155
156}
157
158#endif
virtual void clean_plans()=0
Clean up the plans for this library.
void add()
Add a pointer to this instance to the libraries attribute.
Definition FTransformAgent.C:75
static Reference::To< Agent > current
The currently installed agent.
Definition FTransformAgent.h:53
virtual Plan2 * get_plan2(size_t nx, size_t ny, type call)=0
Return an appropriate two-dimensional FFT plan from this library.
friend void clean_plans()
Clears out the memory associated with the plans.
static unsigned get_num_libraries()
Get the number of available libraries.
Definition FTransformAgent.h:42
static ThreadContext * context
For use in multithreaded programs.
Definition FTransformAgent.h:56
static std::string get_library_name(unsigned i)
Get the name of the ith available library.
Definition FTransformAgent.h:46
static void set_library(const std::string &name)
Set the current library by name.
Definition FTransformAgent.C:83
std::string name
Name of the transform library.
Definition FTransformAgent.h:27
normalization norm
The normalization type.
Definition FTransformAgent.h:30
friend void set_library(const std::string &name)
Set the library to the specified name.
virtual Plan * get_plan(size_t nfft, type call)=0
Return an appropriate one-dimensional FFT plan from this library.
Abstract base class of two-dimensional Fast Fourier Transforms.
Definition FTransformPlan.h:48
static void enlist()
Add an instance of this class to the Agent::libraries attribute.
Definition FTransformAgent.h:150
Library::Plan * get_plan(size_t nfft, type call)
Return an appropriate plan from this library.
Definition FTransformAgent.h:124
void clean_plans()
Clean up the plans for this library.
Definition FTransformAgent.h:110
std::vector< Reference::To< typename Library::Plan > > plans
The one-dimensional plans managed by the agent for this library.
Definition FTransformAgent.h:101
Library::Plan2 * get_plan2(size_t nx, size_t ny, type call)
Return an appropriate two-dimensional FFT plan from this library.
Definition FTransformAgent.h:138
std::vector< Reference::To< typename Library::Plan2 > > plans2
The two-dimensional plans managed by the agent for this library.
Definition FTransformAgent.h:104
PlanAgent(const std::string &name, normalization norm)
Default constructor.
Definition FTransformAgent.h:116
Abstract base class of one-dimensional Fast Fourier Transforms.
Definition FTransformPlan.h:17
Manages Reference::To references to the instance.
Definition ReferenceAble.h:35
Template class manages Reference::Able objects.
Definition ReferenceTo.h:25
Locks the mutex on construction and unlocks on deletion.
Definition ThreadContext.h:56
ThreadContext class.
Definition ThreadContext.h:15
Defines a single interface to a variety of Fourier transform libraries.
Definition FFTW3_Transform.h:14
type
The FFT type.
Definition FTransform.h:74
normalization
The normalization convention.
Definition FTransform.h:65

Generated using doxygen 1.14.0