STable.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include <ionCore.h>
5 #include <ionMath.h>
6 
7 #include "SRange.h"
8 #include "IDataRecord.h"
9 #include "IDatabase.h"
10 
11 
12 class STable : public IDatabase<f64>
13 {
14 
15 public:
16 
17  class SRow : public IDataRecord<f64>
18  {
19 
20  friend class STable;
21 
22  public:
23 
24  f64 GetField(std::string const & Field) const;
25  f64 & GetField(std::string const & Field);
26 
27  SRow operator = (SRow const & Other);
28 
29  protected:
30 
31  SRow(STable & table, u64 const index);
32 
35 
36  };
37 
39  {
40 
41  public:
42 
43  typedef std::vector<SRow>::iterator::iterator_category iterator_category;
44  typedef f64 value_type;
45  typedef std::vector<SRow>::iterator::difference_type difference_type;
46  typedef f64 * pointer;
47  typedef f64 & reference;
48 
49  SFieldIterator(std::vector<SRow>::iterator iterator, std::string const & field);
50 
51  SFieldIterator & operator ++ ();
52  SFieldIterator operator ++ (int);
53 
54  f64 operator * () const;
55  f64 & operator * ();
56  f64 const * operator -> () const;
57  f64 * operator -> ();
58 
59  bool operator < (SFieldIterator const & other) const;
60  bool operator != (SFieldIterator const & other) const;
61 
62  protected:
63 
64  std::vector<SRow>::iterator Iterator;
65  std::string Field;
66 
67  };
68 
69  std::vector<SRow> const & GetValues() const;
70  std::vector<SRow> const & GetRows() const;
71 
72  SRow & AddRow();
73  void AddField(std::string const & Field);
74  bool HasField(std::string const & Field);
75 
79  SRange<f64> GetFieldRange(std::string const & Field, double const OutlierCutoff = 5, SRange<f64> const & acceptedValues = SRange<f64>::Full) const;
80 
81  SFieldIterator Begin(std::string const & Field);
82  SFieldIterator End(std::string const & Field);
83 
84  vector<SRow>::iterator begin();
85  vector<SRow>::iterator end();
86 
87  u64 Size() const;
88  void Clear();
89  void WriteToFile(std::ofstream & File);
90  void ReadFromFile(std::ifstream & File);
91 
92 protected:
93 
94  std::vector<SRow> Rows;
95  std::map<std::string, std::vector<double> > Fields;
96 
97 };
98 
99 template <class Iterator>
100 Iterator MaximumRealElement(Iterator First, Iterator Last)
101 {
102  Iterator Found = First;
103  if (First != Last)
104  for (; ++ First != Last; )
105  if (*Found != *Found || (*Found < *First && *First == *First))
106  Found = First;
107  return Found;
108 }
109 
110 template <class Iterator>
111 Iterator MinimumRealElement(Iterator First, Iterator Last)
112 {
113  Iterator Found = First;
114  if (First != Last)
115  for (; ++ First != Last; )
116  if (*Found != *Found || (*First < *Found && *First == *First))
117  Found = First;
118  return Found;
119 }
Definition: STable.h:38
SRow operator=(SRow const &Other)
Definition: STable.Row.cpp:23
SRange< f64 > GetFieldRange(std::string const &Field, double const OutlierCutoff=5, SRange< f64 > const &acceptedValues=SRange< f64 >::Full) const
Definition: STable.cpp:34
f64 GetField(std::string const &Field) const
Definition: STable.Row.cpp:4
std::vector< SRow > Rows
Definition: STable.h:94
std::vector< SRow >::iterator::difference_type difference_type
Definition: STable.h:45
std::vector< SRow >::iterator::iterator_category iterator_category
Definition: STable.h:43
void Clear()
Definition: STable.cpp:101
Iterator MinimumRealElement(Iterator First, Iterator Last)
Definition: STable.h:111
std::string Field
Definition: STable.h:65
Uint64 u64
Definition: ionTypes.h:92
f64 & reference
Definition: STable.h:47
Iterator MaximumRealElement(Iterator First, Iterator Last)
Definition: STable.h:100
SFieldIterator Begin(std::string const &Field)
Definition: STable.cpp:76
Definition: STable.h:12
void WriteToFile(std::ofstream &File)
Definition: STable.cpp:106
bool HasField(std::string const &Field)
Definition: STable.cpp:29
void ReadFromFile(std::ifstream &File)
Definition: STable.cpp:133
f64 value_type
Definition: STable.h:44
u64 Index
Definition: STable.h:33
u64 Size() const
Definition: STable.cpp:96
vector< SRow >::iterator end()
Definition: STable.cpp:91
Definition: IDatabase.h:9
Definition: STable.h:17
void AddField(std::string const &Field)
Definition: STable.cpp:24
std::vector< SRow >::iterator Iterator
Definition: STable.h:64
std::map< std::string, std::vector< double > > Fields
Definition: STable.h:95
vector< SRow >::iterator begin()
Definition: STable.cpp:86
SRow(STable &table, u64 const index)
Definition: STable.Row.cpp:31
Definition: SRange.h:8
SFieldIterator End(std::string const &Field)
Definition: STable.cpp:81
f64 * pointer
Definition: STable.h:46
STable & Table
Definition: STable.h:34
std::vector< SRow > const & GetRows() const
Definition: STable.cpp:9
double f64
Definition: ionTypes.h:95
Definition: IDataRecord.h:6
SRow & AddRow()
Definition: STable.cpp:14
Helper methods for dealing with files.
Definition: ionStandardLibrary.h:150
std::vector< SRow > const & GetValues() const
Definition: STable.cpp:4