hce-node application  1.4.3
HCE Hierarchical Cluster Engine node application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
LCore.cpp
Go to the documentation of this file.
1 /*
2  * LCore.cpp
3  *
4  * Created on: Dec 4, 2012
5  * Author: handler
6  */
10 #include <algorithm>
11 #include <functional>
12 using namespace std::placeholders;
13 
17 #include "LCore.hpp"
18 #include "ProcessInfo.hpp"
19 #include "IcuPlugin.hpp"
20 #include "BoostPlugin.hpp"
21 #include "CldPlugin.hpp"
22 #include "SnowballPlugin.hpp"
23 #include "TurglemPlugin.hpp"
24 #include "MecabPlugin.hpp"
25 #include "TagReducePlugin.hpp"
26 #include "FakeHCRCPlugin.hpp"
27 
28 
29 namespace HCE
30 {
31 
32 
33 namespace component
34 {
35 
36 
37 LCore::LCore()
38 {
42  _vectorPlugins.push_back(TPlugin::Ptr(new IcuPlugin));
43  _vectorPlugins.push_back(TPlugin::Ptr(new BoostPlugin));
44  _vectorPlugins.push_back(TPlugin::Ptr(new CldPlugin));
45  _vectorPlugins.push_back(TPlugin::Ptr(new SnowballPlugin));
46  _vectorPlugins.push_back(TPlugin::Ptr(new TurglemPlugin));
47  _vectorPlugins.push_back(TPlugin::Ptr(new MecabPlugin));
48  _vectorPlugins.push_back(TPlugin::Ptr(new TagReducePlugin));
49  _vectorPlugins.push_back(TPlugin::Ptr(new FakeHCRCPlugin));
50 
51 
55  std::vector<TPlugin::Ptr>::iterator plugin_iterator;
56  for( plugin_iterator = _vectorPlugins.begin(); plugin_iterator != _vectorPlugins.end(); ++plugin_iterator )
57  {
58  std::vector<ProcessInfo>::iterator processInfo_iterator;
59  for( processInfo_iterator = (*plugin_iterator)->_exported.begin(); processInfo_iterator != (*plugin_iterator)->_exported.end(); ++processInfo_iterator)
60  {
61  _mapExportedMethods[processInfo_iterator->_methodType].push_back(*processInfo_iterator);
62  }
63  }
64 }
65 
66 
67 LCore::~LCore() {}
68 
69 void LCore::selectMethod(LCoreData& lCData) const
70 {
71  typedef void(TPlugin::*FP)(LCoreData&);
72  TPlugin* plugin = NULL;
73  FP _fp;
74  std::map<unsigned, std::vector<ProcessInfo> >::const_iterator it;
75  std::vector<ProcessInfo>::const_iterator itr;
76 
77  it= _mapExportedMethods.find( lCData._processInfo._methodType );
78  if (it!=_mapExportedMethods.end())
79  {
80  itr = std::find_if( it->second.begin(),
81  it->second.end(),
82  std::bind(&ProcessInfo::compare, _1, lCData._processInfo) );
83 
84  if (itr!=it->second.end())
85  {
86  _fp = (FP)( (*itr)._methodAddress );
87  plugin = (TPlugin*)( (*itr)._object );
88  if ( plugin && _fp )
89  {
90  (plugin->*_fp)(lCData);
92  }
93  }
94  else
95  {
97 #ifdef _DEBUG_
98  std::cout << "Plugin " << lCData._processInfo._about << " not found" << std::endl;
99 #endif
100  }
101  }
102  else
103  {
105 #ifdef _DEBUG_
106  std::cout << "Method " << lCData._processInfo._about << " not found" << std::endl;
107 #endif
108  }
109 }
110 
111 
112 } /* namespace component */
113 
114 
115 } /* namespace HCE */