Skip to content
Browse files

Initial commit created by git-make-initial

Signed-off-by: Stefan Naewe <stefan.naewe@atlas-elektronik.com>
  • Loading branch information...
0 parents commit 208b18cc2eff199aea02b68decd4cbb649d92cce Stefan Naewe committed
Showing with 9,703 additions and 0 deletions.
  1. +37 −0 .gitignore
  2. +1 −0 apue.2e
  3. +1 −0 cppoop
  4. BIN iostreams/examples/doc/IncludeGraph.pdf
  5. BIN iostreams/examples/doc/Includegraph_Seite_1_150dpi.gif
  6. BIN iostreams/examples/doc/Includegraph_Seite_2_150dpi.gif
  7. 0 iostreams/examples/doc/version.1
  8. 0 iostreams/examples/dst.cpp
  9. +3 −0 iostreams/examples/ex049.in
  10. +1 −0 iostreams/examples/ex129.in
  11. BIN iostreams/examples/ex284.dat
  12. +1 −0 iostreams/examples/fil
  13. +1 −0 iostreams/examples/filnam.txt
  14. +1 −0 iostreams/examples/in.txt
  15. +78 −0 iostreams/examples/inc/address_333.h
  16. +67 −0 iostreams/examples/inc/address_put_336.h
  17. +46 −0 iostreams/examples/inc/basic_mendl_183.h
  18. +56 −0 iostreams/examples/inc/bounded_width_190.h
  19. +39 −0 iostreams/examples/inc/buffer_x_device_235.h
  20. +44 −0 iostreams/examples/inc/char_x_device_229.h
  21. +35 −0 iostreams/examples/inc/copyfmterr_206.h
  22. +87 −0 iostreams/examples/inc/date_148.h
  23. +89 −0 iostreams/examples/inc/date_157.h
  24. +101 −0 iostreams/examples/inc/date_159.h
  25. +119 −0 iostreams/examples/inc/date_160.h
  26. +272 −0 iostreams/examples/inc/date_161.h
  27. +269 −0 iostreams/examples/inc/date_170.h
  28. +248 −0 iostreams/examples/inc/date_196.h
  29. +245 −0 iostreams/examples/inc/date_220.h
  30. +47 −0 iostreams/examples/inc/datefmt_210.h
  31. +37 −0 iostreams/examples/inc/defaultpatt_197.h
  32. +57 −0 iostreams/examples/inc/german_address_put_337.h
  33. +33 −0 iostreams/examples/inc/getidx_195.h
  34. +113 −0 iostreams/examples/inc/inbuf_239.h
  35. +67 −0 iostreams/examples/inc/locale_factory_340.h
  36. +45 −0 iostreams/examples/inc/mendl_180.h
  37. +32 −0 iostreams/examples/inc/mendl_184.h
  38. +43 −0 iostreams/examples/inc/ocdatestream_212.h
  39. +87 −0 iostreams/examples/inc/odatestream_215.h
  40. +92 −0 iostreams/examples/inc/odatestream_218.h
  41. +59 −0 iostreams/examples/inc/one_arg_manip_181.h
  42. +62 −0 iostreams/examples/inc/one_arg_manip_183.h
  43. +58 −0 iostreams/examples/inc/one_arg_manip_190.h
  44. +118 −0 iostreams/examples/inc/one_arg_manip_weh_187.h
  45. +118 −0 iostreams/examples/inc/outbuf_236.h
  46. +92 −0 iostreams/examples/inc/setfmt_helper_205.h
  47. +84 −0 iostreams/examples/inc/setfmt_helper_221.h
  48. +36 −0 iostreams/examples/inc/standalonefacet_309.h
  49. +126 −0 iostreams/examples/inc/unbuffered_streambuf_230.h
  50. +56 −0 iostreams/examples/inc/us_address_put_337.h
  51. +44 −0 iostreams/examples/inc/width_179.h
  52. +37 −0 iostreams/examples/inc/width_181.h
  53. +48 −0 iostreams/examples/inc/x_facet_317.h
  54. +43 −0 iostreams/examples/inc/x_facet_323.h
  55. +25 −0 iostreams/examples/inout.txt
  56. +1 −0 iostreams/examples/log.txt
  57. +2 −0 iostreams/examples/my_text_file
  58. +23 −0 iostreams/examples/nil.cpp
  59. +1 −0 iostreams/examples/nil.txt
  60. 0 iostreams/examples/notes.txt
  61. 0 iostreams/examples/out.txt
  62. +1 −0 iostreams/examples/outfile.txt
  63. 0 iostreams/examples/src.cpp
  64. +41 −0 iostreams/examples/src/ex013.cpp
  65. +39 −0 iostreams/examples/src/ex014a.cpp
  66. +53 −0 iostreams/examples/src/ex014b.cpp
  67. +53 −0 iostreams/examples/src/ex015.cpp
  68. +40 −0 iostreams/examples/src/ex017.cpp
  69. +36 −0 iostreams/examples/src/ex018.cpp
  70. +46 −0 iostreams/examples/src/ex020.cpp
  71. +41 −0 iostreams/examples/src/ex021.cpp
  72. +39 −0 iostreams/examples/src/ex022a.cpp
  73. +41 −0 iostreams/examples/src/ex022b.cpp
  74. +55 −0 iostreams/examples/src/ex023.cpp
  75. +32 −0 iostreams/examples/src/ex026.cpp
  76. +33 −0 iostreams/examples/src/ex027.cpp
  77. +81 −0 iostreams/examples/src/ex029a.cpp
  78. +66 −0 iostreams/examples/src/ex029b.cpp
  79. +62 −0 iostreams/examples/src/ex030.cpp
  80. +36 −0 iostreams/examples/src/ex034.cpp
  81. +35 −0 iostreams/examples/src/ex035a.cpp
  82. +45 −0 iostreams/examples/src/ex035b.cpp
  83. +61 −0 iostreams/examples/src/ex036.cpp
  84. +62 −0 iostreams/examples/src/ex037.cpp
  85. +66 −0 iostreams/examples/src/ex038.cpp
  86. +33 −0 iostreams/examples/src/ex039.cpp
  87. +35 −0 iostreams/examples/src/ex040a.cpp
  88. +45 −0 iostreams/examples/src/ex040b.cpp
  89. +52 −0 iostreams/examples/src/ex041a.cpp
  90. +35 −0 iostreams/examples/src/ex041b.cpp
  91. +49 −0 iostreams/examples/src/ex043.cpp
  92. +43 −0 iostreams/examples/src/ex044.cpp
  93. +39 −0 iostreams/examples/src/ex045a.cpp
  94. +67 −0 iostreams/examples/src/ex045b.cpp
  95. +56 −0 iostreams/examples/src/ex046.cpp
  96. +39 −0 iostreams/examples/src/ex048a.cpp
  97. +46 −0 iostreams/examples/src/ex048b.cpp
  98. +71 −0 iostreams/examples/src/ex049.cpp
  99. +50 −0 iostreams/examples/src/ex050a.cpp
  100. +50 −0 iostreams/examples/src/ex050b.cpp
  101. +92 −0 iostreams/examples/src/ex053.cpp
  102. +53 −0 iostreams/examples/src/ex055a.cpp
  103. +47 −0 iostreams/examples/src/ex055b.cpp
  104. +45 −0 iostreams/examples/src/ex056.cpp
  105. +153 −0 iostreams/examples/src/ex058.cpp
  106. +47 −0 iostreams/examples/src/ex066.cpp
  107. +46 −0 iostreams/examples/src/ex072.cpp
  108. +78 −0 iostreams/examples/src/ex074.cpp
  109. +40 −0 iostreams/examples/src/ex078a.cpp
  110. +43 −0 iostreams/examples/src/ex078b.cpp
  111. +73 −0 iostreams/examples/src/ex080.cpp
  112. +71 −0 iostreams/examples/src/ex083.cpp
  113. +59 −0 iostreams/examples/src/ex084.cpp
  114. +35 −0 iostreams/examples/src/ex111.cpp
  115. +59 −0 iostreams/examples/src/ex115.cpp
  116. +72 −0 iostreams/examples/src/ex118.cpp
  117. +68 −0 iostreams/examples/src/ex124.cpp
  118. +46 −0 iostreams/examples/src/ex126.cpp
  119. +44 −0 iostreams/examples/src/ex127a.cpp
  120. +85 −0 iostreams/examples/src/ex127b.cpp
  121. +109 −0 iostreams/examples/src/ex129.cpp
  122. +54 −0 iostreams/examples/src/ex131.cpp
  123. +55 −0 iostreams/examples/src/ex133.cpp
  124. +108 −0 iostreams/examples/src/ex135.cpp
  125. +156 −0 iostreams/examples/src/ex137.cpp
  126. +67 −0 iostreams/examples/src/ex148.cpp
  127. +55 −0 iostreams/examples/src/ex157.cpp
  128. +57 −0 iostreams/examples/src/ex159.cpp
  129. +61 −0 iostreams/examples/src/ex160.cpp
  130. +104 −0 iostreams/examples/src/ex161.cpp
  131. +42 −0 iostreams/examples/src/ex170.cpp
  132. +42 −0 iostreams/examples/src/ex176.cpp
  133. +54 −0 iostreams/examples/src/ex178a.cpp
  134. +48 −0 iostreams/examples/src/ex178b.cpp
  135. +49 −0 iostreams/examples/src/ex179.cpp
  136. +87 −0 iostreams/examples/src/ex181.cpp
  137. +106 −0 iostreams/examples/src/ex183.cpp
  138. +67 −0 iostreams/examples/src/ex187.cpp
  139. +36 −0 iostreams/examples/src/ex195.cpp
  140. +37 −0 iostreams/examples/src/ex196.cpp
  141. +56 −0 iostreams/examples/src/ex207.cpp
  142. +43 −0 iostreams/examples/src/ex210.cpp
  143. +46 −0 iostreams/examples/src/ex221.cpp
  144. +97 −0 iostreams/examples/src/ex234.cpp
  145. +47 −0 iostreams/examples/src/ex236.cpp
  146. +71 −0 iostreams/examples/src/ex239.cpp
  147. +88 −0 iostreams/examples/src/ex247.cpp
  148. +47 −0 iostreams/examples/src/ex268.cpp
  149. +52 −0 iostreams/examples/src/ex269.cpp
  150. +50 −0 iostreams/examples/src/ex270.cpp
  151. +140 −0 iostreams/examples/src/ex272.cpp
  152. +43 −0 iostreams/examples/src/ex273a.cpp
  153. +36 −0 iostreams/examples/src/ex273b.cpp
  154. +39 −0 iostreams/examples/src/ex273c.cpp
  155. +62 −0 iostreams/examples/src/ex278a.cpp
  156. +49 −0 iostreams/examples/src/ex278b.cpp
  157. +71 −0 iostreams/examples/src/ex281.cpp
  158. +131 −0 iostreams/examples/src/ex284.cpp
  159. +63 −0 iostreams/examples/src/ex290.cpp
  160. +46 −0 iostreams/examples/src/ex296.cpp
  161. +39 −0 iostreams/examples/src/ex300.cpp
  162. +41 −0 iostreams/examples/src/ex306.cpp
  163. +42 −0 iostreams/examples/src/ex308.cpp
  164. +46 −0 iostreams/examples/src/ex310.cpp
  165. +80 −0 iostreams/examples/src/ex316.cpp
  166. +62 −0 iostreams/examples/src/ex317.cpp
  167. +51 −0 iostreams/examples/src/ex319.cpp
  168. +54 −0 iostreams/examples/src/ex321.cpp
  169. +60 −0 iostreams/examples/src/ex323.cpp
Sorry, we could not display the entire diff because it was too big.
37 .gitignore
@@ -0,0 +1,37 @@
+# git-ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+*.[oa]
+*~
+*.class
+callgrind.out*
+.sniffdir/
+.Sniff_LastMake
+*.o
+*.obj
+*.idl_dep
+*.omniorb
+*.pdb
+*.opt
+*.ncb
+*.positions
+*.vi
+*%
+*~
+*.?ch
+*.exe
+*.exp
+*.suo
+*.ilk
+*.gch
+*.pch
+*.bak
+*.lib
+a.out
+Debug
+Release
+*.vcproj.*.user
+*cache.dat
+.depend.*
+core*
1 apue.2e
@@ -0,0 +1 @@
+Subproject commit d247d03c33b439fbdf53b9904e82da5fff2db546
1 cppoop
@@ -0,0 +1 @@
+Subproject commit 3d7fd15dc728437fd479177e622acbdaaa57c7e5
BIN iostreams/examples/doc/IncludeGraph.pdf
Binary file not shown.
BIN iostreams/examples/doc/Includegraph_Seite_1_150dpi.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
BIN iostreams/examples/doc/Includegraph_Seite_2_150dpi.gif
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
0 iostreams/examples/doc/version.1
No changes.
0 iostreams/examples/dst.cpp
No changes.
3 iostreams/examples/ex049.in
@@ -0,0 +1,3 @@
+A234567890B234567890C234567890D234567890E234567890F234567890
+A234567890B234567890C234567890D234567890E234567890F234567890G234567890H234567890I234567890J234567890K234567890L234567890M234567890
+A234567890B234567890C234567890D234567890E234567890F234567890
1 iostreams/examples/ex129.in
@@ -0,0 +1 @@
+1 1 2 6 24 120 720 5040 40320 362880 3628800
BIN iostreams/examples/ex284.dat
Binary file not shown.
1 iostreams/examples/fil
@@ -0,0 +1 @@
+Hello world
1 iostreams/examples/filnam.txt
@@ -0,0 +1 @@
+01ABCDE#*9
1 iostreams/examples/in.txt
@@ -0,0 +1 @@
+Hello world
78 iostreams/examples/inc/address_333.h
@@ -0,0 +1,78 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "address_333.h"
+*/
+
+#ifndef ADDRESS_H
+#define ADDRESS_H
+
+// p. 333 {{{
+template <class charT>
+class address
+{
+ friend basic_ostream<charT>&
+ operator << (basic_ostream<charT>& os, const address<charT>& ad)
+ // p. 338 {{{
+ // It is necessary to inline this operator, otherwise a link error occurs.
+ {
+ locale loc = os.getloc();
+
+ try
+ {
+ const address_put<charT>& apFacet = use_facet<address_put<charT> >(loc);
+ apFacet.put(os, ad.firstname_, ad.secname_, ad.lastname_,
+ ad.address1_, ad.address2_, ad.town_, ad.zipcode_,
+ ad.state_, ad.country_, ad.cntrycode_);
+ }
+ catch(bad_cast&)
+ {
+ // locale does not contain a address_put facet;
+ }
+
+ return (os);
+ }
+ // }}}
+
+ typedef basic_string<charT> String;
+
+public:
+ address(const String& firstname, const String& secname,
+ const String& lastname,
+ const String& address1, const String& address2,
+ const String& town, const String& zipcode,
+ const String& state, const String& country,
+ const String& cntrycode)
+ : firstname_(firstname) , secname_(secname), lastname_(lastname),
+ address1_(address1), address2_(address2),
+ town_(town), zipcode_(zipcode), state_(state),
+ country_(country), cntrycode_(cntrycode) {}
+private:
+ String firstname_;
+ String secname_;
+ String lastname_;
+ String address1_;
+ String address2_;
+ String town_;
+ String zipcode_;
+ String state_;
+ String country_;
+ String cntrycode_;
+};
+// }}}
+
+#endif
67 iostreams/examples/inc/address_put_336.h
@@ -0,0 +1,67 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "address_put_336.h"
+*/
+
+#ifndef ADDRESS_INSERTER_H
+#define ADDRESS_INSERTER_H
+
+// p. 335 {{{
+template <class charT, class OutIter = ostreambuf_iterator<charT> >
+class address_put : public locale::facet
+{
+ protected:
+ typedef basic_string<charT> String;
+
+ public:
+ typedef OutIter iter_type;
+
+ static locale::id id;
+
+ address_put(size_t refs = 0) : locale::facet(refs) { }
+
+ void put(OutIter oi,
+ const String& firstname, const String& secname, const String& lastname,
+ const String& address1, const String& address2,
+ const String& town, const String& zipcode, const String& state,
+ const String& country, const String& cntrycode) const
+ {
+ do_put(oi, firstname, secname, lastname,
+ address1, address2, town, zipcode, state, country, cntrycode);
+ }
+// }}}
+// p. 337 {{{
+ protected:
+ virtual void do_put(OutIter oi,
+ const String& firstname, const String& secname, const String& lastname,
+ const String& address1, const String& address2,
+ const String& town, const String& zipcode, const String& state,
+ const String& country, const String& cntrycode) const = 0; // was not = 0 on page 335
+// }}}
+// p. 335 {{{
+ void put_string(OutIter oi, String s) const
+ {
+ typename String::iterator si, end;
+
+ for (si = s.begin(), end = s.end(); si != end; si++, oi++)
+ *oi = *si;
+ }
+};
+// }}}
+
+#endif
46 iostreams/examples/inc/basic_mendl_183.h
@@ -0,0 +1,46 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "basic_mendl_183.h"
+*/
+
+#ifndef BASIC_MENDL_H
+#define BASIC_MENDL_H
+
+#include "one_arg_manip_183.h"
+
+// In the book p. 183 the class is named mendl, but later on top of p. 184
+// it should be renamed to basic_mendl.
+// p. 183 {{{
+template <class charT, class Traits = char_traits<charT> >
+class basic_mendl : public one_arg_manip<charT, Traits, unsigned int> // !!! basic_mendl instead of mendl
+{
+public:
+ explicit basic_mendl(unsigned int i) // !!! basic_mendl instead of mendl
+ : one_arg_manip<charT, Traits, unsigned int>(basic_mendl::fct, i) // !!! basic_mendl instead of mendl
+ {}
+private:
+ static void fct(basic_ostream<charT, Traits>& os, unsigned int n)
+ {
+ for ( int i=0; i<n; ++i )
+ os.put(os.widen('\n'));
+ os.flush();
+ }
+};
+// }}}
+
+#endif
56 iostreams/examples/inc/bounded_width_190.h
@@ -0,0 +1,56 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "bounded_width_190.h"
+*/
+
+#ifndef BOUNDED_WIDTH
+#define BOUNDED_WIDTH
+
+#include "one_arg_manip_190.h"
+
+// p. 190 {{{
+class bounded_width : public one_arg_manip<unsigned int>
+{
+public:
+ bounded_width(unsigned int min, unsigned int max)
+ : one_arg_manip<unsigned int>(bounded_width::fct, min),
+ min_(min), max_(max) {}
+
+ one_arg_manip<unsigned int>& operator() (unsigned int i)
+ {
+ if (i < min_)
+ arg_ = min_;
+ else if (i > max_)
+ arg_ = max_;
+ else
+ arg_ = i;
+ return *this;
+ }
+private:
+ static ios_base& fct(ios_base& ib, unsigned int i)
+ {
+ ib.width(i);
+ return ib;
+ }
+
+ unsigned int min_;
+ unsigned int max_;
+};
+// }}}
+
+#endif
39 iostreams/examples/inc/buffer_x_device_235.h
@@ -0,0 +1,39 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "buffer_x_device_235.h"
+*/
+
+#ifndef BUFFER_X_DEVICE_H
+#define BUFFER_X_DEVICE_H
+
+// p. 235 {{{
+int buffer_to_device (const char * c, int n)
+{
+ if (_write(1,c,n) != n)
+ return -1;
+ else
+ return 0;
+}
+
+int buffer_from_device(char * c, int n)
+{
+ return _read(0, c, n);
+}
+// }}}
+
+#endif
44 iostreams/examples/inc/char_x_device_229.h
@@ -0,0 +1,44 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "char_x_device_229.h"
+*/
+
+#ifndef CHAR_X_DEVICE_H
+#define CHAR_X_DEVICE_H
+
+// p. 229 {{{
+int char_to_device(char c)
+{
+ if ( _write(1, &c, 1) != 1 )
+ return -1;
+// }}}
+// p. 230 {{{
+ else
+ return 0;
+}
+
+int char_from_device(char * c)
+{
+ if (_read(0, c, 1) != 1)
+ return -1;
+ else
+ return 0;
+}
+// }}}
+
+#endif
35 iostreams/examples/inc/copyfmterr_206.h
@@ -0,0 +1,35 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "copyfmterr_206.h"
+*/
+
+#ifndef COPYFMTERR_H
+#define COPYFMTERR_H
+
+// p. 206 {{{
+template <class charT, class Traits>
+ios_base::iostate copyfmtErr(basic_ios<charT, Traits>& os)
+{
+ ios_base::iostate err = static_cast<ios_base::iostate> (os.iword(getIdx()));
+ os.iword(getIdx()) = 0L;
+ os.setstate(err | os.rdstate());
+ return err;
+}
+// }}}
+
+#endif
87 iostreams/examples/inc/date_148.h
@@ -0,0 +1,87 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "date_148.h"
+*/
+
+
+#ifndef DATE_H
+#define DATE_H
+
+// p. 148 {{{
+class date {
+public:
+ date(int d, int m, int y)
+ {
+ tm_date.tm_mday = d;tm_date.tm_mon = m-1; tm_date.tm_year = y-1900;
+ tm_date.tm_sec = tm_date.tm_min = tm_date.tm_hour = 0;
+ tm_date.tm_wday = tm_date.tm_yday = 0;
+ tm_date.tm_isdst = 0;
+ }
+ date(const tm& t) : tm_date(t) {}
+ date()
+ {
+ // get the current date // !!! Comment not in book
+ time_t ltime;
+// }}}
+// p. 149 {{{
+ time(&ltime);
+ tm_date = *localtime(&ltime);
+ }
+ // more constructors and useful member functions
+
+private:
+ tm tm_date;
+
+ template<class charT, class Traits>
+ friend basic_istream<charT, Traits>&
+ operator >>(basic_istream<charT, Traits>& is, date& dat);
+
+ template<class charT, class Traits>
+ friend basic_ostream<charT, Traits>&
+ operator<< (basic_ostream<charT, Traits>& os, const date& dat);
+};
+// }}}
+
+// p. 148 {{{
+// The extractor
+template <class charT, class Traits>
+basic_istream<charT, Traits>&
+operator >> (basic_istream<charT, Traits>& is, date& dat)
+{
+ int tmp;
+ is >> dat.tm_date.tm_mday;
+ is.ignore();
+ is >> tmp; dat.tm_date.tm_mon = tmp-1;
+ is.ignore();
+ is >> tmp; dat.tm_date.tm_year = tmp-1900;
+ return is;
+}
+
+// The inserter
+template <class charT, class Traits>
+basic_ostream<charT, Traits>&
+operator << (basic_ostream<charT , Traits>& os, const date& dat)
+{
+ os << dat.tm_date.tm_mday << '.';
+ os << dat.tm_date.tm_mon+1 << '.';
+ os << dat.tm_date.tm_year+1900;
+ return os;
+}
+// }}}
+
+#endif
89 iostreams/examples/inc/date_157.h
@@ -0,0 +1,89 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "date_157.h"
+*/
+
+#ifndef DATE_H
+#define DATE_H
+
+// p. 148 {{{
+class date {
+public:
+ date(int d, int m, int y)
+ {
+ tm_date.tm_mday = d;tm_date.tm_mon = m-1; tm_date.tm_year = y-1900;
+ tm_date.tm_sec = tm_date.tm_min = tm_date.tm_hour = 0;
+ tm_date.tm_wday = tm_date.tm_yday = 0;
+ tm_date.tm_isdst = 0;
+ mktime(&tm_date);
+ }
+ date(const tm& t) : tm_date(t) {}
+ date()
+ {
+ time_t ltime;
+// }}}
+// p. 149 {{{
+ time(&ltime);
+ tm_date = *localtime(&ltime);
+ }
+ // more constructors and useful member functions
+
+private:
+ tm tm_date;
+
+ template<class charT, class Traits>
+ friend basic_istream<charT, Traits>&
+ operator >>(basic_istream<charT, Traits>& is, date& dat);
+
+ template<class charT, class Traits>
+ friend basic_ostream<charT, Traits>&
+ operator<< (basic_ostream<charT, Traits>& os, const date& dat);
+};
+// }}}
+
+// p. 157 {{{
+template <class charT, class Traits>
+basic_istream<charT, Traits>&
+operator>>(basic_istream<charT, Traits>& is, date& dat)
+{
+ if (!is.good() )
+ return is;
+
+ ios_base::iostate err = ios_base::goodbit;
+
+ use_facet<time_get<charT, istreambuf_iterator<charT, Traits> > >(is.getloc() )
+ .get_date(is, istreambuf_iterator<charT, Traits> (), is, err, &dat.tm_date);
+
+ return is;
+}
+
+template <class charT, class Traits>
+basic_ostream<charT, Traits>&
+operator<< (basic_ostream<charT, Traits>& os, const date& dat)
+{
+ if (!os.good() )
+ return os;
+
+ use_facet<time_put<charT, ostreambuf_iterator<charT, Traits> > >(os.getloc() )
+ .put(os, os, os.fill(), &dat.tm_date,'x');
+
+ return os;
+}
+// }}}
+
+#endif
101 iostreams/examples/inc/date_159.h
@@ -0,0 +1,101 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+// Annotation:
+// The friend operators << and >> must be implemented within class date. Otherwise the compiler claims
+// it can not access the private member date.
+
+/*
+#include "date_159.h"
+*/
+
+
+#ifndef DATE_H
+#define DATE_H
+
+// p. 148 {{{
+class date {
+public:
+ date(int d, int m, int y)
+ {
+ tm_date.tm_mday = d;tm_date.tm_mon = m-1; tm_date.tm_year = y-1900;
+ tm_date.tm_sec = tm_date.tm_min = tm_date.tm_hour = 0;
+ tm_date.tm_wday = tm_date.tm_yday = 0;
+ tm_date.tm_isdst = 0;
+ mktime(&tm_date); // !!!
+ }
+ date(const tm& t) : tm_date(t) {}
+ date()
+ {
+ time_t ltime;
+ time(&ltime);
+ tm_date = *localtime(&ltime);
+ }
+ // more constructors and useful member functions
+
+private:
+ tm tm_date;
+
+ template<class charT, class Traits>
+ friend basic_istream<charT, Traits>&
+ operator >>(basic_istream<charT, Traits>& is, date& dat);
+
+ template<class charT, class Traits>
+ friend basic_ostream<charT, Traits>&
+ operator<< (basic_ostream<charT, Traits>& os, const date& dat);
+};
+// }}}
+
+// p. 159 {{{
+template<class charT, class Traits>
+basic_istream<charT, Traits>&
+operator >>(basic_istream<charT, Traits>& is, date& dat)
+{
+ if (!is.good() )
+ return is;
+
+ ios_base::iostate err = ios_base::goodbit;
+ typename basic_istream<charT, Traits>::sentry ipfx(is);
+ if ( ipfx )
+ {
+ use_facet<time_get<charT, istreambuf_iterator<charT, Traits> > >(is.getloc() )
+ .get_date(is, istreambuf_iterator<charT, Traits>(), is, err, &dat.tm_date);
+ }
+
+ return is;
+}
+
+template<class charT, class Traits>
+basic_ostream<charT, Traits>&
+operator<< (basic_ostream<charT, Traits>& os, const date& dat)
+{
+ if (!os.good() )
+ return os;
+
+ typename basic_ostream<charT, Traits>::sentry opfx(os);
+ if ( opfx )
+ {
+ use_facet<time_put<charT, ostreambuf_iterator<charT, Traits> > >(os.getloc() )
+ .put(os, os, os.fill(), &dat.tm_date, 'x');
+ }
+
+ return os;
+}
+// }}}
+
+
+
+#endif
119 iostreams/examples/inc/date_160.h
@@ -0,0 +1,119 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "date_160.h"
+*/
+
+#ifndef DATE_H
+#define DATE_H
+
+// p. 148 {{{
+class date {
+public:
+ date(int d, int m, int y)
+ {
+ tm_date.tm_mday = d;tm_date.tm_mon = m-1; tm_date.tm_year = y-1900;
+ tm_date.tm_sec = tm_date.tm_min = tm_date.tm_hour = 0;
+ tm_date.tm_wday = tm_date.tm_yday = 0;
+ tm_date.tm_isdst = 0;
+ mktime(&tm_date); // !!!
+ }
+ date(const tm& t) : tm_date(t) {}
+ date()
+ {
+ time_t ltime;
+ time(&ltime);
+ tm_date = *localtime(&ltime);
+ }
+ // more constructors and useful member functions
+
+private:
+ tm tm_date;
+
+ template<class charT, class Traits>
+ friend basic_istream<charT, Traits>&
+ operator >>(basic_istream<charT, Traits>& is, date& dat);
+
+ template<class charT, class Traits>
+ friend basic_ostream<charT, Traits>&
+ operator<< (basic_ostream<charT, Traits>& os, const date& dat);
+};
+// }}}
+
+// p. 159 {{{
+template<class charT, class Traits>
+basic_istream<charT, Traits>&
+operator >>(basic_istream<charT, Traits>& is, date& dat)
+{
+ if (!is.good() )
+ return is;
+
+ ios_base::iostate err = ios_base::goodbit;
+ typename basic_istream<charT, Traits>::sentry ipfx(is);
+ if ( ipfx )
+ {
+ use_facet<time_get<charT, istreambuf_iterator<charT, Traits> > >(is.getloc() )
+ .get_date(is, istreambuf_iterator<charT, Traits>(), is, err, &dat.tm_date);
+ }
+
+ return is;
+}
+// }}}
+
+// p. 160 {{{
+template<class charT, class Traits>
+basic_ostream<charT, Traits>&
+operator <<(basic_ostream<charT, Traits>& os, const date& dat)
+{
+ if (!os.good() )
+ return os;
+
+ typename basic_ostream<charT, Traits>::sentry opfx(os);
+ if (opfx)
+ {
+ basic_ostringstream<charT, Traits> sb;
+
+ use_facet<time_put<charT, ostreambuf_iterator<charT, Traits> > >(os.getloc() )
+ .put(sb, sb, os.fill(), &dat.tm_date,'x');
+
+ basic_string<charT, Traits> s = sb.str();
+ streamsize charToPad = static_cast<streamsize>(os.width() - s.length());
+ ostreambuf_iterator<charT, Traits> sink(os);
+ if (charToPad <= 0)
+ {
+ sink = copy(s.begin(), s.end(), sink);
+ }
+ else
+ {
+ if (os.flags() & ios_base::left)
+ {
+ sink = copy(s.begin(), s.end(), sink);
+ fill_n(sink,charToPad,os.fill());
+ }
+ else
+ {
+ fill_n(sink,charToPad,os.fill());
+ sink = copy(s.begin(), s.end(), sink);
+ }
+ }
+ }
+ os.width(0);
+ return os;
+}
+// }}}
+
+#endif
272 iostreams/examples/inc/date_161.h
@@ -0,0 +1,272 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "date_161.h"
+*/
+
+#ifndef DATE_H
+#define DATE_H
+
+// p. 161 {{{
+class date {
+public:
+ date(int d, int m, int y)
+ {
+ tm_date.tm_mday = d; tm_date.tm_mon = m-1; tm_date.tm_year = y-1900;
+ tm_date.tm_sec = tm_date.tm_min = tm_date.tm_hour = 0;
+ tm_date.tm_wday = tm_date.tm_yday = 0;
+ tm_date.tm_isdst = 0;
+ ok = (valid() & (mktime(&tm_date) != time_t(-1) ) ) ? true : false;
+ }
+ date(const tm& t) : tm_date(t)
+ {
+ ok = (mktime(&tm_date) != time_t(-1) ) ? true : false;
+ }
+// }}}
+// p. 162 {{{
+ date()
+ {
+ time_t ltime;
+ tm* tm_ptr;
+ time(&ltime); // get system time
+ tm_ptr= localtime(&ltime); // convert to tm struct
+ if ( tm_ptr != NULL )
+ {
+ tm_date = *tm_ptr;
+ ok = true;
+ }
+ else // is date before 1-1-1970
+ ok = false;
+ }
+
+ bool operator !() //check for the dates validity
+ {
+ ok = (valid() && (mktime(&tm_date) != time_t(-1) ) ) ? true : false;
+ return !ok;
+ }
+
+private:
+ tm tm_date;
+ bool ok;
+
+ bool valid() // check for sensible date; rejects nonsense like 32.12.1999
+ // The leap - year rule has been simplifies. For example, 1900 wasn't
+ // a leap year and 2100 won't be.
+ {
+ if (tm_date.tm_mon < 0 || tm_date.tm_mon > 11)
+ return false;
+ if (tm_date.tm_mday < 1)
+ switch ( tm_date.tm_mon )
+ {
+ case 0 : // !!! sequence was sorted in example
+ case 2 :
+ case 4 :
+ case 6 :
+ case 7 :
+ case 9 :
+ case 11:
+ if (tm_date.tm_mday > 31)
+ return false;
+ break;
+ case 1:
+ if (tm_date.tm_mday > 29)
+ return false;
+ if (tm_date.tm_mday > 28 && tm_date.tm_year % 4)
+ return false;
+ break;
+ default:
+ if (tm_date.tm_mday > 30)
+ return false;
+ }
+ return true;
+ }
+
+ template<class charT, class Traits>
+ friend basic_istream<charT, Traits>&
+ operator>> (basic_istream<charT, Traits>& is, date& dat);
+
+ template<class charT, class Traits>
+ friend basic_ostream<charT, Traits>&
+ operator<< (basic_ostream<charT, Traits>& os, const date& dat);
+};
+// }}}
+
+// p. 163 {{{
+// The extractor:
+template <class charT, class Traits>
+basic_istream<charT, Traits>&
+operator >>(basic_istream<charT, Traits>& is, date& dat)
+{
+ if (!is.good() )
+ return is;
+
+ ios_base::iostate err = ios_base::goodbit;
+ try
+ {
+ typename basic_istream<charT, Traits>::sentry ipfx(is);
+ if ( ipfx )
+ {
+ use_facet<time_get<charT, istreambuf_iterator<charT, Traits> > >
+ (is.getloc()).get_date
+ (is, istreambuf_iterator<charT, Traits>(), is, err, &dat.tm_date);
+ // check for the date's validity
+ if (!dat)
+ err |= ios_base::failbit;
+ }
+ }
+ catch(bad_alloc&)
+ {
+ err |= ios_base::badbit;
+ ios_base::iostate exception_mask = is.exceptions();
+
+ if ( (exception_mask & ios_base::failbit)
+ && !(exception_mask & ios_base::badbit ) )
+ {
+ is.setstate(err);
+ }
+ else if ( exception_mask& ios_base::badbit)
+ {
+ try {is.setstate(err); }
+ catch (ios_base::failure& ) { }
+ throw;
+ }
+ }
+ catch(...)
+ {
+ err |= ios_base::failbit;
+ ios_base::iostate exception_mask = is.exceptions();
+// }}}
+// p. 164 {{{
+ if ( (exception_mask & ios_base::badbit)
+ && (err & ios_base::badbit ) )
+ {
+ is.setstate(err);
+ }
+ else if(exception_mask & ios_base::failbit)
+ {
+ try {is.setstate(err); }
+ catch( ios_base::failure& ) { }
+ throw;
+ }
+ }
+
+ if (err)
+ is.setstate(err);
+ return is;
+}
+
+// The inserter
+template<class charT, class Traits>
+basic_ostream<charT, Traits>&
+operator<< (basic_ostream<charT, Traits>& os, const date& dat)
+{
+ if (!os.good() )
+ return os;
+
+ ios_base::iostate err = ios_base::goodbit;
+ try
+ {
+ typename basic_ostream<charT, Traits>::sentry opfx(os);
+ if (opfx)
+ {
+ basic_stringbuf<charT, Traits> sb;
+
+ if (use_facet<time_put<charT, ostreambuf_iterator<charT, Traits> > >
+ (os.getloc()).put(&sb,os,os.fill(),&dat.tm_date,'x').failed()
+ )
+ // set the stream state after checking the return iterator
+ err = ios_base::badbit;
+
+ // field width adjustment
+ if ( err == ios_base::goodbit )
+ {
+ basic_string<charT, Traits> s = sb.str();
+ streamsize charToPad = static_cast<streamsize>(os.width() - s.length());
+ ostreambuf_iterator<charT, Traits> sink(os);
+// }}}
+// p. 165 {{{
+ if ( charToPad <= 0 )
+ {
+ sink = copy(s.begin(), s.end(), sink);
+ }
+ else
+ {
+ if (os.flags() & ios_base::left)
+ {
+ sink = copy(s.begin(), s.end(), sink);
+ fill_n(sink, charToPad, os.fill() );
+ }
+ else
+ {
+ fill_n(sink, charToPad, os.fill() );
+ sink = copy(s.begin(), s.end(), sink);
+
+ }
+ }
+
+ if (sink.failed() )
+ err = ios_base::failbit;
+ }
+ os.width(0);
+ }
+ }
+
+ // error handling
+ catch (bad_alloc&)
+ {
+ err |= ios_base::badbit;
+ ios_base::iostate exception_mask = os.exceptions();
+
+ if ( ( exception_mask & ios_base::failbit)
+ && !( exception_mask & ios_base::badbit ) )
+ {
+ os.setstate(err);
+ }
+ else if (exception_mask & ios_base::badbit)
+ {
+ try { os.setstate(err); }
+ catch( ios_base::failure& ) { }
+ throw;
+ }
+ }
+
+ catch(...)
+ {
+ err |= ios_base::failbit;
+ ios_base::iostate exception_mask = os.exceptions();
+// }}}
+// p. 166 {{{
+ if( (exception_mask & ios_base::badbit)
+ && (err & ios_base::badbit) )
+ {
+ os.setstate(err);
+ }
+ else if ( exception_mask & ios_base::failbit )
+ {
+ try { os.setstate (err ); }
+ catch( ios_base::failure& ) { }
+ throw;
+ }
+ }
+
+ if (err)
+ os.setstate( err );
+ return os;
+}
+// }}}
+
+#endif
269 iostreams/examples/inc/date_170.h
@@ -0,0 +1,269 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "date_170.h"
+*/
+
+#ifndef DATE_H
+#define DATE_H
+
+// p. 173 {{{
+class date {
+public:
+ date(int d, int m, int y);
+ date(const tm& t);
+ date()
+ // p. 162 {{{
+ {
+ time_t ltime;
+ tm* tm_ptr;
+ time(&ltime); // get system time
+ tm_ptr= localtime(&ltime); // convert to tm struct
+ if ( tm_ptr != NULL )
+ {
+ tm_date = *tm_ptr;
+ ok = true;
+ }
+ else // is date before 1-1-1970
+ ok = false;
+ }
+ bool operator !()
+ {
+ ok = (valid() && (mktime(&tm_date) != time_t(-1) ) ) ? true : false;
+ return !ok;
+ }
+ // }}}
+
+ template <class charT, class Traits>
+ ios_base::iostate get_from(basic_istream<charT, Traits>& is)
+ {
+ ios_base::iostate err = 0;
+ use_facet<time_get<charT, istreambuf_iterator<charT, Traits> > > (is.getloc()).get_date
+ (is, istreambuf_iterator<char, char_traits<char> > (), is, err, &tm_date);
+ if (!(*this) || err)
+ return ios_base::failbit;
+ else
+ return ios_base::goodbit;
+ }
+
+ template <class charT, class Traits>
+ ios_base::iostate print_on(basic_ostream<charT, Traits>& os) const
+ {
+ const char * const patt = "%x";
+ char fmt[3];
+ basic_stringbuf<charT, Traits> sb;
+ ios_base::iostate err = 0;
+
+ use_facet<ctype<charT> > (os.getloc()).widen(patt, patt+2, fmt);
+ if ( use_facet<time_put<charT, ostreambuf_iterator<charT, Traits> > >
+ (os.getloc()).put(&sb, os, os.fill(), &tm_date, fmt, (fmt+2)).failed()
+ )
+ err = ios_base::failbit;
+ if ( err == ios_base::goodbit )
+ {
+ basic_string<charT, Traits> s = sb.str();
+ streamsize charToPad = static_cast<streamsize> (os.width() - s.length());
+ ostreambuf_iterator<charT, Traits> sink(os);
+ if (charToPad <= 0)
+ sink = copy(s.begin(), s.end(), sink);
+// }}}
+// p. 174 {{{
+ else
+ {
+ if ( os.flags() & ios_base::left )
+ {
+ sink = copy(s.begin(), s.end(), sink);
+ fill_n(sink, charToPad, os.fill() );
+ }
+ else
+ {
+ fill_n(sink, charToPad, os.fill());
+ sink = copy(s.begin(), s.end(), sink);
+ }
+ }
+ if (sink.failed() )
+ err = ios_base::failbit;
+ }
+ return err;
+ }
+private:
+ tm tm_date;
+ bool ok;
+// p. 162
+ bool valid() // check for sensible date; rejects nonsense like 32.12.1999
+ // The leap - year rule has been simplifies. For example, 1900 wasn't
+ // a leap year and 2100 won't be.
+ {
+ if (tm_date.tm_mon < 0 || tm_date.tm_mon > 11)
+ return false;
+ if (tm_date.tm_mday < 1)
+ switch ( tm_date.tm_mon )
+ {
+ case 0 :
+ case 2 :
+ case 4 :
+ case 6 :
+ case 7 :
+ case 9 :
+ case 11:
+ if (tm_date.tm_mday > 31)
+ return false;
+ break;
+ case 1:
+ if (tm_date.tm_mday > 29)
+ return false;
+ if (tm_date.tm_mday > 28 && tm_date.tm_year % 4)
+ return false;
+ break;
+ default:
+ if (tm_date.tm_mday > 30)
+ return false;
+ }
+ return true;
+ }
+// }}}
+};
+// }}}
+
+// p. 170
+// The extractor:
+template <class charT, class Traits, class Argument>
+basic_istream<charT, Traits>& g_extractor
+ (basic_istream<charT, Traits>& is, Argument& arg)
+{
+// }}}
+// p. 171 {{{
+ ios_base::iostate err = ios_base::goodbit;
+ try
+ {
+ typename basic_istream<charT, Traits>::sentry ipfx(is);
+ if ( ipfx )
+ err = arg.get_from(is);
+ }
+ catch(bad_alloc&)
+ {
+ err |= ios_base::badbit;
+ ios_base::iostate exception_mask = is.exceptions();
+ if( (exception_mask & ios_base::failbit)
+ && !(exception_mask & ios_base::badbit ))
+ {
+ is.setstate(err);
+ }
+ else if ( exception_mask & ios_base::badbit )
+ {
+ try { is.setstate(err); }
+ catch (ios_base::failure& ) {}
+ throw;
+ }
+ }
+ catch(...)
+ {
+ err |= ios_base::failbit;
+ ios_base::iostate exception_mask = is.exceptions();
+ if ( (exception_mask & ios_base::badbit)
+ && (err & ios_base::badbit) )
+ {
+ is.setstate(err);
+ }
+ else if ( exception_mask & ios_base::failbit )
+ {
+ try { is.setstate(err); }
+ catch( ios_base::failure& ) { }
+ throw;
+ }
+ }
+
+ if ( err ) is.setstate( err );
+ return is;
+}
+
+// The inserter:
+template <class charT, class Traits, class Argument>
+basic_ostream<charT, Traits>& g_inserter
+ (basic_ostream<charT, Traits>& os, const Argument& arg)
+{
+ ios_base::iostate err = 0;
+ try
+ {
+ typename basic_ostream<charT, Traits>::sentry opfx(os);
+ if ( opfx )
+ {
+ err = arg.print_on(os);
+ os.width(0);
+ }
+ }
+// }}}
+// p. 172 {{{
+ catch(bad_alloc&)
+ {
+ err |= ios_base::badbit;
+ ios_base::iostate exception_mask = os.exceptions();
+ if ( (exception_mask & ios_base::failbit)
+ &&! (exception_mask & ios_base::badbit) )
+ {
+ os.setstate (err);
+ }
+ else if (exception_mask & ios_base::badbit)
+ {
+ try { os.setstate( err ); }
+ catch (ios_base::failure& ) { }
+ throw;
+ }
+ }
+ catch(...)
+ {
+ err |= ios_base::failbit;
+ ios_base::iostate exception_mask = os.exceptions();
+ if ( (exception_mask & ios_base::badbit )
+ && (err & ios_base::badbit))
+ {
+ os.setstate( err );
+ }
+ else if ( exception_mask & ios_base::failbit )
+ {
+ try { os.setstate( err ); }
+ catch( ios_base::failure& ) { }
+ throw;
+ }
+ }
+ if (err )
+ os.setstate( err );
+ return os;
+}
+// }}}
+
+// p. 170 {{{
+template <class charT, class Traits>
+basic_istream<charT, Traits>& operator >>
+ (basic_istream<charT, Traits> &is, date& arg)
+{
+ if (!is.good())
+ return is;
+ return g_extractor(is, arg);
+}
+
+template <class charT, class Traits>
+basic_ostream<charT, Traits>& operator <<
+ (basic_ostream<charT, Traits>& os, const date& arg)
+{
+ if (!os.good() )
+ return os;
+ return g_inserter(os, arg);
+}
+// }}}
+
+#endif
248 iostreams/examples/inc/date_196.h
@@ -0,0 +1,248 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "data_196.h"
+*/
+
+#ifndef DATE_H
+#define DATE_H
+
+#include "getidx_195.h"
+#include "defaultpatt_197.h"
+
+// p. 161 {{{
+class date {
+public:
+ date(int d, int m, int y)
+ {
+ tm_date.tm_mday = d;tm_date.tm_mon = m-1; tm_date.tm_year = y-1900;
+ tm_date.tm_sec = tm_date.tm_min = tm_date.tm_hour = 0;
+ tm_date.tm_wday = tm_date.tm_yday = 0;
+ tm_date.tm_isdst = 0;
+ ok = (valid() & (mktime(&tm_date) != time_t(-1) ) ) ? true : false;
+ }
+ date(const tm& t) : tm_date(t)
+ {
+ ok = (mktime(&tm_date) != time_t(-1) ) ? true : false;
+ }
+// }}}
+// p. 160 {{{
+ date()
+ {
+ time_t ltime;
+ time(&ltime);
+ tm_date = *localtime(&ltime);
+ }
+// }}}
+// p. 196 {{{
+ template <class charT, class Traits>
+ ios_base::iostate print_on(basic_ostream<charT, Traits>& os) const
+ {
+ void *p;
+ basic_string<charT> patt;
+
+ if (( p = os.pword(getIdx() ) ) != 0)
+ patt = *(static_cast<basic_string<charT>* >(p) );
+ else
+ patt = defaultPatt(os);
+
+ if (os.good() &&
+ ! use_facet<time_put<charT, ostreambuf_iterator<charT, Traits> > >
+ (os.getloc()).put(os, os, os.fill(), &tm_date, patt.c_str()
+ ,patt.c_str()+ patt.length()).failed()
+ )
+ return ios_base::goodbit;
+// }}}
+// p. 197 {{{
+ else
+ return ios_base::failbit;
+ }
+// }}}
+// p. 162 {{{
+private:
+ tm tm_date;
+ bool ok;
+
+ bool valid() // check for sensible date; rejects nonsense like 32.12.1999
+ // The leap - year rule has been simplifies. For example, 1900 wasn't
+ // a leap year and 2100 won't be.
+ {
+ if (tm_date.tm_mon < 0 || tm_date.tm_mon > 11)
+ return false;
+ if (tm_date.tm_mday < 1)
+ switch ( tm_date.tm_mon )
+ {
+ case 0 : // !!! sequence was sorted in example
+ case 2 :
+ case 4 :
+ case 6 :
+ case 7 :
+ case 9 :
+ case 11:
+ if (tm_date.tm_mday > 31)
+ return false;
+ break;
+ case 1:
+ if (tm_date.tm_mday > 29)
+ return false;
+ if (tm_date.tm_mday > 28 && tm_date.tm_year % 4)
+ return false;
+ break;
+ default:
+ if (tm_date.tm_mday > 30)
+ return false;
+ }
+ return true;
+ }
+
+ template<class charT, class Traits>
+ friend basic_istream<charT, Traits>&
+ operator >>(basic_istream<charT, Traits>& is, date& dat);
+
+ template<class charT, class Traits>
+ friend basic_ostream<charT, Traits>&
+ operator<< (basic_ostream<charT, Traits>& os, const date& dat);
+};
+// }}}
+// p. 170 {{{
+// The extractor:
+template <class charT, class Traits, class Argument>
+basic_istream<charT, Traits>& g_extractor
+ (basic_istream<charT, Traits>& is, Argument& arg)
+{
+// }}}
+// p. 171 {{{
+ ios_base::iostate err = ios_base::goodbit;
+ try
+ {
+ typename basic_istream<charT, Traits>::sentry ipfx(is);
+ if ( ipfx )
+ err = arg.get_from(is);
+ }
+ catch(bad_alloc&)
+ {
+ err |= ios_base::badbit;
+ ios_base::iostate exception_mask = is.exceptions();
+ if( (exception_mask & ios_base::failbit)
+ && !(exception_mask & ios_base::badbit ))
+ {
+ is.setstate(err);
+ }
+ else if ( exception_mask & ios_base::badbit )
+ {
+ try { is.setstate(err); }
+ catch (ios_base::failure& ) {}
+ throw;
+ }
+ }
+ catch(...)
+ {
+ err |= ios_base::failbit;
+ ios_base::iostate exception_mask = is.exceptions();
+ if ( (exception_mask & ios_base::badbit)
+ && (err & ios_base::badbit) )
+ {
+ is.setstate(err);
+ }
+ else if ( exception_mask & ios_base::failbit )
+ {
+ try { is.setstate(err); }
+ catch( ios_base::failure& ) { }
+ throw;
+ }
+ }
+
+ if ( err ) is.setstate( err );
+ return is;
+}
+
+// The inserter:
+template <class charT, class Traits, class Argument>
+basic_ostream<charT, Traits>& g_inserter
+ (basic_ostream<charT, Traits>& os, const Argument& arg)
+{
+ ios_base::iostate err = 0;
+ try
+ {
+ typename basic_ostream<charT, Traits>::sentry opfx(os);
+ if ( opfx )
+ {
+ err = arg.print_on(os);
+ os.width(0);
+ }
+ }
+// }}}
+// p. 172 {{{
+ catch(bad_alloc&)
+ {
+ err |= ios_base::badbit;
+ ios_base::iostate exception_mask = os.exceptions();
+ if ( (exception_mask & ios_base::failbit)
+ &&! (exception_mask & ios_base::badbit) )
+ {
+ os.setstate (err);
+ }
+ else if (exception_mask & ios_base::badbit)
+ {
+ try { os.setstate( err ); }
+ catch (ios_base::failure& ) { }
+ throw;
+ }
+ }
+ catch(...)
+ {
+ err |= ios_base::failbit;
+ ios_base::iostate exception_mask = os.exceptions();
+ if ( (exception_mask & ios_base::badbit )
+ && (err & ios_base::badbit))
+ {
+ os.setstate( err );
+ }
+ else if ( exception_mask & ios_base::failbit )
+ {
+ try { os.setstate( err ); }
+ catch( ios_base::failure& ) { }
+ throw;
+ }
+ }
+ if (err )
+ os.setstate( err );
+ return os;
+}
+// }}}
+// p. 170 {{{
+template <class charT, class Traits>
+basic_istream<charT, Traits>& operator >>
+ (basic_istream<charT, Traits> &is, date& arg)
+{
+ if (!is.good())
+ return is;
+ return g_extractor(is, arg);
+}
+
+template <class charT, class Traits>
+basic_ostream<charT, Traits>& operator <<
+ (basic_ostream<charT, Traits>& os, const date& arg)
+{
+ if (!os.good() )
+ return os;
+ return g_inserter(os, arg);
+}
+// }}}
+
+
+#endif
245 iostreams/examples/inc/date_220.h
@@ -0,0 +1,245 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "date_220.h"
+*/
+
+#ifndef DATE_H
+#define DATE_H
+
+// p. 161 {{{
+class date {
+public:
+ date(int d, int m, int y)
+ {
+ tm_date.tm_mday = d;tm_date.tm_mon = m-1; tm_date.tm_year = y-1900;
+ tm_date.tm_sec = tm_date.tm_min = tm_date.tm_hour = 0;
+ tm_date.tm_wday = tm_date.tm_yday = 0;
+ tm_date.tm_isdst = 0;
+ ok = (valid() & (mktime(&tm_date) != time_t(-1) ) ) ? true : false;
+ }
+ date(const tm& t) : tm_date(t)
+ {
+ ok = (mktime(&tm_date) != time_t(-1) ) ? true : false;
+ }
+// }}}
+// p. 160 {{{
+ date()
+ {
+ time_t ltime;
+ time(&ltime);
+ tm_date = *localtime(&ltime);
+ }
+// }}}
+// p. 220 {{{
+ template <class charT, class Traits>
+ ios_base::iostate print_on(basic_ostream<charT, Traits>& os) const
+ {
+ basic_string<charT> formatString;
+ datefmt<charT>* p;
+
+ if ((p = dynamic_cast<datefmt<charT>*>(&os)) == 0)
+ formatString = defaultPatt(os);
+ else
+ formatString = p->fmt();
+
+ if (use_facet<time_put<charT, ostreambuf_iterator<charT, Traits> > >
+ (os.getloc()).put(os, os, os.fill(), &tm_date, formatString.c_str(),
+ formatString.c_str() + formatString.length()
+ ).failed()
+ )
+ return ios_base::failbit;
+// }}}
+// p. 221 {{{
+ else
+ return ios_base::goodbit;
+ }
+// }}}
+// p. 162 {{{
+private:
+ tm tm_date;
+ bool ok;
+
+ bool valid() // check for sensible date; rejects nonsense like 32.12.1999
+ // The leap - year rule has been simplifies. For example, 1900 wasn't
+ // a leap year and 2100 won't be.
+ {
+ if (tm_date.tm_mon < 0 || tm_date.tm_mon > 11)
+ return false;
+ if (tm_date.tm_mday < 1)
+ switch ( tm_date.tm_mon )
+ {
+ case 0 : // !!! sequence was sorted in example
+ case 2 :
+ case 4 :
+ case 6 :
+ case 7 :
+ case 9 :
+ case 11:
+ if (tm_date.tm_mday > 31)
+ return false;
+ break;
+ case 1:
+ if (tm_date.tm_mday > 29)
+ return false;
+ if (tm_date.tm_mday > 28 && tm_date.tm_year % 4)
+ return false;
+ break;
+ default:
+ if (tm_date.tm_mday > 30)
+ return false;
+ }
+ return true;
+ }
+
+ template<class charT, class Traits>
+ friend basic_istream<charT, Traits>&
+ operator >>(basic_istream<charT, Traits>& is, date& dat);
+
+ template<class charT, class Traits>
+ friend basic_ostream<charT, Traits>&
+ operator<< (basic_ostream<charT, Traits>& os, const date& dat);
+};
+// }}}
+
+// p. 170 {{{
+// The extractor:
+template <class charT, class Traits, class Argument>
+basic_istream<charT, Traits>& g_extractor
+ (basic_istream<charT, Traits>& is, Argument& arg)
+{
+// }}}
+// p. 171 {{{
+ ios_base::iostate err = ios_base::goodbit;
+ try
+ {
+ typename basic_istream<charT, Traits>::sentry ipfx(is);
+ if ( ipfx )
+ err = arg.get_from(is);
+ }
+ catch(bad_alloc&)
+ {
+ err |= ios_base::badbit;
+ ios_base::iostate exception_mask = is.exceptions();
+ if( (exception_mask & ios_base::failbit)
+ && !(exception_mask & ios_base::badbit ))
+ {
+ is.setstate(err);
+ }
+ else if ( exception_mask & ios_base::badbit )
+ {
+ try { is.setstate(err); }
+ catch (ios_base::failure& ) {}
+ throw;
+ }
+ }
+ catch(...)
+ {
+ err |= ios_base::failbit;
+ ios_base::iostate exception_mask = is.exceptions();
+ if ( (exception_mask & ios_base::badbit)
+ && (err & ios_base::badbit) )
+ {
+ is.setstate(err);
+ }
+ else if ( exception_mask & ios_base::failbit )
+ {
+ try { is.setstate(err); }
+ catch( ios_base::failure& ) { }
+ throw;
+ }
+ }
+
+ if ( err ) is.setstate( err );
+ return is;
+}
+
+// The inserter:
+template <class charT, class Traits, class Argument>
+basic_ostream<charT, Traits>& g_inserter
+ (basic_ostream<charT, Traits>& os, const Argument& arg)
+{
+ ios_base::iostate err = 0;
+ try
+ {
+ typename basic_ostream<charT, Traits>::sentry opfx(os);
+ if ( opfx )
+ {
+ err = arg.print_on(os);
+ os.width(0);
+ }
+ }
+// }}}
+// p. 172 {{{
+ catch(bad_alloc&)
+ {
+ err |= ios_base::badbit;
+ ios_base::iostate exception_mask = os.exceptions();
+ if ( (exception_mask & ios_base::failbit)
+ &&! (exception_mask & ios_base::badbit) )
+ {
+ os.setstate (err);
+ }
+ else if (exception_mask & ios_base::badbit)
+ {
+ try { os.setstate( err ); }
+ catch (ios_base::failure& ) { }
+ throw;
+ }
+ }
+ catch(...)
+ {
+ err |= ios_base::failbit;
+ ios_base::iostate exception_mask = os.exceptions();
+ if ( (exception_mask & ios_base::badbit )
+ && (err & ios_base::badbit))
+ {
+ os.setstate( err );
+ }
+ else if ( exception_mask & ios_base::failbit )
+ {
+ try { os.setstate( err ); }
+ catch( ios_base::failure& ) { }
+ throw;
+ }
+ }
+ if (err )
+ os.setstate( err );
+ return os;
+}
+// }}}
+// p. 170 {{{
+template <class charT, class Traits>
+basic_istream<charT, Traits>& operator >>
+ (basic_istream<charT, Traits> &is, date& arg)
+{
+ if (!is.good())
+ return is;
+ return g_extractor(is, arg);
+}
+
+template <class charT, class Traits>
+basic_ostream<charT, Traits>& operator <<
+ (basic_ostream<charT, Traits>& os, const date& arg)
+{
+ if (!os.good() )
+ return os;
+ return g_inserter(os, arg);
+}
+// }}}
+
+#endif
47 iostreams/examples/inc/datefmt_210.h
@@ -0,0 +1,47 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "datefmt_210.h"
+*/
+
+#ifndef DATEFMT_H
+#define DATEFMT_H
+
+// p. 210 {{{
+template <class charT>
+class datefmt
+{
+ public:
+ datefmt(const charT* f) : myFmt(f) { }
+
+ virtual void fmt(const charT* f)
+ {
+ myFmt = f;
+ }
+
+ virtual const basic_string<charT>& fmt() const
+ {
+ return myFmt;
+ }
+
+ virtual ~datefmt() {}
+ private:
+ basic_string<charT> myFmt;
+};
+// }}}
+
+#endif
37 iostreams/examples/inc/defaultpatt_197.h
@@ -0,0 +1,37 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "defaultpatt_197.h"
+*/
+
+#ifndef DEFAULTPATT_H
+#define DEFAULTPATT_H
+
+// p. 197 {{{
+template <class charT, class Traits>
+const basic_string<charT> defaultPatt(const basic_ostream<charT, Traits>& str)
+{
+ static char const * const c_helper = "%x";
+ static charT helper[3] = {charT('\0'), charT('\0'), charT('\0') };
+
+ use_facet<ctype<charT> > (str.getloc()).widen(c_helper, c_helper+2, helper);
+
+ return helper;
+}
+// }}}
+
+#endif
57 iostreams/examples/inc/german_address_put_337.h
@@ -0,0 +1,57 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "german_address_put_337.h"
+*/
+
+#ifndef GERMAN_ADDRESS_PUT_H
+#define GERMAN_ADDRESS_PUT_H
+
+// p. 337 {{{
+template <class charT, class OutIter = ostreambuf_iterator<charT> >
+class German_address_put : public address_put<charT, OutIter>
+{
+ public:
+ German_address_put(size_t refs = 0) : address_put<charT, OutIter>(refs)
+ { }
+// }}}
+// p. 338 {{{
+ protected:
+ void do_put(OutIter oi,
+ const String& firstname, const String& secname,
+ const String& lastname,
+ const String& address1, const String& address2,
+ const String& town, const String& zipcode,
+ const String& state,
+ const String& country, const String& cntrycode) const
+ {
+ String s(firstname);
+ s.append(" ").append(lastname).append("\n");
+ s.append(address1).append("\n");
+ if (!address2.empty())
+ s.append(address2).append("\n");
+ s.append("\n");
+ if (!cntrycode.empty())
+ s.append(cntrycode).append("-");
+ s.append(zipcode).append(" ").append(town).append("\n");
+
+ put_string(oi, s);
+ }
+};
+// }}}
+
+#endif
33 iostreams/examples/inc/getidx_195.h
@@ -0,0 +1,33 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "getidx_195.h"
+*/
+
+#ifndef GETIDX_H
+#define GETIDX_H
+
+// p.195 {{{
+int getIdx()
+{
+ static const int myIdx = ios_base::xalloc();
+
+ return myIdx;
+}
+// }}}
+
+#endif
113 iostreams/examples/inc/inbuf_239.h
@@ -0,0 +1,113 @@
+/*
+author: "Klaus Wittlich" <Klaus_Wittlich@sae.de>
+
+Based on source code published in the book "Standard C++ IOStreams
+and Locales" by Angelika Langer & Klaus Kreft, Copyright (c) 2000 by
+Addison Wesley Longman, Inc.
+
+Permission to use, copy, and modify this software for any non-profit
+purpose is hereby granted without fee. Neither the author of this
+source code, Klaus Wittlich, nor the authors of the above mentioned
+book, Angelika Langer and Klaus Kreft, nor the publisher, Addison
+Wesley Longman, Inc., make any representations about the suitability of this
+software for any purpose. It is provided "as is" without express or
+implied warranty.
+*/
+
+/*
+#include "inbuf_239.h"
+*/
+
+#ifndef INBUF_H
+#define INBUF_H
+
+// p. 239 {{{
+template <class charT, class Traits>
+class inbuf : public basic_streambuf<charT, Traits>
+{
+ public:
+ inbuf();
+
+ protected:
+ int_type underflow();
+ int_type pbackfail(int_type c);
+
+ private:
+ static const streamsize bufSize = 16;
+ static const streamsize pbSize = 4;
+ char_type buffer[bufSize];
+// }}}
+// p. 240 {{{
+ int buffer_in();
+
+ // prohibit copying and assignment
+ inbuf(const inbuf&);
+ inbuf& operator=(const inbuf&);
+};
+
+