File: Field.h

package info (click to toggle)
quickplot 0.8.6-1.1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 1,548 kB
  • ctags: 1,019
  • sloc: cpp: 10,052; sh: 7,597; makefile: 176
file content (103 lines) | stat: -rw-r--r-- 3,512 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* Copyright (c) 1998, 1999, 2003, 2004  Lance Arsenault, (GNU GPL (v2+))
 */
class Source;
class FileReader;
class FieldReader;

class Field
{
 public:

  Field(Source *s);
  virtual ~Field(void);

  // The source (file) of the field data.
  Source *source;

  // read the list and advance the pointer to the next value in the
  // series.
  virtual value_t read(void) = 0;

  // move the pointer to the first value in the series.
  virtual void rewind(void) = 0;

  virtual inline count_t numberOfValues(void) { return _numberOfValues; }
  
  // append the value to the end of the list.
  // void write(T value); is not in all Field classes
  

  // Find the minimum values in the range of indexes. Indexing starts
  // at 0.  i_max=-1 means upto the numberOfValues.
  virtual value_t max(count_t i_max=((count_t) -1), count_t i_min=0);
  
  // find the minimum values in the range of indexes.  Indexing starts
  // at 0.  i_max=-1 means upto the numberOfValues.
  virtual value_t min(count_t i_max=((count_t) -1), count_t i_min=0);
  
  // Is monotonically increasing, like time.
  virtual inline bool isIncreasing(void) { return _isIncreasing; }
  virtual inline bool isDecreasing(void) { return _isDecreasing; }

  void setName(const char *name_in);
  void setLabel(const char *label_in);
  inline const char *getName(void) { return name; }
  inline const char *getLabel(void) { return label; }

protected:

  // A derived Field class must maintain these numbers or over-write
  // the corresponding virtual method.  This data is waste in a
  // FieldReader.
  value_t _min, _max;
  count_t _numberOfValues;
  bool _isIncreasing;
  bool _isDecreasing;

  
public:

  friend class FieldReader;
  // The class FileReader is a Field that can read() another Field
  // (the source Field) without effecting the reading by the methods,
  // read(void), and rewind(void) of the source Field object that it
  // is reading with.  The FileReader makes it so that you can have
  // more than one object read the data in a Field.  This saves having
  // to have more than one copy of the data in memory.  An example
  // when this is needed is when your wish to read two fields which
  // are derived from the same series of numbers.  The two Fields can
  // share the data if one (or both) of them is a FieldReader.

  // The Field just needs to implement these three methods for the
  // FieldReader to Field interface.  Then any Field can be a source
  // for a FieldReader. Even a FieldReader can be a source for a .
  
  // makeDequeuer sets up so that another object can read from the
  // data in this Field.  Don't forget to clean up in the destructor.
  // One must be sure that the dequeuer pointer is not pointing to a
  // C++/class like thingy, because casing will break it. If in doubt
  // C-ify it with extern "C" {}.
  virtual void *makeDequeuer(count_t number_of_values) = 0;
  virtual void destroyDequeuer(void *dequeuer) = 0;
 
  // The FieldReader object can use this to read.
  virtual value_t read(void *dequeuer) = 0;

  // read backwards through the list.
  virtual value_t readBack(void *dequeuer) = 0;

  // The FieldReader object can use this to rewind.
  virtual void rewind(void *dequeuer) = 0;

  
private:
  
  // fieldReader is the list of FieldReaders that are using this
  // Field.  FieldReaders in the list remove themselfs in
  // FieldReader::~FieldReader().  FieldReader::FieldReader() adds
  // them to this list.
  FieldReader *fieldReader;
  
  char *name;
  char *label;
};