casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DefaultValue.h
Go to the documentation of this file.
1 //# DefaultValue.h: fill a variable with its default value.
2 //# Copyright (C) 1995,1996,2000
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 //#
27 //# $Id$
28 
29 #ifndef CASA_DEFAULTVALUE_H
30 #define CASA_DEFAULTVALUE_H
31 
32 #include <casacore/casa/aips.h>
33 
34 namespace casacore { //# NAMESPACE CASACORE - BEGIN
35 
36 // <summary>
37 // A templated function which sets a variable to a default value.
38 // </summary>
39 
40 // <use visibility=export>
41 
42 // <reviewed reviewer="syang" date="1996/03/14" tests="tDefaultValue.cc" demos="">
43 // </reviewed>
44 
45 // <prerequisite>
46 // </prerequisite>
47 //
48 // <etymology>
49 // The DefaultValue function name is derived from its use to fill a data type
50 // with a default value, usually zero.
51 // </etymology>
52 //
53 // <synopsis>
54 // The DefaultValue function is passed an instance of a data type and the
55 // variable is filled with a default value. The majority of classes may
56 // use the templated version here. Special classes may use their own
57 // non-templated specializations as demonstrated in
58 // ../Utilities/test/tDefaultValue.cc.
59 // </synopsis>
60 //
61 // <example>
62 // <srcblock>
63 // Int foo = 35;
64 // defaultValue(foo);
65 // AlwaysAssert(foo == 0, AipsError);
66 // Array<Float> bar;
67 // defaultValue(bar);
68 // AlwaysAssert(allEQ(bar, 0.0f), AipsError);
69 // </srcblock>
70 // A special class may need its own implementation:
71 // <srcblock>
72 // void defaultValue(MySpecialClass &val){
73 // // make a default value be all zeros
74 // val.operator()(IPosition(2,3,4)) = Table.keywords().defaultval();
75 // };
76 // </srcblock>
77 // </example>
78 //
79 // <motivation>
80 // We needed a common way of setting all objects to zero or some
81 // null/default value. Specializing a templated function seemed the only way
82 // to reach everyone.
83 // </motivation>
84 //
85 // <templating arg=T>
86 // <li> constructor T(Int)
87 // <li> assignment operator (copy semantics)
88 // </templating>
89 //
90 // <thrown>
91 // <li> none
92 // </thrown>
93 //
94 // <todo asof="1996/02/22">
95 // <li> none
96 // </todo>
97 
98 // <group name=defval>
99 
100 template <class T> inline void defaultValue(T &theValue)
101 {
102  theValue = T(0);
103 }
104 
105 // </group>
106 
107 
108 } //# NAMESPACE CASACORE - END
109 
110 #endif
#define casacore
&lt;X11/Intrinsic.h&gt; #defines true, false, casacore::Bool, and String.
Definition: X11Intrinsic.h:42