/home/coin/SVN-release/CoinAll-1.1.0/cppad/cppad/local/tape_rec.hpp

Go to the documentation of this file.
00001 # ifndef CPPAD_TAPE_REC_INCLUDED
00002 # define CPPAD_TAPE_REC_INCLUDED
00003 
00004 /* --------------------------------------------------------------------------
00005 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
00006 
00007 CppAD is distributed under multiple licenses. This distribution is under
00008 the terms of the 
00009                     Common Public License Version 1.0.
00010 
00011 A copy of this license is included in the COPYING file of this distribution.
00012 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
00013 -------------------------------------------------------------------------- */
00014 /*
00015 $begin TapeRec$$ $comment CppAD Developer Documentation$$
00016 
00017 $spell
00018         inline
00019         VecInd
00020         sizeof
00021         Num
00022         Ind
00023         Cpp
00024         Rec
00025         const
00026         Op
00027 $$
00028 
00029 $section A CppAD Program as Recorded on Tape$$
00030 $index tape, record$$
00031 $index record, tape$$
00032 $index TapeRec$$
00033 
00034 $head Syntax$$
00035 $syntax%TapeRec<%Base%> %Rec%$$
00036 $pre
00037 $$
00038 $syntax%TapeRec<%Base%> %Rec%(const TapeRec<%Base%> &%Other%)%$$
00039 
00040 
00041 $head Default Constructors$$
00042 The default constructor 
00043 $syntax%
00044         TapeRec<%Base%> %Rec%
00045 %$$
00046 creates a program recording called $italic Rec$$ with no contents and some
00047 default setting for the size of its buffers.
00048 
00049 $head Copy Constructor$$
00050 The copy constructor
00051 $syntax%
00052         TapeRec<%Base%> %Rec%(const TapeRec<%Base%> &%Other%)
00053 %$$
00054 creates $italic Rec$$ as a program recording with all the same
00055 information as $italic Other$$ and with the smallest possible buffer sizes
00056 that will hold that information.
00057 
00058 $head Erase$$
00059 $index TapeRec, Erase$$
00060 $index Erase, TapeRec$$
00061 The syntax 
00062 $syntax%
00063         void %Rec%.Erase()
00064 %$$
00065 erases the contents of $italic Rec$$.
00066 The buffers used to store the tape information are returned
00067 to the system (so as to conserve on memory).
00068 
00069 $head Put$$
00070 $index TapeRec, Put$$
00071 $index Put, TapeRec$$
00072 
00073 $subhead Op$$
00074 $index PutOp$$
00075 The function call
00076 $syntax%
00077         inline size_t %Rec%.PutOp(OpCode %op%)
00078 %$$
00079 places the value $italic op$$ at the end of the current Op recording
00080 and returns the offset for the corresponding variable 
00081 (if the operator has a resulting variable).
00082 With each call, this index increments by the number of variables required
00083 for the previous call to $code PutOp$$.
00084 
00085 $subhead Ind$$
00086 $index PutInd$$
00087 The function call
00088 $syntax%
00089         inline void %Rec%.PutInd(size_t %ind0%)
00090         inline void %Rec%.PutInd(size_t %ind0%, size_t %ind1%)
00091         %.%
00092         %.%
00093         %.%
00094         inline void %Rec%.PutInd(
00095                 size_t %ind0%, 
00096                 size_t %ind1%, 
00097                 size_t %ind2%, 
00098                 size_t %ind3%,
00099                 size_t %ind4%
00100                 size_t %ind5%)
00101 %$$
00102 places the values passed to $code PutInd$$ at the end of the
00103 Ind recording and in the order passed; i.e., $italic ind0$$
00104 comes before $italic ind1$$ e.t.c.
00105 
00106 
00107 $subhead Par$$
00108 $index PutPar$$
00109 The function call
00110 $syntax%
00111         inline size_t %Rec%.PutPar(const %Base% &%par%)
00112 %$$
00113 places the value $italic par$$ in the Par recording
00114 and returns its index with in the recording.
00115 This value is not necessarily placed at the end of the recording
00116 so there is no specified pattern to the return values.
00117 
00118 $subhead VecInd$$
00119 $index PutVecInd$$
00120 The function call
00121 $syntax%
00122         inline size_t %Rec%.PutVecInd(size_t %vecInd%)
00123 %$$
00124 places the value $italic vecInd$$ at the end of the current VecInd recording
00125 and returns its index with in the recording.
00126 This index starts at zero after each $code Erase$$ or default constructor
00127 and increments by one for each call to this function.
00128 
00129 $head Get$$
00130 $index TapeRec, Get$$
00131 $index Get, TapeRec$$
00132 
00133 $subhead Op$$
00134 $index GetOp$$
00135 The syntax
00136 $syntax%
00137         OpCode %Rec%.GetOp(size_t %i%) const
00138 %$$
00139 returns the value of $italic op$$ in the $th i+1$$ call to 
00140 $syntax%%Rec%.PutOp(%op%)%$$.
00141 
00142 $subhead VecInd$$
00143 $index GetVecInd$$
00144 The syntax
00145 $syntax%
00146         OpCode %Rec%.GetVecInd(size_t %i%) const
00147 %$$
00148 returns the value of $italic vecInd$$ in the corresponding call 
00149 $syntax%%Rec%.PutVecInd(%vecInd%)%$$
00150 where $italic i$$ is the return value of $code PutVecInd$$. 
00151 
00152 $subhead Ind$$
00153 $index GetInd$$
00154 The syntax
00155 $syntax%
00156         const size_t *%Rec%.GetInd(size_t %n%, size_t %i%) const
00157 %$$
00158 returns a pointer to a copy of $italic n$$ values in the Ind recording
00159 starting at the index $italic i$$.
00160 
00161 $subhead Par$$
00162 $index GetPar$$
00163 The syntax
00164 $syntax%
00165         const %Base% *%Rec%.GetPar(size_t %i%) const
00166 %$$
00167 returns a pointer to a value equal to
00168 $italic par$$ in the corresponding call 
00169 $syntax%%Rec%.PutPar(%par%)%$$ 
00170 where $italic i$$ is the return value of $code PutPar$$.
00171 (If $code NDEBUG$$ is not defined, $code GetPar$$ checks that
00172 the argument $italic i$$ is valid.)
00173 
00174 $head Num$$
00175 $index TapeRec, Num$$
00176 $index Num, TapeRec$$
00177 
00178 $subhead Op$$
00179 $index NumOp$$
00180 The syntax
00181 $syntax%
00182         size_t %Rec%.NumOp(void) const
00183 %$$
00184 returns the number of Op values
00185 that are currently stored in $italic Rec$$.
00186 This increments by one each time $code PutOp$$ is called; i.e.,
00187 it is the number of calls to $code PutOp$$.
00188 
00189 $subhead Ind$$
00190 $index NumInd$$
00191 The syntax
00192 $syntax%
00193         size_t %Rec%.NumInd(void) const
00194 %$$
00195 returns the number of Ind values
00196 that are currently stored in $italic Rec$$.
00197 This increments by one for each value that is stored by $code PutInd$$.
00198 
00199 The syntax
00200 $syntax%
00201         size_t %Rec%.NumVecInd(void) const
00202 %$$
00203 returns the number of VecInd values
00204 that are currently stored in $italic Rec$$.
00205 This increments by one each time $code PutVecInd$$ is called.
00206 
00207 $subhead Par$$
00208 $index NumPar$$
00209 The syntax
00210 $syntax%
00211         size_t %Rec%.NumPar(void) const
00212 %$$
00213 returns the number of Par values
00214 that are currently stored in $italic Rec$$.
00215 This increment by one or zero each time $code PutPar$$ is called.
00216 
00217 $head Replace$$
00218 $index TapeRec, Replace$$
00219 $index Replace, TapeRec$$
00220 
00221 $subhead Ind$$
00222 $index ReplaceInd$$
00223 The syntax
00224 $syntax%
00225         size_t %Rec%.ReplaceInd(size_t %index%, size_t %value%)
00226 %$$
00227 Replaces the single value with index $italic index$$ in the sequence of
00228 Ind values stored by calls to $syntax%%Rec%.PutInd%$$.
00229 The argument $italic index$$ must be less than $syntax%%Rec%.NumInd()%$$.
00230 
00231 
00232 $head Memory$$
00233 $index TapeRec, Memory$$
00234 $index Memory, TapeRec$$
00235 The syntax
00236 $syntax%
00237         size_t %Rec%.Memory(void) const
00238 %$$
00239 returns the number of memory units ($code sizeof$$) required to store
00240 the information in $italic Rec$$.
00241 
00242 
00243 
00244 $end
00245 ------------------------------------------------------------------------------
00246 */
00247 
00248 //  BEGIN CppAD namespace
00249 namespace CppAD {
00250 
00251 template <class Base>
00252 class TapeRec {
00253 
00254 public:
00255         // default
00256         TapeRec(void) 
00257         {       
00258                 TotalNumberVar = 0;
00259 
00260                 NumberOp       = 0;
00261                 LengthOp       = 0;
00262                 Op             = CPPAD_NULL;
00263 
00264                 NumberVecInd   = 0;
00265                 LengthVecInd   = 0;
00266                 VecInd         = CPPAD_NULL;
00267 
00268                 NumberInd      = 0;
00269                 LengthInd      = 0;
00270                 Ind            = CPPAD_NULL;
00271 
00272                 NumberPar      = 0;
00273                 LengthPar      = 0;
00274                 Par            = CPPAD_NULL;
00275 
00276                 NumberTxt      = 0;
00277                 LengthTxt      = 0;
00278                 Txt            = CPPAD_NULL;
00279 
00280         }
00281 
00282         // destructor
00283         ~TapeRec(void)
00284         {       if( LengthOp > 0 )
00285                         CPPAD_TRACK_DEL_VEC(Op);
00286                 if( LengthVecInd > 0 )
00287                         CPPAD_TRACK_DEL_VEC(VecInd);
00288                 if( LengthInd > 0 )
00289                         CPPAD_TRACK_DEL_VEC(Ind);
00290                 if( LengthPar > 0 )
00291                         CPPAD_TRACK_DEL_VEC(Par);
00292                 if( LengthTxt > 0 )
00293                         CPPAD_TRACK_DEL_VEC(Txt);
00294         }
00295 
00296         // assignment from another recording
00297         void operator=(const TapeRec &Other)
00298         {       size_t i;
00299 
00300                 if( LengthOp > 0 )
00301                         CPPAD_TRACK_DEL_VEC(Op);
00302                 if( LengthVecInd > 0 )
00303                         CPPAD_TRACK_DEL_VEC(VecInd);
00304                 if( LengthInd > 0 )
00305                         CPPAD_TRACK_DEL_VEC(Ind);
00306                 if( LengthPar > 0 )
00307                         CPPAD_TRACK_DEL_VEC(Par);
00308                 if( LengthTxt > 0 )
00309                         CPPAD_TRACK_DEL_VEC(Txt);
00310 
00311                 // Var
00312                 TotalNumberVar  = Other.TotalNumberVar;
00313 
00314                 // Op
00315                 NumberOp        = Other.NumberOp;
00316                 LengthOp        = Other.NumberOp;
00317 
00318                 // VecInd
00319                 NumberVecInd    = Other.NumberVecInd;
00320                 LengthVecInd    = Other.NumberVecInd;
00321 
00322                 // Ind
00323                 NumberInd       = Other.NumberInd;
00324                 LengthInd       = Other.NumberInd;
00325 
00326                 // Par
00327                 NumberPar       = Other.NumberPar;
00328                 LengthPar       = Other.NumberPar;
00329 
00330                 // Txt
00331                 NumberTxt       = Other.NumberTxt;
00332                 LengthTxt       = Other.NumberTxt;
00333 
00334                 // Allocate the memory
00335                 if( LengthOp == 0 )
00336                         Op = CPPAD_NULL;
00337                 else    Op = CPPAD_TRACK_NEW_VEC(LengthOp,      Op);
00338                 if( LengthVecInd == 0 )
00339                         VecInd = CPPAD_NULL;
00340                 else    VecInd = CPPAD_TRACK_NEW_VEC(LengthVecInd, VecInd);
00341                 if( LengthInd == 0 )
00342                         Ind = CPPAD_NULL;
00343                 else    Ind = CPPAD_TRACK_NEW_VEC(LengthInd,       Ind);
00344                 if( LengthPar == 0 )
00345                         Par = CPPAD_NULL;
00346                 else    Par = CPPAD_TRACK_NEW_VEC(LengthPar,       Par);
00347                 if( LengthTxt == 0 )
00348                         Txt = CPPAD_NULL;
00349                 else    Txt = CPPAD_TRACK_NEW_VEC(LengthTxt,       Txt);
00350 
00351                 // Copy the data
00352                 i = NumberOp;
00353                 while(i--)
00354                         Op[i] = Other.Op[i];
00355                 i = NumberVecInd;
00356                 while(i--)
00357                         VecInd[i] = Other.VecInd[i];
00358                 i = NumberInd;
00359                 while(i--)
00360                         Ind[i] = Other.Ind[i];
00361                 i = NumberPar;
00362                 while(i--)
00363                         Par[i] = Other.Par[i];
00364                 i = NumberTxt;
00365                 while(i--)
00366                         Txt[i] = Other.Txt[i];
00367         }
00368 
00369         // erase all information in recording
00370         void Erase(void)
00371         {       
00372                 TotalNumberVar  = 0;
00373                 NumberOp        = 0;
00374                 NumberVecInd    = 0;
00375                 NumberInd       = 0;
00376                 NumberPar       = 0;
00377                 NumberTxt       = 0;
00378 
00379                 if( LengthOp > 0 )
00380                         CPPAD_TRACK_DEL_VEC(Op);
00381                 if( LengthVecInd > 0 )
00382                         CPPAD_TRACK_DEL_VEC(VecInd);
00383                 if( LengthInd > 0 )
00384                         CPPAD_TRACK_DEL_VEC(Ind);
00385                 if( LengthPar > 0 )
00386                         CPPAD_TRACK_DEL_VEC(Par);
00387                 if( LengthTxt > 0 )
00388                         CPPAD_TRACK_DEL_VEC(Txt);
00389 
00390                 LengthOp        = 0;
00391                 LengthVecInd    = 0;
00392                 LengthInd       = 0;
00393                 LengthPar       = 0;
00394                 LengthTxt       = 0;
00395         }
00396 
00397         // add information to recording
00398         inline size_t PutOp(OpCode op);
00399         inline size_t PutVecInd(size_t vecInd);
00400         inline size_t PutPar(const Base &par);
00401         inline void PutInd(size_t ind0); 
00402         inline void PutInd(size_t ind0, size_t ind1); 
00403         inline void PutInd(size_t ind0, size_t ind1, size_t ind2); 
00404         inline void PutInd(size_t ind0, size_t ind1, size_t ind2, size_t ind3); 
00405         inline void PutInd(size_t ind0, size_t ind1, size_t ind2, size_t ind3,
00406                 size_t ind4);
00407         inline void PutInd(size_t ind0, size_t ind1, size_t ind2, size_t ind3,
00408                 size_t ind4, size_t ind5);
00409 
00410         inline size_t PutTxt(const char *text);
00411 
00412         /*
00413         retrieve information from recording
00414         */
00415         OpCode GetOp (size_t i) const
00416         {       CPPAD_ASSERT_UNKNOWN(i < NumberOp);
00417                 return Op[i];
00418         }
00419         size_t GetVecInd (size_t i) const
00420         {       CPPAD_ASSERT_UNKNOWN(i < NumberVecInd);
00421                 return VecInd[i];
00422         }
00423         const Base *GetPar(size_t i) const
00424         {       CPPAD_ASSERT_UNKNOWN(i < NumberPar);
00425                 return Par + i;
00426         }
00427         const size_t *GetInd(size_t n, size_t i) const
00428         {       CPPAD_ASSERT_UNKNOWN(i + n <= NumberInd)
00429                 return Ind + i;
00430         }
00431         const char *GetTxt(size_t i) const
00432         {       CPPAD_ASSERT_UNKNOWN(i < NumberTxt);
00433                 return Txt + i;
00434         }
00435         
00436         /*
00437         replace information 
00438         */
00439         void ReplaceInd(size_t i, size_t value)
00440         {       CPPAD_ASSERT_UNKNOWN( i < NumberInd);
00441                 Ind[i] = value;
00442         }
00443 
00444         // number of values
00445         size_t TotNumVar(void) const
00446         {       return TotalNumberVar; }
00447         size_t NumOp(void) const
00448         {       return NumberOp; }
00449         size_t NumVecInd(void) const
00450         {       return NumberVecInd; }
00451         size_t NumInd(void) const
00452         {       return NumberInd; }
00453         size_t NumPar(void) const
00454         {       return NumberPar; }
00455         size_t NumTxt(void) const
00456         {       return NumberTxt; }
00457 
00458         // amount of memory used 
00459         size_t Memory(void) const
00460         {       return LengthOp * sizeof(OpCode) 
00461                      + LengthVecInd * sizeof(size_t)
00462                      + LengthInd * sizeof(size_t)
00463                      + LengthPar * sizeof(Base)
00464                      + LengthTxt * sizeof(char);
00465         }
00466 
00467 private:
00468         size_t    TotalNumberVar;
00469 
00470         size_t    NumberOp;
00471         size_t    LengthOp;
00472         OpCode   *Op;
00473 
00474         size_t    NumberVecInd;
00475         size_t    LengthVecInd;
00476         size_t   *VecInd;
00477 
00478         size_t    NumberInd;
00479         size_t    LengthInd;
00480         size_t   *Ind;
00481 
00482         size_t    NumberPar;
00483         size_t    LengthPar;
00484         Base     *Par;
00485 
00486         size_t    NumberTxt;
00487         size_t    LengthTxt;
00488         char     *Txt;
00489 };
00490 
00491 template <class Base>
00492 inline size_t TapeRec<Base>::PutOp(OpCode op)
00493 {       size_t varIndex = TotalNumberVar;
00494         
00495         CPPAD_ASSERT_UNKNOWN( NumberOp <= LengthOp );
00496         if( NumberOp == LengthOp )
00497         {       LengthOp = 2 * LengthOp + 8;
00498                 Op = CPPAD_TRACK_EXTEND(LengthOp, NumberOp, Op);
00499         }
00500         CPPAD_ASSERT_UNKNOWN( NumberOp < LengthOp );
00501         Op[NumberOp++]  = op;
00502         TotalNumberVar += NumVar(op);
00503 
00504         return varIndex;
00505 }
00506 
00507 template <class Base>
00508 inline size_t TapeRec<Base>::PutVecInd(size_t vecInd)
00509 {       
00510         CPPAD_ASSERT_UNKNOWN( NumberVecInd <= LengthVecInd );
00511         if( NumberVecInd == LengthVecInd )
00512         {       LengthVecInd = 2 * LengthVecInd + 8;
00513                 VecInd = CPPAD_TRACK_EXTEND(LengthVecInd, NumberVecInd, VecInd);
00514         }
00515         CPPAD_ASSERT_UNKNOWN( NumberVecInd < LengthVecInd );
00516         VecInd[NumberVecInd++] = vecInd;
00517 
00518         return NumberVecInd - 1;
00519 }
00520 
00521 template <class Base>
00522 inline size_t TapeRec<Base>::PutPar(const Base &par)
00523 {       size_t i;
00524         
00525         CPPAD_ASSERT_UNKNOWN( NumberPar <= LengthPar );
00526         
00527         // check last three values to see if same one came up
00528         if( NumberPar >= 3 )
00529         {       i = NumberPar;
00530                 while(i > NumberPar - 3)
00531                 {       --i;
00532                         if( IdenticalEqualPar(Par[i], par) )
00533                                 return i;
00534                 }
00535         }
00536         
00537         // place a new value in the table
00538         if( NumberPar == LengthPar )
00539         {       LengthPar = 2 * LengthPar + 8;
00540                 Par = CPPAD_TRACK_EXTEND(LengthPar, NumberPar, Par);
00541         }
00542         CPPAD_ASSERT_UNKNOWN( NumberPar < LengthPar );
00543         Par[NumberPar++] = par;
00544 
00545         return NumberPar - 1;
00546 }
00547  // -------------------------- PutInd --------------------------------------
00548 template <class Base>
00549 inline void TapeRec<Base>::PutInd(size_t ind0)
00550 { 
00551         CPPAD_ASSERT_UNKNOWN( NumberInd <= LengthInd );
00552         if( NumberInd == LengthInd )
00553         {       LengthInd = 2 * LengthInd + 8;
00554                 Ind = CPPAD_TRACK_EXTEND(LengthInd, NumberInd, Ind);
00555         }
00556         CPPAD_ASSERT_UNKNOWN( NumberInd < LengthInd );
00557         Ind[NumberInd++] = ind0;
00558 }
00559 template <class Base>
00560 inline void TapeRec<Base>::PutInd(size_t ind0, size_t ind1)
00561 { 
00562         CPPAD_ASSERT_UNKNOWN( NumberInd <= LengthInd );
00563         if( NumberInd + 1 >= LengthInd )
00564         {       LengthInd = 2 * LengthInd + 8;
00565                 Ind = CPPAD_TRACK_EXTEND(LengthInd, NumberInd, Ind);
00566         }
00567         CPPAD_ASSERT_UNKNOWN( NumberInd + 1 < LengthInd );
00568         Ind[NumberInd++] = ind0;
00569         Ind[NumberInd++] = ind1;
00570 }
00571 template <class Base>
00572 inline void TapeRec<Base>::PutInd(size_t ind0, size_t ind1, size_t ind2)
00573 { 
00574         CPPAD_ASSERT_UNKNOWN( NumberInd <= LengthInd );
00575         if( NumberInd + 2 >= LengthInd )
00576         {       LengthInd = 2 * LengthInd + 8;
00577                 Ind = CPPAD_TRACK_EXTEND(LengthInd, NumberInd, Ind);
00578         }
00579         CPPAD_ASSERT_UNKNOWN( NumberInd + 2 < LengthInd );
00580         Ind[NumberInd++] = ind0;
00581         Ind[NumberInd++] = ind1;
00582         Ind[NumberInd++] = ind2;
00583 }
00584 template <class Base>
00585 inline void TapeRec<Base>::PutInd(size_t ind0, size_t ind1, size_t ind2,
00586         size_t ind3)
00587 { 
00588         CPPAD_ASSERT_UNKNOWN( NumberInd <= LengthInd );
00589         if( NumberInd + 3 >= LengthInd )
00590         {       LengthInd = 2 * LengthInd + 8;
00591                 Ind = CPPAD_TRACK_EXTEND(LengthInd, NumberInd, Ind);
00592         }
00593         CPPAD_ASSERT_UNKNOWN( NumberInd + 3 < LengthInd );
00594         Ind[NumberInd++] = ind0;
00595         Ind[NumberInd++] = ind1;
00596         Ind[NumberInd++] = ind2;
00597         Ind[NumberInd++] = ind3;
00598 
00599 }
00600 template <class Base>
00601 inline void TapeRec<Base>::PutInd(size_t ind0, size_t ind1, size_t ind2,
00602         size_t ind3, size_t ind4)
00603 { 
00604         CPPAD_ASSERT_UNKNOWN( NumberInd <= LengthInd );
00605         if( NumberInd + 4 >= LengthInd )
00606         {       LengthInd = 2 * LengthInd + 8;
00607                 Ind = CPPAD_TRACK_EXTEND(LengthInd, NumberInd, Ind);
00608         }
00609         CPPAD_ASSERT_UNKNOWN( NumberInd + 4 < LengthInd );
00610         Ind[NumberInd++] = ind0;
00611         Ind[NumberInd++] = ind1;
00612         Ind[NumberInd++] = ind2;
00613         Ind[NumberInd++] = ind3;
00614         Ind[NumberInd++] = ind4;
00615 
00616 }
00617 template <class Base>
00618 inline void TapeRec<Base>::PutInd(size_t ind0, size_t ind1, size_t ind2, 
00619         size_t ind3, size_t ind4, size_t ind5)
00620 { 
00621         CPPAD_ASSERT_UNKNOWN( NumberInd <= LengthInd );
00622         if( NumberInd + 5 >= LengthInd )
00623         {       LengthInd = 2 * LengthInd + 8;
00624                 Ind = CPPAD_TRACK_EXTEND(LengthInd, NumberInd, Ind);
00625         }
00626         CPPAD_ASSERT_UNKNOWN( NumberInd + 5 < LengthInd );
00627         Ind[NumberInd++] = ind0;
00628         Ind[NumberInd++] = ind1;
00629         Ind[NumberInd++] = ind2;
00630         Ind[NumberInd++] = ind3;
00631         Ind[NumberInd++] = ind4;
00632         Ind[NumberInd++] = ind5;
00633 }
00634 
00635 template <class Base>
00636 inline size_t TapeRec<Base>::PutTxt(const char *text)
00637 {       size_t i;
00638 
00639         // determine length of the text including terminating '\0'
00640         size_t n;
00641         for(n = 0; text[n] != '\0'; n++)
00642                 CPPAD_ASSERT_UNKNOWN( n < 1000 ); // should check in PrintFor
00643         n++;
00644 
00645         CPPAD_ASSERT_UNKNOWN( NumberTxt <= LengthTxt );
00646 
00647         if( NumberTxt + n >= LengthTxt )
00648         {       LengthTxt  = 2 * LengthTxt + n + 8;
00649                 Txt = CPPAD_TRACK_EXTEND(LengthTxt, NumberTxt, Txt);
00650         }
00651         CPPAD_ASSERT_UNKNOWN( NumberTxt + n < LengthTxt );
00652 
00653         // copy text including terminating '\0'
00654         for(i = 0; i < n; i++)
00655                 Txt[NumberTxt++] = text[i];
00656         CPPAD_ASSERT_UNKNOWN( text[i-1] == '\0' );
00657 
00658         return NumberTxt - n;
00659 }
00660 
00661 } // END CppAD namespace
00662 
00663 # endif

Generated on Sun Nov 14 14:06:33 2010 for Coin-All by  doxygen 1.4.7