home *** CD-ROM | disk | FTP | other *** search
- // gstream.cpp
- #include <stdio.h>
- #include <iostream.h>
- #include <string.h>
- #include "gpibio.h"
-
- // GENERIC STREAM Definitions
- gstream::gstream() // constructor
- {
- base_ = ebuf_ = pbase_ = epptr_ = pptr_= gptr_ = NULL;
- gleng_ = 0;
- }
-
- // Destructor
- gstream::~gstream()
- {
- if(base_)
- delete base_; // Free up areas if allocated
- if(pbase_)
- delete pbase_;
- }
-
- // Implementation of sput function
- void gstream::sput(char *s)
- {
- int len = strlen(s);
-
- // If it's too long, flush and reallocate more room
- if(pptr_+len+1 >= epptr_)
- {
- overflow();
-
- // See if it will fit at all
- if(len > (int)(epptr_ - pbase_))
- {
- char *newarea = new char [len+1];
-
- if(newarea == NULL)
- {
- cerr << "Not enough memory to output " << s << endl;
- return;
- }
- else
- delete pbase_;
- pbase_ = newarea;
- pptr_ = pbase_;
- epptr_ = base_ + len + 1;
- }
- }
- strcpy(pptr_,s); // Copy string into output stream
- pptr_ += len;
- }
-
- ... [full source code is on code disk -mb]
-
- // Implementation of gets
- void gstream::gets(char *s)
- {
- if(gptr_ >= egptr_)
- underflow();
- strcpy(s,gptr_); // copy the remaining stream into the string
- gptr_ = egptr_; // update get pointer
- }
-
-