00001 /* 00002 * Describable.hpp 00003 * 00004 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 00005 * 00006 * Oracle is a registered trademarks of Oracle Corporation and/or its 00007 * affiliates. 00008 * 00009 * This software is the confidential and proprietary information of Oracle 00010 * Corporation. You shall not disclose such confidential and proprietary 00011 * information and shall use it only in accordance with the terms of the 00012 * license agreement you entered into with Oracle. 00013 * 00014 * This notice may not be removed or altered. 00015 */ 00016 #ifndef COH_DESCRIBABLE_HPP 00017 #define COH_DESCRIBABLE_HPP 00018 00019 #include "coherence/lang.ns" 00020 00021 #include <ostream> 00022 00023 COH_OPEN_NAMESPACE2(coherence,util) 00024 00025 00026 /** 00027 * Abstract Object extension that simplifies the implementation of toStream() 00028 * for class hierarchies. 00029 * 00030 * Subclasses of Describable should implement the outputDescription() method 00031 * by outputing a delimited list of name-value pair(s) representing the class' 00032 * state. Further subclasses should override the outputDescription() by first 00033 * delegating to the parent class' implementation and then outputing their own 00034 * state. 00035 * 00036 * For example, consider a class hiearchy consisting of parent class A and 00037 * child class B. Class A should implement outputDescription() as follows: 00038 * <pre> 00039 * void A::outputDescription(std::ostream& out) const 00040 * { 00041 * super::outputDescription(out); // noop 00042 * out << "Member1=" << m_hMember1 << ... << ", MemberN=" << m_hMemberN; 00043 * } 00044 * </pre> 00045 * Class B would then override this method as follows: 00046 * <pre> 00047 * void B::outputDescription(std::ostream& out) const 00048 * { 00049 * super::outputDescription(out); 00050 * out << "MemberN+1=" << m_hMemberN1 << ... ; 00051 * } 00052 * </pre> 00053 * 00054 * @author jh 2008.02.13 00055 */ 00056 class COH_EXPORT Describable 00057 : public abstract_spec<Describable> 00058 { 00059 // ----- Describable interface ------------------------------------------ 00060 00061 public: 00062 /** 00063 * Output a human-readable description of the state of this class in 00064 * the form of a delimited list of name-value pairs. Generally it is 00065 * also advisable to start with a call to super::outputDescription(out) 00066 * 00067 * The default implementation does not output anything to the stream. 00068 * 00069 * @param out the stream to output the description to 00070 */ 00071 virtual void outputDescription(std::ostream& out) const; 00072 00073 /** 00074 * Return a human-readable description of the state of this class in 00075 * the form of a delimited list of name-value pairs. 00076 * 00077 * The default implementation delegates to outputDescription 00078 */ 00079 virtual String::View getDescription() const; 00080 00081 00082 // ----- Object interface ----------------------------------------------- 00083 00084 public: 00085 /** 00086 * {@inheritDoc} 00087 */ 00088 virtual void toStream(std::ostream& out) const; 00089 }; 00090 00091 COH_CLOSE_NAMESPACE2 00092 00093 #endif // COH_DESCRIBABLE_HPP