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

gnuplot.h

Go to the documentation of this file.
00001 // -*- c++ -*-
00002 // $Header: /home/asanuma/lib/cvsroot/c/gnuplot/gnuplot.h,v 1.7 2004/08/04 16:14:41 asanuma Exp $
00003 //
00004 
00005 #ifndef __gnuplot_H__
00006 #define __gnuplot_H__
00007 
00008 #ifndef lint
00009 static char *RCSid_gnuplot_h="$Header: /home/asanuma/lib/cvsroot/c/gnuplot/gnuplot.h,v 1.7 2004/08/04 16:14:41 asanuma Exp $";
00010 #endif
00011 
00012 #include <vector>
00013 #include <cstdio>
00014 
00015 #include "gp_base.h"
00016 #include "gp_components.h"
00017 #include "gp_traits.h"
00018 
00020 namespace gnuplotpp{
00021   using components::gprange;
00022   using components::gpset;
00023   using components::gpusing;
00024   using components::gpcoord;
00025   using std::string;
00026   using std::ostream;
00027         
00030   class subplot: public gp_base::gpstream{ // one plot
00031   protected:
00032     virtual string _quote( const string &s ){   return string(s); }
00033         
00034   public:
00035     subplot( void ): gp_base::gpstream() {};
00036     subplot( const subplot &s ): gpstream(s.str()){};
00037         
00038     template<class C1>
00039     subplot( const C1 fn, 
00040              const int u1=gpusing::omit, 
00041              const int u2=gpusing::omit ):
00042       gpstream( fn ){
00043       *this << gpusing(u1,u2);
00044     }
00045         
00046   };
00047       
00049   class subfile: public subplot{
00050   private:
00051     template<class C>
00052     string _quote( const C &s ){ 
00053       std::ostringstream o; o<<"\""<<s<< "\"";
00054       return o.str();
00055     }
00056         
00057   public:
00058     template<class C1>
00059     subfile( const C1 fn, 
00060              const int u1=gpusing::omit, 
00061              const int u2=gpusing::omit  ):
00062       subplot(_quote(fn),u1,u2){};
00063     // note this cannot be done in the initialization list.
00064         
00065   };
00066       
00068   class subfunc: public subplot{
00069   private:
00070     //    string _quote( const string &s ){ return s; }
00071   public:
00072     template<class C1>
00073     subfunc( const C1 fn ):
00074       subplot(fn,gpusing::omit,gpusing::omit){};
00075         
00076   };
00077     
00079 
00085   class plot: 
00086     public gp_base::setbufbase, 
00087     public gp_base::contbase<subplot>,  
00088     public gp_base::plotbase{
00089       
00090     private:
00091     typedef gp_base::contbase<subplot> _contbase;
00092     typedef gp_base::setbufbase        _bufbase;
00093     typedef gp_base::plotbase          _plotbase;
00094     typedef _contbase::_container      _container;
00095     typedef subplot                    _subclass;
00096       
00097     protected:
00098     static const int _omit=gpusing::omit;
00099       
00100     public:
00101     plot(void): _plotbase(_pre,_post) {};
00102 
00103     private:
00104     stream_type &prebuf( void ){ return _pre; }
00105     stream_type &postbuf( void ){ return _post; }
00106 
00107     public:
00108     void print(std::ostream &o )const;
00109     
00110     subplot& _plot( void );
00111     subplot& plotfile( void );
00112     subplot& plotfunc( void );
00113 
00114     template<class C1>
00115       subplot& plotfile( const C1 fn, 
00116                          const int u1=gpusing::omit, 
00117                          const int u2=gpusing::omit ){
00118       _p.push_back(subfile(fn,u1,u2)); 
00119       return _p.back();
00120     }
00121       
00122     template<class C1>
00123       subplot& plotfunc( const C1 fn ){
00124       _p.push_back(subfunc(fn));
00125       return _p.back();
00126     }
00127 
00128 
00129       
00130   }; // class plot
00131     
00132   // std::ostream & operator << (std::ostream &o, const plot &p );      
00133     
00136   class singleplot: public plot, 
00137                     public gp_base::filebase, 
00138                     public gp_base::sizebase{
00139         
00140   private:
00141     typedef plot                       _base;
00142     typedef gp_base::filebase          _filebase;
00143     typedef gp_base::sizebase          _sizebase;
00144 
00145   public:
00146     singleplot( void );
00147     singleplot( const std::string &_s );
00148     singleplot( const char *_s );
00149 
00150   private:
00151     singleplot( const singleplot & ){};
00152 
00153   private:
00154     stream_type &prebuf( void ){ return _pre; }
00155     stream_type &postbuf( void ){ return _post; }
00156 
00157   public: // output 
00158     void print( std::ostream & )const;
00159         
00160   }; // singleplot
00161 
00163   // new stream interface 
00164   // g.set() << set( .... )
00165   // g.x.range()
00167         /*! Each graph can be accessed as
00168          *   g[0] ... g[n]
00169          */
00170   class multiplot: 
00171     public gp_base::setbufbase, 
00172     public gp_base::contbase<plot>, // _p is vector<plot>
00173     public gp_base::plotbase, 
00174     public gp_base::filebase, 
00175     public gp_base::sizebase
00176   {
00177 
00178   protected:
00179     typedef gp_base::contbase<plot>    _contbase;
00180     typedef gp_base::setbufbase        _bufbase;
00181     typedef gp_base::plotbase          _plotbase;
00182     typedef gp_base::filebase          _filebase;
00183     typedef gp_base::sizebase          _sizebase;
00184     typedef _contbase::_container      _container;
00185     typedef plot                       _subclass;
00186 
00187   public: // constructor
00188     multiplot( int n=1 );
00189     multiplot( const std::string &_s, int n=1 );
00190     multiplot( const char *_s, int n=1 );
00191 
00192   private:
00193     multiplot( const multiplot & );
00194 
00195   private:
00196     stream_type &prebuf( void ){ return _pre; }
00197     stream_type &postbuf( void ){ return _post; }
00198 
00199   public: // iterator
00200     typedef _container::iterator        iterator;
00201     typedef _container::const_iterator  const_iterator;
00202     iterator       begin(void)     { return _p.begin();};
00203     const_iterator begin(void)const{ return _p.begin();};
00204     iterator       end  (void)     { return _p.end();};
00205     const_iterator end  (void)const{ return _p.end();};
00206 
00207     typedef _container::reverse_iterator       reverse_iterator;
00208     typedef _container::const_reverse_iterator const_reverse_iterator;
00209     reverse_iterator       rbegin(void)     { return _p.rbegin();};
00210     const_reverse_iterator rbegin(void)const{ return _p.rbegin();};
00211     reverse_iterator       rend  (void)     { return _p.rend();};
00212     const_reverse_iterator rend  (void)const{ return _p.rend();};
00213 
00214   public: // output 
00215     void print( std::ostream & )const;
00216 
00217   }; // class multiplot 
00218 
00221 
00226   class gptable:
00227     public gp_base::setbufbase, 
00228     public gp_base::contbase<std::vector<plot> >,
00229     public gp_base::plotbase, 
00230     public gp_base::filebase, 
00231     public gp_base::sizebase{
00232 
00233   private:
00234     typedef gp_base::contbase<std::vector<plot> >    _contbase;
00235     typedef gp_base::setbufbase        _bufbase;
00236     typedef gp_base::plotbase          _plotbase;
00237     typedef gp_base::filebase          _filebase;
00238     typedef gp_base::sizebase          _sizebase;
00239     typedef _contbase::_container      _container;
00240     typedef std::vector<plot>          _subcontainer;
00241     typedef plot                       _subclass;
00242 
00243   private:
00244     int _nx, _ny;
00245 
00246   public:
00247     gptable( int nx, int ny );
00248     gptable( const char *_s, int nx, int ny );
00249 
00250   private:
00251     gptable( const gptable & );
00252 
00253   private:
00254     stream_type &prebuf( void ){ return _pre; }
00255     stream_type &postbuf( void ){ return _post; }
00256 
00257   public:
00258     void print( std::ostream & )const;
00259     size_t xsize( void )const{ return _nx; };
00260     size_t ysize( void )const{ return _ny; };
00261 
00262   private:
00263     void outsize( void ) ;
00264 
00265   }; // class gptable
00266  
00269   class gpsquare: public singleplot{
00270   public:
00271     gpsquare( void );
00272     gpsquare( const char *_s ); // not implemented yet
00273 
00274   private:
00275     gpsquare( const gpsquare &){};
00276 
00277   public:
00278     void setsize( double x );
00279     template<typename C1, typename C2>
00280     void setrange( const C1 & c1, const C2 &c2 ){
00281       x.range( c1, c2 ); y.range( c1, c2 );
00282     }
00283 
00284   private:
00285     void outsize( void );
00286                 
00287   }; // class gptable
00288  
00289 
00290 } // namespace gnuplotpp
00291 
00292 #endif // __ggnuplot_H__
00293 

Generated on Wed Apr 27 00:09:36 2005 for gnuplot++ by doxygen1.2.15