casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
BlockIO.h
Go to the documentation of this file.
1 //# BlockIO.h: Functions to perform IO for the Block class
2 //# Copyright (C) 1993,1994,1995,1999,2000,2001
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef CASA_BLOCKIO_H
29 #define CASA_BLOCKIO_H
30 
31 #include <casacore/casa/aips.h>
32 
33 //# Forward declarations.
34 #include <casacore/casa/iosfwd.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 template<class T> class Block;
39 class AipsIO;
40 
41 // <summary>IO functions for Block</summary>
42 // <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="" demos="">
43 // </reviewed>
44 // <use visibility=export>
45 //
46 // <synopsis>
47 // These functions allow the user to write either an entire or a
48 // partial <src>Block</src> out to an <src>ostream</src> or to
49 // <src>AipsIO</src>. These functions provide simple storage and
50 // display capabilities for <src>Block</src>.
51 // </synopsis>
52 //
53 // <linkfrom anchor=BlockIO classes="Block">
54 // Global Block <here>IO functions</here>
55 // </linkfrom>
56 //
57 // <group name='BlockIO'>
58 
59 //# It appears that (at least for the SUN compiler) the 3rd argument
60 //# cannot be an uInt (otherwise the compiler says no match when
61 //# called as e.g. putBlock(ios,blk,10);).
62 //#
63 //# Note that as of 29-Dec-2008 the size of Block is a size_t, so nr should
64 //# also be a size_t. However, because AipsIO cannot handle sizes larger than
65 //# an uInt, it makes no sense to make that change.
66 //
67 // These functions allow the user to read and write <src>Block</src>s
68 // from the <src>AipsIO</src> stream.
69 //
70 // <src>putBlock</src> writes the <src>Block</src> to the stream. If
71 // a number, <src>nr</src>, of elements is specified, only the first
72 // <src>nr</src> elements will be written out to <src>AipsI0</src>.
73 //
74 // <src>getBlock</src> reads a <src>Block</src> in from an
75 // <src>AipsIO</src> stream.
76 //
77 // <group>
78 template<class T> void putBlock (AipsIO&, const Block<T>&, Int nr);
79 
80 template<class T> void putBlock (AipsIO& ios, const Block<T>& blk)
81  { putBlock (ios, blk, (Int)(blk.nelements())); }
82 
83 template<class T> void getBlock (AipsIO&, Block<T>&);
84 // </group>
85 
86 
87 // These functions allow the user to write <src>Block</src>s out to
88 // a standard <src>ostream</src>. The user can either write the entire
89 // <src>Block</src> out to the stream, or if a number of elements,
90 // <src>nr</src>, is specified, only the first <src>nr</src> elements
91 // of the <src>Block</src> will be written out.
92 //
93 // <group>
94 template<class T> void showBlock (std::ostream&, const Block<T>&, Int nr);
95 
96 template<class T> void showBlock (std::ostream& ios, const Block<T>& blk)
97  { showBlock (ios, blk, (Int)(blk.nelements())); }
98 // </group>
99 
100 // These are the standard shift operators for writing an entire
101 // <src>Block</src> out to a stream. Shift operators are provided
102 // to write the block out to either <src>AipsIO</src> or
103 // <src>ostream</src>. A shift operator is also provided for
104 // reading a <src>Block</src> in from <src>AipsIO</src>.
105 // <note> STL containers like vector and list are written in the same way as
106 // a Block, so they can be written one way and read back the other.
107 // </note>
108 //
109 // <group>
110 template<class T> AipsIO& operator<< (AipsIO& ios, const Block<T>& blk)
111 {
112  putBlock (ios, blk, (Int)(blk.nelements()));
113  return ios;
114 }
115 
116 template<class T> AipsIO& operator>> (AipsIO& ios, Block<T>& blk)
117 {
118  getBlock (ios, blk);
119  return ios;
120 }
121 
122 template<class T> std::ostream& operator<< (std::ostream& ios, const Block<T>& blk)
123 {
124  showBlock (ios, blk, (Int)(blk.nelements()));
125  return ios;
126 }
127 // </group>
128 // </group>
129 
130 
131 //# Implement the specialization for the void* data type.
132 //# This will not do anything at all.
133 //# This specialization is needed for StColMirAIO.cc.
134 inline void putBlock (AipsIO&, const Block<void*>&, Int)
135 {}
136 inline void getBlock (AipsIO&, Block<void*>&)
137 {}
138 inline void showBlock (AipsIO&, const Block<void*>&, Int)
139 {}
140 
141 
142 
143 } //# NAMESPACE CASACORE - END
144 
145 #ifndef CASACORE_NO_AUTO_TEMPLATES
146 #include <casacore/casa/Containers/BlockIO.tcc>
147 #endif //# CASACORE_NO_AUTO_TEMPLATES
148 #endif
int Int
Definition: aipstype.h:50
void showBlock(AipsIO &, const Block< void * > &, Int)
Definition: BlockIO.h:138
AipsIO is the object persistency mechanism of Casacore.
Definition: AipsIO.h:168
void getBlock(AipsIO &, Block< void * > &)
Definition: BlockIO.h:136
ostream & operator>>(ostream &is, MVTime &meas)
size_t nelements() const
The number of elements contained in this Block&lt;T&gt;.
Definition: Block.h:611
void putBlock(AipsIO &ios, const Block< T > &blk)
Definition: BlockIO.h:80
void putBlock(AipsIO &, const Block< void * > &, Int)
Definition: BlockIO.h:134
simple 1-D array
void showBlock(std::ostream &ios, const Block< T > &blk)
Definition: BlockIO.h:96
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42