00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00070 bool prep() {return bool(get_driver());}
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