Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

GPIBEquipment.h

Go to the documentation of this file.
00001 /*
00002  * Time-stamp: <00/08/04 01:11:18 pagey>
00003  *
00004  * $Format: " * $Id: GPIBEquipment.h,v 0.11 2000/08/04 09:48:04 pagey Exp $"$
00005  * GPIBEquipment.h 1.2 Sun, 05 Mar 2000 05:10:09 -0800 pagey
00006  *
00007  */
00008 #ifndef GPIBEquipment_h
00009 #define GPIBEquipment_h
00010 
00011 #include <iosfwd>
00012 //
00013 // If using the STLport version of the STL we need to include 
00014 // streambuf and istream. 
00015 //
00016 #ifdef __STLPORT_STD
00017 #include <streambuf>
00018 #include <istream>
00019 #endif
00020 #include <string>
00021 #include "LibGPIB.h"
00022 
00023 extern "C++" {
00024   namespace LibGPIB {
00025     class GPIBController ;
00026     class GPIBEquipment ;
00027 
00038     class GPIBEquipmentBuffer : public streambuf {
00039 #ifdef __GNUG__
00040       //
00041       // GNU GCC implementation of STL does not define these in
00042       // streambuf so we have to define them manually. 
00043       //
00044       typedef char char_type ;
00045       typedef int  int_type ;
00046       typedef int  streamsize ;
00047 #endif
00048     public:
00058       GPIBEquipmentBuffer(GPIBEquipment *device) ;
00059     protected:
00077       virtual streambuf* setbuf(char_type *, streamsize) ;
00078       
00084       virtual int_type   overflow(int_type c) ;
00085 
00093       virtual int_type   uflow() ;
00094 
00102       virtual int_type   underflow() ;
00103 
00110       virtual streamsize xsgetn(char_type *s, streamsize n) ;
00111       
00118       virtual streamsize xsputn(const char_type* s, streamsize n) ;
00119       
00127       virtual int_type pbackfail(int_type c = EOF) ;
00128     private:
00132       GPIBEquipment *mParentGPIBEquipment ;
00133 
00139       char mPutbackChar ;
00140 
00146       bool mPutbackAvailable ;
00147       
00153       char_type GetChar() ;
00154 
00159       void PutChar(const char_type c) ;
00160     } ;
00161 
00162     inline 
00163     GPIBEquipmentBuffer::GPIBEquipmentBuffer(GPIBEquipment *device) :
00164       mParentGPIBEquipment(device), 
00165       mPutbackAvailable(false),
00166       mPutbackChar(0) {
00167       //
00168       // The I/O from/to the GPIBEquipment will always be unbuffered.
00169       //
00170       setbuf(0, 0) ;
00171     }
00172 
00173     inline 
00174     streambuf *
00175     GPIBEquipmentBuffer::setbuf(char_type *, streamsize) {
00176       //
00177       // We force unbuffered I/O even if someone tries to provide 
00178       // a buffer. 
00179       //
00180       return streambuf::setbuf(0, 0) ;
00181     }
00182     
00183     inline
00184     GPIBEquipmentBuffer::int_type 
00185     GPIBEquipmentBuffer::overflow(int_type c) {
00186       PutChar(c) ;
00187       return c ;
00188     }
00189 
00190     inline
00191     GPIBEquipmentBuffer::int_type
00192     GPIBEquipmentBuffer::underflow() {
00193       return GetChar() ;
00194     }
00195 
00196     inline
00197     GPIBEquipmentBuffer::int_type
00198     GPIBEquipmentBuffer::uflow() {
00199       return GetChar() ;
00200     }
00201     
00202 
00203     inline
00204     GPIBEquipmentBuffer::int_type 
00205     GPIBEquipmentBuffer::pbackfail(int_type c) {
00206       mPutbackChar = c ;
00207       mPutbackAvailable = true ;
00208       return c ;
00209     }
00210 
00220     class GPIBEquipment : public iostream {
00221     public: 
00222       friend GPIBEquipmentBuffer ;
00223 
00235       void SetController(GPIBController *controller) ;
00236 
00241       void Clear() ;
00242 
00247       int PrimAddress(const int addr) ;
00248 
00252       int PrimAddress() const ; 
00253 
00258       int SecAddress(const int addr) ;
00259 
00263       int SecAddress() const ; 
00264 
00268       int DeviceID() const ;
00269 
00274       void SendCommand(const string command) ;
00275 
00280       const string ReadData(int read_bytes) ;
00281 
00286       void SetLocal() ;
00287 
00292       GPIBEquipment() ;
00293 
00297       virtual ~GPIBEquipment()  ;
00298       
00299       /* A template function to intercept all I/O operations for this
00300           class and direct them to the corresponding functions of the
00301           GPIBController class.
00302 
00303       */
00304       //template <class ValueType> 
00305       //ostream& operator<<(ValueType val) {
00306       //if( mController ) {
00307       //mController << mController.SendCommandPrefix(PrimAddress(), SecAddress()) 
00308       //<< val << mController.SendCommandPostfix(PrimAddress(), SecAddress()) ;
00309       //}
00310       //}
00311 
00312       //template <class ValueType>
00313       //istream& operator>>(ValueType& val) {
00314       //if (mController) {
00315       //mController << mController.ReadDataPrefix(PrimAddress(), SecAddress()) ;
00316       //mController >> val ;
00317       //mController << mController.ReadDataPostfix(PrimAddress(), SecAddress()) ;
00318       //}
00319       //}
00320 
00321     private:
00325       int mAddress ;
00326 
00330       int mSecAddress ;
00331 
00335       GPIBController *mController ;
00336       
00340       GPIBEquipmentBuffer *mBuffer ;
00341     protected:
00345       int mDeviceID ;
00346 
00350       GPIBController& Controller() ;
00351     } ;
00352 
00353 
00354     inline 
00355     int 
00356     GPIBEquipment::PrimAddress(const int addr) { mAddress = addr ; return mAddress ; }
00357 
00358     inline 
00359     int 
00360     GPIBEquipment::PrimAddress() const { return mAddress ; } 
00361 
00362     inline 
00363     int 
00364     GPIBEquipment::SecAddress(const int addr) { return mSecAddress = addr ; } 
00365 
00366     inline 
00367     int 
00368     GPIBEquipment::SecAddress() const { return mSecAddress ; } 
00369 
00370     inline 
00371     int 
00372     GPIBEquipment::DeviceID() const { return mDeviceID ; }
00373   } // namespace LibGPIB
00374 }  // extern "C++"
00375 #endif

Generated at Tue Aug 8 01:37:55 2000 for libgpib by doxygen1.1.4 written by Dimitri van Heesch, © 1997-2000