• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List

seqdriver.h

00001 /***************************************************************************
00002                           seqdriver.h  -  description
00003                              -------------------
00004     begin                : Sat Apr 3 2004
00005     copyright            : (C) 2001 by Thies H. Jochimsen
00006     email                : jochimse@cns.mpg.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef SEQDRIVER_H
00019 #define SEQDRIVER_H
00020 
00021 
00022 #include <odinseq/seqclass.h>
00023 #include <odinseq/seqplatform.h>
00024 
00025 class SeqDriverBase : public virtual SeqClass {
00026 
00027  public:
00028   SeqDriverBase() {}
00029   virtual ~SeqDriverBase() {}
00030   virtual odinPlatform get_driverplatform() const = 0;
00031 };
00032 
00033 
00035 
00036 
00041 template<class D>
00042 class SeqDriverInterface : public SeqClass {
00043  public:
00044   typedef D* (*create_driver_callback)();
00045 
00046   SeqDriverInterface(const STD_string& driverlabel="unnamedSeqDriverInterface")
00047    : current_driver(0) {
00048     set_label(driverlabel);
00049   }
00050 
00051   virtual ~SeqDriverInterface(){
00052     if(current_driver) delete current_driver;
00053   }
00054 
00055   SeqDriverInterface& operator = (const SeqDriverInterface& di) {
00056     SeqClass::operator = (di);
00057     if(current_driver) delete current_driver;
00058     current_driver=0;
00059     if(di.current_driver) current_driver=di.current_driver->clone_driver();
00060     return *this;
00061   }
00062   
00063   D& operator *  () {return *get_driver();}
00064   D* operator -> () {return get_driver();}
00065 
00066   
00067  private:
00068 
00069   // overwriting virtual functions from SeqClass
00070   bool prep() {return bool(get_driver());} // make sure correct driver is loaded
00071 
00072   D* get_driver() {
00073     odinPlatform current_pf=SeqPlatformProxy::get_current_platform();
00074     if(!current_driver) allocate_driver();
00075     else {
00076       odinPlatform driver_platform=current_driver->get_driverplatform();
00077       if(driver_platform!=current_pf) {
00078         delete current_driver;
00079         allocate_driver();
00080       }
00081     }
00082     if(!current_driver) {
00083       STD_cerr << "ERROR: " << get_label() << ": Driver missing for platform " << SeqPlatformProxy::get_platform_str(current_pf) << STD_endl;
00084     }
00085     if(current_driver->get_driverplatform()!=current_pf) {
00086       STD_string drvplat(SeqPlatformProxy::get_possible_platforms()[current_driver->get_driverplatform()]);
00087       STD_cerr << "ERROR: " << get_label() << ": Driver has wrong platform signature " << drvplat << ", but expected " << SeqPlatformProxy::get_platform_str(current_pf) << STD_endl;
00088     }
00089     return current_driver;
00090   }
00091 
00092   void allocate_driver() {
00093     current_driver=pfinterface->create_driver(current_driver);
00094     if(current_driver) current_driver->set_label(get_label());
00095   }
00096 
00097   
00098   SeqPlatformProxy pfinterface;
00099   D* current_driver;
00100 };
00101 
00102 #endif

Generated on Tue Dec 18 2012 15:11:14 by  doxygen 1.7.1