pl_io.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00048
#ifndef pl_io_INC
00049
#define pl_io_INC
00050
00051
00052
#include <iostream>
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
#include <plearn/math/pl_math.h>
00063
00064
00065
namespace PLearn {
00066
using namespace std;
00067
00068
00069
00070
00073
template<
class T>
00074 inline void binwrite(ostream& out,
const T* x,
int n)
00075 {
for (
int i=0;i<n;i++)
binwrite(out,
x[i]); }
00076
00077
template<
class T>
00078 inline void binread(istream& in, T* x,
int n)
00079 {
for (
int i=0;i<n;i++)
binread(in,
x[i]); }
00080
00081
template<
class A,
class B>
00082 inline void binwrite(ostream& out,
const pair<A,B> x)
00083 {
binwrite(out,
x.first);
binwrite(out,
x.second); }
00084
00085
template<
class A,
class B>
00086 inline void binread(istream& in, pair<A,B>& x)
00087 {
binread(in,
x.first);
binread(in,
x.second); }
00088
00089
00091 inline void binwrite(ostream& out,
char x) { out.put(
x); }
00092 inline void binread(istream& in,
char& x) { in.get(
x); }
00093 inline void binwrite(ostream& out,
unsigned char x) { out.put(
x); }
00094 inline void binread(istream& in,
unsigned char& x) { in.get((
char&)
x); }
00095 inline void binwrite(ostream& out,
int x) { out.write((
char*)&
x,
sizeof(
int)); }
00096 inline void binread(istream& in,
int& x) { in.read((
char*)&
x,
sizeof(
int)); }
00097 inline void binwrite(ostream& out,
unsigned int x) { out.write((
char*)&
x,
sizeof(
unsigned int)); }
00098 inline void binread(istream& in,
unsigned int& x) { in.read((
char*)&
x,
sizeof(
unsigned int)); }
00099 inline void binwrite(ostream& out,
short x) { out.write((
char*)&
x,
sizeof(
short)); }
00100 inline void binread(istream& in,
short& x) { in.read((
char*)&
x,
sizeof(
short)); }
00101 inline void binwrite(ostream& out,
unsigned short x) { out.write((
char*)&
x,
sizeof(
unsigned short)); }
00102 inline void binread(istream& in,
unsigned short& x) { in.read((
char*)&
x,
sizeof(
unsigned short)); }
00104 inline void binwrite(ostream& out,
bool x) {
binwrite(out,(
unsigned short)
x); }
00105
00106
00107
00108 inline void binread(istream& in,
bool& x) {
00109
unsigned short u;
binread(in,u);
00110 u == 0 ?
x =
false :
x =
true;
00111 }
00112
00113
00114 inline void binwrite(ostream& out,
float x) { out.write((
char*)&
x,
sizeof(
float)); }
00115 inline void binread(istream& in,
float& x) { in.read((
char*)&
x,
sizeof(
float)); }
00116 inline void binwrite(ostream& out,
double x) {
binwrite(out,
float(
x)); }
00117 inline void binread(istream& in,
double& x) {
float f;
binread(in,f);
x = double(f); }
00118
00119
00120 inline void binwrite_double(ostream& out,
double x) { out.write((
char*)&
x,
sizeof(
double)); }
00121 inline void binread_double(istream& in,
double& x) { in.read((
char*)&
x,
sizeof(
double)); }
00122 inline void binwrite_double(ostream& out,
float x) {
binwrite_double(out,
double(
x)); }
00123 inline void binread_double(istream& in,
float& x) {
double d;
binread_double(in,d);
x = float(d); }
00124
00125
00127 inline void binwrite(ostream& out,
const int* x,
int n) { out.write((
char*)
x, n*
sizeof(
int)); }
00128 inline void binread(istream& in,
int* x,
int n) { in.read((
char*)
x, n*
sizeof(
int)); }
00129 inline void binwrite(ostream& out,
const unsigned int* x,
int n) { out.write((
char*)
x, n*
sizeof(
unsigned int)); }
00130 inline void binread(istream& in,
unsigned int* x,
int n) { in.read((
char*)
x, n*
sizeof(
unsigned int)); }
00131 inline void binwrite(ostream& out,
const short* x,
int n) { out.write((
char*)
x, n*
sizeof(
short)); }
00132 inline void binread(istream& in,
short* x,
int n) { in.read((
char*)
x, n*
sizeof(
short)); }
00133 inline void binwrite(ostream& out,
const unsigned short* x,
int n) { out.write((
char*)
x, n*
sizeof(
unsigned short)); }
00134 inline void binread(istream& in,
unsigned short* x,
int n) { in.read((
char*)
x, n*
sizeof(
unsigned short)); }
00135
00136
00137 inline void binwrite(ostream& out,
const float *x,
int n) { out.write((
char*)
x, n*
sizeof(
float)); }
00138 inline void binread(istream& in,
float* x,
int n) { in.read((
char*)
x, n*
sizeof(
float)); }
00139 inline void binwrite(ostream& out,
const double* x,
int n) {
for(
int i=0; i<n; i++)
binwrite(out,
x[i]); }
00140 inline void binread(istream& in,
double* x,
int n) {
for(
int i=0; i<n; i++)
binread(in,
x[i]); }
00141
00142
00143 inline void binwrite_double(ostream& out,
const double *x,
int n) { out.write((
char*)
x, n*
sizeof(
double)); }
00144 inline void binread_double(istream& in,
double* x,
int n) { in.read((
char*)
x, n*
sizeof(
double)); }
00145 inline void binwrite_double(ostream& out,
const float* x,
int n) {
for(
int i=0; i<n; i++)
binwrite(out,
x[i]); }
00146 inline void binread_double(istream& in,
float* x,
int n) {
for(
int i=0; i<n; i++)
binread(in,
x[i]); }
00147
00150
void binwrite_compressed(ostream& out,
const double* data,
int l);
00151
void binread_compressed(istream& in,
double* data,
int l);
00152
void binwrite_compressed(ostream& out,
const float* data,
int l);
00153
void binread_compressed(istream& in,
float* data,
int l);
00154
00155
00156
00157
00160
template<
class T>
00161 inline void binwrite(FILE* out,
const T* x,
int n)
00162 {
for (
int i=0;i<n;i++)
binwrite(out,
x[i]); }
00163
00164
template<
class T>
00165 inline void binread(FILE* in, T* x,
int n)
00166 {
for (
int i=0;i<n;i++)
binread(in,
x[i]); }
00167
00168
template<
class A,
class B>
00169 inline void binwrite(FILE* out,
const pair<A,B> x)
00170 {
binwrite(out,
x.first);
binwrite(out,
x.second); }
00171
00172
template<
class A,
class B>
00173 inline void binread(FILE* in, pair<A,B>& x)
00174 {
binread(in,
x.first);
binread(in,
x.second); }
00175
00176
00178 inline void binwrite(FILE* out,
char x) { putc((
unsigned char)
x, out); }
00179 inline void binread(FILE* in,
char& x) {
x = (
char)getc(in); }
00180 inline void binwrite(FILE* out,
unsigned char x) { putc(
x,out); }
00181 inline void binread(FILE* in,
unsigned char& x) {
x = (
unsigned char)getc(in); }
00182 inline void binwrite(FILE* out,
int x) { fwrite(&
x,
sizeof(
int),1,out); }
00183 inline void binread(FILE* in,
int& x) { fread(&
x,
sizeof(
int),1,in); }
00184 inline void binwrite(FILE* out,
unsigned int x) { fwrite(&
x,
sizeof(
unsigned int),1,out); }
00185 inline void binread(FILE* in,
unsigned int& x) { fread(&
x,
sizeof(
unsigned int),1,in); }
00186 inline void binwrite(FILE* out,
short x) { fwrite(&
x,
sizeof(
short),1,out); }
00187 inline void binread(FILE* in,
short& x) { fread(&
x,
sizeof(
short),1,in); }
00188 inline void binwrite(FILE* out,
unsigned short x) { fwrite(&
x,
sizeof(
unsigned short),1,out); }
00189 inline void binread(FILE* in,
unsigned short& x) { fread(&
x,
sizeof(
unsigned short),1,in); }
00191 inline void binwrite(FILE* out,
bool x) {
binwrite(out,(
unsigned short)
x); }
00192
00193
00194 inline void binread(FILE* in,
bool& x) {
00195
unsigned short u;
binread(in,u);
00196 u == 0 ?
x =
false :
x =
true;
00197 }
00198
00199
00200 inline void binwrite(FILE* out,
float x) { fwrite(&
x,
sizeof(
float),1,out); }
00201 inline void binread(FILE* in,
float& x) { fread(&
x,
sizeof(
float),1,in); }
00202 inline void binwrite(FILE* out,
double x) {
binwrite(out,
float(
x)); }
00203 inline void binread(FILE* in,
double& x) {
float f;
binread(in,f);
x = double(f); }
00204
00205
00206 inline void binwrite_double(FILE* out,
double x) { fwrite(&
x,
sizeof(
double),1,out); }
00207 inline void binread_double(FILE* in,
double& x) { fread(&
x,
sizeof(
double),1,in); }
00208 inline void binwrite_double(FILE* out,
float x) {
binwrite_double(out,
double(
x)); }
00209 inline void binread_double(FILE* in,
float& x) {
double d;
binread_double(in,d);
x = float(d); }
00210
00211
00213 inline void binwrite(FILE* out,
const int* x,
int n) { fwrite(
x,
sizeof(
int),n,out); }
00214 inline void binread(FILE* in,
int* x,
int n) { fread(
x,
sizeof(
int),n,in); }
00215 inline void binwrite(FILE* out,
const unsigned int* x,
int n) { fwrite(
x,
sizeof(
unsigned int),n,out); }
00216 inline void binread(FILE* in,
unsigned int* x,
int n) { fread(
x,
sizeof(
unsigned int),n,in); }
00217 inline void binwrite(FILE* out,
const short* x,
int n) { fwrite(
x,
sizeof(
short),n,out); }
00218 inline void binread(FILE* in,
short* x,
int n) { fread(
x,
sizeof(
short),n,in); }
00219 inline void binwrite(FILE* out,
const unsigned short* x,
int n) { fwrite(
x,
sizeof(
unsigned short),n,out); }
00220 inline void binread(FILE* in,
unsigned short* x,
int n) { fread(
x,
sizeof(
unsigned short),n,in); }
00221
00222
00223 inline void binwrite(FILE* out,
const float *x,
int n) { fwrite(
x,
sizeof(
float),n,out); }
00224 inline void binread(FILE* in,
float* x,
int n) { fread(
x,
sizeof(
float),n,in); }
00225 inline void binwrite(FILE* out,
const double* x,
int n) {
for(
int i=0; i<n; i++)
binwrite(out,
x[i]); }
00226 inline void binread(FILE* in,
double* x,
int n) {
for(
int i=0; i<n; i++)
binread(in,
x[i]); }
00227
00228
00229 inline void binwrite_double(FILE* out,
const double *x,
int n) { fwrite(
x,
sizeof(
double),n,out); }
00230 inline void binread_double(FILE* in,
double* x,
int n) { fread(
x,
sizeof(
double),n,in); }
00231 inline void binwrite_double(FILE* out,
const float* x,
int n) {
for(
int i=0; i<n; i++)
binwrite(out,
x[i]); }
00232 inline void binread_double(FILE* in,
float* x,
int n) {
for(
int i=0; i<n; i++)
binread(in,
x[i]); }
00233
00234
void binwrite_compressed(FILE* out,
const double* data,
int l);
00235
void binread_compressed(FILE* in,
double* data,
int l);
00236
void binwrite_compressed(FILE* out,
const float* data,
int l);
00237
void binread_compressed(FILE* in,
float* data,
int l);
00238
00240
inline void read_compr_mode_and_size_ptr(
char*& in,
unsigned char& mode,
int& size);
00241
void compress_vec(
char* comprbuf,
const double* data,
int l,
bool double_stored_as_float=
false);
00242
void uncompress_vec(
char* comprbuf,
double* data,
int l,
bool double_stored_as_float=
false);
00243
00244
00245
00246
00247
00252 size_t
new_write_compressed(FILE* out,
real* vec,
int l,
double tolerance=1e-6,
bool swap_endians=
false);
00253
00258 size_t
new_read_compressed(FILE* in,
real* vec,
int l,
bool swap_endians=
false);
00259
00260
00261
00262 }
00263
00264
00265
#endif
Generated on Tue Aug 17 16:01:25 2004 for PLearn by
1.3.7