DefaultValue.h

Go to the documentation of this file.
00001 //# DefaultValue.h: fill a variable with its default value.
00002 //# Copyright (C) 1995,1996,2000
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 //#
00027 //# $Id$
00028 
00029 #ifndef CASA_DEFAULTVALUE_H
00030 #define CASA_DEFAULTVALUE_H
00031 
00032 #include <casa/aips.h>
00033 
00034 namespace casa { //# NAMESPACE CASA - BEGIN
00035 
00036 // <summary>
00037 // A templated function which sets a variable to a default value.
00038 // </summary>
00039 
00040 // <use visibility=export>
00041 
00042 // <reviewed reviewer="syang@nrao.edu" date="1996/03/14" tests="tDefaultValue.cc" demos="">
00043 // </reviewed>
00044 
00045 // <prerequisite>
00046 //   <li> none
00047 // </prerequisite>
00048 //
00049 // <etymology>
00050 // The DefaultValue function name is derived from its use to fill a data type
00051 // with a default value, usually zero.
00052 // </etymology>
00053 //
00054 // <synopsis>
00055 // The DefaultValue function is passed an instance of a data type and the 
00056 // variable is filled with a default value.  The majority of classes may 
00057 // use the templated version here.  Special classes may use their own 
00058 // non-templated specializations as demonstrated in 
00059 // ../Utilities/test/tDefaultValue.cc.
00060 // </synopsis>
00061 //
00062 // <example>
00063 // <srcblock>
00064 // Int foo = 35;
00065 // defaultValue(foo);
00066 // AlwaysAssert(foo == 0, AipsError);
00067 // Array<Float> bar;
00068 // defaultValue(bar);
00069 // AlwaysAssert(allEQ(bar, 0.0f), AipsError);
00070 // </srcblock>
00071 // A special class may need its own implementation:
00072 // <srcblock>
00073 // void defaultValue(MySpecialClass &val){
00074 //  // make a default value be all zeros
00075 //  val.operator()(IPosition(2,3,4)) = Table.keywords().defaultval();
00076 // };
00077 // </srcblock>
00078 // </example>
00079 //
00080 // <motivation>
00081 // We needed a common way of setting all objects to zero or some 
00082 // null/default value.  Specializing a templated function seemed the only way
00083 // to reach everyone.
00084 // </motivation>
00085 //
00086 // <templating arg=T>
00087 //    <li> constructor T(Int)
00088 //    <li> assignment operator (copy semantics)
00089 // </templating>
00090 //
00091 // <thrown>
00092 //    <li> none
00093 // </thrown>
00094 //
00095 // <todo asof="1996/02/22">
00096 //   <li> none
00097 // </todo>
00098 
00099 // <group name=defval>
00100 
00101 template <class T> inline void defaultValue(T &theValue)
00102 {
00103   theValue = T(0);
00104 };
00105 
00106 // </group>
00107 
00108 
00109 } //# NAMESPACE CASA - END
00110 
00111 #endif
00112 
00113 
00114 
00115 
00116 

Generated on Mon Sep 1 22:33:59 2008 for NRAOCASA by  doxygen 1.5.1