KSquare Utilities
ScannerFileEntry.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 #include <stdlib.h>
3 #include <memory.h>
4 
5 #include <string>
6 #include <iostream>
7 #include <fstream>
8 #include <vector>
9 #include <map>
10 
11 #include "MemoryDebug.h"
12 using namespace std;
13 
14 
15 #include "GlobalGoalKeeper.h"
16 #include "KKBaseTypes.h"
17 #include "KKStrParser.h"
18 #include "OSservices.h"
19 #include "KKStr.h"
20 using namespace KKB;
21 
22 #include "Variables.h"
23 
24 #include "ScannerFileEntry.h"
25 #include "ScannerFile.h"
26 using namespace KKLSC;
27 
28 
30  description (),
31  fullName (),
32  pixelsPerScanLine (0),
33  rootName (_rootName),
34  scanRate (0.0f)
35 {
36 
37 }
38 
39 
40 
42  description (entry.description),
43  fullName (entry.fullName),
44  pixelsPerScanLine (entry.pixelsPerScanLine),
45  rootName (entry.rootName),
46  scanRate (entry.scanRate)
47 {
48 }
49 
50 
51 
52 
54 {
55 }
56 
57 
58 
60 {
61  kkint32 mem = sizeof (*this) +
62  description.MemoryConsumedEstimated () +
65  return mem;
66 }
67 
68 
69 
70 ScannerFileEntryListPtr ScannerFileEntry::globalList = NULL;
71 
72 
74 {
75  delete globalList;
76  globalList = NULL;
77 }
78 
79 
81 {
82  KKStr r (256);
83  r << "Description" << "\t" << description << "\t"
84  << "FullName" << "\t" << fullName << "\t"
85  << "PixelsPerScanLine" << "\t" << pixelsPerScanLine << "\t"
86  << "RootName" << "\t" << rootName << "\t"
87  << "ScanRate" << "\t" << scanRate;
88 
89  return r;
90 } /* ToTabDelStr */
91 
92 
94 {
95  KKStr fieldName = ln.ExtractToken2 ("\t");
96  while (!ln.Empty ())
97  {
98  KKStr fieldName = ln.ExtractToken2 ("\t");
99 
100  if (fieldName.EqualIgnoreCase ("Description"))
101  description = ln.ExtractToken2 ("\t");
102 
103  else if (fieldName.EqualIgnoreCase ("FullName"))
104  fullName = ln.ExtractToken2 ("\t");
105 
106  else if (fieldName.EqualIgnoreCase ("PixelsPerScanLine"))
107  pixelsPerScanLine = ln.ExtractTokenUint ("\t");
108 
109  else if (fieldName.EqualIgnoreCase ("RootName"))
110  rootName = ln.ExtractToken2 ("\t");
111 
112  else if (fieldName.EqualIgnoreCase ("scanRate"))
113  scanRate = (float)ln.ExtractTokenDouble ("\t");
114  }
115 
116  return;
117 } /* ParseTabDelStr */
118 
119 
120 
122 {
123  description = entry.description;
124  fullName = entry.fullName;
125  pixelsPerScanLine = entry.pixelsPerScanLine;
126  rootName = entry.rootName;
127  scanRate = entry.scanRate;
128 } /* ReFresh */
129 
130 
131 
132 ScannerFileEntryPtr ScannerFileEntry::GetOrCreateScannerFileEntry (const KKStr& rootName)
133 {
134  ScannerFileEntryPtr entry = NULL;
135 
137  if (globalList == NULL)
138  {
139  globalList = new ScannerFileEntryList ();
140  atexit (CleanUp);
141  }
142 
143  entry = globalList->LookUpByRootName (rootName);
144  if (entry == NULL)
145  {
146  entry = new ScannerFileEntry (rootName);
147  globalList->AddEntry (entry);
148  }
149 
151 
152  return entry;
153 }
154 
155 
156 
157 ScannerFileEntryPtr ScannerFileEntry::GetOrCreateScannerFileEntry (KKLSC::ScannerFilePtr scannerFile)
158 {
159  ScannerFileEntryPtr entry = NULL;
160 
162  if (globalList == NULL)
163  {
164  globalList = new ScannerFileEntryList ();
165  atexit (CleanUp);
166  }
167 
168  KKStr rootName = osGetRootName (scannerFile->FileName ());
169  entry = globalList->LookUpByRootName (rootName);
170  if (entry == NULL)
171  {
172  entry = new ScannerFileEntry (rootName);
173  entry->FullName (scannerFile->FileName ());
175  entry->ScanRate (scannerFile->ScanRate ());
176  globalList->AddEntry (entry);
177  }
178 
180 
181  return entry;
182 }
183 
184 
185 
186 
187 
188 
191 {
192 }
193 
194 
196 {
197  for (idx = begin (); idx != end (); ++idx)
198  {
199  ScannerFileEntryPtr sfe = idx->second;
200  delete sfe;
201  }
202 }
203 
204 
206 {
207  kkint32 mem = sizeof (*this);
208 
209  for (idx = begin (); idx != end (); ++idx)
210  {
211  ScannerFileEntryPtr sfe = idx->second;
212  mem += sfe->MemoryConsumedEstimated ();
213  }
214 
215  return mem;
216 }
217 
218 
219 
220 
221 void ScannerFileEntryList::AddEntry (ScannerFileEntryPtr entry)
222 {
223  insert (KeyPair (entry->RootName (), entry));
224 }
225 
226 
227 
228 ScannerFileEntryPtr ScannerFileEntryList::LookUpByRootName (const KKStr& rootName)
229 {
230  idx = find (rootName);
231  if (idx == end ())
232  return NULL;
233  else
234  return idx->second;
235 }
void ScanRate(float _scanRate)
void FullName(const KKStr &_fullName)
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for &#39;size&#39; characters.
Definition: KKStr.cpp:655
const KKStr & FileName() const
Definition: ScannerFile.h:92
bool EqualIgnoreCase(const char *s2) const
Definition: KKStr.cpp:1257
kkint32 MemoryConsumedEstimated() const
Definition: KKStr.cpp:766
__int32 kkint32
Definition: KKBaseTypes.h:88
kkuint32 ExtractTokenUint(const char *delStr)
Definition: KKStr.cpp:3141
void ParseTabDelStr(KKStr parser)
ScannerFileEntryPtr LookUpByRootName(const KKStr &rootName)
KKStr ExtractToken2(const char *delStr="\n\t\r ")
Extract first Token from the string.
Definition: KKStr.cpp:3026
KKStr ToTabDelStr() const
float ScanRate() const
Definition: ScannerFile.h:109
static ScannerFileEntryPtr GetOrCreateScannerFileEntry(const KKStr &rootName)
KKStr & operator=(KKStr &&src)
Definition: KKStr.cpp:1369
KKTHread * KKTHreadPtr
Class that keeps track of parameter details of a single scanner file.
kkint32 MemoryConsumedEstimated()
double ExtractTokenDouble(const char *delStr)
Definition: KKStr.cpp:3180
KKStr(const KKStr &str)
Copy Constructor.
Definition: KKStr.cpp:561
bool Empty() const
Definition: KKStr.h:241
void PixelsPerScanLine(kkuint32 _pixelsPerScanLine)
static ScannerFileEntryPtr GetOrCreateScannerFileEntry(KKLSC::ScannerFilePtr scannerFile)
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.
ScannerFileEntry(const KKStr &_rootName)
ScannerFileEntryList * ScannerFileEntryListPtr
ScannerFileEntry * ScannerFileEntryPtr
KKStr & operator=(const KKStr &src)
Definition: KKStr.cpp:1390
ScannerFileEntryList()
kkint32 MemoryConsumedEstimated()
ScannerFileEntry(const ScannerFileEntry &entry)
~ScannerFileEntryList()
kkuint32 PixelsPerScanLine() const
Definition: ScannerFile.h:108
void Assign(const ScannerFileEntry &sf)
Maintains one instance of a GoalKeeper object that can be used anywhere in the application.
void AddEntry(ScannerFileEntryPtr enytry)
static void CleanUp()
KKStr osGetRootName(const KKStr &fullFileName)
~ScannerFileEntry()