Factory.h
Go to the documentation of this file.
1 #ifndef __FACTORY_H__
2 #define __FACTORY_H__
3 
4 #include <functional>
5 #include <map>
6 #include <string>
7 #include <mex.h>
8 #include <matrix.h>
9 
10 typedef void mxFunc(int, mxArray*[], int, const mxArray*[]);
11 
12 struct func_data {
13  std::function<mxFunc> f;
14  int out, in_min, in_max;
15  func_data() : f(), out(0), in_min(0), in_max(0) {};
16  func_data(std::function<mxFunc> function, int out_args, int in_args) : func_data(function, out_args, in_args, in_args) {}
17  func_data(std::function<mxFunc> function, int out_args, int in_min_args, int in_max_args) : f(function), out(out_args), in_min(in_min_args), in_max(in_max_args) {}
18 };
19 
21 {
22 private:
24  std::map<std::string, func_data> funcs;
25 public:
26  ClassFactory(std::string n) : name(n), funcs() {}
27  void record(std::string fname, int out, int in, std::function<mxFunc> func)
28  {
29  funcs.emplace(fname, func_data(func, out, in));
30  }
31  void record(std::string fname, int out, int in_min, int in_max, std::function<mxFunc> func)
32  {
33  funcs.emplace(fname, func_data(func, out, in_min, in_max));
34  }
35 
36  std::string get_name() { return name; }
37 
39  auto func = funcs.find(f);
40  if (func == funcs.end()) return func_data();
41  return func->second;
42  }
43 };
44 
45 class Factory
46 {
47 private:
48  std::map<std::string, ClassFactory> classes;
49 public:
50  Factory() = default;
51  void record(ClassFactory cls) { classes.emplace(cls.get_name(), cls); }
52 
54  auto cls = classes.find(c);
55  if (cls == classes.end()) return func_data();
56  return cls->second.get(f);
57  }
58 };
59 
60 #endif
std::string name
Definition: Factory.h:23
ClassFactory(std::string n)
Definition: Factory.h:26
func_data(std::function< mxFunc > function, int out_args, int in_args)
Definition: Factory.h:16
GLuint const GLchar * name
std::map< std::string, func_data > funcs
Definition: Factory.h:24
std::map< std::string, ClassFactory > classes
Definition: Factory.h:48
GLsizei const GLchar *const * string
GLdouble n
Definition: glext.h:1966
func_data()
Definition: Factory.h:15
std::string get_name()
Definition: Factory.h:36
void record(ClassFactory cls)
Definition: Factory.h:51
GLdouble f
void record(std::string fname, int out, int in_min, int in_max, std::function< mxFunc > func)
Definition: Factory.h:31
const GLubyte * c
Definition: glext.h:12690
int in_max
Definition: Factory.h:14
int in_min
Definition: Factory.h:14
GLenum func
void record(std::string fname, int out, int in, std::function< mxFunc > func)
Definition: Factory.h:27
fname
Definition: rmse.py:13
GLuint in
Definition: glext.h:8859
func_data(std::function< mxFunc > function, int out_args, int in_min_args, int in_max_args)
Definition: Factory.h:17
std::function< mxFunc > f
Definition: Factory.h:13
void mxFunc(int, mxArray *[], int, const mxArray *[])
Definition: Factory.h:10
int out
Definition: Factory.h:14


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:14