pl_io_deprecated.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_deprecated_INC
00049
#define pl_io_deprecated_INC
00050
00051
00052
#include <plearn/base/plerror.h>
00053
00054
#include <plearn/base/byte_order.h>
00055
#include <iostream>
00056
00057
namespace PLearn {
00058
using namespace std;
00059
00060
00061
00062
00063
00064
00065
00066
00069 inline void reverse_uint(
const unsigned int* ptr,
int n) {
endianswap((
unsigned int*) ptr,n); }
00070 inline void reverse_int(
const int* ptr,
int n) {
endianswap((
int*)ptr,n); }
00071 inline void reverse_float(
const float* ptr,
int n) {
endianswap((
float*)ptr,n); }
00072 inline void reverse_double(
const double* ptr,
int n) {
endianswap((
double*)ptr,n); }
00073 inline void reverse_ushort(
const unsigned short* ptr,
int n) {
endianswap((
unsigned short*)ptr,n); }
00074 inline void reverse_short(
const short* ptr,
int n) {
endianswap((
short*)ptr,n); }
00075
00078
void fwrite_int(FILE *f,
const int* ptr,
int n,
bool is_file_bigendian=
true);
00079
void fwrite_float(FILE *f,
const float* ptr,
int n,
bool is_file_bigendian=
true);
00080
void fwrite_float(FILE *f,
const double* ptr,
int n,
bool is_file_bigendian=
true);
00081
void fwrite_double(FILE *f,
const double* ptr,
int n,
bool is_file_bigendian=
true);
00082
void fwrite_double(FILE *f,
const float* ptr,
int n,
bool is_file_bigendian=
true);
00083
00086
void fread_int(FILE *f,
int* ptr,
int n,
bool is_file_bigendian=
true);
00087
void fread_float(FILE *f,
float* ptr,
int n,
bool is_file_bigendian=
true);
00088
void fread_float(FILE *f,
double* ptr,
int n,
bool is_file_bigendian=
true);
00089
void fread_double(FILE *f,
double* ptr,
int n,
bool is_file_bigendian=
true);
00090
void fread_double(FILE *f,
float* ptr,
int n,
bool is_file_bigendian=
true);
00091
void fread_short(FILE *f,
unsigned short* ptr,
int n,
bool is_file_bigendian=
true);
00092
00097 inline int fread_int(FILE *f,
bool is_file_bigendian=
true)
00098 {
int res;
fread_int(f,&res,1,is_file_bigendian);
return res; }
00099 inline float fread_float(FILE *f,
bool is_file_bigendian=
true)
00100 {
float res;
fread_float(f,&res,1,is_file_bigendian);
return res; }
00101 inline double fread_double(FILE *f,
bool is_file_bigendian=
true)
00102 {
double res;
fread_double(f,&res,1,is_file_bigendian);
return res; }
00103
00106 inline void fwrite_int(FILE *f,
int value,
bool is_file_bigendian=
true)
00107 {
fwrite_int(f, &value, 1, is_file_bigendian); }
00108 inline void fwrite_float(FILE *f,
float value,
bool is_file_bigendian=
true)
00109 {
fwrite_float(f, &value, 1, is_file_bigendian); }
00110 inline void fwrite_double(FILE *f,
double value,
bool is_file_bigendian=
true)
00111 {
fwrite_double(f, &value, 1, is_file_bigendian); }
00112
00115
void write_int(ostream& out,
const int* ptr,
int n,
bool is_file_bigendian);
00116
void write_short(ostream& out,
const short* ptr,
int n,
bool is_file_bigendian);
00117
void write_double(ostream& out,
const double* ptr,
int n,
bool is_file_bigendian);
00118
void write_float(ostream& out,
const float* ptr,
int n,
bool is_file_bigendian);
00119 inline void write_uint(ostream& out,
const unsigned int* ptr,
int n,
bool is_file_bigendian)
00120 {
write_int(out,(
int*)ptr,n,is_file_bigendian); }
00121 inline void write_ushort(ostream& out,
const unsigned short* ptr,
int n,
bool is_file_bigendian)
00122 {
write_short(out,(
short*)ptr,n,is_file_bigendian); }
00123
void write_bool(ostream& out,
const bool* ptr,
int n,
bool is_file_bigendian);
00124
00127 inline void write_int(ostream& out,
int value,
bool is_file_bigendian=
true)
00128 {
write_int(out, &value, 1, is_file_bigendian); }
00129 inline void write_short(ostream& out,
short value,
bool is_file_bigendian=
true)
00130 {
write_short(out, &value, 1, is_file_bigendian); }
00131 inline void write_float(ostream& out,
float value,
bool is_file_bigendian=
true)
00132 {
write_float(out, &value, 1, is_file_bigendian); }
00133 inline void write_double(ostream& out,
double value,
bool is_file_bigendian=
true)
00134 {
write_double(out, &value, 1, is_file_bigendian); }
00135 inline void write_uint(ostream& out,
unsigned int value,
bool is_file_bigendian=
true)
00136 {
write_uint(out, &value, 1, is_file_bigendian); }
00137 inline void write_ushort(ostream& out,
unsigned short value,
bool is_file_bigendian=
true)
00138 {
write_ushort(out, &value, 1, is_file_bigendian); }
00139 inline void write_sbyte(ostream& out,
signed char x) { out.put(
x); }
00140 inline void write_ubyte(ostream& out,
unsigned char x) { out.put(
x); }
00141
00144
void read_int(istream& in,
int* ptr,
int n,
bool is_file_bigendian);
00145
void read_short(istream& in,
short* ptr,
int n,
bool is_file_bigendian);
00146
void read_float(istream& in,
float* ptr,
int n,
bool is_file_bigendian);
00147
void read_double(istream& in,
double* ptr,
int n,
bool is_file_bigendian);
00148 inline void read_uint(istream& in,
unsigned int* ptr,
int n,
bool is_file_bigendian)
00149 {
read_int(in,(
int*)ptr,n,is_file_bigendian); }
00150 inline void read_ushort(istream& in,
unsigned short* ptr,
int n,
bool is_file_bigendian)
00151 {
read_short(in,(
short*)ptr,n,is_file_bigendian); }
00152
void read_bool(istream& in,
bool* ptr,
int n,
bool is_file_bigendian);
00153
00158 inline int read_int(istream& in,
bool is_file_bigendian=
true)
00159 {
int res;
read_int(in,&res,1,is_file_bigendian);
return res; }
00160 inline short read_short(istream& in,
bool is_file_bigendian=
true)
00161 {
short res;
read_short(in,&res,1,is_file_bigendian);
return res; }
00162 inline float read_float(istream& in,
bool is_file_bigendian=
true)
00163 {
float res;
read_float(in,&res,1,is_file_bigendian);
return res; }
00164 inline double read_double(istream& in,
bool is_file_bigendian=
true)
00165 {
double res;
read_double(in,&res,1,is_file_bigendian);
return res; }
00166 inline unsigned int read_uint(istream& in,
bool is_file_bigendian=
true)
00167 {
unsigned int res;
read_uint(in,&res,1,is_file_bigendian);
return res; }
00168 inline unsigned short read_ushort(istream& in,
bool is_file_bigendian=
true)
00169 {
unsigned short res;
read_ushort(in,&res,1,is_file_bigendian);
return res; }
00170 inline signed char read_sbyte(istream& in)
00171 {
00172
char res;
00173 in.read(&res,1);
00174
return (
signed char) res;
00175 }
00176 inline unsigned char read_ubyte(istream& in)
00177 {
00178
char res;
00179 in.read(&res,1);
00180
return (
unsigned char) res;
00181 }
00182
00183
00184
00185
00186
00189
void writeHeader(ostream& out,
const string& classname,
int version=0);
00190
void writeFooter(ostream& out,
const string& classname);
00191
int readHeader(istream& in,
const string& classname);
00192
void readFooter(istream& in,
const string& classname);
00193
00194
00196 inline void writeNewline(ostream& out)
00197 { out <<
'\n'; }
00198
00200 inline void readNewline(istream& in)
00201 {
if(in.get()!=
'\n')
PLERROR(
"In readNewline: character read is not a newline char"); }
00202
00203
00209
void writeFieldName(ostream& out,
const string& fieldname);
00210
00211
00212
bool readFieldName(istream& in,
const string& fieldname,
bool force=
false);
00213
00215
template<
class T>
00216 void writeField(ostream& out,
const string& fieldname,
const T& x)
00217 {
00218
00219
00220
#ifndef WIN32
00221
writeFieldName(out,fieldname);
write(out,
x); out <<
'\n';
00222
#endif
00223
}
00224
00225
template<
class T>
00226 void readField(istream& in,
const string& fieldname, T& x)
00227 {
00228
00229
00230
#ifndef WIN32
00231
readFieldName(in,fieldname,
true);
00232
read(in,
x);
00233
if(!isspace(in.get()))
00234 in.unget();
00235
#endif
00236
}
00237
00239
template<
class T>
00240 void binwriteField(ostream& out,
const string& fieldname,
const T& x)
00241 {
writeFieldName(out,fieldname);
binwrite(out,
x); out <<
'\n'; }
00242
00243
template<
class T>
00244 void binreadField(istream& in,
const string& fieldname, T& x)
00245 {
readFieldName(in,fieldname,
true);
binread(in,
x); in.get(); }
00246
00247
template<
class T>
00248 void binwriteField_double(ostream& out,
const string& fieldname,
const T& x)
00249 {
writeFieldName(out,fieldname);
binwrite_double(out,
x); out <<
'\n'; }
00250
00251
template<
class T>
00252 void binreadField_double(istream& in,
const string& fieldname, T& x)
00253 {
readFieldName(in,fieldname,
true);
binread_double(in,
x); in.get(); }
00254
00256
template<
class T>
00257 void readField(istream& in,
const string& fieldname, T& x, T default_value)
00258 {
00259
if (
readFieldName(in,fieldname))
00260 {
00261
read(in,
x);
00262
if(!isspace(in.get()))
00263 in.unget();
00264 }
00265
else x=default_value;
00266 }
00267
00268
00269
00270
00271
00272 }
00273
00274
00275
#endif
Generated on Tue Aug 17 16:01:25 2004 for PLearn by
1.3.7