KSquare Utilities
FactoryFVProducer.cpp
Go to the documentation of this file.
1 #include "FirstIncludes.h"
2 
3 #include <stdio.h>
4 #include <fstream>
5 #include <iostream>
6 #include <map>
7 #include <string>
8 #include <vector>
9 
10 #include "MemoryDebug.h"
11 
12 using namespace std;
13 
14 #include "GlobalGoalKeeper.h"
15 #include "KKStr.h"
16 #include "RunLog.h"
17 using namespace KKB;
18 
19 #include "FeatureVector.h"
21 #include "FeatureFileIO.h"
23 
24 #include "FactoryFVProducer.h"
25 using namespace KKMLL;
26 
27 
28 
29 
30 
31 
33  const KKStr& _fvClassName,
34  const KKStr& _description
35  ):
36  description (_description),
37  fvClassName (_fvClassName),
38  name (_name)
39 {
40 }
41 
42 
43 
44 
46 {
47 }
48 
49 
50 FeatureVectorPtr FactoryFVProducer::ManufacturFeatureVector (kkint32 numOfFeatires,
51  RunLog& runLog
52  )
53 {
54  return new FeatureVector (numOfFeatires);
55 }
56 
57 
58 FeatureVectorListPtr FactoryFVProducer::ManufacturFeatureVectorList (bool owner,
59  RunLog& runLog
60  )
61  const
62 {
63  return new FeatureVectorList (FileDesc (), owner);
64 }
65 
66 
67 
68 TrainingConfiguration2Ptr FactoryFVProducer::ManufacturTrainingConfiguration () const
69 {
70  return new TrainingConfiguration2 ();
71 }
72 
73 
74 
75 FeatureVectorProducerPtr FactoryFVProducer::ManufactureInstance (const KKStr& name,
76  RunLog& runLog
77  )
78 {
80  if (factory)
81  return factory->ManufactureInstance (runLog);
82  else
83  return NULL;
84 }
85 
86 
87 
88 
89 FactoryFVProducerPtr FactoryFVProducer::LookUpFactory (const KKStr& _name)
90 {
91  FactoryFVProducerPtr factory = NULL;
92 
94 
95  if (!factories)
96  {
97  factories = new FactoryMap ();
98  atexit (FactoryFVProducer::FinaleCleanUp);
99  atExitDefined = true;
100  }
101 
102  FactoryMap::iterator idx;
103 
104  idx = factories->find (_name);
105  if (idx != factories->end ())
106  factory = idx->second;
107 
109  return factory;
110 } /* LookUpFactory */
111 
112 
113 
114 
115 
117  RunLog* runLog
118  )
119 {
120  bool weOwnRunLog = false;
121  if (runLog == NULL)
122  {
123  runLog = new RunLog ();
124  weOwnRunLog = true;
125  }
126 
127  if (factory == NULL)
128  {
129  runLog->Level (-1) << "FactoryFVProducer::RegisterFactory ***ERROR*** factory==NULL" << endl;
130  }
131  else
132  {
134 
135  runLog->Level (30) << "FactoryFVProducer::RegisterFactory Name: " << factory->Name () << " Description: " << factory->Description () << endl;
136 
137  if (!factories)
138  {
139  factories = new FactoryMap ();
140  atexit (FactoryFVProducer::FinaleCleanUp);
141  atExitDefined = true;
142  }
143 
144  FactoryMap::iterator idx;
145 
146  idx = factories->find (factory->Name ());
147  if (idx != factories->end ())
148  {
149  runLog->Level (-1) << "FactoryFVProducer::RegisterFactory ***ERROR*** Factory With Name: " << factory->Name () << " already defined." << endl;
150  }
151  else
152  {
153  factories->insert (pair<KKStr,FactoryFVProducerPtr> (factory->Name (), factory));
154  }
155 
157  }
158 
159  if (weOwnRunLog)
160  {
161  delete runLog;
162  runLog = NULL;
163  }
164  return;
165 } /* RegisterFactory */
166 
167 
168 
169 
170 
171 void FactoryFVProducer::FinaleCleanUp ()
172 {
174 
175  FactoryMap::iterator idx;
176 
177  for (idx = factories->begin (); idx != factories->end (); ++idx)
178  {
179  delete idx->second;
180  idx->second = NULL;
181  }
182 
183  delete factories;
184  factories = NULL;
185 
186  atExitDefined = false;
188 } /* CleanUp */
189 
190 
191 
192 
193 
194 bool FactoryFVProducer::atExitDefined = false;
195 
196 FactoryFVProducer::FactoryMap* FactoryFVProducer::factories = NULL;
__int32 kkint32
Definition: KKBaseTypes.h:88
FactoryFVProducer(const KKStr &_name, const KKStr &_fvClassName, const KKStr &_description)
FeatureVector(kkint32 _numOfFeatures)
static FactoryFVProducerPtr LookUpFactory(const KKStr &name)
Returns pointer to existing instance of &#39;FactoryFVProducer&#39; that was previously registered with &#39;name...
static void RegisterFactory(FactoryFVProducerPtr factory, RunLog *runLog)
This is where you register newly instantiated instances of &#39;FactoryFVProducer&#39; derived classes...
FeatureVectorList(FileDescPtr _fileDesc, bool _owner)
Will create a new empty list of FeatureVector&#39;s.
Container class for FeatureVector derived objects.
KKTHread * KKTHreadPtr
KKStr(const KKStr &str)
Copy Constructor.
Definition: KKStr.cpp:561
RunLog()
Creates an instance were logging will go to the console.
Definition: RunLog.cpp:32
virtual FeatureVectorListPtr ManufacturFeatureVectorList(bool owner, RunLog &runLog) const
Manufactures a instance of a derived &#39;FeatureVectorList&#39; class that is appropriate for containing ins...
virtual FeatureVectorProducerPtr ManufactureInstance(RunLog &runLog)=0
Derived classes will instantiate appropriate instances of &#39;FeatureVectorProducer&#39;.
static KKStr Concat(const std::vector< std::string > &values)
Concatenates the list of &#39;std::string&#39; strings.
Definition: KKStr.cpp:1082
FactoryFVProducer * FactoryFVProducerPtr
static FeatureVectorProducerPtr ManufactureInstance(const KKStr &name, RunLog &runLog)
Will instantiate a new instance of the appropriate &#39;FeatureVectorProducer&#39; class given the supplied n...
virtual TrainingConfiguration2Ptr ManufacturTrainingConfiguration() const
Returns a &#39;TrainingConfiguration2&#39; derived instance.
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)
Responsible for creating a FeatureFectorProducer instance.
virtual FeatureVectorPtr ManufacturFeatureVector(kkint32 numOfFeatires, RunLog &runLog)
Manufactures a instance of a derived &#39;FeatureVector&#39; class that is appropriate for containing instanc...
Represents a Feature Vector of a single example, labeled or unlabeled.
Definition: FeatureVector.h:59
Maintains one instance of a GoalKeeper object that can be used anywhere in the application.
virtual FileDescPtr FileDesc() const =0
virtual ~FactoryFVProducer()
A Factory can near be deleted until the application terminates; the atexit method will perform the de...