Kashub's Code Barn - "ioformat "

podświetlone jako cpp (dodał(a) xmoon @ 2009-09-28 17:02:07)

Twoja wyszukiwarka
Podświetl ten kod w:
Ostatnio dodane:
Losowe wpisy:
#ifndef IOFORMAT_H
#define IOFORMAT_H
 
#include <fstream>
 
namespace seelib{
  // classes using strategy pattern
  // strategy
 
  using std::ofstream;
  using std::ifstream;
 
  class format_io{
    public:
      format_io(ofstream * ofs):fout(ofs){}
      format_io(ifstream * ifs):fin(ifs){}
      void set_out(ofstream * ofs){
        fout = ofs; // set new output stream
      }
      void set_in(ifstream * ifs){
        fin = ifs; // set new input stream
      }
      // TODO: correct this declarations
      // method templates cannot be virtual...
      // write field 
      template <class T>
      virtual format_io & operator<<(T & value) = 0;
      // read field
      template <class T>
      virtual format_io & operator>>(T & value) = 0;
    private:
 
      ofstream * fout;
      ifstream * fin;
  };
 
  // concrete strategy
  class text_format: public format_io{
    public:
      template <class T>
      virtual format_io & operator<<(T & value);
      template <class T>
      virtual format_io & operator>>(T & value);
  };
 
  // concrete strategy
  class xml_format: public format_io{
    public:
      template <class T>
      virtual format_io & operator<<(T & value);
      template <class T>
      virtual format_io & operator>>(T & value);
    private:
      bool _created;
  };
 
  // concrete strategy
  class bin_format: public format_io{
    public:
      template <class T>
      virtual format_io & operator<<(T & value);
      template <class T>
      virtual format_io & operator>>(T & value);
  };
 
}
#endif
 
| Katalog Sklepów internetowych | | sklep z bielizną | | Kredyty mieszkaniowe | | Programista Trójmiasto | | Darmowe Blogi | | Darmowe Blogi | | Wklejacz kodów | | Skróć link | | Gnieżdżewo | | Smutne Opisy |