CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ad_io.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_CORE_AD_IO_HPP
2 # define CPPAD_CORE_AD_IO_HPP
3 
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 
15 /*
16 $begin ad_input$$
17 $spell
18  VecAD
19  std
20  istream
21  const
22 $$
23 
24 
25 $section AD Output Stream Operator$$
26 $mindex >> input write$$
27 
28 $head Syntax$$
29 $icode%is% >> %x%$$
30 
31 
32 $head Purpose$$
33 Sets $icode x$$ to a $cref/parameter/glossary/Parameter/$$
34 with value $icode b$$ corresponding to
35 $codei%
36  %is% >> %b%
37 %$$
38 where $icode b$$ is a $icode Base$$ object.
39 It is assumed that this $icode Base$$ input operation returns
40 a reference to $icode is$$.
41 
42 $head is$$
43 The operand $icode is$$ has prototype
44 $codei%
45  std::istream& %is%
46 %$$
47 
48 $head x$$
49 The operand $icode x$$ has one of the following prototypes
50 $codei%
51  AD<%Base%>& %x%
52 %$$
53 
54 $head Result$$
55 The result of this operation can be used as a reference to $icode is$$.
56 For example, if the operand $icode y$$ has prototype
57 $codei%
58  AD<%Base%> %y%
59 %$$
60 then the syntax
61 $codei%
62  %is% >> %x% >> %y%
63 %$$
64 will first read the $icode Base$$ value of $icode x$$ from $icode is$$,
65 and then read the $icode Base$$ value to $icode y$$.
66 
67 $head Operation Sequence$$
68 The result of this operation is not an
69 $cref/AD of Base/glossary/AD of Base/$$ object.
70 Thus it will not be recorded as part of an
71 AD of $icode Base$$
72 $cref/operation sequence/glossary/Operation/Sequence/$$.
73 
74 $head Example$$
75 $children%
76  example/general/ad_input.cpp
77 %$$
78 The file
79 $cref ad_input.cpp$$
80 contains an example and test of this operation.
81 It returns true if it succeeds and false otherwise.
82 
83 $end
84 ------------------------------------------------------------------------------
85 $begin ad_output$$
86 $spell
87  VecAD
88  std
89  ostream
90  const
91 $$
92 
93 
94 $section AD Output Stream Operator$$
95 $mindex <<$$
96 
97 $head Syntax$$
98 $icode%os% << %x%$$
99 
100 
101 $head Purpose$$
102 Writes the $icode Base$$ value, corresponding to $icode x$$,
103 to the output stream $icode os$$.
104 
105 $head Assumption$$
106 If $icode b$$ is a $icode Base$$ object,
107 $codei%
108  %os% << %b%
109 %$$
110 returns a reference to $icode os$$.
111 
112 $head os$$
113 The operand $icode os$$ has prototype
114 $codei%
115  std::ostream& %os%
116 %$$
117 
118 $head x$$
119 The operand $icode x$$ has one of the following prototypes
120 $codei%
121  const AD<%Base%>& %x%
122  const VecAD<%Base%>::reference& %x%
123 %$$
124 
125 $head Result$$
126 The result of this operation can be used as a reference to $icode os$$.
127 For example, if the operand $icode y$$ has prototype
128 $codei%
129  AD<%Base%> %y%
130 %$$
131 then the syntax
132 $codei%
133  %os% << %x% << %y%
134 %$$
135 will output the value corresponding to $icode x$$
136 followed by the value corresponding to $icode y$$.
137 
138 $head Operation Sequence$$
139 The result of this operation is not an
140 $cref/AD of Base/glossary/AD of Base/$$ object.
141 Thus it will not be recorded as part of an
142 AD of $icode Base$$
143 $cref/operation sequence/glossary/Operation/Sequence/$$.
144 
145 $head Example$$
146 $children%
147  example/general/ad_output.cpp
148 %$$
149 The file
150 $cref ad_output.cpp$$
151 contains an example and test of this operation.
152 It returns true if it succeeds and false otherwise.
153 
154 $end
155 ------------------------------------------------------------------------------
156 */
157 namespace CppAD { // BEGIN_CPPAD_NAMESPACE
158 /*!
159 \file ad_io.hpp
160 AD<Base> input and ouput stream operators.
161 */
162 // ---------------------------------------------------------------------------
163 /*!
164 Read an AD<Base> object from an input stream.
165 
166 \tparam Base
167 Base type for the AD object.
168 
169 \param is [in,out]
170 Is the input stream from which that value is read.
171 
172 \param x [out]
173 is the object that is being set to a value.
174 Upone return, x.value_ is read from the input stream
175 and x.tape_is_ is zero; i.e., x is a parameter.
176 */
177 template <class Base>
179 std::istream& operator >> (std::istream& is, AD<Base>& x)
180 { // like assignment to a base type value
181  x.tape_id_ = 0;
183  return (is >> x.value_);
184 }
185 // ---------------------------------------------------------------------------
186 /*!
187 Write an AD<Base> object to an output stream.
188 
189 \tparam Base
190 Base type for the AD object.
191 
192 \param os [in,out]
193 Is the output stream to which that value is written.
194 
195 \param x
196 is the object that is being written to the output stream.
197 This is equivalent to writing x.value_ to the output stream.
198 */
199 template <class Base>
201 std::ostream& operator << (std::ostream &os, const AD<Base> &x)
202 { return (os << x.value_); }
203 // ---------------------------------------------------------------------------
204 /*!
205 Write a VecAD_reference<Base> object to an output stream.
206 
207 \tparam Base
208 Base type for the VecAD_reference object.
209 
210 \param os [in,out]
211 Is the output stream to which that value is written.
212 
213 \param x
214 is the element of the VecAD object that is being written to the output stream.
215 This is equivalent to writing the corresponing Base value to the stream.
216 */
217 template <class Base>
219 std::ostream& operator << (std::ostream &os, const VecAD_reference<Base> &x)
220 { return (os << x.ADBase()); }
221 
222 } // END_CPPAD_NAMESPACE
223 # endif
Base value_
Definition: ad.hpp:38
Definition: ad.hpp:34
#define CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION
A version of the inline command that works with MC compiler.
Definition: define.hpp:43
#define CPPAD_ASSERT_UNKNOWN(exp)
Check that exp is true, if not terminate execution.
tape_id_t tape_id_
Definition: ad.hpp:41
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION bool Parameter(const AD< Base > &x)
Definition: par_var.hpp:80
CPPAD_INLINE_FRIEND_TEMPLATE_FUNCTION std::istream & operator>>(std::istream &is, AD< Base > &x)
Read an AD&lt;Base&gt; object from an input stream.
Definition: ad_io.hpp:179