factory.h

00001
00002 /***************************************************************************
00003  *  factory.h - Camera factory
00004  *
00005  *  Created: Wed Apr 11 14:40:22 2007
00006  *  Copyright  2005-2007  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version. A runtime exception applies to
00014  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00022  */
00023
00024 #ifndef __FIREVISION_CAMS_FACTORY_H_
00025 #define __FIREVISION_CAMS_FACTORY_H_
00026 
00027 #include <core/exception.h>
00028 #include <core/exceptions/software.h>
00029
00030 #include <cams/camera.h>
00031 #include <cams/cam_exceptions.h>
00032
00033 #include <cstddef>
00034
00035 class CameraArgumentParser;
00036
00037 class CameraFactory
00038 {
00039  public:
00040   static Camera * instance(const char *as);
00041   static Camera * instance(const CameraArgumentParser *cap);
00042 
00043   /** Get typed instance of camera.
00044    * Creates a new instance and converts it to the requested type. If the type
00045    * does not match the requested camera an exception is thrown.
00046    * @param as camera argument string
00047    * @return typed camera instance
00048    * @exception TypeMismatchException thrown, if requested camera does not match
00049    * requested type.
00050    */
00051   template <class C>
00052     static C* instance(const char *as);
00053 };
00054
00055
00056 template <class C>
00057 C *
00058 CameraFactory::instance(const char *as)
00059 {
00060   Camera *c = CameraFactory::instance(as);
00061   C *tc = dynamic_cast<C *>(c);
00062   if ( tc == NULL ) {
00063     throw fawkes::TypeMismatchException();
00064   }
00065   return tc;
00066 }
00067
00068 #endif