ccp4srs  Version 1.0.0
memio_.h
Go to the documentation of this file.
1 // $Id: memio_.h $
2 // =================================================================
3 //
4 // CCP4 SRS Library: Storage, Retrievak and Search support for
5 // CCP4 ligand data.
6 //
7 // Copyright (C) Eugene Krissinel 2010-2013.
8 //
9 // This library is free software: you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License version 3, modified in accordance with the provisions
12 // of the license to address the requirements of UK law.
13 //
14 // You should have received a copy of the modified GNU Lesser
15 // General Public License along with this library. If not, copies
16 // may be downloaded from http://www.ccp4.ac.uk/ccp4license.php
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // =================================================================
24 //
25 // 03.02.14 <-- Date of Last Modification.
26 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27 // -----------------------------------------------------------------
28 //
29 // **** Module : memio_ <interface>
30 // ~~~~~~~~~
31 // **** Classes : ccp4srs::MemIO - buffered I/O
32 // ~~~~~~~~~
33 //
34 // (C) E. Krissinel 2010-2014
35 //
36 // =================================================================
37 //
38 
39 #ifndef MEMIO_H
40 #define MEMIO_H
41 
42 #include "mmdb2/mmdb_io_file.h"
43 
44 namespace ccp4srs {
45 
46  DefineClass(MemIO);
47 
48  class MemIO {
49 
50  public:
51 
54 
55  MemIO();
56  virtual ~MemIO();
57 
58  void setCompressionLevel ( int compressionLevel ); // 0,1,2,3
59 
60  int read ( mmdb::cpstr fileName,
61  mmdb::io::GZ_MODE gzMode=mmdb::io::GZM_NONE );
62  int read ( mmdb::io::RFile f );
63 
64  int write ( mmdb::cpstr fileName,
65  mmdb::io::GZ_MODE gzMode=mmdb::io::GZM_NONE );
66  int write ( mmdb::io::RFile f );
67 
68  int length() { return buffer_length; }
69 
70  void reset();
71  void free ();
72 
73  void * get_buffer ( const int length );
74  void set_buffer_length ( const int len ) { buffer_length = len; }
75  void get_buffer ( mmdb::pstr * buf, int * length );
76 
77  void write_buffer ( const void * src, const int length );
78  bool read_buffer ( void * dest, const int length,
79  bool * Ok = NULL);
80 
81  void put_integer ( int I );
82  void put_ishort ( int I ); // saves as short
83  void put_ibyte ( int I ); // saves as byte
84  void put_byte ( mmdb::byte B );
85  void put_short ( short I );
86  void put_long ( long I );
87  void put_word ( mmdb::word W );
88  void put_real ( mmdb::realtype R );
89  void put_float ( mmdb::realtype R ); // stores single precision
90  void put_shortreal ( mmdb::shortreal R );
91  void put_line ( mmdb::cpstr L ); // for static strings
92  void put_string ( mmdb::cpstr L ); // for dynamic strings
93  void put_bool ( bool B );
94 
95  bool get_integer ( int & I, bool * Ok = NULL );
96  bool get_ishort ( int & I, bool * Ok = NULL );
97  bool get_ibyte ( int & I, bool * Ok = NULL );
98  bool get_byte ( mmdb::byte & B, bool * Ok = NULL );
99  bool get_short ( short & I, bool * Ok = NULL );
100  bool get_long ( long & I, bool * Ok = NULL );
101  bool get_word ( mmdb::word & W, bool * Ok = NULL );
102  bool get_real ( mmdb::realtype & R, bool * Ok = NULL );
103  bool get_float ( mmdb::realtype & R, bool * Ok = NULL );
104  bool get_shortreal ( mmdb::shortreal & R, bool * Ok = NULL );
105  bool get_line ( mmdb::pstr L, bool * Ok = NULL );
106  bool get_string ( mmdb::pstr & L, bool * Ok = NULL );
107  bool get_bool ( bool & B, bool * Ok = NULL );
108 
109  private:
110  int compression_level;
111  mmdb::bvector buffer,compression_buffer;
112  int buffer_length,buffer_pos,alloc_length,chunk_size;
113  int compression_alloc;
114 
115  };
116 
117 } // namespace ccp4srs
118 
119 #endif // MEMIO_H
Definition: memio_.h:48
bool get_shortreal(mmdb::shortreal &R, bool *Ok=NULL)
Definition: memio_.cpp:448
bool get_string(mmdb::pstr &L, bool *Ok=NULL)
Definition: memio_.cpp:476
void reset()
Definition: memio_.cpp:221
DefineClass(Angle)
bool read_buffer(void *dest, const int length, bool *Ok=NULL)
Definition: memio_.cpp:343
Definition: memio_.h:52
void put_integer(int I)
Definition: memio_.cpp:263
void put_long(long I)
Definition: memio_.cpp:292
bool get_line(mmdb::pstr L, bool *Ok=NULL)
Definition: memio_.cpp:459
bool get_ibyte(int &I, bool *Ok=NULL)
Definition: memio_.cpp:378
Definition: memio_.h:52
void put_byte(mmdb::byte B)
Definition: memio_.cpp:282
bool get_float(mmdb::realtype &R, bool *Ok=NULL)
Definition: memio_.cpp:437
bool get_integer(int &I, bool *Ok=NULL)
Definition: memio_.cpp:354
int write(mmdb::cpstr fileName, mmdb::io::GZ_MODE gzMode=mmdb::io::GZM_NONE)
Definition: memio_.cpp:157
MemIO()
Definition: memio_.cpp:46
bool get_short(short &I, bool *Ok=NULL)
Definition: memio_.cpp:393
void free()
Definition: memio_.cpp:225
Definition: memio_.h:52
void put_shortreal(mmdb::shortreal R)
Definition: memio_.cpp:316
Definition: memio_.h:53
bool get_real(mmdb::realtype &R, bool *Ok=NULL)
Definition: memio_.cpp:426
Definition: memio_.h:53
virtual ~MemIO()
Definition: memio_.cpp:60
Definition: memio_.h:53
void put_real(mmdb::realtype R)
Definition: memio_.cpp:304
void put_line(mmdb::cpstr L)
Definition: memio_.cpp:322
void put_ibyte(int I)
Definition: memio_.cpp:275
bool get_ishort(int &I, bool *Ok=NULL)
Definition: memio_.cpp:365
Definition: memio_.h:52
void put_word(mmdb::word W)
Definition: memio_.cpp:298
void set_buffer_length(const int len)
Definition: memio_.h:74
void put_bool(bool B)
Definition: memio_.cpp:335
bool get_bool(bool &B, bool *Ok=NULL)
Definition: memio_.cpp:491
void put_float(mmdb::realtype R)
Definition: memio_.cpp:310
bool get_long(long &I, bool *Ok=NULL)
Definition: memio_.cpp:404
Definition: memio_.h:52
void setCompressionLevel(int compressionLevel)
Definition: memio_.cpp:64
bool get_byte(mmdb::byte &B, bool *Ok=NULL)
Definition: memio_.cpp:389
void put_short(short I)
Definition: memio_.cpp:286
Definition: ccp4srs_angle.cpp:42
void * get_buffer(const int length)
Definition: memio_.cpp:234
int length()
Definition: memio_.h:68
void write_buffer(const void *src, const int length)
Definition: memio_.cpp:249
int read(mmdb::cpstr fileName, mmdb::io::GZ_MODE gzMode=mmdb::io::GZM_NONE)
Definition: memio_.cpp:74
Definition: memio_.h:52
void put_ishort(int I)
Definition: memio_.cpp:269
void put_string(mmdb::cpstr L)
Definition: memio_.cpp:326
bool get_word(mmdb::word &W, bool *Ok=NULL)
Definition: memio_.cpp:415