casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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: DefaultValue.h 21024 2011-03-01 11:46:18Z gervandiepen $
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" date="1996/03/14" tests="tDefaultValue.cc" demos="">
00043 // </reviewed>
00044 
00045 // <prerequisite>
00046 // </prerequisite>
00047 //
00048 // <etymology>
00049 // The DefaultValue function name is derived from its use to fill a data type
00050 // with a default value, usually zero.
00051 // </etymology>
00052 //
00053 // <synopsis>
00054 // The DefaultValue function is passed an instance of a data type and the 
00055 // variable is filled with a default value.  The majority of classes may 
00056 // use the templated version here.  Special classes may use their own 
00057 // non-templated specializations as demonstrated in 
00058 // ../Utilities/test/tDefaultValue.cc.
00059 // </synopsis>
00060 //
00061 // <example>
00062 // <srcblock>
00063 // Int foo = 35;
00064 // defaultValue(foo);
00065 // AlwaysAssert(foo == 0, AipsError);
00066 // Array<Float> bar;
00067 // defaultValue(bar);
00068 // AlwaysAssert(allEQ(bar, 0.0f), AipsError);
00069 // </srcblock>
00070 // A special class may need its own implementation:
00071 // <srcblock>
00072 // void defaultValue(MySpecialClass &val){
00073 //  // make a default value be all zeros
00074 //  val.operator()(IPosition(2,3,4)) = Table.keywords().defaultval();
00075 // };
00076 // </srcblock>
00077 // </example>
00078 //
00079 // <motivation>
00080 // We needed a common way of setting all objects to zero or some 
00081 // null/default value.  Specializing a templated function seemed the only way
00082 // to reach everyone.
00083 // </motivation>
00084 //
00085 // <templating arg=T>
00086 //    <li> constructor T(Int)
00087 //    <li> assignment operator (copy semantics)
00088 // </templating>
00089 //
00090 // <thrown>
00091 //    <li> none
00092 // </thrown>
00093 //
00094 // <todo asof="1996/02/22">
00095 //   <li> none
00096 // </todo>
00097 
00098 // <group name=defval>
00099 
00100 template <class T> inline void defaultValue(T &theValue)
00101 {
00102   theValue = T(0);
00103 }
00104 
00105 // </group>
00106 
00107 
00108 } //# NAMESPACE CASA - END
00109 
00110 #endif