COVISE Core
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
istreamBLK.h
Go to the documentation of this file.
1 /* This file is part of COVISE.
2 
3  You can use it under the terms of the GNU Lesser General Public License
4  version 2.1 or later, see lgpl-2.1.txt.
5 
6  * License: LGPL 2+ */
7 
8 #ifndef _ISTREAMBLK_H_
9 #define _ISTREAMBLK_H_
10 
11 #include <covise/covise.h>
12 #include <util/coTypes.h>
13 
14 #ifdef _WIN32
15 #include <io.h>
16 #include <fcntl.h>
17 #endif
18 #if defined(__linux__) || defined(CO_hp) || defined(_WIN32) || defined(__APPLE__) || defined(__hpux)
19 #define lseek64 lseek
20 #define off64_t off_t
21 #endif
22 
23 namespace covise
24 {
25 
27 {
28 private:
29  off64_t d_blocksize, d_blockMask;
31  int d_errFlag;
32  off64_t d_preRead;
34 
35 public:
36  istreamBLK(int filedesc, long blockSize);
38  {
39  if (d_filedesc > 0)
40  close(d_filedesc);
41  }
42 
44  off64_t read(void *data, off64_t len);
45 
46  off64_t skipBlk(off64_t len); // skip len bytes, filled to full block
47  off64_t skip(off64_t len); // skip len bytes, d_preRead in Block
48  off64_t skipBlocks(int blocks); // skip blocks
49  off64_t seekBlock(int blockNo); // seek block, start with 1 !
50 
52 
53  off64_t read(int *data, off64_t len)
54  {
55  return read((void *)data, len * sizeof(int));
56  }
57 
58  off64_t read(float *data, off64_t len)
59  {
60  return read((void *)data, len * sizeof(float));
61  }
62 
63  off64_t read(double *data, off64_t len)
64  {
65  return read((void *)data, len * sizeof(double));
66  }
67 
68  off64_t skipInt(off64_t len)
69  {
70  return skip(len * sizeof(int));
71  }
72 
73  off64_t skipFloat(off64_t len)
74  {
75  return skip(len * sizeof(float));
76  }
77 
78  off64_t skipDouble(off64_t len)
79  {
80  return skip(len * sizeof(double));
81  }
82 
83  off64_t skipIntBlk(off64_t len)
84  {
85  return skipBlk(len * sizeof(int));
86  }
87 
88  off64_t skipFloatBlk(off64_t len)
89  {
90  return skipBlk(len * sizeof(float));
91  }
92 
93  off64_t skipDoubleBlk(off64_t len)
94  {
95  return skipBlk(len * sizeof(double));
96  }
97 
98  off64_t numRec(off64_t len) const
99  {
100  return ((len * sizeof(float) - 1) & d_blockMask) / d_blocksize + 1;
101  }
102 
103  int fail()
104  {
105  return (d_errFlag != 0);
106  }
107 
109  {
110  d_errFlag = 0;
111  }
112 
113  void setByteSwap(int val)
114  {
115  d_byteSwap = (val != 0);
116  }
117 
118  void rewind();
119 };
120 }
121 #endif
GLenum GLsizei len
Definition: khronos-glext.h:7440
off64_t d_blocksize
Definition: istreamBLK.h:29
#define STAREXPORT
Definition: coExport.h:188
off64_t read(int *data, off64_t len)
Definition: istreamBLK.h:53
off64_t skipInt(off64_t len)
Definition: istreamBLK.h:68
~istreamBLK()
Definition: istreamBLK.h:37
off64_t skipDouble(off64_t len)
Definition: istreamBLK.h:78
void setByteSwap(int val)
Definition: istreamBLK.h:113
GLuint GLfloat * val
Definition: khronos-glext.h:7898
off64_t read(float *data, off64_t len)
Definition: istreamBLK.h:58
void resetErrorFlag()
Definition: istreamBLK.h:108
Definition: istreamBLK.h:26
off64_t skipFloat(off64_t len)
Definition: istreamBLK.h:73
off64_t skipIntBlk(off64_t len)
Definition: istreamBLK.h:83
int d_byteSwap
Definition: istreamBLK.h:33
off64_t skipDoubleBlk(off64_t len)
Definition: istreamBLK.h:93
int d_errFlag
Definition: istreamBLK.h:31
off64_t numRec(off64_t len) const
Definition: istreamBLK.h:98
int d_filedesc
Definition: istreamBLK.h:30
off64_t skipFloatBlk(off64_t len)
Definition: istreamBLK.h:88
int fail()
Definition: istreamBLK.h:103
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: khronos-glext.h:6354
off64_t read(double *data, off64_t len)
Definition: istreamBLK.h:63
off64_t d_preRead
Definition: istreamBLK.h:32