Empirical
Public Member Functions | Protected Types | Protected Attributes | List of all members
emp::ContainerDataFile< CONTAINER > Class Template Reference

#include <DataFile.h>

Inheritance diagram for emp::ContainerDataFile< CONTAINER >:
emp::DataFile

Public Member Functions

 ContainerDataFile (const std::string &filename, const std::string &b="", const std::string &s=",", const std::string &e="\n")
 
 ~ContainerDataFile ()
 
void SetUpdateContainerFun (const fun_update_container_t fun)
 
void PrintHeaderKeys ()
 Print a header containing the name of each column. More...
 
void PrintHeaderComment (const std::string &cstart="# ")
 Print a header containing comments describing all of the columns. More...
 
const container_t GetCurrentRows () const
 
void OutputLine (const data_t d)
 
void Update () override
 Run all of the functions and print the results as a new line in the file. More...
 
void Update (size_t update)
 Update the file with an additional set of lines. More...
 
size_t Add (const std::function< void(std::ostream &, data_t)> &fun, const std::string &key, const std::string &desc)
 
template<typename T >
size_t AddContainerFun (const std::function< T(const data_t)> &fun, const std::string &key="", const std::string &desc="")
 Add a function that returns a value to be printed to the file. More...
 
const std::string & GetFilename () const
 Get the filename used for this file. More...
 
const std::string & GetLineBegin () const
 Returns the string that is printed at the beginning of each line. More...
 
const std::string & GetSpacer () const
 Returns the string that is printed between elements on each line (i.e. the delimeter). More...
 
const std::string & GetLineEnd () const
 Returns the string that is printed at the end of each line. More...
 
void SetTiming (time_fun_t fun)
 
void SetTimingOnce (size_t print_time)
 
void SetTimingRepeat (size_t step)
 Setup this file to print every 'step' updates. More...
 
void SetTimingRange (size_t first, size_t step, size_t last)
 Setup this file to print only in a specified time range, and a given frequency (step). More...
 
void SetLineBegin (const std::string &_in)
 Print. More...
 
void SetSpacer (const std::string &_in)
 Print. More...
 
void SetLineEnd (const std::string &_in)
 Print. More...
 
void SetupLine (const std::string &b, const std::string &s, const std::string &e)
 Set line begin character (. More...
 
size_t Add (const std::function< void(std::ostream &)> &fun, const std::string &key, const std::string &desc)
 
template<typename T >
size_t AddFun (const std::function< T()> &fun, const std::string &key="", const std::string &desc="")
 Add a function that returns a value to be printed to the file. More...
 
template<typename T >
size_t AddVar (const T &var, const std::string &key="", const std::string &desc="")
 Add a function that always prints the current value of. More...
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddCurrent (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddMean (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddTotal (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddMin (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddMax (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddVariance (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddStandardDeviation (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddSkew (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddKurtosis (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
void AddStats (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
void AddAllStats (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddHistBin (DataNode< VAL_TYPE, MODS... > &node, size_t bin_id, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 
template<typename VAL_TYPE , emp::data... MODS>
size_t AddInferiority (DataNode< VAL_TYPE, MODS... > &node, const std::string &key="", const std::string &desc="", const bool &reset=false, const bool &pull=false)
 

Protected Types

using container_t = typename std::remove_reference< CONTAINER >::type
 
using raw_container_t = typename remove_ptr_type< container_t >::type
 
using data_t = typename raw_container_t::value_type
 
using container_fun_t = void(std::ostream &, data_t)
 
using fun_update_container_t = std::function< container_t(void)>
 
using fun_t = void(std::ostream &)
 
using time_fun_t = std::function< bool(size_t)>
 

Protected Attributes

fun_update_container_t update_container_fun
 
container_t current_rows
 
FunctionSet< container_fun_tcontainer_funs
 
emp::vector< std::string > container_keys
 
emp::vector< std::string > container_descs
 
std::string filename
 Name of the file that we are printing to (if one exists) More...
 
std::ostream * os
 Stream to print to. More...
 
FunctionSet< fun_tfuns
 Set of functions to call, one per column in the file. More...
 
emp::vector< std::string > keys
 Keywords associated with each column. More...
 
emp::vector< std::string > descs
 Full description for each column. More...
 
time_fun_t timing_fun
 Function to determine updates to print on (default: all) More...
 
std::string line_begin
 What should we print at the start of each line? More...
 
std::string line_spacer
 What should we print between entries? More...
 
std::string line_end
 What should we print at the end of each line? More...
 

Detailed Description

template<typename CONTAINER>
class emp::ContainerDataFile< CONTAINER >

Sometimes you may want a data file where a set of functions is run on every item in a container every time you write to the file. ContainerDataFiles do that.

Note: CONTAINER type can be a pointer to a container and the datafile will handle derefeferencing it appropriately.

Member Typedef Documentation

template<typename CONTAINER>
using emp::ContainerDataFile< CONTAINER >::container_fun_t = void(std::ostream &, data_t)
protected
template<typename CONTAINER>
using emp::ContainerDataFile< CONTAINER >::container_t = typename std::remove_reference<CONTAINER>::type
protected
template<typename CONTAINER>
using emp::ContainerDataFile< CONTAINER >::data_t = typename raw_container_t::value_type
protected
using emp::DataFile::fun_t = void(std::ostream &)
protectedinherited
template<typename CONTAINER>
using emp::ContainerDataFile< CONTAINER >::fun_update_container_t = std::function<container_t(void)>
protected
template<typename CONTAINER>
using emp::ContainerDataFile< CONTAINER >::raw_container_t = typename remove_ptr_type<container_t>::type
protected
using emp::DataFile::time_fun_t = std::function<bool(size_t)>
protectedinherited

Constructor & Destructor Documentation

template<typename CONTAINER>
emp::ContainerDataFile< CONTAINER >::ContainerDataFile ( const std::string &  filename,
const std::string &  b = "",
const std::string &  s = ",",
const std::string &  e = "\n" 
)
inline
template<typename CONTAINER>
emp::ContainerDataFile< CONTAINER >::~ContainerDataFile ( )
inline

Member Function Documentation

size_t emp::DataFile::Add ( const std::function< void(std::ostream &)> &  fun,
const std::string &  key,
const std::string &  desc 
)
inlineinherited

If a function takes an ostream, pass in the correct one. Generic function for adding a column to the DataFile. In practice, you probably want to call one of the more specific ones.

template<typename CONTAINER>
size_t emp::ContainerDataFile< CONTAINER >::Add ( const std::function< void(std::ostream &, data_t)> &  fun,
const std::string &  key,
const std::string &  desc 
)
inline

If a function takes an ostream, pass in the correct one. Generic function for adding a column to the DataFile. In practice, you probably want to call one of the more specific ones.

template<typename VAL_TYPE , emp::data... MODS>
void emp::DataFile::AddAllStats ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add multiple functions that pull all stats measurements (mean, variance, min, max, skew, and kurtosis) from the DataNode

Parameters
nodeRequires that
nodehave the data::Stats or data::FullStats modifier.
keyand
descwill have the name of the stat appended to the beginning. Note: excludes standard deviation, because it is easily calculated from variance
template<typename CONTAINER>
template<typename T >
size_t emp::ContainerDataFile< CONTAINER >::AddContainerFun ( const std::function< T(const data_t)> &  fun,
const std::string &  key = "",
const std::string &  desc = "" 
)
inline

Add a function that returns a value to be printed to the file.

template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddCurrent ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add a function that always pulls the current value from the DataNode

Parameters
node.Requires that
nodehave the data::Current modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename T >
size_t emp::DataFile::AddFun ( const std::function< T()> &  fun,
const std::string &  key = "",
const std::string &  desc = "" 
)
inlineinherited

Add a function that returns a value to be printed to the file.

template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddHistBin ( DataNode< VAL_TYPE, MODS... > &  node,
size_t  bin_id,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add a function that always pulls the count of the

Parameters
bin_id'th bin of the histogram from
node.Requires that
nodehave the data::Histogram modifier and at least bins. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddInferiority ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add a function that always pulls the inferiority (mean divided by max) from the DataNode

Parameters
node.Requires that
nodehave the data::Range or data::FullRange modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddKurtosis ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add a function that always pulls the kurtosis from the DataNode

Parameters
nodeRequires that
nodehave the data::Stats or data::FullStats modifier.
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddMax ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add a function that always pulls the maximum value from the DataNode

Parameters
node.Requires that
nodehave the data::Range or data::FullRange modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddMean ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add a function that always pulls the mean value from the DataNode

Parameters
node.Requires that
nodehave the data::Range or data::FullRange modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddMin ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add a function that always pulls the minimum value from the DataNode

Parameters
node.Requires that
nodehave the data::Range or data::FullRange modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddSkew ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add a function that always pulls the skewness from the DataNode

Parameters
nodeRequires that
nodehave the data::Stats or data::FullStats modifier.
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddStandardDeviation ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add a function that always pulls the standard deviation from the DataNode

Parameters
nodeRequires that
nodehave the data::Stats or data::FullStats modifier.
template<typename VAL_TYPE , emp::data... MODS>
void emp::DataFile::AddStats ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add multiple functions that pull common stats measurements (mean, variance, min, and max) from the DataNode

Parameters
node.Requires that
nodehave the data::Stats or data::FullStats modifier.
keyand
descwill have the name of the stat appended to the beginning. Note: excludes standard deviation, because it is easily calculated from variance
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddTotal ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add a function that always pulls the total value from the DataNode

Parameters
node.Requires that
nodehave the data::Range or data::FullRange modifier. If
resetis set true, we will call Reset on that DataNode after pulling the current value from the node
template<typename T >
size_t emp::DataFile::AddVar ( const T &  var,
const std::string &  key = "",
const std::string &  desc = "" 
)
inlineinherited

Add a function that always prints the current value of.

Parameters
var.
template<typename VAL_TYPE , emp::data... MODS>
size_t emp::DataFile::AddVariance ( DataNode< VAL_TYPE, MODS... > &  node,
const std::string &  key = "",
const std::string &  desc = "",
const bool &  reset = false,
const bool &  pull = false 
)
inlineinherited

Add a function that always pulls the variance from the DataNode

Parameters
nodeRequires that
nodehave the data::Stats or data::FullStats modifier.
template<typename CONTAINER>
const container_t emp::ContainerDataFile< CONTAINER >::GetCurrentRows ( ) const
inline
const std::string& emp::DataFile::GetFilename ( ) const
inlineinherited

Get the filename used for this file.

const std::string& emp::DataFile::GetLineBegin ( ) const
inlineinherited

Returns the string that is printed at the beginning of each line.

const std::string& emp::DataFile::GetLineEnd ( ) const
inlineinherited

Returns the string that is printed at the end of each line.

const std::string& emp::DataFile::GetSpacer ( ) const
inlineinherited

Returns the string that is printed between elements on each line (i.e. the delimeter).

template<typename CONTAINER>
void emp::ContainerDataFile< CONTAINER >::OutputLine ( const data_t  d)
inline
template<typename CONTAINER>
void emp::ContainerDataFile< CONTAINER >::PrintHeaderComment ( const std::string &  cstart = "# ")
inlinevirtual

Print a header containing comments describing all of the columns.

Reimplemented from emp::DataFile.

template<typename CONTAINER>
void emp::ContainerDataFile< CONTAINER >::PrintHeaderKeys ( )
inlinevirtual

Print a header containing the name of each column.

Reimplemented from emp::DataFile.

void emp::DataFile::SetLineBegin ( const std::string &  _in)
inlineinherited

Print.

Parameters
_inat the beginning of each line.
void emp::DataFile::SetLineEnd ( const std::string &  _in)
inlineinherited

Print.

Parameters
_inat the end of each line.
void emp::DataFile::SetSpacer ( const std::string &  _in)
inlineinherited

Print.

Parameters
_inbetween elements (i.e. make
_inthe delimeter).
void emp::DataFile::SetTiming ( time_fun_t  fun)
inlineinherited

Provide a timing function with a bool(size_t update) signature. The timing function is called with the update, and returns a bool to indicate if files should print this update.

void emp::DataFile::SetTimingOnce ( size_t  print_time)
inlineinherited

Setup this file to print only once, at the specified update. Note that this timing function can be replaced at any time, even after being triggered.

void emp::DataFile::SetTimingRange ( size_t  first,
size_t  step,
size_t  last 
)
inlineinherited

Setup this file to print only in a specified time range, and a given frequency (step).

void emp::DataFile::SetTimingRepeat ( size_t  step)
inlineinherited

Setup this file to print every 'step' updates.

template<typename CONTAINER>
void emp::ContainerDataFile< CONTAINER >::SetUpdateContainerFun ( const fun_update_container_t  fun)
inline

Tell this file what function to run to update the contents of the container that data is being calculated on.

void emp::DataFile::SetupLine ( const std::string &  b,
const std::string &  s,
const std::string &  e 
)
inlineinherited

Set line begin character (.

Parameters
b),columndelimeter (
s),andline end character (
e)
template<typename CONTAINER>
void emp::ContainerDataFile< CONTAINER >::Update ( )
inlineoverridevirtual

Run all of the functions and print the results as a new line in the file.

Reimplemented from emp::DataFile.

template<typename CONTAINER>
void emp::ContainerDataFile< CONTAINER >::Update ( size_t  update)
inline

Update the file with an additional set of lines.

Member Data Documentation

template<typename CONTAINER>
emp::vector<std::string> emp::ContainerDataFile< CONTAINER >::container_descs
protected
template<typename CONTAINER>
FunctionSet<container_fun_t> emp::ContainerDataFile< CONTAINER >::container_funs
protected
template<typename CONTAINER>
emp::vector<std::string> emp::ContainerDataFile< CONTAINER >::container_keys
protected
template<typename CONTAINER>
container_t emp::ContainerDataFile< CONTAINER >::current_rows
protected
emp::vector<std::string> emp::DataFile::descs
protectedinherited

Full description for each column.

std::string emp::DataFile::filename
protectedinherited

Name of the file that we are printing to (if one exists)

FunctionSet<fun_t> emp::DataFile::funs
protectedinherited

Set of functions to call, one per column in the file.

emp::vector<std::string> emp::DataFile::keys
protectedinherited

Keywords associated with each column.

std::string emp::DataFile::line_begin
protectedinherited

What should we print at the start of each line?

std::string emp::DataFile::line_end
protectedinherited

What should we print at the end of each line?

std::string emp::DataFile::line_spacer
protectedinherited

What should we print between entries?

std::ostream* emp::DataFile::os
protectedinherited

Stream to print to.

time_fun_t emp::DataFile::timing_fun
protectedinherited

Function to determine updates to print on (default: all)

template<typename CONTAINER>
fun_update_container_t emp::ContainerDataFile< CONTAINER >::update_container_fun
protected

The documentation for this class was generated from the following file: