~ubuntu-branches/ubuntu/jaunty/aspectc++/jaunty

« back to all changes in this revision

Viewing changes to Puma/src/basics/Printable.h

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-07-07 14:41:02 UTC
  • mfrom: (1.1.3 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080707144102-lzml7t07f3sl00r5
Tags: 1.0pre4~svn.20080711-1
* new upstream snapshot.
* include all upstream documentation. Clarifying emails regarding
  licensing has been included into debian/copyright.
* reformat description following recomendations of
  http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Description
  (Closes: #480316)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
#ifndef __printable_h__
20
20
#define __printable_h__
21
21
 
 
22
/** \file
 
23
 *  Object printing. */
 
24
 
22
25
#include <iostream>
23
26
using namespace std;
24
27
 
25
28
namespace Puma {
26
29
 
27
30
 
 
31
/** \class Printable Printable.h Puma/Printable.h
 
32
 *  Provides that possibility for an object to be 
 
33
 *  used with output streams (std::ostream). Derived 
 
34
 *  classes have to implement method Printable::print(). 
 
35
 *
 
36
 *  Example:
 
37
 *  \code
 
38
 * class Name : public Puma::Printable {
 
39
 *   const char* the_name;
 
40
 * public:
 
41
 *   Name(const char* n) : the_name(n) {}
 
42
 *   void print(ostream &os) { 
 
43
 *     os << "[name: " << the_name << "]"; 
 
44
 *   }
 
45
 * };
 
46
 *
 
47
 * Name adam("adam");
 
48
 * std::cout << adam << std::endl;  // prints "[name: adam]\n"
 
49
 *  \endcode */
28
50
class Printable {
29
51
public:
 
52
  /** Destructor. */
30
53
  virtual ~Printable () {}
 
54
  /** Print something on the given output stream.
 
55
   *  \param os The output stream. */
31
56
  virtual void print (ostream &os) const = 0;
32
57
};
33
58
 
34
59
 
 
60
/** Output stream operator for Puma::Printable objects. 
 
61
 *  Calls method Printable::print() on the output stream.
 
62
 *  \param os The output stream. 
 
63
 *  \param object The object to print. */
35
64
inline ostream &operator << (ostream &os, const Printable &object) {
36
65
  object.print (os);
37
66
  return os;