Commit 9d36be1d authored by Christopher Subich's avatar Christopher Subich Committed by Christopher Subich
Browse files

Sanitize template instantiation for add_diagnostic

The template form of add_diagnostic<x> is attractive, but to
be properly used the template implementation must be visible
at the same time as the header file itself.  The
instantiations formerly in BaseCase.cpp were not likely to
be visible to a program, increasing compile time (if they
were re-instantiated) or causing an error (if the
implementation was not visible).  This change:

*) Moves the implementation of add_diagnostic to a new
BaseCase_impl.cc
*) Includes this impementation file from BaseCase.hpp, with
a double-inclusion guard
*) Preserves instantiations of <double> and <int>, with new
'extern' declarations in BaseCase.hpp to prevent
double-definition.
parent 90c67e3c
......@@ -395,17 +395,8 @@ void BaseCase::successful_dump(int plot_number, double final_time, double plot_i
}
}
// append a diagnostic to string for printing into diagnostic file
template <class T> void BaseCase::add_diagnostic(const string str, const T val,
string & header, string & line) {
// append to the header
header.append(str + ", ");
// append to the line of values
ostringstream oss;
oss.precision(17);
oss << scientific << val;
line.append(oss.str() + ", ");
}
// Explicitly instantiate common add_diagnostic templates, for integer and double
// types
template void BaseCase::add_diagnostic<int>(const string str, const int val,
string & header, string & line);
template void BaseCase::add_diagnostic<double>(const string str, const double val,
......
......@@ -172,6 +172,14 @@ class BaseCase {
Array<double,1> *xx=0, Array<double,1> *yy=0, Array<double,1> *zz=0);
};
#include "BaseCase_impl.cc" // Include the implementation of the add_diagnostic template
// Note explicitly instantiated add_diagnostic template functions
extern template void BaseCase::add_diagnostic<int>(const string str, const int val,
string & header, string & line);
extern template void BaseCase::add_diagnostic<double>(const string str, const double val,
string & header, string & line);
// parse expansion types
void parse_boundary_conditions(const string xgrid_type, const string ygrid_type,
const string zgrid_type, DIMTYPE & intype_x, DIMTYPE & intype_y, DIMTYPE & intype_z);
......
#ifndef BASECASE_IMPL
#define BASECASE_IMPL 1
// append a diagnostic to string for printing into diagnostic file
template <class T> void BaseCase::add_diagnostic(const string str, const T val,
string & header, string & line) {
// append to the header
header.append(str + ", ");
// append to the line of values
ostringstream oss;
oss.precision(17);
oss << scientific << val;
line.append(oss.str() + ", ");
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment