Commit c48698e3 authored by Bednárek David RNDr. Ph.D.'s avatar Bednárek David RNDr. Ph.D.
Browse files

compilable, runnable, nonsensical aggregation

parent b45e0501
......@@ -49,7 +49,7 @@ namespace fmwkng {
virtual bool useful() const = 0;
virtual bool reducible() const = 0;
virtual element_ptr aggregate_init() const = 0;
virtual void aggregate_with(const abstract_element* other) = 0;
virtual void aggregate_to(abstract_element* aggr) const = 0;
virtual element_sense sense() const = 0;
};
......@@ -369,7 +369,7 @@ namespace fmwkng {
assert(sz == src.size());
for (std::size_t i = 0; i < sz; ++i)
{
rv.first->second[i]->aggregate_with(src[i]);
src[i]->aggregate_to(rv.first->second[i]);
}
}
}
......@@ -394,8 +394,8 @@ namespace fmwkng {
}
else
{
std::cout << "Reducing \t";
print_list(rn.source_range);
//std::cout << "Reducing \t";
//print_list(rn.source_range);
reduced_list nl;
reduce_list(nl, rn.children);
......@@ -439,7 +439,7 @@ namespace fmwkng {
void print_all(element_list_view el, element_list_view prefix = {})
{
print_list(el, prefix);
//print_list(el, prefix);
auto nel = reduce_list(el);
print_list(nel, prefix);
}
......@@ -481,18 +481,23 @@ namespace fmwkng {
}
virtual element_ptr aggregate_init() const
{
return std::make_unique< typename my_traits::template aggregator<sense_p>>(my_traits::aggregator_data(d_));
return std::make_unique< my_aggregate>(my_traits::aggregator_data(d_));
}
virtual void aggregate_with(const abstract_element* other)
virtual void aggregate_to(abstract_element* aggr) const
{
auto p = dynamic_cast<const self_*>(other);
auto p = dynamic_cast<my_aggregate*>(aggr);
assert(!!p);
my_traits::aggregate(d_, p->d_);
my_traits::aggregate(p->data(), d_);
}
data_t& data()
{
return d_;
}
private:
using my_traits = element_traits_t<tag, sense_p>;
using self_ = element< tag, sense_p, data_t>;
data_t d_;
using my_aggregate = typename my_traits::template aggregator<sense_p>;
};
template< typename tag, element_sense sense_p>
......@@ -530,14 +535,16 @@ namespace fmwkng {
}
virtual element_ptr aggregate_init() const
{
return std::make_unique< typename my_traits::template aggregator<sense_p>>();
return std::make_unique< my_aggregate>();
}
virtual void aggregate_with(const abstract_element* other)
virtual void aggregate_to(abstract_element* aggr) const
{
assert(!!dynamic_cast<my_aggregate*>(aggr));
}
private:
using my_traits = element_traits_t<tag, sense_p>;
using self_ = element< tag, sense_p, void>;
using my_aggregate = typename my_traits::template aggregator<sense_p>;
};
template< typename tag, element_sense sense>
......@@ -549,9 +556,18 @@ namespace fmwkng {
template< typename tag>
using config_element_traits_t = config_element_traits< typename tag::tag_category, tag>;
template< typename tag_category, typename tag>
struct result_element_traits;
template< typename tag>
using result_element_traits_t = result_element_traits< typename tag::tag_category, tag>;
template< typename tag, element_sense sense_p>
class config_element;
template< typename tag, element_sense sense_p>
class result_element;
template< typename tag>
class config_element< tag, element_sense::OPEN> : public abstract_element {
private:
......@@ -562,7 +578,7 @@ namespace fmwkng {
explicit config_element(data_t d)
: d_(std::move(d))
{}
element_ptr clone() const
virtual element_ptr clone() const
{
return std::make_unique< self_>(d_);
}
......@@ -593,17 +609,22 @@ namespace fmwkng {
}
virtual element_ptr aggregate_init() const
{
return std::make_unique< typename my_traits::template aggregator<element_sense::OPEN>>(my_traits::aggregator_data(d_));
return std::make_unique< my_aggregate>(my_traits::aggregator_data(d_));
}
virtual void aggregate_with(const abstract_element* other)
virtual void aggregate_to(abstract_element* aggr) const
{
auto p = dynamic_cast<const self_*>(other);
auto p = dynamic_cast<my_aggregate*>(aggr);
assert(!!p);
my_traits::aggregate(d_, p->d_);
my_traits::aggregate(p->data(), d_);
}
data_t & data()
{
return d_;
}
private:
using self_ = config_element< tag, element_sense::OPEN>;
data_t d_;
using my_aggregate = typename my_traits::template aggregator<element_sense::OPEN>;
};
template< typename tag>
......@@ -643,14 +664,124 @@ namespace fmwkng {
}
virtual element_ptr aggregate_init() const
{
return std::make_unique< typename my_traits::template aggregator<element_sense::CLOSE>>();
return std::make_unique< my_aggregate>();
}
virtual void aggregate_with(const abstract_element* other)
virtual void aggregate_to(abstract_element* aggr) const
{
assert(!!dynamic_cast<my_aggregate*>(aggr));
}
private:
using my_traits = config_element_traits_t<tag>;
using self_ = config_element< tag, element_sense::CLOSE>;
using my_aggregate = typename my_traits::template aggregator<element_sense::CLOSE>;
};
template< typename tag>
class result_element< tag, element_sense::OPEN> : public abstract_element {
private:
using my_element_traits = element_traits_t<tag, element_sense::OPEN>;
public:
result_element()
{}
element_ptr clone() const
{
return std::make_unique< self_>();
}
virtual std::size_t data_size() const
{
return 0;
}
virtual void data_text(std::ostream& os, std::size_t i) const
{
assert(false);
}
virtual void metadata_marker(std::ostream& os) const
{
my_traits::metadata_marker_close(os);
}
virtual element_sense sense() const
{
return element_sense::OPEN;
}
virtual bool useful() const
{
return false;
}
virtual bool reducible() const
{
return false;
}
virtual element_ptr aggregate_init() const
{
return std::make_unique< my_aggregate>();
}
virtual void aggregate_to(abstract_element* aggr) const
{
assert(!!dynamic_cast<my_aggregate*>(aggr));
}
private:
using my_traits = result_element_traits_t<tag>;
using self_ = result_element< tag, element_sense::OPEN>;
using my_aggregate = typename my_traits::template aggregator<element_sense::OPEN>;
};
template< typename tag>
class result_element< tag, element_sense::CLOSE> : public abstract_element {
private:
using my_element_traits = element_traits_t<tag, element_sense::CLOSE>;
using my_traits = result_element_traits_t<tag>;
using data_t = typename my_traits::data_type;
public:
explicit result_element(data_t d)
: d_(std::move(d))
{}
virtual element_ptr clone() const
{
return std::make_unique< self_>(d_);
}
virtual std::size_t data_size() const
{
return 1;
}
virtual void data_text(std::ostream& os, std::size_t i) const
{
assert(i == 0);
my_traits::data_text(os, d_);
}
virtual void metadata_marker(std::ostream& os) const
{
my_traits::metadata_marker_open(os);
}
virtual element_sense sense() const
{
return element_sense::CLOSE;
}
virtual bool useful() const
{
return false;
}
virtual bool reducible() const
{
return false;
}
virtual element_ptr aggregate_init() const
{
return std::make_unique< my_aggregate>(my_traits::aggregator_data(d_));
}
virtual void aggregate_to(abstract_element* aggr) const
{
auto p = dynamic_cast<my_aggregate*>(aggr);
assert(!!p);
my_traits::aggregate(p->data(), d_);
}
data_t& data()
{
return d_;
}
private:
using self_ = result_element< tag, element_sense::CLOSE>;
data_t d_;
using my_aggregate = typename my_traits::template aggregator<element_sense::CLOSE>;
};
#pragma endregion
......@@ -1561,11 +1692,11 @@ namespace fmwkng {
using aggregator = config_element< range_tag, sense>;
static aggregator_data_type aggregator_data(const data_type& v)
{
return aggregator_data_type(v.second); // USE THE CONFIG AS THE AGGREGATE
return v.second; // USE THE CONFIG AS THE AGGREGATE
}
static void aggregate(data_type& r, const data_type& v)
static void aggregate(aggregator_data_type& r, const data_type& v)
{
assert(0); // AGGREGATING TO A RANGE VALUE IS NONSENSE
assert(r == v.second); // AGGREGATING TO A RANGE VALUE IS NONSENSE
}
};
......@@ -1941,7 +2072,7 @@ namespace fmwkng {
};
template<>
struct config_element_traits< measurement_tag_category, measurement_tag>
struct result_element_traits< measurement_tag_category, measurement_tag>
{
static void metadata_marker_open(std::ostream& os)
{
......@@ -2042,6 +2173,10 @@ namespace fmwkng {
static constexpr bool reducible = true;
template< element_sense sense>
using aggregator = element_t< result_tag, sense>;
static data_type aggregator_data(const data_type& v)
{
return v;
}
static void aggregate(data_type& r, const data_type& v)
{
r += v; // !!! NONSENSE
......@@ -2185,7 +2320,7 @@ namespace fmwkng {
*/
static constexpr bool reducible = true;
template< element_sense sense>
using aggregator = config_element< auto_measurement_tag< measurement_policy>, sense>;
using aggregator = result_element< auto_measurement_tag< measurement_policy>, sense>;
};
template< typename measurement_policy>
......@@ -2203,10 +2338,45 @@ namespace fmwkng {
static constexpr bool useful = true;
static constexpr bool reducible = true;
template< element_sense sense>
using aggregator = config_element< auto_measurement_tag< measurement_policy>, sense>;
using aggregator = result_element< auto_measurement_tag< measurement_policy>, sense>;
using aggregator_data_type = std::pair< double, std::size_t>;
static aggregator_data_type aggregator_data(const data_type& v)
{
return std::make_pair(v,1);
}
static void aggregate(aggregator_data_type& r, const data_type& v)
{
r.first += v; // !!! WE WANT THE LAST MEASUREMENT, NOT THE AVERAGE
r.second += 1;
}
};
template< typename measurement_policy>
struct result_element_traits< measurement_tag_category, auto_measurement_tag< measurement_policy>>
{
static void metadata_marker_open(std::ostream& os)
{
os << "<";
}
static void metadata_marker_close(std::ostream& os)
{
os << ">";
}
using data_type = std::pair< double, std::size_t>;
static void data_text(std::ostream& os, const data_type& d)
{
os << (d.first / d.second);
}
template< element_sense sense>
using aggregator = result_element< auto_measurement_tag< measurement_policy>, sense>;
static data_type aggregator_data(const data_type& v)
{
return v;
}
static void aggregate(data_type& r, const data_type& v)
{
r += v; // !!! NONSENSE
r.first += v.first;
r.second += v.second;
}
};
......@@ -2830,11 +3000,11 @@ namespace fmwkng {
os << v_count_;
}
void aggregate(const auto_repeat& b)
bool operator==(const auto_repeat& b)
{
v_count_ += b.v_count_; // ???
// IGNORE ANY DIFFERENCES, REPORT THE FIRST COUNT return v_count_ == b.v_count_;
return true;
}
private:
value_type v_count_;
};
......
Supports Markdown
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