Chombo + EB  3.0
Printable.H
Go to the documentation of this file.
1 #ifdef CH_LANG_CC
2 /*
3  * _______ __
4  * / ___/ / ___ __ _ / / ___
5  * / /__/ _ \/ _ \/ V \/ _ \/ _ \
6  * \___/_//_/\___/_/_/_/_.__/\___/
7  * Please refer to Copyright.txt, in Chombo's root directory.
8  */
9 #endif
10 
11 #ifndef _PRINTABLE_H_
12 #define _PRINTABLE_H_
13 
14 #include <ostream>
15 #include "BaseNamespaceHeader.H"
16 
17 
18 /**
19  * This class encapsulates the concept of `printability',
20  * it automatically associates the output operator
21  * to a derived class via a virtual method
22  * to get around the problem of polymorphic operator being illegal in C++.
23  *
24  * Typical usage:
25  * (1) inherit from Printable
26  * Class A : Class Printable
27  * (2) define the method print() in A
28  * (3) use '<<' operator for objects of class A
29  *
30  * Variants of print can be added for different flavors.
31  */
32 class Printable
33 {
34 public:
35  virtual ~Printable()
36  {
37  }
38 
39  virtual void print(std::ostream& ) const = 0;
40 };
41 
42 inline std::ostream& operator<< (std::ostream& os, const Printable& p)
43 {
44  p.print(os);
45  return os;
46 }
47 
48 #include "BaseNamespaceFooter.H"
49 #endif
virtual ~Printable()
Definition: Printable.H:35
std::ostream & operator<<(std::ostream &os, const Printable &p)
Definition: Printable.H:42
virtual void print(std::ostream &) const =0
Definition: Printable.H:32