MrSID Decode SDK for LiDAR Reference Manual  1.1.2.4045
Stream.h
Go to the documentation of this file.
1 /* //////////////////////////////////////////////////////////////////////////
2 // //
3 // This code is Copyright (c) 2008-2010 LizardTech, Inc, 1008 Western //
4 // Avenue, Suite 200, Seattle, WA 98104. Unauthorized use or distribution //
5 // prohibited. Access to and use of this code is permitted only under //
6 // license from LizardTech, Inc. Portions of the code are protected by //
7 // US and foreign patents and other filings. All Rights Reserved. //
8 // //
10 /* PUBLIC */
11 
12 #ifndef __LIDAR_STREAM_H__
13 #define __LIDAR_STREAM_H__
14 
15 #include "lidar/IO.h"
16 #include "lidar/Endian.h"
17 
18 LT_BEGIN_LIDAR_NAMESPACE
19 
23 class Stream
24 {
25  SIMPLE_OBJECT(Stream);
26 public:
30  enum { DefaultBufferSize = 1 << 12 };
31 
35  enum Mode
36  {
38  MODE_SET = 0,
40  MODE_CUR = 1,
43  };
44 
49 
53  IO *getIO();
54 
55 protected:
56  ~Stream(void);
57  Stream(void);
58 
59  typedef unsigned char byte_t;
60 
61  IO *m_io;
62  size_t m_size;
67 };
68 
75 class StreamReader : public Stream
76 {
77  SIMPLE_OBJECT(StreamReader);
78 public:
79  ~StreamReader(void);
80  StreamReader(void);
81 
91  void init(IO *io, bool open, size_t bufferSize = DefaultBufferSize);
100  void init(const IO::Location &location,
101  size_t bufferSize = DefaultBufferSize);
102 
110  void open(size_t bufferSize = DefaultBufferSize);
111 
117  void close(void);
118 
125  void flush(void);
126 
135  void seek(offset_type offset, Mode whence);
136 
142  offset_type tell(void);
143 
153  size_t read(void *buf, size_t nbytes);
154 
163  template<typename TYPE> bool get_le(TYPE &value)
164  {
165  size_t nbytes = read(&value, sizeof(TYPE));
167  Endian::swap<sizeof(TYPE)>(&value);
168  return nbytes == sizeof(TYPE);
169  }
170 
179  template<typename TYPE> bool get_be(TYPE &value)
180  {
181  size_t nbytes = read(&value, sizeof(TYPE));
183  Endian::swap<sizeof(TYPE)>(&value);
184  return nbytes == sizeof(TYPE);
185  }
186 
198  bool get_str(char *&line, size_t &length);
199 };
200 
204 class StreamWriter : public Stream
205 {
206  SIMPLE_OBJECT(StreamWriter);
207 public:
208  ~StreamWriter(void);
209  StreamWriter(void);
210 
220  void init(IO *io, bool open, size_t bufferSize = DefaultBufferSize);
221 
229  void open(size_t bufferSize = DefaultBufferSize);
230 
237  void close(bool doFlush = true);
238 
244  void flush(void);
245 
255  void seek(offset_type offset, Mode whence);
256 
262  offset_type tell(void);
263 
273  size_t write(const void *buf, size_t nbytes);
274 
283  template<typename TYPE> bool put_le(TYPE value)
284  {
286  Endian::swap<sizeof(TYPE)>(&value);
287  return write(&value, sizeof(TYPE)) == sizeof(TYPE);
288  }
289 
298  template<typename TYPE> bool put_be(TYPE value)
299  {
301  Endian::swap<sizeof(TYPE)>(&value);
302  return write(&value, sizeof(TYPE)) == sizeof(TYPE);
303  }
304 
315  bool put_str(const char *str, size_t length = static_cast<size_t>(-1));
316 
327  bool copy(IO *io, offset_type offset, offset_type length);
328 
337  bool copy(IO::Location &location);
338 
348  bool copy(StreamReader &stream, offset_type length);
349 };
350 
351 LT_END_LIDAR_NAMESPACE
352 #endif // __LIDAR_STREAM_H__

LizardTech