vil_stream.h
Go to the documentation of this file.
1 // This is core/vil/vil_stream.h
2 #ifndef vil_stream_h_
3 #define vil_stream_h_
4 //:
5 // \file
6 // \brief Stream interface for VIL image loaders
7 // \author awf@robots.ox.ac.uk
8 // \date 16 Feb 00
9 
10 #include <vxl_config.h>
11 #include <vcl_atomic_count.h>
12 
13 #if VXL_HAS_INT_64
14 typedef vxl_int_64 vil_streampos;
15 #else //VXL_HAS_INT_64
16 typedef vxl_int_32 vil_streampos;
17 #endif //VXL_HAS_INT_64
18 
19 //: Stream interface for VIL image loaders
20 // This allows the loaders to be used with any type of stream.
22 {
23  public:
24  //: Return false if the stream is broken.
25  virtual bool ok() const = 0;
26 
27  //: Write n bytes from buf. Returns number of bytes written.
28  // The return value is less than n only in case of device failure.
29  virtual vil_streampos write(void const* buf, vil_streampos n) = 0;
30 
31  //: Read n bytes into buf. Returns number of bytes read.
32  // The return value is less than n only at eof.
33  virtual vil_streampos read(void* buf, vil_streampos n) = 0;
34 
35  //: Return file pointer
36  virtual vil_streampos tell() const = 0;
37 
38  //: Goto file pointer
39  virtual void seek(vil_streampos position) = 0;
40 
41  //: Amount of data in the stream
42  virtual vil_streampos file_size() const = 0;
43 
44  //: up/down the reference count
45  void ref() { ++refcount_; }
46 
47  void unref();
48 
49  protected:
50  vil_stream();
51  virtual ~vil_stream();
52 
53  private: // use the methods, Luke!
54  vcl_atomic_count refcount_;
55 };
56 
57 #endif // vil_stream_h_
virtual vil_streampos tell() const =0
Return file pointer.
vcl_atomic_count refcount_
Definition: vil_stream.h:54
virtual vil_streampos write(void const *buf, vil_streampos n)=0
Write n bytes from buf. Returns number of bytes written.
virtual void seek(vil_streampos position)=0
Goto file pointer.
virtual vil_streampos read(void *buf, vil_streampos n)=0
Read n bytes into buf. Returns number of bytes read.
Stream interface for VIL image loaders.
Definition: vil_stream.h:21
void ref()
up/down the reference count.
Definition: vil_stream.h:45
virtual ~vil_stream()
Definition: vil_stream.cxx:23
void unref()
Definition: vil_stream.cxx:31
virtual bool ok() const =0
Return false if the stream is broken.
vxl_int_32 vil_streampos
Definition: vil_stream.h:16
virtual vil_streampos file_size() const =0
Amount of data in the stream.