03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

12.1. TRANSCENDING LEGACY APPLICATIONS 255<br />

virtual void transition(state type& input) = 0;<br />

};<br />

boost::shared ptr scattering object;<br />

template struct scattering model:scattering concept<br />

{<br />

T scattering instance;<br />

scattering model(const T& x):scattering instance(x) {}<br />

numeric type rate(const state type& input) const ;<br />

void transition(state type& input) ;<br />

};<br />

numeric type rate(const state type& input) const;<br />

void transition(state type& input) ;<br />

template <br />

scatter facade(const T& x):scattering object(new scattering model(x)){}<br />

∼scatter facade() {}<br />

};<br />

there<strong>for</strong>e introduces a scattering facade which wraps a scattering concept part. The<br />

virtual inheritance is used to configure the necessary interface parts, in this case rate() and<br />

transition(), which have to be implemented by any scattering model. In the given example<br />

the state type is still available <strong>for</strong> explicit parametrization.<br />

In contrast to other applications of runtime concepts, e.g. in computer graphics, it is not<br />

necessary to provide mechanisms <strong>for</strong> deep copies, as the actual physical models remain unaltered<br />

once they have been created and would only serve unnecessarily increase the memory footprint.<br />

There<strong>for</strong>e a boost::shared ptr is used <strong>for</strong> memory management.<br />

The legacy application has been writte in plain ANSI C, which makes it easily compatible with<br />

the new C ++ implementation. Several design decisions, such as the use of global and static<br />

variables, make it difficult to extend and update appropriately <strong>for</strong> modern multi-core CPUs.<br />

To interface this novel approach a core structure is implemented which wraps the implementations<br />

of the scattering models by using runtime concepts.<br />

template<br />

struct scattering rate A<br />

{<br />

...<br />

const ParameterType& parameters;<br />

scattering rate A(const ParameterType& parameters):parameters(parameters){}<br />

template <br />

numeric type<br />

operator() (const StateType& state) const<br />

{<br />

return A rate(state, parameters);<br />

}<br />

};

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!