CppAD: A C++ Algorithmic Differentiation Package  20130102
ad_io.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 # ifndef CPPAD_AD_IO_INCLUDED
00003 # define CPPAD_AD_IO_INCLUDED
00004 
00005 /* --------------------------------------------------------------------------
00006 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-12 Bradley M. Bell
00007 
00008 CppAD is distributed under multiple licenses. This distribution is under
00009 the terms of the 
00010                     Eclipse Public License Version 1.0.
00011 
00012 A copy of this license is included in the COPYING file of this distribution.
00013 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00014 -------------------------------------------------------------------------- */
00015 
00016 /*
00017 $begin ad_input$$
00018 $spell
00019      VecAD
00020      std
00021      istream
00022      const
00023 $$
00024 
00025 $index >>, AD input$$
00026 $index AD, stream input$$
00027 $index input, AD$$
00028 $index stream, AD input$$
00029 $index write, AD$$
00030 
00031 $section AD Output Stream Operator$$ 
00032 
00033 $head Syntax$$
00034 $icode%is% >> %x%$$
00035 
00036 
00037 $head Purpose$$
00038 Sets $icode x$$ to a $cref/parameter/glossary/Parameter/$$
00039 with value $icode b$$ corresponding to
00040 $codei%
00041      %is% >> %b%
00042 %$$
00043 where $icode b$$ is a $icode Base$$ object.
00044 It is assumed that this $icode Base$$ input operation returns
00045 a reference to $icode is$$.
00046 
00047 $head is$$
00048 The operand $icode is$$ has prototype
00049 $codei%
00050      std::istream& %is%
00051 %$$
00052 
00053 $head x$$
00054 The operand $icode x$$ has one of the following prototypes
00055 $codei%
00056      AD<%Base%>&               %x%
00057 %$$
00058 
00059 $head Result$$
00060 The result of this operation can be used as a reference to $icode is$$.
00061 For example, if the operand $icode y$$ has prototype
00062 $codei%
00063      AD<%Base%> %y%
00064 %$$
00065 then the syntax
00066 $codei%
00067      %is% >> %x% >> %y%
00068 %$$
00069 will first read the $icode Base$$ value of $icode x$$ from $icode is$$,
00070 and then read the $icode Base$$ value to $icode y$$. 
00071 
00072 $head Operation Sequence$$
00073 The result of this operation is not an
00074 $cref/AD of Base/glossary/AD of Base/$$ object.
00075 Thus it will not be recorded as part of an
00076 AD of $icode Base$$
00077 $cref/operation sequence/glossary/Operation/Sequence/$$.
00078 
00079 $head Example$$
00080 $children%
00081      example/ad_input.cpp
00082 %$$
00083 The file
00084 $cref ad_input.cpp$$
00085 contains an example and test of this operation.
00086 It returns true if it succeeds and false otherwise.
00087 
00088 $end
00089 ------------------------------------------------------------------------------
00090 $begin ad_output$$
00091 $spell
00092      VecAD
00093      std
00094      ostream
00095      const
00096 $$
00097 
00098 $index <<, AD output$$
00099 $index AD, stream output$$
00100 $index output, AD$$
00101 $index stream, AD output$$
00102 $index write, AD$$
00103 
00104 $section AD Output Stream Operator$$ 
00105 
00106 $head Syntax$$
00107 $icode%os% << %x%$$
00108 
00109 
00110 $head Purpose$$
00111 Writes the $icode Base$$ value, corresponding to $icode x$$,
00112 to the output stream $icode os$$.
00113 
00114 $head Assumption$$
00115 If $icode b$$ is a $icode Base$$ object,
00116 $codei%
00117      %os% << %b%
00118 %$$
00119 returns a reference to $icode os$$.
00120 
00121 $head os$$
00122 The operand $icode os$$ has prototype
00123 $codei%
00124      std::ostream& %os%
00125 %$$
00126 
00127 $head x$$
00128 The operand $icode x$$ has one of the following prototypes
00129 $codei%
00130      const AD<%Base%>&               %x%
00131      const VecAD<%Base%>::reference& %x%
00132 %$$
00133 
00134 $head Result$$
00135 The result of this operation can be used as a reference to $icode os$$.
00136 For example, if the operand $icode y$$ has prototype
00137 $codei%
00138      AD<%Base%> %y%
00139 %$$
00140 then the syntax
00141 $codei%
00142      %os% << %x% << %y%
00143 %$$
00144 will output the value corresponding to $icode x$$
00145 followed by the value corresponding to $icode y$$. 
00146 
00147 $head Operation Sequence$$
00148 The result of this operation is not an
00149 $cref/AD of Base/glossary/AD of Base/$$ object.
00150 Thus it will not be recorded as part of an
00151 AD of $icode Base$$
00152 $cref/operation sequence/glossary/Operation/Sequence/$$.
00153 
00154 $head Example$$
00155 $children%
00156      example/ad_output.cpp
00157 %$$
00158 The file
00159 $cref ad_output.cpp$$
00160 contains an example and test of this operation.
00161 It returns true if it succeeds and false otherwise.
00162 
00163 $end
00164 ------------------------------------------------------------------------------
00165 */
00166 CPPAD_BEGIN_NAMESPACE
00167 /*!
00168 \defgroup ad_io_hpp ad_io.hpp
00169 \{
00170 \file ad_io.hpp
00171 AD<Base> input and ouput stream operators.
00172 */
00173 // ---------------------------------------------------------------------------
00174 /*!
00175 Read an AD<Base> object from an input stream.
00176 
00177 \tparam Base
00178 Base type for the AD object.
00179 
00180 \param is [in,out]
00181 Is the input stream from which that value is read.
00182 
00183 \param x [out]
00184 is the object that is being set to a value. 
00185 Upone return, x.value_ is read from the input stream
00186 and x.tape_is_ is zero; i.e., x is a parameter.
00187 */
00188 template <class Base>
00189 CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
00190 std::istream& operator >> (std::istream& is, AD<Base>& x)
00191 {    // like assignment to a base type value
00192      x.tape_id_ = 0;
00193      CPPAD_ASSERT_UNKNOWN( Parameter(x) );
00194      return (is >> x.value_); 
00195 }
00196 // ---------------------------------------------------------------------------
00197 /*!
00198 Write an AD<Base> object to an output stream.
00199 
00200 \tparam Base
00201 Base type for the AD object.
00202 
00203 \param os [in,out]
00204 Is the output stream to which that value is written.
00205 
00206 \param x
00207 is the object that is being written to the output stream.
00208 This is equivalent to writing x.value_ to the output stream. 
00209 */
00210 template <class Base>
00211 CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
00212 std::ostream& operator << (std::ostream &os, const AD<Base> &x)
00213 {    return (os << x.value_); }
00214 // ---------------------------------------------------------------------------
00215 /*!
00216 Write a VecAD_reference<Base> object to an output stream.
00217 
00218 \tparam Base
00219 Base type for the VecAD_reference object.
00220 
00221 \param os [in,out]
00222 Is the output stream to which that value is written.
00223 
00224 \param x
00225 is the element of the VecAD object that is being written to the output stream.
00226 This is equivalent to writing the corresponing Base value to the stream. 
00227 */
00228 template <class Base>
00229 CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
00230 std::ostream& operator << (std::ostream &os, const VecAD_reference<Base> &x)
00231 {    return (os << x.ADBase()); }
00232 
00233 /*! \} */
00234 CPPAD_END_NAMESPACE
00235 # endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines