KSquare Utilities
MLClass.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 #include <stdio.h>
3 #include <string>
4 #include <iostream>
5 #include <fstream>
6 #include <map>
7 #include <vector>
8 #include "MemoryDebug.h"
9 using namespace std;
10 
11 #include "GlobalGoalKeeper.h"
12 #include "KKBaseTypes.h"
13 #include "KKStrParser.h"
14 #include "OSservices.h"
15 #include "RunLog.h"
16 using namespace KKB;
17 
18 #include "FileDesc.h"
19 #include "MLClass.h"
20 using namespace KKMLL;
21 
22 
23 
24 MLClassListPtr MLClass::existingMLClasses = NULL;
25 map<MLClassListPtr,MLClassListPtr> MLClass::existingClassLists;
26 
27 GoalKeeperPtr MLClass::blocker = NULL;
28 bool MLClass::needToRunFinalCleanUp = false;
29 
30 
31 // Will instantiate an instance of "GoalKeeper" if "blocker" does not already
32 // point one.
33 void MLClass::CreateBlocker ()
34 {
35  if (!blocker)
36  {
37  GoalKeeper::Create ("GlobalMLClass", blocker); // Will handle Race condition.
38  blocker->StartBlock ();
39  if (!needToRunFinalCleanUp)
40  {
41  needToRunFinalCleanUp = true;
42  atexit (MLClass::FinalCleanUp);
43  }
44  blocker->EndBlock ();
45  }
46 }
47 
48 
49 
51 {
52  if (!existingMLClasses)
53  {
54  CreateBlocker ();
55  blocker->StartBlock ();
56  if (!existingMLClasses)
57  {
58  existingMLClasses = new MLClassList ();
59  existingMLClasses->Owner (true);
60  }
61  blocker->EndBlock ();
62  }
63  return existingMLClasses;
64 } /* GlobalClassList */
65 
66 
67 
68 /** @brief Called by MLClassList constructors to add to list of existing MLClassList instances. */
69 void MLClass::AddImageClassList (MLClassListPtr list)
70 {
71  CreateBlocker ();
72  blocker->StartBlock ();
73  existingClassLists.insert (pair<MLClassListPtr,MLClassListPtr> (list, list));
74  blocker->EndBlock ();
75 }
76 
77 
78 
79 /** @brief Called by MLClassList destructor to remove from list of existing MLClassList instances. */
80 void MLClass::DeleteImageClassList (MLClassListPtr list)
81 {
82  blocker->StartBlock ();
83 
84  map<MLClassListPtr,MLClassListPtr>::iterator idx;
85  idx = existingClassLists.find (list);
86  if (idx != existingClassLists.end ())
87  {
88  existingClassLists.erase (idx);
89  }
90  else
91  {
92  cerr << endl << endl << "MLClass::DeleteImageClassList MLClassList instance was not found." << endl << endl;
93  }
94 
95  blocker->EndBlock ();
96 }
97 
98 
99 
101  kkint32 _classId
102  )
103 {
104  KKStr upperName = _name.ToUpper ();
105 
106  MLClassListPtr globalList = existingMLClasses;
107  if (!globalList)
108  globalList = GlobalClassList ();
109 
110  MLClassPtr mlClass = globalList->LookUpByName (_name);
111  if (mlClass == NULL)
112  {
113  if (!blocker)
114  CreateBlocker ();
115  blocker->StartBlock ();
116 
117  mlClass = globalList->LookUpByName (_name);
118  if (mlClass == NULL)
119  {
120  MLClassPtr temp = new MLClass (_name);
121  temp->ClassId (_classId);
122  existingMLClasses->AddMLClass (temp);
123  mlClass = temp;
124  }
125 
126  blocker->EndBlock ();
127  }
128 
129  if ((mlClass->ClassId () < 0) && (_classId >= 0))
130  ((MLClassPtr)mlClass)->ClassId (_classId);
131 
132  return mlClass;
133 } /* CreateNewMLClass */
134 
135 
136 
138 {
139  return GlobalClassList ()->LookUpByClassId (_classId);
140 } /* GetByClassId */
141 
142 
143 
144 
146 {
147  if (parent == NULL)
148  return NULL;
149 
150  GlobalClassList (); // Make sure that 'existingMLClasses' exists.
151 
152  MLClassListPtr results = new MLClassList ();
153  results->PushOnBack (parent);
154 
155  MLClassPtr startingAncestor = NULL;
156 
157  for (auto existingMLClass: *existingMLClasses)
158  {
159  if (!existingMLClass)
160  continue;
161  startingAncestor = existingMLClass;
162  MLClassPtr ancestor = startingAncestor->Parent ();
163  while (ancestor != NULL)
164  {
165  if (ancestor == parent)
166  {
167  results->PushOnBack (startingAncestor);
168  break;
169  }
170  ancestor = ancestor->Parent ();
171  if (ancestor == startingAncestor)
172  break;
173  }
174  }
175 
176  return results;
177 } /* BuildListOfDecendents */
178 
179 
180 
182  const KKStr& newName,
183  bool& successful
184  )
185 {
186  successful = true;
187  KKStr oldName = mlClass->Name();
188 
189  if (!blocker)
190  CreateBlocker ();
191  blocker->StartBlock ();
192 
193  existingMLClasses->ChangeNameOfClass (mlClass, oldName, newName, successful);
194  if (!successful)
195  {
196  cerr << endl
197  << "MLClass::ChangeNameOfClass 'existingMLClasses' failed to vahne name." << endl
198  << " NewName[" << newName << "]" << endl
199  << " OldName[" << mlClass->Name () << "]" << endl
200  << endl;
201  successful = false;
202  }
203  else
204  {
205  // It is okay to change the name; we will also need to inform all
206  // instances of MLClassList that the name changed so they can
207  // update their nameIndex structures.
208  mlClass->Name (newName);
209 
210  map<MLClassListPtr,MLClassListPtr>::iterator idx;
211  for (idx = existingClassLists.begin (); idx != existingClassLists.end (); ++idx)
212  {
213  MLClassListPtr list = idx->first;
214  kkuint32 classInList = list->PtrToIdx (mlClass);
215  if (classInList >= 0)
216  {
217  bool nameChangedInList = false;
218  list->ChangeNameOfClass (mlClass, oldName, newName, nameChangedInList);
219  }
220  }
221  }
222 
223  blocker->EndBlock ();
224 
225  return;
226 } /* ChangeNameOfClass */
227 
228 
230 {
231  CreateBlocker ();
232  blocker->StartBlock ();
233 
234  MLClassListPtr globalClassList = GlobalClassList ();
235 
236  MLClassPtr allClasses = globalClassList->LookUpByName ("AllClasses");
237 
238  MLClassList::iterator idx;
239  for (idx = globalClassList->begin (); idx != globalClassList->end (); ++idx)
240  {
241  MLClassPtr ic = *idx;
242  if (ic == allClasses)
243  ic->Parent (NULL);
244  else
245  ic->Parent (allClasses);
246  }
247  blocker->EndBlock ();
248 } /* ResetAllParentsToNull */
249 
250 
251 
252 void MLClass::Name (const KKStr& _name)
253 {
254  name = _name;
255  upperName = name.ToUpper ();
256 }
257 
258 
259 
260 
262 {
263  return CreateNewMLClass ("UNKNOWN");
264 } /* GetUnKnownClassStatic */
265 
266 
267 
268 /** @brief Call this at very end of program to clean up existingMLClasses. */
270 {
271  if (!needToRunFinalCleanUp)
272  return;
273 
274  blocker->StartBlock ();
275  if (needToRunFinalCleanUp)
276  {
278  {
279  //cerr << endl << "MLClass::FinalCleanUp ***ERROR*** Need to run MLClass::FinalCleanUp before FileDesc::FinalCleanUp" << endl << endl;
281  }
282 
283  if (existingMLClasses)
284  {
285  delete existingMLClasses;
286  existingMLClasses = NULL;
287  }
288 
289  needToRunFinalCleanUp = false;
290  }
291  blocker->EndBlock ();
292 
293  GoalKeeper::Destroy (blocker);
294  blocker = NULL;
295 } /* FinalCleanUp */
296 
297 
298 
299 
300 MLClass::MLClass (const KKStr& _name):
301  classId (-1),
302  countFactor (0.0f),
303  description (),
304  mandatory (false),
305  name (_name),
306  parent (NULL),
307  storedOnDataBase (false),
308  summarize (false)
309 
310 {
311  if (name.Empty ())
312  {
313  cerr << endl
314  << "MLClass::MLClass *** ERROR *** Empty Name" << endl
315  << endl;
316  }
317 
318  upperName = name.ToUpper ();
319  KKStr topLevel = upperName;
320  kkuint32 x = upperName.LocateCharacter ('_');
321  if (x >= 0)
322  topLevel = upperName.SubStrPart (0, x - 1);
323 
324  unDefined = upperName.Empty () ||
325  (upperName == "UNKNOWN") ||
326  (upperName == "UNDEFINED") ||
327  (upperName == "NONPLANKTON") ||
328  (topLevel == "NOISE");
329 }
330 
331 
332 
333 
334 
335 MLClass::MLClass (const MLClass& mlClass)
336 {
337  cerr << endl
338  << "MLClass::MLClass (const MLClass& mlClass) *** ERROR ***" << endl
339  << "Should never ever call this method." << endl
340  << endl;
342  exit (-1);
343 }
344 
345 
346 
347 
348 MLClass::~MLClass ()
349 {
350 }
351 
352 
353 
354 const KKStr& MLClass::ParentName () const
355 {
356  if (parent)
357  return parent->Name ();
358  return KKStr::EmptyStr ();
359 }
360 
361 
362 
363 
365 {
366  KKStr str (name);
367  return str;
368 }
369 
370 
371 
373 {
374  KKStr className = osGetRootNameOfDirectory (subDir);
375  kkint32 x = className.LocateLastOccurrence ('_');
376  if (x > 0)
377  {
378  // Now lets eliminate any sequence number in name
379  // We are assuming that a underscore{"_") character separates the class name from the sequence number.
380  // So if there is an underscore character, and all the characters to the right of it are
381  // numeric characters, then we will remove the underscore and the following numbers.
382 
383  kkuint32 y = x + 1;
384 
385  bool allFollowingCharsAreNumeric = true;
386  while ((y < className.Len ()) && (allFollowingCharsAreNumeric))
387  {
388  char ch = className[y];
389  allFollowingCharsAreNumeric = ((ch >= '0') && (ch <= '9'));
390  y++;
391  }
392 
393  if (allFollowingCharsAreNumeric)
394  {
395  className = className.SubStrPart (0, x - 1);
396  }
397  }
398 
399  return className;
400 } /* GetClassNameFromDirName */
401 
402 
403 
404 
406 {
407  if (c == this)
408  return true;
409 
410  if (parent == NULL)
411  return false;
412 
413  return parent->IsAnAncestor (c);
414 }
415 
416 
417 
418 
420 {
421  return (kkuint16)name.InstancesOfChar ('_') + 1;
422 }
423 
424 
425 
426 
428 {
429  VectorKKStr levelNames = name.Split ('_');
430  KKStr fullLevelName = "";
431 
432  kkuint16 curLevel = 0;
433  while ((curLevel < level) && (curLevel < levelNames.size ()))
434  {
435  if (curLevel < 1)
436  fullLevelName = levelNames[curLevel];
437  else
438  fullLevelName << "_" << levelNames[curLevel];
439 
440  curLevel++;
441  }
442 
443  return MLClass::CreateNewMLClass (fullLevelName);
444 } /* MLClassForGivenHierarchialLevel*/
445 
446 
447 
448 void MLClass::WriteXML (const KKStr& varName,
449  ostream& o
450  ) const
451 {
452  XmlTag startTag ("MLClass", XmlTag::TagTypes::tagEmpty);
453  if (!varName.Empty())
454  startTag.AddAtribute ("VarName", varName);
455 
456  startTag.AddAtribute ("Name", name);
457  if (parent != NULL)
458  startTag.AddAtribute ("Parent", parent->Name ());
459 
460  if (classId >= 0)
461  startTag.AddAtribute ("ClassId", classId);
462 
463  if (countFactor != 0.0f)
464  startTag.AddAtribute ("CountFactor", countFactor);
465 
466  if (description.Empty ())
467  startTag.AddAtribute ("Description", description);
468 
469  startTag.AddAtribute ("Mandatory", mandatory);
470  startTag.AddAtribute ("StoredOnDataBase", storedOnDataBase);
471  startTag.AddAtribute ("Summarize", summarize);
472  startTag.WriteXML (o);
473  o << endl;
474 } /* WriteXML */
475 
476 
477 
478 
479 
480 
482  XmlStream& s,
483  VolConstBool& cancelFlag,
484  RunLog& log
485  ):
486  XmlElement (tag, s, log),
487  value (NULL)
488 {
489 
490  KKStrConstPtr className = tag->AttributeValueByName ("Name");
491  if (!className)
492  {
493  // We are missing a mandatory field.
494  value = NULL;
495  return;
496  }
497 
498  value = MLClass::CreateNewMLClass (*className);
499 
500  kkint32 c = tag->AttributeCount ();
501  for (kkint32 x = 0; x < c; ++x)
502  {
503  KKStrConstPtr n = tag->AttributeNameByIndex (x);
504  KKStrConstPtr v = tag->AttributeValueByIndex (x);
505  if (v != NULL)
506  {
507  if ((n->EqualIgnoreCase ("Parent")) && (!v->Empty ()))
509 
510  else if (n->EqualIgnoreCase ("CountFactor"))
512 
513  else if (n->EqualIgnoreCase ("Description"))
514  value->Description (*v);
515 
516  else if (n->EqualIgnoreCase ("Mandatory"))
517  value->Mandatory (v->ToBool ());
518 
519  else if (n->EqualIgnoreCase ("StoredOnDataBase"))
521 
522  else if (n->EqualIgnoreCase ("Summarize"))
523  value->Summarize (v->ToBool ());
524  }
525  }
526 
527  XmlTokenPtr t = s.GetNextToken (cancelFlag, log);
528  while (t && (!cancelFlag))
529  t = s.GetNextToken (cancelFlag, log);
530 }
531 
532 
533 
535 {
536  value = NULL;
537 }
538 
539 
541 {
542  return value;
543 }
544 
545 
546 
547 void XmlElementMLClass::WriteXML (const MLClass& mlClass,
548  const KKStr& varName,
549  ostream& o
550  )
551 {
552  mlClass.WriteXML (varName, o);
553 }
554 
555 
557 
558 
559 
561  KKQueue<MLClass> (false),
562  undefinedLoaded (false)
563 {
564  MLClass::AddImageClassList (this);
565 }
566 
567 
568 
569 
570 MLClassList::MLClassList (const MLClassList& _mlClasses):
571  KKQueue<MLClass> (false)
572 {
573  MLClass::AddImageClassList (this);
574 
575  kkuint32 numOfClasses = _mlClasses.QueueSize ();
576  kkuint32 x;
577 
578  for (x = 0; x < numOfClasses; x++)
579  {
580  AddMLClass (_mlClasses.IdxToPtr (x));
581  }
582 }
583 
584 
585 
586 
587 
588 MLClassList::MLClassList (const KKStr& _fileName,
589  bool& _successfull
590  ):
591  KKQueue<MLClass> (false),
592  undefinedLoaded (false)
593 {
594  MLClass::AddImageClassList (this);
595 
596  Load (_fileName, _successfull);
597 
598  if (!undefinedLoaded)
599  {
600  // We have to make sure that there is a UnDefined MLClass.
602  undefinedLoaded = true;
603  }
604 }
605 
606 
607 
608 
610 {
611  MLClass::DeleteImageClassList (this);
612 }
613 
614 
615 
617 {
618  return sizeof (MLClassList) + sizeof (MLClassPtr) * size ();
619 }
620 
621 
622 
624 {
625  clear ();
626  nameIndex.clear ();
627 }
628 
629 
630 
631 /** @brief Update the nameIndex structure about a class name change. */
632 void MLClassList::ChangeNameOfClass (MLClassPtr mlClass,
633  const KKStr& oldName,
634  const KKStr& newName,
635  bool& successful
636  )
637 {
638  MLClassPtr existingClass = this->LookUpByName (newName);
639  if ((existingClass != NULL) && (existingClass != mlClass))
640  {
641  cerr << endl
642  << "MLClassList::ChangeNameOfClass NewName[" << newName << "] alreadty used." << endl
643  << endl;
644  successful = false;
645  }
646  else
647  {
648  NameIndex::iterator idx = nameIndex.find (oldName.ToUpper ());
649  if (idx == nameIndex.end ())
650  {
651  cerr << endl
652  << "MLClassList::ChangeNameOfClass NewName[" << oldName << "] not found." << endl
653  << endl;
654  successful = false;
655  }
656  else
657  {
658  nameIndex.erase (idx);
659  nameIndex.insert (pair<KKStr,MLClassPtr> (newName.ToUpper (), mlClass));
660  successful = true;
661  }
662  }
663 } /* ChangeNameOfClass */
664 
665 
666 
667 
669 {
670  kkuint16 numHierarchialLevels = 0;
671  MLClassList::const_iterator idx;
672  for (idx = begin (); idx != end (); idx++)
673  numHierarchialLevels = Max (numHierarchialLevels, (*idx)->NumHierarchialLevels ());
674  return numHierarchialLevels;
675 } /* NumHierarchialLevels*/
676 
677 
678 
679 
680 
681 void MLClassList::Load (const KKStr& _fileName,
682  bool& _successfull
683  )
684 {
685  kkint32 lineCount = 0;
686 
687  FILE* inputFile = osFOPEN (_fileName.Str (), "r");
688  if (!inputFile)
689  {
690  cerr << "MLClassList::ReadInData *** ERROR ***" << endl
691  << " Input File[" << _fileName << "] not Valid." << endl;
692  _successfull = false;
693  return;
694  }
695 
696  bool eof = false;
697  KKStrPtr dataRow = KKB::osReadRestOfLine (inputFile, eof);
698  while (!eof)
699  {
700  dataRow->TrimRight ();
701 
702  MLClassPtr oneRow = MLClass::CreateNewMLClass (*dataRow);
703 
704  AddMLClass (oneRow);
705 
706  if (oneRow->UnDefined ())
707  undefinedLoaded = true;
708 
709  lineCount++;
710  delete dataRow;
711  dataRow = KKB::osReadRestOfLine (inputFile, eof);
712  }
713  delete dataRow;
714  dataRow = NULL;
715 
716  fclose (inputFile);
717  _successfull = true;
718 } /* ReadInData */
719 
720 
721 
722 
723 void MLClassList::Save (KKStr _fileName,
724  bool& _successfull
725  )
726 {
727  ofstream outFile (_fileName.Str ());
728 
729  kkint32 idx;
730  kkint32 qSize = QueueSize ();
731  MLClassPtr mlClass = NULL;
732 
733  for (idx = 0; idx < qSize; idx++)
734  {
735  mlClass = IdxToPtr (idx);
736  outFile << mlClass->ToString ().Str () << endl;
737  }
738 
739  _successfull = true;
740  return;
741 } /* WriteOutData */
742 
743 
744 
745 
746 void MLClassList::AddMLClassToNameIndex (MLClassPtr _mlClass)
747 {
748  NameIndex::iterator idx;
749  idx = nameIndex.find (_mlClass->UpperName ());
750  if (idx == nameIndex.end ())
751  nameIndex.insert (pair<KKStr,MLClassPtr>(_mlClass->UpperName (), _mlClass));
752 }
753 
754 
755 
757 {
758  if (_mlClass->Name ().Empty ())
759  {
760  cerr << "MLClassList::AddMLClass Class Name Empty" << endl;
761  }
762  KKQueue<MLClass>::PushOnBack (_mlClass);
763  AddMLClassToNameIndex (_mlClass);
764 }
765 
766 
767 
769 {
770  NameIndex::iterator idx;
771  MLClassPtr ic = KKQueue<MLClass>::PopFromBack ();
772  if (!ic)
773  return NULL;
774 
775  idx = nameIndex.find (ic->UpperName ());
776  if (idx != nameIndex.end ())
777  nameIndex.erase (idx);
778  return ic;
779 } /* PopFromBack*/
780 
781 
782 
784 {
785  NameIndex::iterator idx;
786  MLClassPtr ic = KKQueue<MLClass>::PopFromFront ();
787  if (!ic)
788  return NULL;
789 
790  idx = nameIndex.find (ic->UpperName ());
791  if (idx != nameIndex.end ())
792  nameIndex.erase (idx);
793  return ic;
794 } /* PopFromFront*/
795 
796 
797 
799  {
800  if (_mlClass->Name ().Empty ())
801  {
802  cerr << "MLClassList::PushOnBack Class Name Empty" << endl;
803  }
804 
805  KKQueue<MLClass>::PushOnBack (_mlClass);
806  AddMLClassToNameIndex (_mlClass);
807  }
808 
809 
810 
812 {
813  if (_mlClass->Name ().Empty ())
814  {
815  cerr << "MLClassList::PushOnFront Class Name Empty" << endl;
816  }
817 
818  KKQueue<MLClass>::PushOnBack (_mlClass);
819  AddMLClassToNameIndex (_mlClass);
820 }
821 
822 
823 
824 /**
825  *@brief Returns a pointer of MLClass object with name (_name); if none
826  * in list will then return NULL.
827  *@param[in] _name Name of MLClass to search for.
828  *@return Pointer to MLClass or NULL if not Found.
829  */
831 {
832  NameIndex::const_iterator idx;
833  idx = nameIndex.find (_name.ToUpper ());
834  if (idx == nameIndex.end ())
835  return NULL;
836  else
837  return idx->second;
838 } /* LookUpByName */
839 
840 
841 
842 
844 {
845  MLClassList::const_iterator idx;
846  MLClassPtr mlClass;
847  for (idx = begin (); idx != end (); idx++)
848  {
849  mlClass = *idx;
850  if (mlClass->ClassId () == _classId)
851  return mlClass;
852  }
853 
854  return NULL;
855 } /* LookUpClassId */
856 
857 
858 
859 
860 /** @brief return pointer to instance with '_name'; if none exists, create one and add to list. */
862 {
863  MLClassPtr ic = LookUpByName (_name);
864  if (ic == NULL)
865  {
866  ic = MLClass::CreateNewMLClass (_name);
867  AddMLClass (ic);
868  }
869  return ic;
870 } /* GetMLClassPtr */
871 
872 
873 
874 
876 {
877  MLClassPtr noiseClass = NULL;
878  for (auto idx: *this)
879  {
880  if (idx->UnDefined ())
881  {
882  noiseClass = idx;
883  break;
884  }
885  }
886  return noiseClass;
887 } /* GetNoiseClass */
888 
889 
890 
891 
892 
894 {
895  MLClassPtr unKnownClass = LookUpByName ("UNKNOWN");
896  if (!unKnownClass)
897  {
898  unKnownClass = MLClass::CreateNewMLClass ("UNKNOWN");
899  PushOnBack (unKnownClass);
900  }
901 
902  return unKnownClass;
903 } /* GetUnKnownClass */
904 
905 
906 
907 
908 
910 {
911 public:
913 
914  bool operator () (MLClassPtr p1,
915  MLClassPtr p2
916  )
917  {
918  return (p1->UpperName () < p2->UpperName ());
919  }
920 }; /* MLClassNameComparison */
921 
922 
923 
924 
925 
927 {
929  sort (begin (), end (), *c);
930  delete c;
931 } /* SortByName */
932 
933 
934 
935 
936 
938 {
939  KKStr s (10 * QueueSize ());
940 
941  for (kkint32 i = 0; i < QueueSize (); i++)
942  {
943  if (i > 0)
944  s << "\t";
945 
946  s << IdxToPtr (i)->Name ();
947  }
948 
949  return s;
950 } /* ToString */
951 
952 
953 
954 
956 {
957  KKStr s (10 * QueueSize ());
958  for (kkint32 i = 0; i < QueueSize (); i++)
959  {
960  if (i > 0) s << "\t";
961  s << IdxToPtr (i)->Name ();
962  }
963 
964  return s;
965 } /* ToTabDelimitedStr */
966 
967 
968 
969 
971 {
972  KKStr s (10 * QueueSize ());
973  for (kkint32 i = 0; i < QueueSize (); i++)
974  {
975  if (i > 0) s << ",";
976  s << IdxToPtr (i)->Name ();
977  }
978 
979  return s;
980 } /* ToCommaDelimitedStr */
981 
982 
983 
984 
986 {
987  KKStr s (10 * QueueSize ());
988  for (kkint32 i = 0; i < QueueSize (); i++)
989  {
990  if (i > 0) s << ",";
991  s << IdxToPtr (i)->Name ().QuotedStr ();
992  }
993 
994  return s;
995 } /* ToCommaDelimitedQuotedStr */
996 
997 
998 
999 
1000 
1002 {
1003  MLClassListPtr result = new MLClassList ();
1004 
1005  const_iterator idx;
1006  for (idx = begin(); idx != end (); ++idx)
1007  {
1008  if ((*idx)->Summarize ())
1009  result->PushOnBack (*idx);
1010  }
1011 
1012  return result;
1013 } /* ExtractSummarizeClasses */
1014 
1015 
1016 
1017 
1019 {
1020  MLClassListPtr result = new MLClassList ();
1021 
1022  const_iterator idx;
1023  for (idx = begin(); idx != end (); ++idx)
1024  {
1025  if ((*idx)->Mandatory ())
1026  result->PushOnBack (*idx);
1027  }
1028 
1029  return result;
1030 } /* ExtractMandatoryClasses */
1031 
1032 
1033 
1034 
1036  KKStr& titleLine2
1037  ) const
1038 {
1039  titleLine1 = "";
1040  titleLine2 = "";
1041 
1042  kkint32 x;
1043  for (x = 0; x < QueueSize (); x++)
1044  {
1045  if (x > 0)
1046  {
1047  titleLine1 << "\t";
1048  titleLine2 << "\t";
1049  }
1050 
1051  KKStr className = IdxToPtr (x)->Name ();
1052  kkint32 y = className.LocateCharacter ('_');
1053  if (y < 0)
1054  {
1055  titleLine2 << className;
1056  }
1057  else
1058  {
1059  titleLine1 << className.SubStrPart (0, y - 1);
1060  titleLine2 << className.SubStrPart (y + 1);
1061  }
1062  }
1063 } /* ExtractTwoTitleLines */
1064 
1065 
1066 
1067 
1069  KKStr& titleLine2,
1070  KKStr& titleLine3
1071  ) const
1072 {
1073  titleLine1 = "";
1074  titleLine2 = "";
1075  titleLine3 = "";
1076 
1077  kkint32 x;
1078  for (x = 0; x < QueueSize (); x++)
1079  {
1080  if (x > 0)
1081  {
1082  titleLine1 << "\t";
1083  titleLine2 << "\t";
1084  titleLine3 << "\t";
1085  }
1086 
1087  KKStr part1, part2, part3;
1088  part1 = part2 = part3 = "";
1089  kkint32 numOfParts = 0;
1090 
1091  KKStr className = IdxToPtr (x)->Name ();
1092  className.TrimLeft ();
1093  className.TrimRight ();
1094 
1095  numOfParts = 1;
1096  part1 = className.ExtractToken ("_");
1097  if (!className.Empty ())
1098  {
1099  numOfParts = 2;
1100  part2 = className.ExtractToken ("_");
1101 
1102  if (!className.Empty ())
1103  {
1104  numOfParts = 3;
1105  part3 = className;
1106  }
1107  }
1108 
1109 
1110  switch (numOfParts)
1111  {
1112  case 1: titleLine3 << part1;
1113  break;
1114 
1115  case 2: titleLine2 << part1;
1116  titleLine3 << part2;
1117  break;
1118 
1119  case 3: titleLine1 << part1;
1120  titleLine2 << part2;
1121  titleLine3 << part3;
1122  break;
1123  }
1124  }
1125 } /* ExtractThreeTitleLines */
1126 
1127 
1128 
1129 
1131  KKStr& titleLine2,
1132  KKStr& titleLine3,
1133  kkint32 fieldWidth
1134  ) const
1135 {
1136  titleLine1 = "";
1137  titleLine2 = "";
1138  titleLine3 = "";
1139 
1140  KKStr blankField;
1141  blankField.RightPad (fieldWidth);
1142 
1143  kkint32 x;
1144  for (x = 0; x < QueueSize (); x++)
1145  {
1146  KKStr part1, part2, part3;
1147  part1 = part2 = part3 = "";
1148  kkint32 numOfParts = 0;
1149 
1150  KKStr className = IdxToPtr (x)->Name ();
1151  className.TrimLeft ();
1152  className.TrimRight ();
1153 
1154  numOfParts = 1;
1155  part1 = className.ExtractToken ("_");
1156  if (!className.Empty ())
1157  {
1158  numOfParts = 2;
1159  part2 = className.ExtractToken ("_");
1160 
1161  if (!className.Empty ())
1162  {
1163  numOfParts = 3;
1164  part3 = className;
1165  }
1166  }
1167 
1168  part1.LeftPad (fieldWidth);
1169  part2.LeftPad (fieldWidth);
1170  part3.LeftPad (fieldWidth);
1171 
1172  switch (numOfParts)
1173  {
1174  case 1: titleLine1 << blankField;
1175  titleLine2 << blankField;
1176  titleLine3 << part1;
1177  break;
1178 
1179  case 2: titleLine1 << blankField;
1180  titleLine2 << part1;
1181  titleLine3 << part2;
1182  break;
1183 
1184  case 3: titleLine1 << part1;
1185  titleLine2 << part2;
1186  titleLine3 << part3;
1187  break;
1188  }
1189  }
1190 } /* ExtractThreeTitleLines */
1191 
1192 
1193 
1194 
1196 {
1197  KKStr header (QueueSize () * 50);
1198 
1199  kkuint16 x;
1200 
1201  MLClassList::const_iterator idx;
1202  for (idx = begin (); idx != end (); idx++)
1203  {
1204  MLClassPtr ic = *idx;
1205 
1206  VectorKKStr parts = ic->Name ().Split ('_');
1207 
1208  header << "<th>";
1209  for (x = 0; x < parts.size (); x++)
1210  {
1211  if (x > 0)
1212  header << "<br />";
1213  header << parts[x];
1214  }
1215  header << "</th>";
1216  }
1217 
1218  return header;
1219 } /* ExtractHTMLTableHeader */
1220 
1221 
1222 
1224 {
1225  MLClassListPtr newList = new MLClassList ();
1226 
1227  MLClassList::iterator idx;
1228  for (idx = begin (); idx != end (); idx++)
1229  {
1230  MLClassPtr c = *idx;
1231  MLClassPtr classForLevel = c->MLClassForGivenHierarchialLevel (level);
1232 
1233  if (newList->PtrToIdx (classForLevel) < 0)
1234  newList->AddMLClass (classForLevel);
1235  }
1236 
1237  newList->SortByName ();
1238  return newList;
1239 } /* ExtractListOfClassesForAGivenHierarchialLevel */
1240 
1241 
1242 
1243 
1244 
1246  const MLClassList& list2
1247  )
1248 {
1249  MLClassListPtr result = new MLClassList (list1);
1250  MLClassList::const_iterator idx;
1251 
1252  for (idx = list2.begin (); idx != list2.end (); idx++)
1253  {
1254  MLClassPtr ic = *idx;
1255  if (result->PtrToIdx (ic) < 0)
1256  {
1257  // This entry (*idx) from list2 was not in list 1
1258  result->AddMLClass (ic);
1259  }
1260  }
1261 
1262  return result;
1263 } /* MergeClassList */
1264 
1265 
1266 
1267 
1269  char delimiter
1270  )
1271 {
1272  VectorKKStr names = s.Split (',');
1273  MLClassListPtr classList = new MLClassList ();
1274 
1275  VectorKKStr::iterator idx;
1276  for (idx = names.begin (); idx != names.end (); idx++)
1277  MLClassPtr c = classList->GetMLClassPtr (*idx);
1278 
1279  return classList;
1280 } /* BuildListFromCommaDelimtedStr */
1281 
1282 
1283 
1284 
1285 
1286 void MLClassList::WriteXML (const KKStr& varName,
1287  ostream& o
1288  ) const
1289 {
1290  XmlTag startTag ("MLClassList", XmlTag::TagTypes::tagStart);
1291  if (!varName.Empty())
1292  startTag.AddAtribute ("VarName", varName);
1293  startTag.AddAtribute ("Count", (kkint32)size ());
1294  startTag.WriteXML (o);
1295  o << endl;
1296 
1297  MLClassList::const_iterator idx;
1298  for (idx = begin (); idx != end (); idx++)
1299  {
1300  MLClassPtr c = *idx;
1301  c->WriteXML ("", o);
1302  }
1303 
1304  XmlTag endtag ("MLClassList", XmlTag::TagTypes::tagEnd);
1305  endtag.WriteXML (o);
1306  o << endl;
1307 } /* WriteXML */
1308 
1309 
1310 
1311 
1312 
1313 bool MLClassList::operator== (const MLClassList& right) const
1314 {
1315  if (QueueSize () != right.QueueSize ())
1316  return false;
1317 
1318  for (kkint32 i = 0; i < QueueSize (); i++)
1319  {
1320  MLClassPtr mlClass = IdxToPtr (i);
1321 
1322  if (right.LookUpByName (mlClass->Name ()) == NULL)
1323  return false;
1324  }
1325 
1326  return true;
1327 } /* operator== */
1328 
1329 
1330 
1331 
1332 bool MLClassList::operator!= (const MLClassList& right) const
1333 {
1334  return (!operator== (right));
1335 } /* operator== */
1336 
1337 
1338 
1339 
1341 {
1342  if (&right == this)
1343  {
1344  while (QueueSize () > 0)
1345  PopFromBack ();
1346  return *this;
1347  }
1348 
1349 
1350  MLClassList::const_iterator idx;
1351  for (idx = right.begin (); idx != right.end (); idx++)
1352  {
1353  MLClassPtr ic = *idx;
1354  DeleteEntry (ic); // if 'ic' exists in our list it will be deleted.
1355  }
1356 
1357  return *this;
1358 } /* operator=- */
1359 
1360 
1361 
1362 MLClassList& MLClassList::operator+= (const MLClassList& right) // add all classes that are in the 'right' parameter
1363 {
1364  if (this == &right)
1365  return *this;
1366 
1367  MLClassList::const_iterator idx;
1368  for (idx = right.begin (); idx != right.end (); idx++)
1369  {
1370  MLClassPtr ic = *idx;
1371  if (PtrToIdx (ic) < 0)
1372  PushOnBack (ic);
1373  }
1374 
1375  return *this;
1376 }
1377 
1378 
1379 
1380 
1382 {
1383  if (&right == this)
1384  return *this;
1385 
1386  Clear ();
1387 
1388  MLClassList::const_iterator idx;
1389  for (idx = right.begin (); idx != right.end (); idx++)
1390  {
1391  MLClassPtr ic = *idx;
1392  PushOnBack (ic);
1393  }
1394 
1395  return *this;
1396 } /* operator= */
1397 
1398 
1399 
1401 {
1402  MLClassList result;
1403 
1404  MLClassList::const_iterator idx;
1405  for (idx = begin (); idx != end (); idx++)
1406  {
1407  MLClassPtr ic = *idx;
1408  if (right.PtrToIdx (ic) < 0)
1409  result.PushOnBack (ic);
1410  }
1411 
1412  return result;
1413 } /* operator- */
1414 
1415 
1416 
1417 ostream& KKMLL::operator<< ( ostream& os,
1418  const MLClassList& classList
1419  )
1420 {
1421  os << classList.ToString ();
1422  return os;
1423 }
1424 
1425 
1426 
1427 KKStr& KKMLL::operator<< ( KKStr& str,
1428  const MLClassList& classList
1429  )
1430 {
1431  str << classList.ToString ();
1432  return str;
1433 }
1434 
1435 
1436 
1437 
1439  XmlStream& s,
1440  VolConstBool& cancelFlag,
1441  RunLog& log
1442  ):
1443  XmlElement (tag, s, log),
1444  value (NULL)
1445 {
1446  value = new MLClassList ();
1447  XmlTokenPtr t = s.GetNextToken (cancelFlag, log);
1448  while (t && (!cancelFlag))
1449  {
1450  if (typeid (*t) == typeid(XmlContent))
1451  {
1452  XmlContentPtr contentToken = dynamic_cast<XmlContentPtr> (t);
1453  KKStrConstPtr s = contentToken->Content ();
1454  if (s)
1455  {
1456  KKStrParser p (*s);
1457  p.TrimWhiteSpace (" ");
1458  while (p.MoreTokens ())
1459  {
1460  KKStr className = p.GetNextToken (",\t");
1461  if (!className.Empty ())
1463  }
1464  }
1465  }
1466 
1467  delete t;
1468  t = s.GetNextToken (cancelFlag, log);
1469  }
1470  delete t;
1471  t = NULL;
1472 }
1473 
1474 
1475 
1477 {
1478  delete value;
1479  value = NULL;
1480 }
1481 
1482 
1483 
1485 {
1486  return value;
1487 }
1488 
1489 
1490 
1492 {
1493  MLClassListPtr v = value;
1494  value = NULL;
1495  return v;
1496 }
1497 
1498 
1500  const KKStr& varName,
1501  ostream& o
1502  )
1503 {
1504  XmlTag startTag ("MLClassNameList", XmlTag::TagTypes::tagStart);
1505  if (!varName.Empty ())
1506  startTag.AddAtribute ("VarName", varName);
1507  startTag.WriteXML (o);
1508 
1510 
1511  XmlTag endTag ("MLClassNameList", XmlTag::TagTypes::tagEnd);
1512  endTag.WriteXML (o);
1513  o << endl;
1514 }
1515 
1516 XmlFactoryMacro(MLClassNameList)
1517 
1518 
1519 
1520 
1521 
1522 
1523 
1524 
1525 
1527  largestIndex (-1)
1528 {
1529 }
1530 
1531 
1533 {
1534  const_iterator idx;
1535  bool dupEntry = false;
1536  for (idx = _list.begin (); idx != _list.end (); idx++)
1537  {
1538  AddClassIndexAssignment (idx->first, idx->second, dupEntry);
1539  }
1540 }
1541 
1542 
1543 
1545  largestIndex(-1)
1546 {
1547  MLClassList::const_iterator idx;
1548  for (idx = classes.begin (); idx != classes.end (); idx++)
1549  {
1550  largestIndex++;
1551  insert (pair<MLClassPtr, kkint16> (*idx, largestIndex));
1552  shortIdx.insert (pair<kkint16, MLClassPtr> (largestIndex, *idx));
1553  }
1554 }
1555 
1556 
1557 
1559 {
1560  clear ();
1561  shortIdx.clear ();
1562  largestIndex = 0;
1563 }
1564 
1565 
1566 
1567 
1568 
1570 {
1571  return sizeof (MLClassIndexList) + (shortIdx.size () * (sizeof (kkint16) + sizeof (MLClassPtr) + 10)); // added 10- bytes per entry for overhead.
1572 }
1573 
1574 
1575 
1577  bool& _dupEntry
1578  )
1579 {
1580  _dupEntry = false;
1581  map<MLClassPtr, kkint16>::iterator p;
1582  p = find (_ic);
1583  if (p != end ())
1584  {
1585  _dupEntry = true;
1586  return;
1587  }
1588 
1589  kkint32 index = largestIndex + 1;
1590  largestIndex = index;
1591 
1592  insert (pair<MLClassPtr, kkint16> (_ic, index));
1593  shortIdx.insert (pair<kkint16, MLClassPtr> (index, _ic));
1594 } /* AddClass */
1595 
1596 
1597 
1599  kkint16 _classIndex,
1600  bool& _dupEntry
1601  )
1602 {
1603  _dupEntry = false;
1604  map<MLClassPtr, kkint16>::iterator p;
1605  p = find (_ic);
1606  if (p != end ())
1607  {
1608  _dupEntry = true;
1609  return;
1610  }
1611 
1612  insert (pair<MLClassPtr, kkint16> (_ic, _classIndex));
1613  shortIdx.insert (pair<kkint16, MLClassPtr> (_classIndex, _ic));
1614 
1615  if (_classIndex > largestIndex)
1616  largestIndex = _classIndex;
1617 } /* AddClassIndexAssignment */
1618 
1619 
1620 
1622 {
1623  kkint32 index = -1;
1624  map<MLClassPtr, kkint16>::iterator p;
1625  p = find (c);
1626  if (p == end ())
1627  index = -1;
1628  else
1629  index = p->second;
1630 
1631  return index;
1632 } /* GetClassIndex */
1633 
1634 
1635 
1637 {
1638  map<kkint16, MLClassPtr>::iterator p;
1639  p = shortIdx.find (classIndex);
1640  if (p == shortIdx.end ())
1641  return NULL;
1642  else
1643  return p->second;
1644 } /* GetMLClass */
1645 
1646 
1647 
1648 
1650  RunLog& log
1651  )
1652 {
1653  Clear ();
1654  largestIndex = -1;
1655  KKStrParser parser (s);
1656  parser.TrimWhiteSpace (" ");
1657  while (parser.MoreTokens ())
1658  {
1659  kkint32 classIndex = -1;
1660  KKStr className = parser.GetNextToken (",:");
1661  if (parser.LastDelimiter () == ',')
1662  {
1663  // we should have encountered a ':' character but came across a ',' instead; we are missing the Index Assignment
1664  classIndex = -1;
1665  log.Level (-1) << endl
1666  << "MLClassIndexList::ParseClassIndexList ***ERROR*** Missing index for Class: " << className << endl
1667  << endl;
1668  }
1669  else
1670  {
1671  classIndex = parser.GetNextToken (",").ToInt16 ();
1672  }
1673 
1674  bool duplicate = false;
1675  AddClassIndexAssignment (MLClass::CreateNewMLClass (className), classIndex, duplicate);
1676  if (duplicate)
1677  {
1678  log.Level (-1) << endl
1679  << "MLClassIndexList::ParseClassIndexList ***ERROR*** Duplicate ClassIndex[" << classIndex << "] specified for class[" << className << "]" << endl
1680  << endl;
1681  }
1682  }
1683 } /* ParseClassIndexList */
1684 
1685 
1686 
1687 
1688 
1690 {
1691  KKStr delStr (255);
1692  map<kkint16, MLClassPtr>::const_iterator idx;
1693  for (idx = shortIdx.begin (); idx != shortIdx.end (); idx++)
1694  {
1695  if (!delStr.Empty ())
1696  delStr << ",";
1697  delStr << idx->second->Name ().QuotedStr () << ":" << idx->first;
1698  }
1699  return delStr;
1700 } /* ToCommaDelString */
1701 
1702 
1704  XmlTagConstPtr tag,
1705  VolConstBool& cancelFlag,
1706  RunLog& log
1707  )
1708 {
1709  largestIndex = -1;
1710  shortIdx.clear ();
1711 
1712  XmlTokenPtr t = s.GetNextToken (cancelFlag, log);
1713  while (t && (!cancelFlag))
1714  {
1715  if (typeid (*t) == typeid (XmlContent))
1716  {
1717  XmlContentPtr c = dynamic_cast<XmlContentPtr> (t);
1718  if (c && c->Content ())
1719  {
1720  KKStrConstPtr text = c->Content ();
1721  ParseClassIndexList (*text, log);
1722  }
1723  }
1724 
1725  delete t;
1726  t = s.GetNextToken (cancelFlag, log);
1727  }
1728  delete t;
1729  t = NULL;
1730 } /* ReadXML */
1731 
1732 
1733 void MLClassIndexList::WriteXML (const KKStr& varName,
1734  ostream& o
1735  ) const
1736 {
1737  XmlTag startTag ("MLClassIndexList", XmlTag::TagTypes::tagStart);
1738  if (!varName.Empty ())
1739  startTag.AddAtribute ("VarName", varName);
1740  startTag.WriteXML (o);
1741 
1743 
1744  XmlTag endTag ("MLClassIndexList", XmlTag::TagTypes::tagEnd);
1745  endTag.WriteXML (o);
1746  o << endl;
1747 }
1748 
1749 
1750 XmlFactoryMacro(MLClassIndexList)
static void WriteXML(const MLClass &mlClass, const KKStr &varName, std::ostream &o)
Definition: MLClass.cpp:547
__int16 kkint16
16 bit signed integer.
Definition: KKBaseTypes.h:85
KKStr(kkint32 size)
Creates a KKStr object that pre-allocates space for &#39;size&#39; characters.
Definition: KKStr.cpp:655
XmlTag(const KKStr &_name, TagTypes _tagType)
Definition: XmlStream.cpp:586
MLClass * MLClassPtr
Definition: MLClass.h:46
void StoredOnDataBase(bool _storedOnDataBase)
Definition: MLClass.h:169
Provides a detailed description of the attributes of a dataset.
Definition: FileDesc.h:72
bool EqualIgnoreCase(const char *s2) const
Definition: KKStr.cpp:1257
void AddAtribute(const KKStr &attributeName, bool attributeValue)
Definition: XmlStream.cpp:611
MLClassPtr GetUnKnownClass()
Return a pointer to the MLClass object that represents the unknown Class in the list.
Definition: MLClass.cpp:893
__int32 kkint32
Definition: KKBaseTypes.h:88
static MLClassListPtr MergeClassList(const MLClassList &list1, const MLClassList &list2)
Definition: MLClass.cpp:1245
Maintains a list of classes and their associated integer index.
Definition: MLClass.h:459
virtual void ReadXML(XmlStream &s, XmlTagConstPtr tag, VolConstBool &cancelFlag, RunLog &log)
Definition: MLClass.cpp:1703
void TrimWhiteSpace(const char *_whiteSpace=" ")
After this call all leading and trailing whitespace will be trimmed from tokens.
Definition: KKStrParser.cpp:95
KKStr ToCommaDelimitedStr() const
Definition: MLClass.cpp:970
GoalKeeper * GoalKeeperPtr
KKStr & TrimRight(const char *whiteSpaceChars="\n\r\t ")
Definition: KKStr.cpp:1695
MLClassPtr Value() const
Definition: MLClass.cpp:540
MLClassPtr GetNoiseClass() const
Definition: MLClass.cpp:875
XmlElement(XmlTagPtr _nameTag, XmlStream &s, RunLog &log)
Definition: XmlStream.cpp:758
KKStrConstPtr AttributeValueByIndex(kkuint32 index) const
Definition: XmlStream.cpp:664
KKStr GetNextToken(const char *delStr="\n\t\r ")
Extract next Token from string, tokens will be separated by delimiter characters. ...
KKStr ToCommaDelString() const
Returns string consisting of all contained classes indicating ClassIndex assigned to each class...
Definition: MLClass.cpp:1689
void LeftPad(kkint32 width, uchar ch= ' ')
pads the string with enough &#39;ch&#39; characters on the left side until the string is as long as &#39;width&#39; c...
Definition: KKStr.cpp:2303
static bool FinalCleanUpRanAlready()
Definition: FileDesc.h:88
void osWaitForEnter()
KKStr ExtractToken(const char *delStr="\n\t\r ")
Definition: KKStr.cpp:2969
kkint16 GetClassIndex(MLClassPtr c)
Returns the corresponding index to the class &#39;c&#39;; if not in list will return -1.
Definition: MLClass.cpp:1621
kkint32 InstancesOfChar(char ch) const
Definition: KKStr.cpp:2041
KKStr ExtractHTMLTableHeader() const
Will generate a HTML formatted string that can be used in a HTML table.
Definition: MLClass.cpp:1195
MLClassIndexList(const MLClassIndexList &_list)
Definition: MLClass.cpp:1532
unsigned __int16 kkuint16
16 bit unsigned integer.
Definition: KKBaseTypes.h:86
static void ChangeNameOfClass(MLClassPtr mlClass, const KKStr &newName, bool &changeSuccessful)
Changes the name of an existing class verifying that a duplicate does not get created.
Definition: MLClass.cpp:181
KKStr & operator=(const char *src)
Definition: KKStr.cpp:1442
static void Destroy(volatile GoalKeeperPtr &_goalKeeperInstance)
Destroys an existing instance of GoalKeeper.
Definition: GoalKeeper.cpp:491
Represents a "Class" in the Machine Learning Sense.
Definition: MLClass.h:52
void ExtractTwoTitleLines(KKStr &titleLine1, KKStr &titleLine2) const
Using the class names create two title lines where we split names by "_" characters between the two l...
Definition: MLClass.cpp:1035
static void WriteXML(const MLClassList &mlClassList, const KKStr &varName, std::ostream &o)
Definition: MLClass.cpp:1499
char LastDelimiter() const
Definition: KKStrParser.h:72
XmlContent * XmlContentPtr
Definition: XmlStream.h:24
MLClassList operator-(const MLClassList &right) const
Definition: MLClass.cpp:1400
bool operator!=(const MLClassList &right) const
Definition: MLClass.cpp:1332
static KKStr GetClassNameFromDirName(const KKStr &subDir)
Definition: MLClass.cpp:372
bool operator==(const char *rtStr) const
Definition: KKStr.cpp:1588
bool UnDefined() const
Definition: MLClass.h:183
KKStr ToUpper() const
Definition: KKStr.cpp:2517
static MLClassPtr GetUnKnownClassStatic()
Definition: MLClass.cpp:261
kkint32 MemoryConsumedEstimated() const
Definition: MLClass.cpp:616
bool operator==(const MLClassList &right) const
Definition: MLClass.cpp:1313
XmlElementMLClassNameList(XmlTagPtr tag, XmlStream &s, VolConstBool &cancelFlag, RunLog &log)
Definition: MLClass.cpp:1438
virtual MLClassPtr LookUpByName(const KKStr &_name) const
Returns a pointer of MLClass object with name (_name); if none in list will then return NULL...
Definition: MLClass.cpp:830
const KKStr & ParentName() const
Definition: MLClass.cpp:354
void Parent(MLClassPtr _parent)
Definition: MLClass.h:158
virtual void WriteXML(const KKStr &varName, std::ostream &o) const
Definition: MLClass.cpp:1733
static void Create(const KKStr &_name, volatile GoalKeeperPtr &_newGoalKeeper)
Create a GoalKeeper object and avoid a race condition doing it.
Definition: GoalKeeper.cpp:346
static void FinalCleanUp()
Call this as the last thing the application does, will delete all existing instances of &#39;MLClass&#39;...
Definition: MLClass.cpp:269
XmlToken * XmlTokenPtr
Definition: XmlStream.h:18
void CountFactor(float _countFactor)
Definition: MLClass.h:140
unsigned __int32 kkuint32
Definition: KKBaseTypes.h:89
void Mandatory(bool _mandatory)
Definition: MLClass.h:150
kkint16 ToInt16() const
Definition: KKStr.cpp:3576
KKStr ToCommaDelimitedQuotedStr() const
Definition: MLClass.cpp:985
char operator[](kkuint32 i) const
Definition: KKStr.cpp:3430
MLClassPtr GetMLClass(kkint16 classIndex)
Locates the MLClass that was assigned classIndex.
Definition: MLClass.cpp:1636
bool operator()(MLClassPtr p1, MLClassPtr p2)
Definition: MLClass.cpp:914
bool MoreTokens() const
Definition: KKStrParser.h:74
static void FinalCleanUp()
Clean up function, call just before exiting the application.
Definition: FileDesc.cpp:57
KKStr & operator=(KKStr &&src)
Definition: KKStr.cpp:1369
void Description(const KKStr &_description)
Definition: MLClass.h:143
MLClassIndexList(const MLClassList &_classes)
Definition: MLClass.cpp:1544
void Save(KKStr _fileName, bool &_successfull)
Definition: MLClass.cpp:723
XmlElementMLClass(XmlTagPtr tag, XmlStream &s, VolConstBool &cancelFlag, RunLog &log)
Definition: MLClass.cpp:481
static MLClassListPtr BuildListFromDelimtedStr(const KKStr &s, char delimiter)
Definition: MLClass.cpp:1268
kkuint32 Len() const
Returns the number of characters in the string.
Definition: KKStr.h:366
KKStrConstPtr AttributeValueByName(const KKStr &name) const
Definition: XmlStream.cpp:658
void AddAtribute(const KKStr &attributeName, kkint32 attributeValue)
Definition: XmlStream.cpp:620
KKTHread * KKTHreadPtr
MLClassList & operator+=(const MLClassList &right)
Definition: MLClass.cpp:1362
KKStrParser(const KKStr &_str)
Definition: KKStrParser.cpp:42
kkint32 AttributeCount() const
Definition: XmlStream.h:196
virtual MLClassPtr PopFromFront()
Definition: MLClass.cpp:783
MLClassList & operator-=(const MLClassList &right)
Definition: MLClass.cpp:1340
KKStr(const KKStr &str)
Copy Constructor.
Definition: KKStr.cpp:561
void AddClass(MLClassPtr _ic, bool &_dupEntry)
Definition: MLClass.cpp:1576
MLClassListPtr ExtractMandatoryClasses() const
Definition: MLClass.cpp:1018
void StartBlock()
Initiates a Block as long as another thread has not already locked this object.
Definition: GoalKeeper.cpp:214
void AddAtribute(const KKStr &attributeName, const KKStr &attributeValue)
Definition: XmlStream.cpp:602
KKStr ToTabDelimitedStr() const
Definition: MLClass.cpp:955
kkint32 ClassId() const
Definition: MLClass.h:136
void TrimLeft(const char *whiteSpaceChars="\n\r\t ")
Definition: KKStr.cpp:1745
virtual void Clear()
Clears the contents of this list and updates nameIndex structure.
Definition: MLClass.cpp:623
bool Empty() const
Definition: KKStr.h:241
XmlTag const * XmlTagConstPtr
Definition: KKStr.h:45
MLClassListPtr TakeOwnership()
Definition: MLClass.cpp:1491
Manages the reading and writing of objects in a simple XML format. For a class to be supported by Xml...
Definition: XmlStream.h:46
virtual ~XmlElementMLClass()
Definition: MLClass.cpp:534
KKStr SubStrPart(kkint32 firstChar, kkint32 lastChar) const
returns a SubString consisting of all characters starting at index &#39;firstChar&#39; and ending at &#39;lastInd...
Definition: KKStr.cpp:2802
kkuint16 NumHierarchialLevels() const
Definition: MLClass.cpp:419
virtual void PushOnBack(MLClassPtr mlClass)
Definition: MLClass.cpp:798
MLClassListPtr Value() const
Definition: MLClass.cpp:1484
void EndBlock()
Ends the block and allows other threads to pass through StatBlock.
Definition: GoalKeeper.cpp:295
static void ResetAllParentsToAllClasses()
Definition: MLClass.cpp:229
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
kkint32 LocateLastOccurrence(char ch) const
Returns index of last occurrence of &#39;ch&#39; otherwise -1.
Definition: KKStr.cpp:2118
MLClassList(const KKStr &fileName, bool &successfull)
Construct a MLClassList object from the contents of a file.
Definition: MLClass.cpp:588
kkint32 LocateCharacter(char ch) const
Returns index of 1st occurrence of &#39;ch&#39; otherwise -1.
Definition: KKStr.cpp:2021
static const KKStr & EmptyStr()
Static method that returns an Empty String.
Definition: KKStr.cpp:3453
void ExtractThreeTitleLines(KKStr &titleLine1, KKStr &titleLine2, KKStr &titleLine3) const
Using the class names create three title lines where we split names by "_" characters between the thr...
Definition: MLClass.cpp:1068
KKB::kkuint16 NumHierarchialLevels() const
Definition: MLClass.cpp:668
void AddClassIndexAssignment(MLClassPtr _ic, kkint16 _classIndex, bool &_dupEntry)
Definition: MLClass.cpp:1598
MLClassListPtr ExtractListOfClassesForAGivenHierarchialLevel(kkint32 level)
Definition: MLClass.cpp:1223
KKStr osGetRootNameOfDirectory(KKStr fullDirName)
const KKStr & UpperName() const
Definition: MLClass.h:155
MLClassList & operator=(const MLClassList &right)
Definition: MLClass.cpp:1381
void ParseClassIndexList(const KKStr &s, RunLog &log)
Definition: MLClass.cpp:1649
const KKStr & Name() const
Definition: MLClass.h:154
void ClassId(kkint32 _classId)
Definition: MLClass.h:137
virtual MLClassPtr LookUpByClassId(kkint32 _classId) const
Definition: MLClass.cpp:843
std::ostream &__cdecl operator<<(std::ostream &os, const KKStr &str)
virtual ~MLClassList()
Definition: MLClass.cpp:609
const char * Str() const
Returns a pointer to a ascii string.
Definition: KKStr.h:422
static MLClassPtr CreateNewMLClass(const KKStr &_name, kkint32 _classId=-1)
Static method used to create a new instance of a MLClass object.
Definition: MLClass.cpp:100
void RightPad(kkint32 width, char ch= ' ')
Pads string on the right side with specified character so that the string will be of specified length...
Definition: KKStr.cpp:2239
void WriteXML(const KKStr &varName, std::ostream &o) const
Definition: MLClass.cpp:1286
MLClassList(const MLClassList &_mlClasses)
Copy constructor; will copy list but not own the contents.
Definition: MLClass.cpp:570
KKStr ToString() const
Definition: MLClass.cpp:364
void Summarize(bool _summarize)
Definition: MLClass.h:177
virtual MLClassPtr PopFromBack()
Definition: MLClass.cpp:768
void ExtractThreeTitleLines(KKStr &titleLine1, KKStr &titleLine2, KKStr &titleLine3, kkint32 fieldWidth) const
Definition: MLClass.cpp:1130
FILE * osFOPEN(const char *fileName, const char *mode)
Definition: OSservices.cpp:74
static void WriteXml(const KKStr &s, std::ostream &o)
Definition: XmlStream.cpp:853
void WriteXML(std::ostream &o)
Definition: XmlStream.cpp:723
static MLClassListPtr BuildListOfDecendents(MLClassPtr parent)
Definition: MLClass.cpp:145
KKStr & operator=(const KKStr &src)
Definition: KKStr.cpp:1390
KKStrPtr const Content() const
Definition: XmlStream.h:338
Used for logging messages.
Definition: RunLog.h:49
void EncodeProblem(const struct svm_paramater &param, struct svm_problem &prob_in, struct svm_problem &prob_out)
XmlToken * XmlTokenPtr
Definition: XmlStream.h:255
bool operator<(const KKStr &right) const
Definition: KKStr.cpp:1635
void Load(const KKStr &_fileName, bool &_successfull)
Definition: MLClass.cpp:681
MLClassList * MLClassListPtr
Definition: MLClass.h:49
void WriteXML(const KKStr &varName, std::ostream &o) const
Definition: MLClass.cpp:448
virtual MLClassPtr GetMLClassPtr(const KKStr &_name)
return pointer to instance with &#39;_name&#39;; if none exists, create one and add to list.
Definition: MLClass.cpp:861
static MLClassListPtr GlobalClassList()
Definition: MLClass.cpp:50
kkint32 MemoryConsumedEstimated() const
Definition: MLClass.cpp:1569
Class that manages the extraction of tokens from a String without being destructive to the original s...
Definition: KKStrParser.h:18
MLClassListPtr ExtractSummarizeClasses() const
Definition: MLClass.cpp:1001
float ToFloat() const
Definition: KKStr.cpp:3553
KKStr ToString() const
Definition: MLClass.cpp:937
virtual XmlTokenPtr GetNextToken(VolConstBool &cancelFlag, RunLog &log)
Definition: XmlStream.cpp:116
VectorKKStr Split(char del) const
Splits the string up into tokens using &#39;del&#39; as the separator returning them in a vector...
Definition: KKStr.cpp:3500
bool ToBool() const
Returns the bool equivalent of the string, ex &#39;Yes&#39; = true, &#39;No&#39; = false, &#39;True&#39; = true...
Definition: KKStr.cpp:3523
Maintains a list of MLClass instances.
Definition: MLClass.h:233
virtual void PushOnFront(MLClassPtr mlClass)
Definition: MLClass.cpp:811
virtual void AddMLClass(MLClassPtr _mlClass)
Definition: MLClass.cpp:756
Will only write the ClassName rather than complete MLClass instances.
Definition: MLClass.h:580
static MLClassPtr GetByClassId(kkint32 _classId)
Definition: MLClass.cpp:137
MLClassPtr MLClassForGivenHierarchialLevel(KKB::kkuint16 level) const
Definition: MLClass.cpp:427
KKStr SubStrPart(kkint32 firstChar) const
returns a SubString consisting of all characters starting at index &#39;firstChar&#39; until the end of the s...
Definition: KKStr.cpp:2780
bool IsAnAncestor(MLClassPtr c) const
Definition: MLClass.cpp:405
#define XmlFactoryMacro(NameOfClass)
Definition: XmlStream.h:688
KKStrConstPtr AttributeNameByIndex(kkuint32 index) const
Definition: XmlStream.cpp:670
KKB::KKStrPtr osReadRestOfLine(FILE *in, bool &eof)
void AddAtribute(const KKStr &attributeName, double attributeValue)
Definition: XmlStream.cpp:638
virtual void Clear()
Definition: MLClass.cpp:1558
volatile const bool VolConstBool
Definition: KKBaseTypes.h:163