soma-io  5.0.5
streamdatasource.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 #ifndef SOMAIO_DATASOURCE_STREAMDATASOURCE_H
35 #define SOMAIO_DATASOURCE_STREAMDATASOURCE_H
36 //--- soma-io ----------------------------------------------------------------
38 #include <soma-io/datasource/datasource.h> // base class
39 //--- cartobase --------------------------------------------------------------
40 #include <cartobase/smart/rcptr.h> // member: _rcstr
41 //--- system -----------------------------------------------------------------
42 #include <iostream>
43 #include <string>
44 //----------------------------------------------------------------------------
45 
46 namespace soma
47 {
48 
49  //==========================================================================
50  // S T R E A M
51  //==========================================================================
54  {
55  public:
57  StreamDataSource( std::iostream &,
58  const std::string & url = std::string() );
61  const std::string & url = std::string() );
62  virtual ~StreamDataSource();
63  std::iostream & stream();
64 
65  virtual std::string url() const;
66  virtual DataSource* clone() const;
67  virtual bool open( int mode );
68  virtual bool allowsMemoryMapping() const;
69  virtual int iterateMode() const;
70  virtual bool isOpen() const;
71  virtual bool eof() const;
72  virtual bool operator ! () const;
73  virtual void close();
75  virtual offset_t size() const;
76  virtual offset_t at() const;
77  virtual bool at( offset_t pos );
78  virtual long readBlock( char* data, unsigned long maxlen );
79  virtual long writeBlock( const char* data, unsigned long len );
80  virtual int getch();
81  virtual int putch( int ch );
82  virtual bool ungetch( int ch );
83  bool isFile() const;
84 
85  private:
86  std::iostream *_stream;
88  std::string _url;
89  };
90 
91  //==========================================================================
92  // I S T R E A M
93  //==========================================================================
96  {
97  public:
99  IStreamDataSource( std::istream &,
100  const std::string & url = std::string() );
103  const std::string & url = std::string() );
104  virtual ~IStreamDataSource();
105  std::istream & stream();
106 
107  virtual std::string url() const;
108  virtual DataSource* clone() const;
109  virtual bool open( int mode );
110  virtual bool allowsMemoryMapping() const;
111  virtual int iterateMode() const;
112  virtual bool isOpen() const;
113  virtual bool eof() const;
114  virtual bool operator ! () const;
115  virtual void close();
117  virtual offset_t size() const;
118  virtual offset_t at() const;
119  virtual bool at( offset_t pos );
120  virtual long readBlock( char* data, unsigned long maxlen );
122  virtual long writeBlock( const char* data, unsigned long len );
123  virtual int getch();
125  virtual int putch( int ch );
126  virtual bool ungetch( int ch );
127  bool isFile() const;
128 
129  private:
130  std::istream *_stream;
132  std::string _url;
133  };
134 
135  //==========================================================================
136  // O S T R E A M
137  //==========================================================================
140  {
141  public:
143  OStreamDataSource( std::ostream &,
144  const std::string & url = std::string() );
147  const std::string & url = std::string() );
148  virtual ~OStreamDataSource();
149  std::ostream & stream();
150 
151  virtual std::string url() const;
152  virtual DataSource* clone() const;
153  virtual bool open( int mode );
154  virtual bool allowsMemoryMapping() const;
155  virtual int iterateMode() const;
156  virtual bool isOpen() const;
157  virtual bool eof() const;
158  virtual bool operator ! () const;
159  virtual void close();
161  virtual offset_t size() const;
162  virtual offset_t at() const;
163  virtual bool at( offset_t pos );
165  virtual long readBlock( char* data, unsigned long maxlen );
166  virtual long writeBlock( const char* data, unsigned long len );
168  virtual int getch();
169  virtual int putch( int ch );
171  virtual bool ungetch( int ch );
172  bool isFile() const;
173 
174  private:
175  std::ostream *_stream;
177  std::string _url;
178  };
179 
180 }
181 #endif
virtual std::string url() const
virtual bool open(int mode)
virtual void close()
virtual offset_t at() const
int mode() const
access mode(s) (read/write): bitwise OR of Mode values
DataSource on a std::ostream (write-only stream)
virtual bool isOpen() const
Abstraction layer for various data sources (file, buffer, socket...).
Definition: datasource.h:64
Definition: allocator.h:48
virtual long writeBlock(const char *data, unsigned long len)
DataSource on a std::istream (read-only stream)
virtual bool eof() const
virtual bool allowsMemoryMapping() const
virtual offset_t size() const
always returns 0
virtual int iterateMode() const
possible iteration mode(s): bitwise OR of IterateMode values
virtual DataSource * clone() const
virtual bool operator!() const
unsigned long long offset_t
Offsets are 64 bits if supported.
Definition: datasource.h:51
virtual bool ungetch(int ch)
virtual long readBlock(char *data, unsigned long maxlen)
virtual int putch(int ch)
DataSource on a std::iostream (read/write stream)
StreamDataSource(std::iostream &, const std::string &url=std::string())
Using an existing, external stream.
std::iostream & stream()