Fawkes API  Fawkes Development Version
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 <fvcams/camera.h>
00031 #include <fvcams/cam_exceptions.h>
00032 
00033 #include <cstddef>
00034 
00035 namespace firevision {
00036 #if 0 /* just to make Emacs auto-indent happy */
00037 }
00038 #endif
00039 
00040 class CameraArgumentParser;
00041 
00042 class CameraFactory
00043 {
00044  public:
00045   static Camera * instance(const char *as);
00046   static Camera * instance(const CameraArgumentParser *cap);
00047 
00048   /** Get typed instance of camera.
00049    * Creates a new instance and converts it to the requested type. If the type
00050    * does not match the requested camera an exception is thrown.
00051    * @param as camera argument string
00052    * @return typed camera instance
00053    * @exception TypeMismatchException thrown, if requested camera does not match
00054    * requested type.
00055    */
00056   template <class C>
00057     static C* instance(const char *as);
00058 };
00059 
00060 
00061 template <class C>
00062 C *
00063 CameraFactory::instance(const char *as)
00064 {
00065   Camera *c = CameraFactory::instance(as);
00066   C *tc = dynamic_cast<C *>(c);
00067   if ( tc == NULL ) {
00068     throw fawkes::TypeMismatchException();
00069   }
00070   return tc;
00071 }
00072 
00073 } // end namespace firevision
00074 
00075 #endif