OOFILE  1.9
oofSrSet.cpp
Go to the documentation of this file.
1 // COPYRIGHT 1996 A.D. Software, All rights reserved
2 
3 // =================================================================================
4 // oofSrSet.cp
5 // =================================================================================
6 
7 #include "oofpch_g.h" // for precompilation of graph files
8 
9 #ifndef H_OOFRECT
10  #include "oofRect.h"
11 #endif
12 #ifndef H_OOFSRSET
13  #include "oofSrSet.h"
14 #endif
15 #include <string.h>
16 #ifndef H_OOFDSTYL
17  #include "oofDStyl.h"
18 #endif
19 
20 #ifdef OOF_MEM_DEBUG_LAST_INCLUDE
21  #include OOF_MEM_DEBUG_LAST_INCLUDE
22 #endif
23 
24 #ifndef OOF_NO_STDLIB
25  #ifndef std
26  using namespace std;
27  #endif
28 #endif
29 
30 
31 
32 // ---------------------------------------------------------------------------------
33 // oofSeries
34 // ---------------------------------------------------------------------------------
35 
36 
38  mName(0),mLastGeo(0)
39 {
40 }
41 
42 
43 oofSeries::oofSeries(const char *theName, const bool isSymbol):
44  mLastGeo(0),
45  mSymbol(isSymbol)
46 {
47  mName=new char[strlen(theName)+1];
48  strcpy(mName,theName);
49 }
50 
51 
52 oofSeries::oofSeries(const char *theName, const oofColor& inColor, const bool isSymbol):
53  oofColorable(inColor),
54  mLastGeo(0),
55  mSymbol(isSymbol)
56 {
57  mName=new char[strlen(theName)+1];
58  strcpy(mName,theName);
59 }
60 
61 
63 {
64  delete [] mName;
65 }
66 
67 
68 // ---------------------------------------------------------------------------------
69 // oofSeriesSetItem
70 // ---------------------------------------------------------------------------------
71 
73  : mNext(0),
74  mItem(inItem)
75 {
76 }
77 
78 
80 {
81  delete mItem; // oofSeriesSetItem owns the oofSeries
82 }
83 
84 
87 {
88  return mNext;
89 }
90 
91 
92 oofSeries*
94 {
95  return mItem;
96 }
97 
98 
99 void
101 {
102  mNext = inItem;
103 }
104 
105 
106 // ---------------------------------------------------------------------------------
107 // oofSeriesSet
108 // ---------------------------------------------------------------------------------
109 
111  : mCount(0),
112  mFirst(0),
113  mLast(0)
114 {
115 }
116 
117 
118 void
120 {
121  oofSeriesSetItem *theItem = new oofSeriesSetItem(inItem);
122 
123  if (isEmpty()) { // list is empty
124  mFirst = theItem;
125  mLast = theItem;
126  }
127  else { // else put it after last
128  mLast->setNext(theItem);
129  mLast = theItem;
130  }
131  mCount++;
132 }
133 
134 
135 const oofSeries*
137 {
138  if (isEmpty())
139  return 0;
140 
141  oofSeriesSetItem *theItem = mFirst;
142  const oofSeries *theSeries = mFirst->item();
143 
144  if (mFirst == mLast) { // list had one item, now has none
145  mFirst = 0;
146  mLast = 0;
147  } else {
148  mFirst = theItem->next();
149  }
150 
151  mCount--;
152 
153  delete theItem;
154  return theSeries;
155 }
156 
157 
160 {
161  return mFirst; // return first element
162 }
163 
164 
165 int
167 {
168  return (mCount==0); // is the list empty?
169 }
170 
171 
172 unsigned long
174 {
175  return mCount; // Return the number of items
176 }
177 
178 
180 {
181  while (mCount)
182  remove();
183 }
184 
185 oofSeries*
186 oofSeriesSet::findSeriesByName(const char* theName, const bool makeNewItemSymbol)
187 {
188  for(oofSeriesSetItem *theItem=first();theItem;theItem=theItem->next()) {
189  oofSeries* theSeries=theItem->item();
190  if (strcmp(theSeries->Name(),theName)==0)
191  return(theSeries);
192  }
193  // We didn't find an existing one - add a new one
194  oofSeries *newSeries=new oofSeries(theName,makeNewItemSymbol);
195  append(newSeries);
196 
197  return newSeries;
198 }
199 
200 oofSeries*
201 oofSeriesSet::operator[](unsigned long index)
202 {
203  if(!mFirst)
204  return 0;
205 
206  if(!index)
207  return mFirst->item();
208 
209  if(index>mCount)
210  return mLast->item();
211 
212  unsigned long i=0;
213  for(oofSeriesSetItem *theItem=first();theItem;theItem=theItem->next()){
214  if(index==i)
215  return theItem->item();
216  i++;
217  }
218 
219  // never get here !
220  return 0;
221 }
222 
223 void
225 {
226  for(oofSeriesSetItem *theItem=first();theItem;theItem=theItem->next()) {
227  // oofSeries* theSeries=theItem->Item();
228  // theSeries->setDrawStyle(inSet.getNextDrawStyle());
229  theItem->item()->setDrawStyle(inSet.getNextDrawStyle());
230  }
231 }
232 
233 
234 void
236 {
237  unsigned long index = 0;
238  for(oofSeriesSetItem *theItem=first();theItem;theItem=theItem->next()) {
239  theItem->item()->setDrawStyle(inArray.item(index));
240  index++;
241  }
242 }
243 
244 
245 /*
246 void
247 oofSeriesSet::ChangeSeriesColor(int inSeriesNumber, RGBColor NewBaseColor)
248 {
249  for(oofSeriesSetItem *theItem=First();theItem;theItem=theItem->Next()) {
250  oofSeries* theSeries=theItem->Item();
251  if (theSeries->SeriesNumber() == inSeriesNumber)
252  theSeries->SetColor(NewBaseColor);
253  }
254 }
255 */
const oofDrawStyle & item(unsigned long index) const
Definition: oofDStyl.cpp:320
Base for anything that can be drawn in color.
Definition: oofClrbl.h:15
oofSeries * findSeriesByName(const char *theSeries, const bool makeNewItemSymbol=false)
Definition: oofSrSet.cpp:186
oofSeries * item()
Definition: oofSrSet.cpp:93
Track a single oofSeries in an oofSeriesSet.
Definition: oofSrSet.h:43
char * Name() const
Definition: oofSrSet.h:26
void append(oofSeries *inItem)
Definition: oofSrSet.cpp:119
virtual ~oofSeries()
Definition: oofSrSet.cpp:62
oofSeriesSetItem(oofSeries *inItem)
Definition: oofSrSet.cpp:72
void setNext(oofSeriesSetItem *)
Definition: oofSrSet.cpp:100
int isEmpty()
Definition: oofSrSet.cpp:166
unsigned long count()
Definition: oofSrSet.cpp:173
oofSeriesSetItem * first()
Definition: oofSrSet.cpp:159
Virtual base for generator class returning sequence of oofDrawStyle.
Definition: oofDStyl.h:113
const oofSeries * remove()
Definition: oofSrSet.cpp:136
Cross-platform color specification class.
Definition: oofcolor.h:123
void setDrawStyles(oofDrawStyleSet &)
Definition: oofSrSet.cpp:224
Array of owned oofDrawStyle's adopting them for correct lifetime management.
Definition: oofDStyl.h:86
oofSeriesSetItem * next()
Definition: oofSrSet.cpp:86
virtual ~oofSeriesSet()
Definition: oofSrSet.cpp:179
oofSeries * operator[](unsigned long index)
Definition: oofSrSet.cpp:201
Contains series of data in a graph, eg: a single line of a graph.
Definition: oofSrSet.h:19
virtual oofDrawStyle getNextDrawStyle()
Definition: oofDStyl.cpp:360