PLearn 0.1
pl_streambuf.h
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // PLearn (A C++ Machine Learning Library)
00004 // Copyright (C) 2002 Xavier Saint-Mleux <saintmlx@iro.umontreal.ca>
00005 //
00006 
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 // 
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 // 
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 // 
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 // 
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 // 
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00043 #ifndef pl_streambuf_INC
00044 #define pl_streambuf_INC
00045 
00046 //#include <iosfwd>
00047 #include <iostream>
00048 #include <cstdio> //Needed by g++ 4.5.1
00049 //#include "plerror.h"
00050 #include <plearn/base/PP.h>
00051 
00052 namespace PLearn {
00053 
00054 using namespace std;
00055 
00056 class ioassignstream; //fwd decl.
00057 class pl_streambuf; // fwd decl.
00058 class pl_streammarker; // fwd decl.
00059 
00064 class pl_streambuf : public streambuf, public PPointable
00065 {
00066 #if __GNUC__ < 3 && !defined(WIN32)
00067     typedef int int_type;
00068     typedef char char_type;
00069 #endif
00070 
00071     static const int_type eof = EOF;
00072 
00073     friend class pl_streammarker;
00074     friend class ioassignstream;
00075   
00076 private:
00077     typedef streambuf inherited;
00078 
00079 protected:
00080   
00081     streambuf& original_buf; 
00082     char* inbuf;             
00083     int inbuflen;            
00084     static const int pback_size= 4;     
00085     static const int min_buf_size= 16;  
00086 
00087     pl_streammarker* first_marker;  
00088 
00089     virtual int_type underflow();   
00090     virtual int_type uflow();       
00091 
00092 
00093     virtual streamsize xsgetn(char* s, streamsize n);
00094     virtual streamsize xsputn(const char* s, streamsize n);
00095 
00096 
00097     virtual int_type overflow(int_type meta = pl_streambuf::eof); 
00098     virtual int_type sync();        
00099     virtual int_type pbackfail(int_type c= eof);  
00100 
00101     //inline int curpos() const { return gptr() - inbuf; }  //!< return current position within the input buffer
00102     // norman: explicit cast:
00103     inline int curpos() const { return (int)(gptr() - inbuf); }  
00104 
00105 public:
00106 
00108     pl_streambuf(streambuf& _original_buf, int_type _inbuflen= 0);
00109     virtual ~pl_streambuf();
00110 
00111     void seekmark(const pl_streammarker& mark);  
00112 
00113 };
00114 
00118 class pl_streammarker
00119 {
00120     friend class pl_streambuf;
00121 
00122 protected:
00123 
00124     pl_streambuf* buf;  
00125     pl_streammarker* next_marker;  
00126     int pos;            
00127 
00128 public:
00129 
00130     pl_streammarker(pl_streambuf* _buf);  
00131     pl_streammarker(streambuf* _buf);  
00132 
00133     virtual ~pl_streammarker(); 
00134 
00135 };
00136 
00137 
00138 } // namespace PLearn
00139 
00140 #endif //ndef pl_streambuf_INC
00141 
00142 
00143 /*
00144   Local Variables:
00145   mode:c++
00146   c-basic-offset:4
00147   c-file-style:"stroustrup"
00148   c-file-offsets:((innamespace . 0)(inline-open . 0))
00149   indent-tabs-mode:nil
00150   fill-column:79
00151   End:
00152 */
00153 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines