OOFILE  1.9
oofGrDta.cpp
Go to the documentation of this file.
1 // COPYRIGHT 1997 A.D. Software, All rights reserved
2 
3 //=================================================================================
4 // oofGrDta.cpp
5 //=================================================================================
6 #include "oofpch_g.h" // for precompilation of graph files
7 
8 #include "oofGrDta.h"
9 #ifndef H_OOFGRPHS
10  #include "oofGrphs.h"
11 #endif
12 #ifndef _STDIO
13  #include "stdio.h"
14 #endif
15 #ifndef H_OOF4
16  #include "oof4.h"
17 #endif
18 #ifndef H_OOFVIEW
19  #include "oofview.h"
20 #endif
21 
22 #include "assert.h"
23 
24 #ifdef OOF_MEM_DEBUG_LAST_INCLUDE
25  #include OOF_MEM_DEBUG_LAST_INCLUDE
26 #endif
27 
28 #ifndef OOF_NO_STDLIB
29  #ifndef std
30  using namespace std;
31  #endif
32 #endif
33 
34 
35 oofGraphData::oofGraphData(dbView* theView, dbView* overlayView)
36 {
37  mFirstField = (dbField *) (*theView)[(unsigned int)0];
38  // Hideously unsafe assumption about the field being a string below
39  assert(mFirstField->fieldType()==charField);
40 
41  // Discern the valid data types
42  mSeriesField = (dbField *) (*theView)[1];
43  switch(mSeriesField->fieldType()){
44  case charField: mFormat=standard;
45  break;
46 
47  case longField: mFormat=xy;
48  mSerType=integer;
49  mSerScaling=10;
50  break;
51 
52  case realField: mFormat=xy;
53  mSerType=real;
54  mSerScaling=100;
55  break;
56 
57  default: assert(0);
58  }
59 
60  mDataField = (dbField *) (*theView)[2];
61  switch(mDataField->fieldType()){
62  case longField: mDataType=integer;
63  mDataScaling=10;
64  break;
65 
66  case realField: mDataType=real;
67  mDataScaling=100;
68  break;
69 
70  default: assert(0);
71  }
72 
73  if(overlayView) {
74  mOverlayField = (dbField *) (*overlayView)[(unsigned int)0];
75  assert((mOverlayField->fieldType()==longField)||(mOverlayField->fieldType()==realField));
76  assert(mOverlayField->fieldType()==mDataField->fieldType());
77  } else
78  mOverlayField = 0;
79 }
80 
82 {
83 }
84 
85 long
87 {
88  assert(mFormat==xy); // Otherwise this call is meaningless !
89 
90  switch(mSerType){
91  case integer: return (*(dbLong*)mSeriesField * mSerScaling);
92  break; // for completeness !
93 
94  case real: return (long)(*(dbReal*)mSeriesField * (double)mSerScaling + 0.5);
95  break; // for completeness !
96 
97  default: assert(0);
98  }
99 
100  return 0; // Should never get here !
101 }
102 
103 long
105 {
106  switch(mDataType){
107  case integer: return (*(dbLong*)mDataField * mDataScaling);
108  break; // for completeness !
109 
110  case real: return (long)(*(dbReal*)mDataField * (double)mDataScaling + 0.5);
111  break; // for completeness !
112 
113  default: assert(0);
114  }
115 
116  return 0; // Should never get here !
117 }
118 
119 long
121 {
122  assert(mOverlayField); // In case we were never given an overlay view !
123 
124  switch(mDataType){
125  case integer: return (*(dbLong*)mOverlayField * mDataScaling);
126  break; // for completeness !
127 
128  case real: return (long)(*(dbReal*)mOverlayField * (double)mDataScaling + 0.5);
129  break; // for completeness !
130 
131  default: assert(0);
132  }
133 
134  return 0; // Should never get here !
135 }
136 
137 long
139 {
140  return (value / mSerScaling);
141 }
142 
143 long
145 {
146  return (value / mDataScaling);
147 }
148 
149 double
151 {
152  return (value / (double)mSerScaling);
153 }
154 
155 double
157 {
158  return (value / (double)mDataScaling);
159 }
160 
161 long
163 {
164  return (value * mSerScaling);
165 }
166 
167 long
169 {
170  return (value * mDataScaling);
171 }
172 
173 double
175 {
176  return (value * (double)mSerScaling);
177 }
178 
179 double
181 {
182  return (value * (double)mDataScaling);
183 }
184 
185 
186 char*
188 {
189  char* labelStr=new char[255];
190 
191  assert(labelStr);
192 
193  setScaleString(scaleVal, labelStr, oofGraph::defaultSettings());
194 
195  return labelStr;
196 }
197 
198 
199 void
200 oofGraphData::setScaleString(long scaleVal, char* theString, const oofGraphSettings* settings)
201 {
202  switch(mDataType){
203  case integer:
204  {
205  const char* intMask = settings->intTickLabelMask();
206  sprintf(theString,"%d",scaleVal/mDataScaling);
207  break;
208  }
209  case real:
210  const char* realMask = settings->realTickLabelMask();
211  sprintf(theString, realMask, (double)scaleVal/(double)mDataScaling);
212  break;
213  }
214 }
long seriesValue()
Definition: oofGrDta.cpp:86
long dataValue()
Definition: oofGrDta.cpp:104
Persistent field used to store a double.
Definition: oof4.h:521
long scaleSeriesValue(long)
Definition: oofGrDta.cpp:138
char * makeScaleString(long)
Definition: oofGrDta.cpp:187
Settings object for overriding behaviours of an instance of oofGraph.
Definition: oofSting.h:24
void setScaleString(long, char *, const oofGraphSettings *)
Definition: oofGrDta.cpp:200
Definition: oof3.h:26
long scaleDataValue(long)
Definition: oofGrDta.cpp:144
static oofGraphSettings * defaultSettings()
Definition: oofGrphs.cpp:206
long overlayValue()
Definition: oofGrDta.cpp:120
Definition: oof3.h:26
Provide an iterable set of fields.
Definition: oofview.h:26
long unScaleDataValue(long)
Definition: oofGrDta.cpp:168
long unScaleSeriesValue(long)
Definition: oofGrDta.cpp:162
const char * realTickLabelMask() const
Definition: oofSting.cpp:655
Definition: oof3.h:26
const char * intTickLabelMask() const
Definition: oofSting.cpp:634
oofGraphData(dbView *, dbView *overlayView=0)
Definition: oofGrDta.cpp:35
Base class for persistent fields in dbTable's.
Definition: oof3.h:63
Persistent field used to store a long.
Definition: oof4.h:433