test_factory.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 /* -------------------------------------------------------------------------- */
11 /* --- INCLUDES ------------------------------------------------------------- */
12 /* -------------------------------------------------------------------------- */
13 #include <dynamic-graph/entity.h>
15 
16 #include <iostream>
17 #include <sot/core/debug.hh>
19 #include <sot/core/factory.hh>
21 #include <string>
22 
23 #include "../test-paths.h"
24 using namespace std;
25 using namespace dynamicgraph::sot;
26 using namespace dg;
27 
28 #ifdef WIN32
29 #include <Windows.h>
30 #else
31 #include <dlfcn.h>
32 #endif
33 
34 #ifdef WIN32
35 typedef HMODULE sotPluginKey;
36 #else
37 typedef void *sotPluginKey;
38 #endif
39 
40 class TestFeature : public FeatureAbstract {
41  public:
43  virtual ~TestFeature(void) {}
44  virtual unsigned int &getDimension(unsigned int &res, int /*time*/) {
45  return res;
46  }
47 
48  virtual dg::Vector &computeError(dg::Vector &res, int /*time*/) {
49  return res;
50  }
51  virtual dg::Matrix &computeJacobian(dg::Matrix &res, int /*time*/) {
52  return res;
53  }
54  virtual dg::Vector &computeActivation(dg::Vector &res, int /*time*/) {
55  return res;
56  }
57 };
58 
59 int main() {
60  sotDEBUG(0) << "# In {" << endl;
61  // Entity test("");
62  // ExceptionFeature t2(ExceptionFeature::BAD_INIT);
63  // ExceptionSignal t4(ExceptionSignal::COPY_NOT_INITIALIZED);
64  // Flags t3;
65  // TestFeature t5;
66 
67 #ifdef WIN32
68  sotPluginKey dlib = LoadLibrary(PLUGIN_LIB_INSTALL_PATH
69  "/feature-visual-point" TESTS_DYNLIBSUFFIX);
70 #else
71  sotPluginKey dlib =
72  dlopen(PLUGIN_LIB_INSTALL_PATH "/feature-visual-point" TESTS_DYNLIBSUFFIX,
73  RTLD_NOW);
74 #endif
75 
76  if (NULL == dlib) {
77  cerr << " Error dl" << endl;
78 #ifndef WIN32
79  cerr << dlerror() << endl;
80 #else
81  // Retrieve the system error message for the last-error code
82  LPTSTR pszMessage;
83  DWORD dwLastError = GetLastError();
84  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
85  FORMAT_MESSAGE_IGNORE_INSERTS,
86  NULL, dwLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
87  (LPTSTR)&pszMessage, 0, NULL);
88 
89  cerr << pszMessage << endl;
90  LocalFree(pszMessage);
91 #endif
92 
93  exit(1);
94  }
95 
96 #ifdef WIN32
97  dlib =
98  LoadLibrary(PLUGIN_LIB_INSTALL_PATH "/gain-adaptive" TESTS_DYNLIBSUFFIX);
99 #else
100  dlib = dlopen(PLUGIN_LIB_INSTALL_PATH "/gain-adaptive" TESTS_DYNLIBSUFFIX,
101  RTLD_NOW);
102 #endif
103 
104  if (NULL == dlib) {
105  cerr << " Error dl" << endl;
106 #ifndef WIN32
107  cerr << dlerror() << endl;
108 #else
109  // Retrieve the system error message for the last-error code
110  LPTSTR pszMessage;
111  DWORD dwLastError = GetLastError();
112  FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
113  FORMAT_MESSAGE_IGNORE_INSERTS,
114  NULL, dwLastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
115  (LPTSTR)&pszMessage, 0, NULL);
116 
117  cerr << pszMessage << endl;
118  LocalFree(pszMessage);
119 #endif
120  exit(1);
121  }
122 
123  Entity *gain =
124  FactoryStorage::getInstance()->newEntity("GainAdaptive", "Gain");
125  FeatureAbstract *point =
126  sotFactory.newFeature("FeatureVisualPoint", "DynamicTest.");
127 
128  try {
129  gain->display(cout);
130  cout << endl;
131  cout << gain->getClassName();
132  cout << endl;
133 
134  point->display(cout);
135  cout << endl;
136  cout << point->getClassName();
137  cout << endl;
138  } catch (ExceptionSignal e) {
139  cout << "Exception caught! " << e << endl;
140  }
141 
142  sotDEBUG(0) << "# Out }" << endl;
143 }
TestFeature::computeError
virtual dg::Vector & computeError(dg::Vector &res, int)
Definition: test_factory.cpp:48
factory.hh
feature-visual-point.hh
dynamicgraph
dynamicgraph::Entity
dynamicgraph::sot::FeatureAbstract::getClassName
virtual const std::string & getClassName(void) const
Returns the name class.
Definition: feature-abstract.hh:82
dynamicgraph::Matrix
Eigen::MatrixXd Matrix
TestFeature::~TestFeature
virtual ~TestFeature(void)
Definition: test_factory.cpp:43
dynamicgraph::sot::FeatureAbstract
This class gives the abstract definition of a feature.
Definition: feature-abstract.hh:76
debug.hh
res
res
TestFeature::getDimension
virtual unsigned int & getDimension(unsigned int &res, int)
Definition: test_factory.cpp:44
dynamicgraph::Entity::getClassName
virtual const std::string & getClassName() const
dynamicgraph::Entity::display
virtual void display(std::ostream &os) const
dynamicgraph::Vector
Eigen::VectorXd Vector
main
int main()
Definition: test_factory.cpp:59
dynamicgraph::ExceptionSignal
exception-feature.hh
linear-algebra.h
TestFeature::computeActivation
virtual dg::Vector & computeActivation(dg::Vector &res, int)
Definition: test_factory.cpp:54
dynamicgraph::sot
TestFeature
Definition: test_factory.cpp:40
TestFeature::TestFeature
TestFeature(void)
Definition: test_factory.cpp:42
TestFeature::computeJacobian
virtual dg::Matrix & computeJacobian(dg::Matrix &res, int)
Definition: test_factory.cpp:51
sotPluginKey
void * sotPluginKey
Definition: test_factory.cpp:37
sotDEBUG
#define sotDEBUG(level)
Definition: debug.hh:168


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:32