File: mmdb_io_stream.cpp

package info (click to toggle)
mmdb 2.0.22-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,760 kB
  • sloc: cpp: 45,786; sh: 11,570; makefile: 35
file content (112 lines) | stat: -rw-r--r-- 3,852 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//  $Id: mmdb_io_stream.cpp $
//  =================================================================
//
//   CCP4 Coordinate Library: support of coordinate-related
//   functionality in protein crystallography applications.
//
//   Copyright (C) Eugene Krissinel 2000-2013.
//
//    This library is free software: you can redistribute it and/or
//    modify it under the terms of the GNU Lesser General Public
//    License version 3, modified in accordance with the provisions
//    of the license to address the requirements of UK law.
//
//    You should have received a copy of the modified GNU Lesser
//    General Public License along with this library. If not, copies
//    may be downloaded from http://www.ccp4.ac.uk/ccp4license.php
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU Lesser General Public License for more details.
//
//  =================================================================
//
//    11.09.13   <--  Date of Last Modification.
//                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//  -----------------------------------------------------------------
//
//  **** Module  :  Stream_ <interface>
//       ~~~~~~~~~
//  **** Classes :  mmdb::io::Stream  ( Basic Stream Class )
//       ~~~~~~~~~
//
//   (C) E. Krissinel 1995-2013
//
//  =================================================================
//

#include "mmdb_io_stream.h"

namespace mmdb  {

  namespace io  {

    //  ==========================  CStream  ===========================

    //     Each streamable class should be derived from Stream
    //  and have constructor Class(PStream & Object), which should
    //  initialize all memory of the class, and virtual functions
    //  read(..) and write(..) (see below). Constructor Class(PStream&)
    //  must not touch the Object variable. This constructor is used
    //  only once just before read(..) function. It is assumed that
    //  read/write functions of Class provide storage/reading of
    //  all vital data. Function read(..) must read data in exactly
    //  the same way as function write(..) stores it.
    //     For using Class in streams, three following functions should
    //  be supplied:
    //
    //     1.
    //     void StreamWrite ( RFile f, RPClass Object )  {
    //       StreamWrite ( f,(PStream)PClass );
    //     }
    //
    //     2.
    //     PCStream ClassInit ( RPStream Object )  {
    //       return (PStream)(new Class(Object));
    //     }
    //
    //     3.
    //     void StreamRead ( RFile f, RPClass Object )  {
    //       StreamRead_ ( f,(PStream)Object,ClassInit );
    //     }
    //
    //    All these functions are automatically generated by macros
    //  DefineStreamFunctions(CClass) -- in the header -- and
    //  MakeStreamFunctions(CClass) -- in the implementation body.
    //  Then CClass may be streamed in/out using functions #1 and #3.
    //    StreamRead will return NULL for Object if it was not
    //  in the stream. If Object existed before StreamRead(..) but
    //  was not found in the stream, it will be disposed.

    void StreamRead_ ( RFile f, RPStream Object,
                       InitStreamObject Init )  {
    int i;
      f.ReadInt ( &i );
      if (i)  {
        if (!Object)
          Object = Init(Object); //Object = new CStream ( Object );
        Object->read ( f );
      } else  {
        if (Object)  delete Object;
        Object = NULL;
      }
    }

    void StreamWrite_ ( RFile f, RPStream Object )  {
    int i;
      if (Object)  {
        i = 1;
        f.WriteInt ( &i );
        Object->write ( f );
      } else  {
        i = 0;
        f.WriteInt ( &i );
      }
    }

    MakeStreamFunctions(Stream)

  }

}