HatchKeeper  0.90
The Free Open-Source Egg Incubation Software
HK_Storage.cpp
Go to the documentation of this file.
1 /*******************************************************************/
9 #include "../headers/Storage.h"
10 
13 
15 void HK_Storage::Add(string Name, int ID, HK_Date Date, string Text, int Number){
16  HK_StoreName.push_back(Name);
17  HK_StoreID.push_back(ID);
18  HK_StoreDate.push_back(Date);
19  HK_StoreText.push_back(Text);
20  HK_StoreNumber.push_back(Number);
21 }
22 
24 void HK_Storage::Add(string Name, int ID, HK_Date Date, string Text){
25  HK_StoreName.push_back(Name);
26  HK_StoreID.push_back(ID);
27  HK_StoreDate.push_back(Date);
28  HK_StoreText.push_back(Text);
29 }
30 
32 void HK_Storage::Add(string Name, int ID, string Text, int Number) {
33  HK_StoreName.push_back(Name);
34  HK_StoreID.push_back(ID);
35  HK_StoreText.push_back(Text);
36  HK_StoreNumber.push_back(Number);
37 }
38 
40 void HK_Storage::Add(string Name, int ID, string Text){
41  HK_StoreName.push_back(Name);
42  HK_StoreID.push_back(ID);
43  HK_StoreText.push_back(Text);
44 }
45 
47 void HK_Storage::Add(string Name, int ID, int Number){
48  HK_StoreName.push_back(Name);
49  HK_StoreID.push_back(ID);
50  HK_StoreNumber.push_back(Number);
51 }
52 
54 void HK_Storage::Add(string Name, int ID, HK_Date Date){
55  HK_StoreName.push_back(Name);
56  HK_StoreID.push_back(ID);
57  HK_StoreDate.push_back(Date);
58 }
59 
61 string HK_Storage::GetName(int Select){
62  return HK_StoreName[Select];
63 }
64 
66 int HK_Storage::GetID(int Select){
67  return HK_StoreID[Select];
68 }
69 
72  return HK_StoreDate[Select];
73 }
74 
76 int HK_Storage::GetDay(int Select){
77  return HK_StoreDate[Select].GetDay();
78 }
79 
81 int HK_Storage::GetMonth(int Select){
82  return HK_StoreDate[Select].GetMonth();
83 }
84 
86 int HK_Storage::GetYear(int Select){
87  return HK_StoreDate[Select].GetYear();
88 }
89 
91 string HK_Storage::GetText(int Select){
92  return HK_StoreText[Select];
93 }
94 
96 int HK_Storage::GetNumber(int Select){
97  return HK_StoreNumber[Select];
98 }
99 
102  return HK_StoreName.size();
103 }
104 
107 {
108  int A = 0, B, ID = -1;
109  bool Found = false;
110  while(ID == -1) {
111  Found = false;
112  for(B = 0;B < GetCount(); B++) {
113  if( GetID(B) == A) {
114  Found = true;
115  break;
116  }
117  }
118  if(!Found) {
119  ID = A;
120  break;
121  }
122  A++;
123  }
124  return A;
125 }
126 
128 bool HK_Storage::IsValidName(string Name)
129 {
130  for(int A = 0; A < GetCount(); A++) {
131  if(GetName(A) == Name)
132  return false;
133  }
134  return true;
135 }
136 
138 HK_KeyValue HK_Storage::Search(string Prefix, string Value)
139 {
140  HK_KeyValue Results;
141  string Name, Text;
142 
143  transform(Value.begin(),Value.end(),Value.begin(), ::tolower);
144 
145  for(int A = 0; A < GetCount(); A++) {
146  Name = HK_StoreName[A];
147  transform(Name.begin(),Name.end(),Name.begin(), ::tolower);
148 
149  if(Name.find(Value) != string::npos){
150  Results.Add(
151  Prefix + " " + HK_StoreName[A] + "'s Name",
152  HK_StoreName[A]
153  );
154  }
155 
156  if(!HK_StoreText.empty()) {
157  Text = HK_StoreText[A];
158  transform(Text.begin(),Text.end(),Text.begin(), ::tolower);
159  if(Text.find(Value) != string::npos){
160  Results.Add(
161  Prefix + " " + HK_StoreName[A] + "'s Comment",
162  HK_StoreText[A]
163  );
164  }
165  }
166  }
167 
168  return Results;
169 }
170 
172 void HK_Storage::SetName(int Select, string Name){
173  HK_StoreName[Select] = Name;
174 }
175 
177 void HK_Storage::SetID(int Select, int ID){
178  HK_StoreID[Select] = ID;
179 }
180 
182 void HK_Storage::SetDate(int Select, HK_Date Date){
183  HK_StoreDate[Select] = Date;
184 }
185 
187 void HK_Storage::SetDay(int Select, int Days){
188  HK_StoreDate[Select].SetDay(Days);
189 }
190 
192 void HK_Storage::SetMonth(int Select, int Month){
193  HK_StoreDate[Select].SetMonth(Month);
194 }
195 
197 void HK_Storage::SetYear(int Select, int Year){
198  HK_StoreDate[Select].SetYear(Year);
199 }
200 
202 void HK_Storage::SetText(int Select, string Text){
203  HK_StoreText[Select] = Text;
204 }
205 
207 void HK_Storage::SetNumber(int Select, int Number){
208  HK_StoreNumber[Select] = Number;
209 }
210 
213  HK_StoreName.clear();
214  HK_StoreID.clear();
215  HK_StoreDate.clear();
216  HK_StoreText.clear();
217  HK_StoreNumber.clear();
218  HK_StoreName.shrink_to_fit();
219  HK_StoreID.shrink_to_fit();
220  HK_StoreDate.shrink_to_fit();
221  HK_StoreText.shrink_to_fit();
222  HK_StoreNumber.shrink_to_fit();
223 }
A Class For Managing Dates.
Definition: Date.h:25
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
bool IsValidName(string Name)
Returns True If Name Isn't Already In Use.
Definition: HK_Storage.cpp:128
int GetDay(int Select)
Returns The Selected Day From The Stored Date.
Definition: HK_Storage.cpp:76
vector< int > HK_StoreNumber
Definition: Storage.h:32
vector< int > HK_StoreID
Definition: Storage.h:29
int GetMonth(int Select)
Returns The Selected Month From The Stored Date.
Definition: HK_Storage.cpp:81
HK_Date GetDate(int Select)
Returns The Selected Stored Date.
Definition: HK_Storage.cpp:71
vector< string > HK_StoreText
Definition: Storage.h:31
int GetValidID()
Returns A Valid ID For Adding Entries To The Database.
Definition: HK_Storage.cpp:106
int GetCount()
Returns The Number Of Elements Stored.
Definition: HK_Storage.cpp:101
void SetMonth(int Select, int Month)
Sets The Selected Month From The Stored Date.
Definition: HK_Storage.cpp:192
int GetNumber(int Select)
Returns The Selected Stored Number.
Definition: HK_Storage.cpp:96
void SetNumber(int Select, int Number)
Sets The Selected Stored Number.
Definition: HK_Storage.cpp:207
HK_KeyValue Search(string Prefix, string Value)
Returned HK_KeyValue's Key Holds Name And Value Holds String Where Match Was Found.
Definition: HK_Storage.cpp:138
void SetName(int Select, string Name)
Sets The Selected Stored Name.
Definition: HK_Storage.cpp:172
void SetID(int Select, int ID)
Sets The Selected Stored ID.
Definition: HK_Storage.cpp:177
HK_Storage()
Constructor.
Definition: HK_Storage.cpp:12
vector< HK_Date > HK_StoreDate
Definition: Storage.h:30
void SetDay(int Select, int Days)
Sets The Selected Day From The Stored Date.
Definition: HK_Storage.cpp:187
vector< string > HK_StoreName
Definition: Storage.h:28
void SetDate(int Select, HK_Date Date)
Sets The Selected Stored Date.
Definition: HK_Storage.cpp:182
string GetName(int Select)
Returns The Selected Stored Name.
Definition: HK_Storage.cpp:61
int GetYear(int Select)
Returns The Selected Year From The Stored Date.
Definition: HK_Storage.cpp:86
string GetText(int Select)
Returns The Selected Stored Text.
Definition: HK_Storage.cpp:91
void Add(string Name, int ID, HK_Date Date, string Text, int Number)
Adds An Item To Storage.
Definition: HK_Storage.cpp:15
void SetYear(int Select, int Year)
Sets The Selected Year From The Stored Date.
Definition: HK_Storage.cpp:197
int GetID(int Select)
Returns The Selected Stored ID.
Definition: HK_Storage.cpp:66
void Clear()
Clears All Data And Shrinks The Arrays.
Definition: HK_Storage.cpp:212
void SetText(int Select, string Text)
Sets The Selected Stored Text.
Definition: HK_Storage.cpp:202