container.hpp
Go to the documentation of this file.
#ifndef container_hpp
#define container_hpp
#include <typeindex>
#include <vector>
#include <map>
#include "value.hpp"
#include "filter.hpp"
template class std::vector<std::vector<float> >;
template class std::vector<std::vector<int> >;
namespace fv::util{
std::string get_type_name(const std::type_index& index){
std::map<std::type_index, std::string> _map;
// Add to this list as needed :)
_map[typeid(int)]="int";
_map[typeid(unsigned int)]="unsigned int";
_map[typeid(float)]="float";
_map[typeid(double)]="double";
_map[typeid(std::vector<int>)]="std::vector<int>";
_map[typeid(std::vector<float>)]="std::vector<float>";
_map[typeid(std::map<std::string,std::string>)] = "std::map<std::string,std::string>";
if (_map[index] == ""){
CRITICAL("Cannot lookup type name of \"" << index.name() << "\"",-1);
}
return _map[index];
}
}
namespace fv{
enum SaveOption{
PNG = 0,
PDF = 1,
ROOT = 2
};
class GenContainer{
private:
std::string name;
std::string desc;
std::vector<ObsFilter*> filters;
protected:
virtual void _fill() = 0;
public:
GenContainer(const std::string name, const std::string& desc)
:name(name),desc(desc) { }
GenContainer(const std::string name)
:GenContainer(name,"N/A"){ }
GenContainer* add_filter(GenValue* filter){
filters.push_back(dynamic_cast<ObsFilter*>(filter));
return this;
}
void fill(){
for (auto filter : filters){
if (!filter->get_value()) return;
}
_fill();
}
void set_description(const std::string& description){
desc = description;
}
const std::string& get_name(){
return name;
}
virtual const std::string& get_value_name(){
return "N/A";
}
virtual void save_as(const std::string& fname, const SaveOption& option) = 0;
virtual void save(const SaveOption& option=SaveOption::PNG) {
save_as(get_name(), option);
}
};
template <typename H, typename V>
class Container : public GenContainer{
protected:
H* container;
Value<V> *value;
public:
Container(const std::string& name, Value<V>* value)
:GenContainer(name),
container(nullptr),
value(value){ }
virtual H* get_container(){
return container;
}
virtual const std::string& get_value_name(){
return value->get_name();
}
};
template <typename T>
class ContainerMean : public Container<T,T>{
private:
int count;
T sum;
void _fill(){
count++;
sum += this->value->get_value();
}
public:
ContainerMean(const std::string& name, Value<T>* value)
:Container<std::vector<T>,T>(name, value){
this->container = new T();
}
T* get_container(){
*(this->container) = sum/count;
return (this->container);
}
void save_as(const std::string& fname) {
WARNING("Saving of ContainerMean objects not supported");
}
};
}
#endif // container_hpp
fv::util
Definition: argparse.hpp:39
fv::SaveOption
SaveOption
Enumeration of different options that can be used to save Containers.
Definition: container.hpp:69
fv::ContainerMean
Calculate the Mean of a Value over a series of observations.
Definition: container.hpp:160
fv
The namespace containing all filval classes and functions.
Definition: api.hpp:46
fv::Value< V >
fv::GenContainer
Generic, untyped parent class of Container.
Definition: container.hpp:79
fv::Container
A class that is used to "hold" values.
Definition: container.hpp:132