Download Software Component Engineering
Transcript
30
SOFTWARE COMPONENT ENGINEERING WITH RESOLVE/C++, VOLUME 2
// ---- Horner's rule, done recursively ---output << "Horner's rule (recursive):\n";
Write_Polynomial (output, a);
k = 0;
t.Restart ();
while (k < 1000)
{
evaluation = Horner_Recursive_Evaluation (a, x);
k++;
}
elapsed_time = t.Reading ();
output << "p(" << x << ") = " << evaluation << "\n"
<< "execution time = " << elapsed_time
<< " usec\n\n";
// Close input and output streams
input.Close_External ();
output.Close_External ();
}
Figure 2-2: Poly_Eval.cpp
This program introduces only one substantially new feature of Resolve/C++: the use of a
concrete template, Sequence_Kernel_1a_C. Like the abstract template it implements, a concrete
template has formal parameters that must be bound to actual parameters in a client program uses
it. There can be many alternative concrete templates that might implement a given abstract
template. After deciding which of these concrete templates to use in a given situation—a choice
that depends on matching the performance (time and space) characteristics of the candidate
implementations with the application’s performance requirements—the client programmer needs
to do two things in order to use the selected concrete template:
•
Bring the desired concrete template into scope in the application program.
•
Instantiate it to create a concrete instance.
2.2.1 Bringing a Concrete Template Into Scope
Let’s continue with the Poly_Eval example to see exactly how this works. The appendix for the
Sequence family lists just one implementation of Sequence_Kernel, which is called
Sequence_Kernel_1a_C; so there isn’t much choice here.1 The appendix explains:
To bring this component into scope you write:
#include "CT/Sequence/Kernel_1a_C.h"
Hence, you see this exact statement in the global context section near the beginning of Figure
2-2.
1
In fact, there are other implementations of Sequence_Kernel in the Resolve/C++ Catalog, but we
ignore them here and in the appendix in order to concentrate on how to use a chosen concrete
template.