#include <coherence/util/Describable.hpp>
Inherits Object.
Inherited by AbstractMap, EventObject, MapEventFilter, and AbstractProcessor.
Subclasses of Describable should implement the getDescription() method by outputing a delimited list of name-value pair(s) representing the class' state. Further subclasses should override the getDescription() by first delegating to the parent class' implementation and then outputing their own state.
For example, consider a class hiearchy consisting of parent class A and child class B. Class A should implement getDescription() as follows:
String::View A::getDescription() const { return COH_TO_STRING(super::getDescription() << "Member1=" << m_hMember1 << ... << ", MemberN=" << m_hMemberN); }Class B would then override this method as follows:
String::View B::getDescription() const { return COH_TO_STRING(super::getDescription() << "MemberN+1=" << m_hMemberN1 << ... ); }
Public Types | |
typedef spec::Handle | Handle |
Describable Handle definition. | |
typedef spec::View | View |
Describable View definition. | |
typedef spec::Holder | Holder |
Describable Holder definition. | |
Public Member Functions | |
virtual String::View | getDescription () const |
Return a human-readable description of the state of this class in the form of a delimited list of name-value pairs. | |
virtual TypedHandle < const String > | toString () const |
Output a human-readable description of this Object to the given stream. Note that when overriding this method the return type must be TypedHandle<const String> rather then String::View. These two types are assignment compatible but not equivalent and declaring the override with String::View will not be a compatible override. coherence::lang::operator<<(std::ostream, Object::View) is defined and will call into the toString method, to output Objects. If a managed String object is desired, the COH_TO_STRING macro can be used to build up a String from streamable contents and is generally how toString() will be implemented.
Object::View vKey = ... Object::View vValue = ... std::cout << vKey << " = " << vValue << std::endl; String::View vs = COH_TO_STRING(vKey << " = " << vValue); The COH_TO_STRING macro is also the most common way to implement the toString method. For example:
virtual TypedHandle<const String> Person::toString() const { return COH_TO_STRING("Name: " << f_sName << " SSN: " << f_nSSN); }
|
virtual String::View getDescription | ( | ) | const [virtual] |
Return a human-readable description of the state of this class in the form of a delimited list of name-value pairs.
The default implementation returns an empty string
Reimplemented in CacheEvent, EventObject, CacheEventFilter, MapEventFilter, MapEvent, MapListenerSupport::FilterEvent, NumberIncrementor, and NumberMultiplier.