00001 /* 00002 * Describable.hpp 00003 * 00004 * Copyright (c) 2000, 2017, 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 00022 00023 COH_OPEN_NAMESPACE2(coherence,util) 00024 00025 00026 /** 00027 * Abstract Object extension that simplifies the implementation of toString() 00028 * for class hierarchies. 00029 * 00030 * Subclasses of Describable should implement the getDescription() method 00031 * by outputing a delimited list of name-value pair(s) representing the class' 00032 * state. Further subclasses should override the getDescription() 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 getDescription() as follows: 00038 * <pre> 00039 * String::View A::getDescription() const 00040 * { 00041 * return COH_TO_STRING(super::getDescription() << "Member1=" << m_hMember1 << ... << ", MemberN=" << m_hMemberN); 00042 * } 00043 * </pre> 00044 * Class B would then override this method as follows: 00045 * <pre> 00046 * String::View B::getDescription() const 00047 * { 00048 * return COH_TO_STRING(super::getDescription() << "MemberN+1=" << m_hMemberN1 << ... ); 00049 * } 00050 * </pre> 00051 * 00052 * @author jh 2008.02.13 00053 */ 00054 class COH_EXPORT Describable 00055 : public abstract_spec<Describable> 00056 { 00057 // ----- Describable interface ------------------------------------------ 00058 00059 public: 00060 /** 00061 * Return a human-readable description of the state of this class in 00062 * the form of a delimited list of name-value pairs. 00063 * 00064 * The default implementation returns an empty string 00065 */ 00066 virtual String::View getDescription() const; 00067 00068 00069 // ----- Object interface ----------------------------------------------- 00070 00071 public: 00072 /** 00073 * {@inheritDoc} 00074 */ 00075 virtual TypedHandle<const String> toString() const; 00076 }; 00077 00078 COH_CLOSE_NAMESPACE2 00079 00080 #endif // COH_DESCRIBABLE_HPP