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