00001 #ifndef _LCORE_Protocol_H_ 00002 00003 /* 00004 * Copyright (C) 1991-9 Eric M. Hopper <hopper@omnifarious.mn.org> 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of the GNU Lesser General Public License as published 00008 * by the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, but 00012 * WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 * Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public 00017 * License along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 /* $Header: /home/hopper/src/cvs/C++/LCore/LCore/Protocol.h,v 1.7 2002/11/25 05:40:05 hopper Exp $ */ 00022 00023 // For a log, see ../ChangeLog 00024 // 00025 // Revision 1.2 1996/03/26 16:23:01 hopper 00026 // Moved ReferenceCounting class over from Container library. 00027 // Fixed up class numbering system so LCore uses a seperate library number 00028 // from the container library. 00029 // 00030 // Revision 1.1.1.1 1995/07/22 04:09:25 hopper 00031 // Imported sources 00032 // 00033 // Revision 0.2 1994/10/30 04:41:41 hopper 00034 // Moved various things into the new LCore library. 00035 // 00036 // Revision 0.1 1994/07/21 05:38:24 hopper 00037 // Genesis! 00038 // 00039 00040 #ifdef __GNUG__ 00041 # pragma interface 00042 #endif 00043 00044 #ifndef _LCORE_HopClTypes_H_ 00045 # include <LCore/HopClTypes.h> 00046 #endif 00047 00048 #define _LCORE_Protocol_H_ 00049 00050 namespace strmod { 00051 namespace lcore { 00052 00053 /** 00054 * \class Protocol Protocol.h LCore/Protocol.h 00055 * A base class for my own type identification system. 00056 * 00057 * This type identification system uses IDs that are assigned to a class by a 00058 * programmer so they remain constant. This means you can use the IDs for 00059 * type identification of data in persistent storage. 00060 */ 00061 class Protocol { 00062 public: 00063 static const LCore_ClassIdent identifier; 00064 00065 /** 00066 * Gets the identifier for the class the object actually is. 00067 * 00068 * This is an interface mistake I'll have to live with until I get the 00069 * gumption to make the pervasive changes to correct it. 00070 * 00071 * Originally the plan was to have this return different types (derived 00072 * from ClassIdent) in different classes. After I tried it a couple of 00073 * times, I realized what a bad idea that was, and am now left with this 00074 * interface. 00075 * 00076 * In order to achieve the original goal, a function that was virtual was 00077 * needed to return that actual identifier, and a non-virtual function was 00078 * needed to do the possible cast. I decided to have just one interface 00079 * for getting the ClassIdent, so I made the virtual function protected. 00080 * That's why this looks like it does. 00081 */ 00082 const ClassIdent &GetIdent() const { return(*i_GetIdent()); } 00083 /** 00084 * Asks if a class is of a particular type, or publicly derived from that 00085 * type. 00086 * 00087 * Overriden in every derived class (with a static identifier member) to 00088 * compare against the identifier, then call the AreYouA methods of all the 00089 * superclasses. 00090 * 00091 * @param cid Usually <class>::identifier for the class you want to ask if 00092 * the object is an instance of. 00093 */ 00094 virtual int AreYouA(const lcore::ClassIdent &cid) const { 00095 return(identifier == cid); 00096 } 00097 00098 //! Do nothing constructor for interface class with no member variables. 00099 Protocol() {} 00100 //! Do nothing (virtual) destructor for interface class with no member 00101 //! variables. 00102 virtual ~Protocol() {} 00103 00104 protected: 00105 /** 00106 * Returns the class identifier for the class the object actually is. 00107 * 00108 * Should <strong>always</strong> be overridden in any class that has a 00109 * static identifier member. 00110 */ 00111 inline virtual const ClassIdent *i_GetIdent() const; 00112 }; 00113 00114 inline const ClassIdent *Protocol::i_GetIdent() const 00115 { 00116 return(&identifier); 00117 } 00118 00119 } // namespace lcore 00120 } // namespace strmod 00121 00122 #endif
1.3-rc1