casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ContainerIO.h
Go to the documentation of this file.
00001 //# ContainerIO.h: text output IO for any container
00002 //# Copyright (C) 2011
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //# 
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //# 
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //# 
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //# 
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: ContainerIO.h 21013 2011-01-06 08:35:09Z gervandiepen $
00027 
00028 #ifndef CASA_CONTAINERIO_H
00029 #define CASA_CONTAINERIO_H
00030 
00031 //# Includes
00032 #include <casa/aips.h>
00033 #include <casa/iostream.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 // <summary>
00038 //    Input/output operators for Containers.
00039 // </summary>
00040 
00041 // <use visibility=export>
00042 
00043 // <reviewed reviewer="Paul Shannon" date="1995/02/21" tests="" demos="">
00044 // </reviewed>
00045 
00046 // <prerequisite>
00047 //   <li> STL container concept
00048 // </prerequisite>
00049 
00050 // <synopsis> 
00051 // The function <src>showContainer</src> makes it possible to show
00052 // any STL-like container (having forward iterators) on an ostream.
00053 // This include casacore classes like Array, IPosition, and Block, but
00054 // also STL classes like vector. The separator, prefix, and postfix
00055 // can be defined at will (they default to , [ ]).
00056 //
00057 // The function <src>showDataIter</src> is similar to <src>showContainer</src>,
00058 // but uses iterators directly.
00059 // </synopsis>
00060 
00061 // <example>
00062 // <srcblock>
00063 // IPosition shape (3,10,10,3);
00064 // showContainer (cout, shape);
00065 // </srcblock>
00066 //
00067 // <motivation>
00068 // Effortless input/output is clearly a big win.
00069 // </motivation>
00070 //
00071 // <group name="Container IO">
00072 
00073 // Write out an ascii representation of any container using the
00074 // given begin and end iterator.
00075 // An arbitrary separator, prefix, and postfix can be given.
00076 // E.g. for separator ', ' the output looks like [1, 2, 3].
00077 template<class ITER> void showDataIter (ostream&,
00078                                         ITER begin, const ITER& end,
00079                                         const char* separator=",",
00080                                         const char* prefix="[",
00081                                         const char* postfix="]");
00082 
00083 // Write out an ascii representation of any container having a
00084 // forward iterator.
00085 // Note that a multi-dimensional Array object is linearized.
00086 // An arbitrary separator, prefix, and postfix can be given.
00087 // E.g. for separator ', ' the output looks like [1, 2, 3].
00088 template<class CONTAINER> void showContainer (ostream& os, const CONTAINER& c,
00089                                               const char* separator=",",
00090                                               const char* prefix="[",
00091                                               const char* postfix="]")
00092   { showDataIter (os, c.begin(), c.end(), separator, prefix, postfix); }
00093 
00094 } //# NAMESPACE CASA - END
00095 
00096 #ifndef CASACORE_NO_AUTO_TEMPLATES
00097 #include <casa/Containers/ContainerIO.tcc>
00098 #endif //# CASACORE_NO_AUTO_TEMPLATES
00099 #endif