Fawkes API  Fawkes Development Version
factory.h
1 
2 /***************************************************************************
3  * factory.h - Camera factory
4  *
5  * Created: Wed Apr 11 14:40:22 2007
6  * Copyright 2005-2007 Tim Niemueller [www.niemueller.de]
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __FIREVISION_CAMS_FACTORY_H_
25 #define __FIREVISION_CAMS_FACTORY_H_
26 
27 #include <core/exception.h>
28 #include <core/exceptions/software.h>
29 
30 #include <fvcams/camera.h>
31 #include <fvcams/cam_exceptions.h>
32 
33 #include <cstddef>
34 
35 namespace firevision {
36 #if 0 /* just to make Emacs auto-indent happy */
37 }
38 #endif
39 
40 class CameraArgumentParser;
41 
43 {
44  public:
45  static Camera * instance(const char *as);
46  static Camera * instance(const CameraArgumentParser *cap);
47 
48  /** Get typed instance of camera.
49  * Creates a new instance and converts it to the requested type. If the type
50  * does not match the requested camera an exception is thrown.
51  * @param as camera argument string
52  * @return typed camera instance
53  * @exception TypeMismatchException thrown, if requested camera does not match
54  * requested type.
55  */
56  template <class C>
57  static C* instance(const char *as);
58 };
59 
60 
61 template <class C>
62 C *
63 CameraFactory::instance(const char *as)
64 {
66  C *tc = dynamic_cast<C *>(c);
67  if ( tc == NULL ) {
68  throw fawkes::TypeMismatchException("Returned camera is not of expected type");
69  }
70  return tc;
71 }
72 
73 } // end namespace firevision
74 
75 #endif
Camera interface for image aquiring devices in FireVision.
Definition: camera.h:35
Camera factory.
Definition: factory.h:42
Camera argument parser.
Definition: camargp.h:38
static Camera * instance(const char *as)
Get camera instance.
Definition: factory.cpp:239