#ifndef VERBOSE #define VERBOSE #include #include using namespace std; /********************* * Class Declaration * *********************/ template class Verbose; /********************************** * Global Operator << Declaration * **********************************/ template ostream &operator<<( ostream &, Verbose const & ); /**************************** * Class Member Declaration * ****************************/ template class Verbose { private: T value; int id; static int id_count; public: static const string PREFIX = " - "; Verbose( T const & = T() ); // Constructor Verbose( Verbose const & ); // Copy Constructor ~Verbose(); // Destructor Verbose &operator=( Verbose const & ); // Accessors T get() const; // Mutators void set( T const & ); friend ostream &operator << <> ( ostream &, Verbose const & ); }; /********************************** * Static Variable Initialization * **********************************/ template int Verbose::id_count = 0; /************************************* * Class Member Function Definitions * *************************************/ template Verbose::Verbose( T const &v ):value( v ), id( ++id_count ) { cout << PREFIX << *this << ": Calling the constructor" << endl; } template Verbose::Verbose( Verbose const & vcc ):value( vcc.value ), id( ++id_count ) { cout << PREFIX << *this << ": Calling the copy constructor" << endl; } template Verbose::~Verbose() { cout << PREFIX << *this << ": Calling the destructor" << endl; } template Verbose &Verbose::operator=( Verbose const & rhs ) { value = rhs.value; cout << PREFIX << "Assigning to " << *this << " the object " << rhs << endl; } template T Verbose::get() const { cout << PREFIX << *this << ": Getting the value " << value << endl; return value; } template void Verbose::set( T const & v ) { cout << PREFIX << *this << ": Setting the value from " << value << " to " << v << endl; value = v; } /********************************* * Global Operator << Definition * *********************************/ template ostream &operator<<( ostream & out, Verbose const &v ) { out << "#" << v.id << " (= " << (&v) << ")"; return out; } #endif