KSquare Utilities
ScannerHeaderFields.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 #include <stdio.h>
3 #include <errno.h>
4 #include <string.h>
5 #include <ctype.h>
6 
7 #include <iostream>
8 #include <fstream>
9 #include <map>
10 #include <vector>
11 
12 #include "MemoryDebug.h"
13 using namespace std;
14 
15 #include "GoalKeeper.h"
16 #include "KKBaseTypes.h"
17 #include "KKQueue.h"
18 #include "KKStr.h"
19 using namespace KKB;
20 
22 using namespace KKLSC;
23 
24 
26  map<KKStr,KKStr> (),
27  goalie (NULL)
28 {
29  GoalKeeper::Create ("ScannerHeaderFields", goalie);
30 }
31 
32 
33 
35  map<KKStr,KKStr> (),
36  goalie (NULL)
37 {
38  GoalKeeper::Create ("ScannerHeaderFields", goalie);
39  ScannerHeaderFields::const_iterator idx;
40  for (idx = fields.begin (); idx != fields.end (); ++idx)
41  Add (idx->first, idx->second);
42 }
43 
44 
45 
47 {
48  GoalKeeper::Destroy (goalie);
49  goalie = NULL;
50 }
51 
52 
53 
55 {
56  goalie->StartBlock ();
57 
58  kkint32 mem = sizeof (*this);
59 
60  if (goalie) mem += goalie->MemoryConsumedEstimated ();
61 
62  for (idx2 = begin (); idx2 != end (); ++idx2)
63  {
64  mem = mem + (idx2->first.MemoryConsumedEstimated () + idx2->second.MemoryConsumedEstimated ());
65  }
66 
67  goalie->EndBlock ();
68 
69  return mem;
70 }
71 
72 
73 
75 {
76  if (!fields)
77  return;
78  ScannerHeaderFields::const_iterator idx;
79  for (idx = fields->begin (); idx != fields->end (); ++idx)
80  Add (idx->first, idx->second);
81 }
82 
83 
84 
85 void ScannerHeaderFields::Add (const KKB::KKStr& fieldName,
86  const KKB::KKStr& fieldValue
87  )
88 {
89  goalie->StartBlock ();
90 
91  idx1 = this->find (fieldName);
92  if (idx1 == end ())
93  insert (pair<KKStr,KKStr>(fieldName, fieldValue));
94  else
95  idx1->second = fieldValue;
96 
97  goalie->EndBlock ();
98 }
99 
100 
101 void ScannerHeaderFields::Add (const KKB::KKStr& fieldName,
102  bool fieldValue
103  )
104 {
105  KKStr fieldValueStr = (fieldValue ? "Yes" : "No");
106  Add (fieldName, fieldValueStr);
107 }
108 
109 
110 void ScannerHeaderFields::Add (const KKStr& fieldName,
111  kkint32 fieldValue
112  )
113 {
114  KKStr fieldValueStr = StrFromInt64 (fieldValue);
115  Add (fieldName, fieldValueStr);
116 }
117 
118 
119 
120 void ScannerHeaderFields::Add (const KKStr& fieldName,
121  kkint64 fieldValue
122  )
123 {
124  KKStr fieldValueStr = StrFromInt64 (fieldValue);
125  Add (fieldName, fieldValueStr);
126 }
127 
128 
129 
130 void ScannerHeaderFields::Add (const KKStr& fieldName,
131  double fieldValue
132  )
133 {
134  KKStr fieldValueStr (20);
135  fieldValueStr << fieldValue;
136  Add (fieldName, fieldValueStr);
137 }
138 
139 
140 
141 
142 void ScannerHeaderFields::Add (const KKStr& fieldName,
143  DateTime fieldValue
144  )
145 {
146  KKStr s (20);
147  s << fieldValue;
148  Add (fieldName, s);
149 }
150 
151 
152 
153 
155 {
156  goalie->StartBlock ();
157  clear ();
158  goalie->EndBlock ();
159 }
160 
161 
162 
163 bool ScannerHeaderFields::FieldExists (const KKStr& fieldName) const
164 {
165  bool exists = false;
166  goalie->StartBlock ();
167  idx2 = this->find (fieldName);
168  exists = (idx2 != end ());
169  goalie->EndBlock ();
170  return exists;
171 }
172 
173 
174 
175 const KKStr& ScannerHeaderFields::GetValue (const KKStr& fieldName) const
176 {
177  const KKStr* value = NULL;
178 
179  goalie->StartBlock ();
180  idx2 = this->find (fieldName);
181  if (idx2 == end ())
182  value = &(KKStr::EmptyStr ());
183  else
184  value = &(idx2->second);
185  goalie->EndBlock ();
186 
187  return *value;
188 }
189 
190 
191 
192 float ScannerHeaderFields::GetValueFloat (const KKStr& fieldName) const
193 {
194  KKStr s = GetValue (fieldName);
195  return s.ToFloat ();
196 }
197 
198 
199 
201 {
202  KKStr s = GetValue (fieldName);
203  return s.ToInt32 ();
204 }
205 
206 
207 
208 
210 {
211  goalie->StartBlock ();
212 }
213 
214 
215 
217 {
218  goalie->EndBlock ();
219 }
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for &#39;size&#39; characters.
Definition: KKStr.cpp:655
__int32 kkint32
Definition: KKBaseTypes.h:88
KKStr StrFromInt64(kkint64 i)
Definition: KKStr.cpp:5198
kkint32 GetValueInt32(const KKStr &fieldName) const
void Add(const KKStr &fieldName, kkint32 fieldValue)
static void Destroy(volatile GoalKeeperPtr &_goalKeeperInstance)
Destroys an existing instance of GoalKeeper.
Definition: GoalKeeper.cpp:491
bool FieldExists(const KKStr &fieldName) const
kkint32 MemoryConsumedEstimated() const
Definition: GoalKeeper.cpp:166
static void Create(const KKStr &_name, volatile GoalKeeperPtr &_newGoalKeeper)
Create a GoalKeeper object and avoid a race condition doing it.
Definition: GoalKeeper.cpp:346
__int64 kkint64
Definition: KKBaseTypes.h:90
KKTHread * KKTHreadPtr
void Add(const KKStr &fieldName, double fieldValue)
void StartBlock()
Initiates a Block as long as another thread has not already locked this object.
Definition: GoalKeeper.cpp:214
float GetValueFloat(const KKStr &fieldName) const
void EndBlock()
Ends the block and allows other threads to pass through StatBlock.
Definition: GoalKeeper.cpp:295
kkint32 ToInt32() const
Definition: KKStr.cpp:3587
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
Contains Classes that are specific to Cameras physical characteristics.
ScannerHeaderFields * ScannerHeaderFieldsPtr
Represents a list of header fields from a Scanner File.
void Add(const KKStr &fieldName, KKB::DateTime fieldValue)
const KKStr & GetValue(const KKStr &fieldName) const
void Add(const KKB::KKStr &fieldName, bool fieldValue)
float ToFloat() const
Definition: KKStr.cpp:3553
ScannerHeaderFields(const ScannerHeaderFields &fields)
void Add(const KKStr &fieldName, kkint64 fieldValue)
void Add(ScannerHeaderFieldsPtr fields)
void Add(const KKB::KKStr &fieldName, const KKB::KKStr &fieldValue)