HatchKeeper  0.90
The Free Open-Source Egg Incubation Software
HK_Batches.cpp
Go to the documentation of this file.
1 /*******************************************************************/
9 #include "../headers/Batches.h"
10 
13 
16  HK_BatchInstance.push_back(Batch);
17  HK_BatchDirty.push_back(false);
18 }
19 
21 void HK_Batches::Add(int ID, string Name, string Type,
22  string Breed, string Group, string Comments, string Incubator,
23  int Eggs, int Fertile, int Chicks,
24  HK_Date Start, HK_Date Candle, HK_Date Lockdown, HK_Date Hatch,
25  int Remind, int Adv)
26 {
27  //Push Empty Batch
28  HK_Batch Batch;
29  HK_BatchInstance.push_back(Batch);
30  HK_BatchInstance[GetCount() - 1].Set(
31  ID, Name, Type, Breed, Group, Comments, Incubator,Eggs,
32  Fertile, Chicks, Start, Candle, Lockdown, Hatch, Remind, Adv
33  );
34  HK_BatchDirty.push_back(false);
35 }
36 
39 {
40  int Select = -1;
41 
42  for(int A = 0; A < GetCount(); A++)
43  if(Adv.GetID() == GetID(A))
44  Select = A;
45 
46  if(Select == -1)
47  return false;
48  else
49  HK_BatchInstance[Select].SetAdvanced(Adv);
50 
51  return true;
52 }
53 
56 {
57  return HK_BatchInstance[Select];
58 }
59 
61 int HK_Batches::GetID(int Select){return HK_BatchInstance[Select].GetID();}
63 string HK_Batches::GetName(int Select){return HK_BatchInstance[Select].GetName();}
65 string HK_Batches::GetType(int Select){return HK_BatchInstance[Select].GetType();}
67 string HK_Batches::GetBreed(int Select){return HK_BatchInstance[Select].GetBreed();}
69 string HK_Batches::GetGroup(int Select){return HK_BatchInstance[Select].GetGroup() ;}
71 string HK_Batches::GetComments(int Select){return HK_BatchInstance[Select].GetComments();}
73 string HK_Batches::GetIncubator(int Select){return HK_BatchInstance[Select].GetIncubator();}
75 int HK_Batches::GetEggs(int Select){return HK_BatchInstance[Select].GetEggs();}
77 int HK_Batches::GetFertile(int Select){return HK_BatchInstance[Select].GetFertile();}
79 int HK_Batches::GetChicks(int Select){return HK_BatchInstance[Select].GetChicks();}
81 HK_Date HK_Batches::GetStart(int Select){return HK_BatchInstance[Select].GetStart();}
83 HK_Date HK_Batches::GetCandle(int Select){return HK_BatchInstance[Select].GetCandle();}
85 HK_Date HK_Batches::GetLockdown(int Select){return HK_BatchInstance[Select].GetLockdown();}
87 HK_Date HK_Batches::GetHatch(int Select){return HK_BatchInstance[Select].GetHatch();}
89 int HK_Batches::GetRemind(int Select){return HK_BatchInstance[Select].GetRemind();}
91 int HK_Batches::GetAdv(int Select){return HK_BatchInstance[Select].GetAdv();}
93 HK_Advanced HK_Batches::GetAdvanced(int Select){return HK_BatchInstance[Select].GetAdvanced();}
94 
96 vector<string> HK_Batches::GetSQL(int Select, int ID)
97 {
98  return HK_BatchInstance[Select].GetSQL(ID);
99 }
100 
102 bool HK_Batches::IsDirty(int Select){return HK_BatchDirty[Select];}
103 
106 {
107  return HK_BatchInstance[Select].PercentFertile();
108 }
109 
112 {
113  return HK_BatchInstance[Select].PercentOfFertile();
114 }
115 
118 {
119  return HK_BatchInstance[Select].PercentOfTotal();
120 }
121 
124 {
125  return HK_BatchInstance[Select].FertileUnhatched();
126 }
127 
130 {
131  return HK_BatchInstance[Select].PercentOfTotalUnhatched();
132 }
133 
134 
137 {
138  int Total = 0;
139  for(int A = 0; A < GetCount(); A++)
140  Total += GetEggs(A);
141  return Total;
142 }
143 
146 {
147  int Total = 0;
148  for(int A = 0; A < GetCount(); A++)
149  Total += GetChicks(A);
150  return Total;
151 }
152 
155 {
156  int Total = 0;
157  for(int A = 0; A < GetCount(); A++)
158  Total += PercentFertile(A);
159  return Total / GetCount();
160 }
161 
164 {
165  int Total = 0;
166  for(int A = 0; A < GetCount(); A++)
167  Total += PercentOfTotal(A);
168  return Total / GetCount();
169 }
170 
173 {
174  int Total = 0;
175  for(int A = 0; A < GetCount(); A++)
176  Total += PercentOfFertile(A);
177  return Total / GetCount();
178 }
179 
182 {
183  int Total = 0;
184  for(int A = 0; A < GetCount(); A++)
185  Total += PercentOfTotalUnhatched(A);
186  return Total / GetCount();
187 }
188 
189 
192 
195 {
196  int A = 0, B, ID = -1;
197  bool Found = false;
198  while(ID == -1) {
199  Found = false;
200  for(B = 0;B < GetCount(); B++) {
201  if( GetID(B) == A) {
202  Found = true;
203  break;
204  }
205  }
206  if(!Found) {
207  ID = A;
208  break;
209  }
210  A++;
211  }
212  return A;
213 }
214 
216 bool HK_Batches::IsValidName(string Name)
217 {
218  for(int A = 0; A < GetCount(); A++)
219  if(GetName(A) == Name)
220  return false;
221 
222  return true;
223 }
224 
227 {
228  HK_BatchInstance.clear();
229  HK_BatchInstance.shrink_to_fit();
230 }
231 
233 HK_KeyValue HK_Batches::Search(string Value, bool SearchBatch, bool SearchAdv)
234 {
235  HK_KeyValue Results;
236 
237  for(int A = 0; A < GetCount(); A++)
238  Results.Add(HK_BatchInstance[A].Search(Value, SearchBatch, SearchAdv));
239 
240  return Results;
241 }
242 
244 void HK_Batches::SetAdvEgg(int Select, HK_Egg Egg, int EggSelect)
245 {
246  HK_BatchInstance[Select].SetAdvEgg(Egg,EggSelect);
247  SetDirty(Select);
248 }
250 void HK_Batches::SetAdvUpdate(int Select, bool Status){HK_BatchInstance[Select].SetAdvUpdate(Status);}
251 
253 void HK_Batches::SetBatch(int Select, HK_Batch Batch)
254 {
255  HK_BatchInstance[Select] = Batch;
256  SetDirty(Select);
257 }
259 void HK_Batches::SetClean(int Select){HK_BatchDirty[Select] = false;}
261 void HK_Batches::SetDirty(int Select){HK_BatchDirty[Select] = true;}
HK_Storage Remind
Definition: Declare.h:40
A Class For Managing Multiple HK_Egg Instances.
Definition: Advanced.h:20
int GetID()
Returns ID.
Definition: HK_Advanced.cpp:42
Holds Data For One Batch, Includes Basic Set/Get Methods.
Definition: Batch.h:22
HK_Advanced GetAdvanced(int Select)
Returns Advanced Egg Data Selected Batch.
Definition: HK_Batches.cpp:93
HK_Date GetHatch(int Select)
Returns Hatch Date For Selected Batch.
Definition: HK_Batches.cpp:87
void Clear()
Clears All Batches.
Definition: HK_Batches.cpp:226
int GetID(int Select)
Returns Batch ID For Selected Batch.
Definition: HK_Batches.cpp:61
void SetDirty(int Select)
Sets Dirty Mark For Selected Batch.
Definition: HK_Batches.cpp:261
int PercentOfTotalUnhatched(int Select)
Returns The Percentage Of Total Eggs That Didn't Hatch For The Selected Batch.
Definition: HK_Batches.cpp:129
vector< bool > HK_BatchDirty
Definition: Batches.h:25
HK_Date GetStart(int Select)
Returns Start Date For Selected Batch.
Definition: HK_Batches.cpp:81
void Add(HK_Batch Batch)
Adds Another HK_Batch.
Definition: HK_Batches.cpp:15
void SetClean(int Select)
Clears Dirty Mark For Selected Batch.
Definition: HK_Batches.cpp:259
int AvgTotalUnHatch()
Returns Average Percentage Of Total Eggs That Did Not Hatch In This HK_Batches Instance.
Definition: HK_Batches.cpp:181
int AvgFertileHatch()
Returns Average Percentage Of Fertile Eggs That Hatched In This HK_Batches Instance.
Definition: HK_Batches.cpp:172
string GetIncubator(int Select)
Returns Batch Incubator For Selected Batch.
Definition: HK_Batches.cpp:73
void SetAdvUpdate(int Select, bool Status)
Sets The Update Status HK_Advanced.
Definition: HK_Batches.cpp:250
int GetAdv(int Select)
Returns Advanced Status For Selected Batch.
Definition: HK_Batches.cpp:91
int GetValidID()
Returns An ID That Isn't Used By Any HK_Batch In This HK_Batches Instance.
Definition: HK_Batches.cpp:194
int AvgFertile()
Returns Average Percentage Of Eggs Fertile In This HK_Batches Instance.
Definition: HK_Batches.cpp:154
void SetBatch(int Select, HK_Batch Batch)
Replaces Batch In Selected Position In Array. Use Add() To Add A Batch.
Definition: HK_Batches.cpp:253
int GetChicks(int Select)
Returns Number Of Hatched Eggs For Selected Batch.
Definition: HK_Batches.cpp:79
bool IsDirty(int Select)
Returns True If Batch Has Dirty Mark Set.
Definition: HK_Batches.cpp:102
int GetFertile(int Select)
Returns Number Of Fertile Eggs For Selected Batch.
Definition: HK_Batches.cpp:77
bool AddAdvanced(HK_Advanced Adv)
Add Advanced Data To The Batch That Has A Matching ID.
Definition: HK_Batches.cpp:38
int PercentOfTotal(int Select)
Returns The Percentage Of Total Eggs That Hatched For The Selected Batch.
Definition: HK_Batches.cpp:117
HK_Date GetCandle(int Select)
Returns Candle Date For Selected Batch.
Definition: HK_Batches.cpp:83
int TotalEggs()
Returns Total Number Of Eggs In This HK_Batches Instance.
Definition: HK_Batches.cpp:136
string GetType(int Select)
Returns Batch Type For Selected Batch.
Definition: HK_Batches.cpp:65
vector< string > GetSQL(int Select, int ID)
Returns SQL String(s) To Set Batch In Database For Selected Batch.
Definition: HK_Batches.cpp:96
HK_KeyValue Search(string Value, bool SearchBatch, bool SearchAdv)
Returned HK_KeyValue's Key Holds Name And Value Holds String Where Match Was Found.
Definition: HK_Batches.cpp:233
int AvgTotalHatch()
Returns Average Percentage Of Total Eggs That Hatched In This HK_Batches Instance.
Definition: HK_Batches.cpp:163
HK_Batch GetBatch(int Select)
Returns The Selected Batch.
Definition: HK_Batches.cpp:55
bool IsValidName(string Name)
Returns True If Name Isn't Already In Use.
Definition: HK_Batches.cpp:216
string GetGroup(int Select)
Returns Batch Group For Selected Batch.
Definition: HK_Batches.cpp:69
vector< HK_Batch > HK_BatchInstance
Definition: Batches.h:24
void SetAdvEgg(int Select, HK_Egg Egg, int EggSelect)
Sets The Selected Egg For HK_Advanced.
Definition: HK_Batches.cpp:244
int GetEggs(int Select)
Returns Number Of Eggs For Selected Batch.
Definition: HK_Batches.cpp:75
int PercentFertile(int Select)
Returns The Percentage Of Egg That Were Fertile For The Selected Batch.
Definition: HK_Batches.cpp:105
int GetCount()
Returns The Number Of Batches Stored.
Definition: HK_Batches.cpp:191
int PercentOfFertile(int Select)
Returns The Percentage Of Fertile Eggs That Hatched For The Selected Batch.
Definition: HK_Batches.cpp:111
int FertileUnhatched(int Select)
Returns The Number Of Fertile Eggs That Didn't Hatch For The Selected Batch.
Definition: HK_Batches.cpp:123
HK_Date GetLockdown(int Select)
Returns Lockdown Date For Selected Batch.
Definition: HK_Batches.cpp:85
int GetRemind(int Select)
Returns Remind Status For Selected Batch.
Definition: HK_Batches.cpp:89
string GetComments(int Select)
Returns Batch Comments For Selected Batch.
Definition: HK_Batches.cpp:71
int TotalChicks()
Returns Total Number Of Chicks In This HK_Batches Instance.
Definition: HK_Batches.cpp:145
string GetName(int Select)
Returns Batch Name For Selected Batch.
Definition: HK_Batches.cpp:63
string GetBreed(int Select)
Returns Batch Breed For Selected Batch.
Definition: HK_Batches.cpp:67
HK_Batches()
Default Constructor.
Definition: HK_Batches.cpp:12
A Class For Managing Dates.
Definition: Date.h:25
A Class For Storing And Retieving Data For One Egg.
Definition: Egg.h:24
A Key and Value Type Storage.
Definition: KeyValue.h:25
void Add(string Key, string Value)
Adds A Key And Value;.
Definition: HK_KeyValue.cpp:33