[Mockpp-commits] mockpp/mockpp/docs/en dev_helper.docbook,1.8,1.9
Brought to you by:
ewald-arnold
From: Ewald A. <ewa...@us...> - 2005-07-24 18:08:13
|
Update of /cvsroot/mockpp/mockpp/mockpp/docs/en In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11090/mockpp/docs/en Modified Files: dev_helper.docbook Log Message: better ostream reuse Index: dev_helper.docbook =================================================================== RCS file: /cvsroot/mockpp/mockpp/mockpp/docs/en/dev_helper.docbook,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- dev_helper.docbook 30 Apr 2005 21:14:41 -0000 1.8 +++ dev_helper.docbook 24 Jul 2005 18:08:01 -0000 1.9 @@ -118,6 +118,11 @@ <token>MOCKPP_ENABLE_DEFAULT_FORMATTER</token> before including the first &mockpp; header file.</para> +<para>It is also possible to reuse already existing streaming operators for +<classname>std::basic_ostream</classname>. The macros <token>MOCKPP_OSTREAMABLE</token> +and <token>MOCKPP_OWSTREAMABLE</token> create code for mockpp which uses the +standard streaming functions.</para> + <para>This collection of functions is inspired by the <classname>QString</classname> class which is part of the <productname>Qt</productname> framework by <ulink url="http://www.troll.no">Trolltech</ulink>.</para> @@ -153,9 +158,23 @@ return formatter; } + class AnotherPerson : public Person + { + // .. + }; + + std::ostream & operator<< (std::ostream &os, const AnotherPerson &pers) + { + os << pers.toString(); + return os; + } + + MOCKPP_OSTREAMABLE(AnotherPerson) <co id="std-shift-op-co" linkends="std-shift-op" /> + Person pers("Bob", 6); - String format = "%4 says: %3 plus %2 gives %1"; - format << "three" << "two" << "one" << pers; + AnotherPerson otherpers("Alice", 7); + String format = "%5 and %4 say: %3 plus %2 gives %1"; + format << "three" << "two" << "one" << pers << otherpers; std::cout << format << std::endl; </programlisting> @@ -171,7 +190,11 @@ <callout arearefs="shift-op-co" id="shift-op" > <para>Output the string representation of the object.</para> <para>The resulting output: - <computeroutput>Bob(6) says: one plus two gives three</computeroutput></para> + <computeroutput>Alice(7) and Bob(6) say: one plus two gives three</computeroutput></para> + </callout> + + <callout arearefs="std-shift-op-co" id="std-shift-op" > + <para>Output the string by using an existing standard streaming operator.</para> </callout> </calloutlist> |