iCub-main
CalibToolFactory.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2007 Jonas Ruesch
5  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
6  *
7  * Written by Jonas Ruesch inspired by Paul Fitzpatrick.
8  */
9 
10 #ifndef __UZH_CALIBTOOLFACTORY__
11 #define __UZH_CALIBTOOLFACTORY__
12 
13 // std
14 #include <vector>
15 #include <string>
16 
17 // iCub
18 #include <iCub/ICalibTool.h>
19 
20 class CalibToolFactory {
21 public:
22  virtual ICalibTool *create() = 0;
23  virtual std::string getName() = 0;
24 };
25 
26 template <class T>
27 class CalibToolFactoryOf : public CalibToolFactory {
28 private:
29  std::string name;
30 public:
31  CalibToolFactoryOf(const char *name) : name(name) {
32  }
33 
34  virtual ICalibTool *create() {
35  return new T;
36  }
37 
38  virtual std::string getName() {
39  return name;
40  }
41 };
42 
43 
44 class CalibToolFactories {
45 public:
46  virtual ~CalibToolFactories() {
47  clear();
48  }
49 
50  void add(CalibToolFactory *factory) {
51  group.push_back(factory);
52  }
53 
55  return pool;
56  }
57 
58  ICalibTool *get(const char *name) {
59  for (unsigned int i=0; i<group.size(); i++) {
60  if (group[i]->getName() == name) {
61  return group[i]->create();
62  }
63  }
64  return NULL;
65  }
66 
67  std::vector<std::string> getNames() {
68  std::vector<std::string> result;
69  for (unsigned int i=0; i<group.size(); i++) {
70  result.push_back(std::string(group[i]->getName().c_str()));
71  }
72  return result;
73  }
74 
75 private:
76  void clear() {
77  for (unsigned int i=0; i<group.size(); i++) {
78  delete group[i];
79  group[i] = NULL;
80  }
81  group.clear();
82  }
83  std::vector<CalibToolFactory*> group;
84  static CalibToolFactories pool;
85 };
86 
87 #endif
static CalibToolFactories & getPool()
std::vector< std::string > getNames()
void add(CalibToolFactory *factory)
ICalibTool * get(const char *name)
virtual ~CalibToolFactories()
virtual ICalibTool * create()
CalibToolFactoryOf(const char *name)
virtual std::string getName()
virtual std::string getName()=0
virtual ICalibTool * create()=0
Interface to calibrate and project input image based on camera's internal parameters and projection m...
Definition: ICalibTool.h:19