Listing 2: Base and derived classes for virtual devices

//file vmod.h
     
//block is the base class for derived abstract classes which
//represent different device types: e.g. a module with four
//counters will be built with four blocks each of them represents
//a single counter.
     
#if !defined MOD_H
#define MOD_H
#include <cstring.h>
     
class CardError
{
public:
    CardError(string message);
    string RetMsg();
private:
    string msg;
};
     
class Block
{
public:
    Block(int slotVal,int posVal,int chnVal):     
        slot(slotVal),pos(posVal),chn(chnVal){} //creator with
                                                //parameters
    Block(){}                                   // creator without
                                                //parameters
    ~Block(){}
    inline int RetSlot() {return slot;}
    inline int RetPos()  {return pos; }
    inline int RetChn()  {return chn; }
    inline void SetSlot(int i) {slot=i;} 
    inline void SetPos(int i)  {pos=i;}
    inline void SetChn(int i)  {chn=i;}
     
private:
    int slot, pos, chn; //indicate the slot, the position in the
                        //slot and the channel of the module where
                        //the block is 'placed'
  };
     
class VAO : public Block //Analog Output block 
{
public:
     
    VAO(int slotVal,int posVal,int chnVal):
        Block(slotVal,posVal,chnVal) {}     //creator with
                                            //parameters
    VAO(): Block(){}                        //creator without
                                            //parameters 
    virtual ~VAO(){}
    virtual void Write(float val)=0; //val is the value that will
                                    //be written 
    virtual void SetRange(float low,float high)=0;
    virtual void GetRange(float *low,float *high)=0; 
    virtual void SetResolution(float res)=0;
    virtual float GetResolution()=0;
    inline void SetConvFact(float i) {cf=i;} 
    inline void SetOffset(float i)   {of=i;} 
    inline float RetConvFact()  {return cf;} 
    inline float RetOffset()    {return of;}
     
private:
    float cf,of;
protected:
    float lowHwd,highHwd,resHwd;
};
     
class VAI : public Block  //Analog Input block 
{
public:
    VAI(int slotVal,int posVal,int chnVal):
        Block(slotVal,posVal,chnVal) {}     //creator with
                                            //parameters
    VAI():Block(){}                         //creator without
                                            //parameters 
    virtual ~VAI(){}
    virtual float Read()=0; // returns the number read
    virtual void SetRange(float low,float high)=0; 
    virtual void GetRange(float *low,float *high)=0; 
    virtual void SetResolution(float res)=0;
    virtual float GetResolution()=0;
    inline void SetConvFact(float i) {cf=i;} 
    inline void SetOffset(float i)   {of=i;} 
    inline float RetConvFact()  {return cf;} 
    inline float RetOffset()    {return of;}
private:
    float cf,of;
protected:
    float lowHwd,highHwd,resHwd;
};
     
class VCNT : public Block //counter block 
{
public:
    VCNT(int slotVal,int posVal,int chnVal):
        Block(slotVal,posVal,chnVal) {}      //creator with
                                             //parameters
    VCNT():Block(){}                         //creator without
                                             //parameters
    virtual ~VCNT(){}
    virtual long Read()=0;
    virtual void Start()=0;
    virtual void Stop()=0;
    virtual void
    Set(unsigned int mode, long preload=0, bool reset=true)=0; 
    inline long RetPreload() {return preload;}
     
protected:
    long preload;
};
     
class VMCNT : public Block // multi counter block 
{
public:
    VMCNT(int slotVal,int posVal,int chnVal):
        Block(slotVal,posVal,chnVal) {}       //creator with
                                              //parameters
    VMCNT():Block(){}                         //creator without
                                              //parameters
    virtual ~VMCNT(){}
    virtual void  MultiRead(unsigned long* data)=0;
    virtual void Start()=0;
    virtual void Stop()=0;
    virtual void
    Set(unsigned int mode, long preload=0, bool reset=true)=0; 
    inline long RetPreload() {return preload;}
     
protected:
    long preload;
};
     
     
class VCLK : public Block // Clock
{
public:
    VCLK(int slotVal,int posVal,int chnVal):
        Block(slotVal,posVal,chnVal) {ticking = false;} //creator
                                                        //with
                                                        //parameters
    VCLK():Block(){ticking = false;}                    //creator
                                                        //without
                                                        //parameters
    virtual ~VCLK(){}
    virtual void Start()=0;
    virtual void Stop()=0;
    virtual void Set(int mant ,short esp,float duty_cycle)=0;
    //mant e esp are the mantissa and the exponent of the frequency; 
    //duty_cycle is a number between 0 and 1 that indicate the duty 
    //cycle of the square wave generated.
    inline bool is_ticking() {return ticking;}
     
    private:
    bool ticking;
};
     
class VOSC : public Block // oscillator 
{
public:
    VOSC(int slotVal,int posVal,int chnVal):
        Block(slotVal,posVal,chnVal) {}      //creator with
                                             //parameters
    VOSC():Block(){}                         //creator without
                                             //parameters
    virtual ~VOSC(){}
    virtual void Start()=0;
    virtual void Stop()=0;
    virtual void
    Set(int type, float freq, float phase, float amp)=0; 
    //type indicates the type of the wave that will be produced. 
    //freq is the frequency of the oscillation
    //phase is the initial phase
    //amp is the amplitude in volts of the wave
    inline void SetConvFact(float i) {cf=i;} 
    inline float RetConvFact()  {return cf;}
     
private:
    float cf;
};
     
#endif
     
//end file vmod.h
/* End of File */