Commit 29030586 authored by Alexander Lapshin's avatar Alexander Lapshin

bisection search now template, add new load json handler

parent 8ae807ab
...@@ -5,6 +5,31 @@ ...@@ -5,6 +5,31 @@
#include "TimeFunctions.h" #include "TimeFunctions.h"
#include "json_functions.h" #include "json_functions.h"
static bool loadjson(const jsonval& parent, const std::string& key, std::vector<TimeJD>& vec, const bool exist = true, bool* loaded = nullptr)
{
jsonval::ConstMemberIterator itr;
if (!extract_value(parent, key, exist, loaded, itr)) {
return false;
}
const jsonval& a = itr->value;
if (!a.IsArray()) {
throw Exp() << "error: element is not an array";
}
for (jsonval::ConstValueIterator it = a.Begin(); it != a.End(); ++it) {
if (it->IsString()) {
vec.emplace_back(StrToDate(it->GetString()));
}
else {
throw Exp() << "error: unsupported type";
}
}
return true;
}
static void loadjson(const jsonval& parent, const std::string& key, TimeJD& value, bool exist = true, bool* loaded = nullptr) static void loadjson(const jsonval& parent, const std::string& key, TimeJD& value, bool exist = true, bool* loaded = nullptr)
{ {
const jsonval::ConstMemberIterator itr = parent.FindMember(key.c_str()); const jsonval::ConstMemberIterator itr = parent.FindMember(key.c_str());
......
...@@ -500,7 +500,6 @@ inline TimeJD get_current_time() ...@@ -500,7 +500,6 @@ inline TimeJD get_current_time()
const auto s_now = get_current_time("%d/%m/%Y %H:%M:%S"); const auto s_now = get_current_time("%d/%m/%Y %H:%M:%S");
StrToDate(s_now, now); StrToDate(s_now, now);
//return StrToDate("16/09/2020 09:00:00");
return now; return now;
} }
...@@ -112,11 +112,12 @@ inline double golden_section_search_stdf( ...@@ -112,11 +112,12 @@ inline double golden_section_search_stdf(
} }
} }
template <typename T>
inline double bisection_search_stdf( inline double bisection_search_stdf(
double a, double a,
double b, double b,
const double accuracy, const double accuracy,
const std::function<bool(const double&)>& f const std::function<T(const double&)>& f
) )
{ {
//f(a) should not be equal f(b) at the first step //f(a) should not be equal f(b) at the first step
......
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