Commit 9c955142 authored by Damien L-G's avatar Damien L-G

Template SplineMap on Sline and rename to Map

parent a4e19548
......@@ -24,7 +24,7 @@ add_dependencies(gsl project_gsl)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
add_library(noname STATIC noname.cpp noname_SplineMap.cpp)
add_library(noname STATIC noname.cpp noname_Map.cpp)
target_include_directories(noname PUBLIC ${CMAKE_SOURCE_DIR})
target_include_directories(noname PUBLIC ${install_dir}/include)
target_link_libraries(noname PRIVATE gsl)
......
#include <noname.h>
#include <noname_Map.hpp>
#include <noname_Spline2D.hpp>
#include <noname_SplineMap.hpp>
using namespace noname;
double noname_spline2d_eval(char const *o, double x, double y) {
auto spline = SplineMap::get_spline(o);
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval(x, y);
}
double noname_spline2d_eval_deriv_x(char const *o, double x, double y) {
auto spline = SplineMap::get_spline(o);
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval_deriv_x(x, y);
}
double noname_spline2d_eval_deriv_y(char const *o, double x, double y) {
auto spline = SplineMap::get_spline(o);
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval_deriv_y(x, y);
}
double noname_spline2d_eval_deriv_xx(char const *o, double x, double y) {
auto spline = SplineMap::get_spline(o);
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval_deriv_xx(x, y);
}
double noname_spline2d_eval_deriv_yy(char const *o, double x, double y) {
auto spline = SplineMap::get_spline(o);
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval_deriv_yy(x, y);
}
double noname_spline2d_eval_deriv_xy(char const *o, double x, double y) {
auto spline = SplineMap::get_spline(o);
auto spline = Map<Spline2D<Bicubic>>::get_spline(o);
return spline->eval_deriv_xy(x, y);
}
......
#include <noname_Map.hpp>
#include <noname_Parser.hpp>
#include <noname_Spline2D.hpp>
#include <noname_SplineMap.hpp>
#include <algorithm>
#include <cstddef>
......@@ -76,7 +76,8 @@ void check_valid_number_of_options(std::vector<std::string> const &options,
}
}
Spline2D<Bicubic> *SplineMap::get_spline(std::string const &which) {
template <typename Spline>
Spline *Map<Spline>::get_spline(std::string const &which) {
auto const options = parse_options(which);
check_valid_number_of_options(options, 5);
......@@ -103,20 +104,25 @@ Spline2D<Bicubic> *SplineMap::get_spline(std::string const &which) {
// object.
auto it = _splines.find(key);
if (it == _splines.end()) {
auto extract_from = [](std::string const &filename,
std::vector<double> (*parse)(std::istream &)) {
std::fstream fs(filename);
return parse(fs);
};
auto extract_from = [](std::string const &filename,
std::vector<double> (*parse)(std::istream &)) {
std::fstream fs(filename);
return parse(fs);
};
auto const x = extract_from(filenames[0], parse_x);
auto const y = extract_from(filenames[1], parse_y);
auto const z = extract_from(filenames[2], parse_z);
auto const tz = transpose_z(x.size(), y.size(), z);
std::tie(it, std::ignore) =
_splines.insert({key, std::make_unique<Spline2D<Bicubic>>(x, y, tz)});
_splines.insert({key, std::make_unique<Spline>(x, y, tz)});
}
return (it->second).get();
}
std::map<std::string, std::unique_ptr<Spline2D<Bicubic>>> SplineMap::_splines;
template <typename Spline>
std::map<std::string, std::unique_ptr<Spline>> Map<Spline>::_splines;
template class Map<Spline2D<Bicubic>>;
template class Map<Spline2D<Bilinear>>;
} // namespace noname
#ifndef NONAME_SPLINEMAP
#define NONAME_SPLINEMAP
#ifndef NONAME_MAP
#define NONAME_MAP
#include <noname_Spline2D.hpp>
......@@ -9,14 +9,14 @@
namespace noname {
class SplineMap {
template <typename Spline> class Map {
public:
static Spline2D<Bicubic> *get_spline(std::string const &which);
static Spline *get_spline(std::string const &which);
static int size() { return _splines.size(); }
static void clear() { _splines.clear(); }
private:
static std::map<std::string, std::unique_ptr<Spline2D<Bicubic>>> _splines;
static std::map<std::string, std::unique_ptr<Spline>> _splines;
};
} // namespace noname
......
#include <noname_SplineMap.hpp>
#include <noname_Map.hpp>
#include <noname_Spline2D.hpp>
#include <noname_TestAssertionMacros.hpp>
#include <cassert>
......@@ -7,6 +8,8 @@
using namespace noname;
using SplineMap = Map<Spline2D<Bicubic>>;
void file_not_found() {
std::string const valid = "dummy.csv";
std::string const invalid = "does_not_exist.csv";
......
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