Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

Class.h

00001 /*
00002  * Class.h -- class interface for class identification
00003  * Copyright (C) 2002  Eric Lemings <elemings@users.sourceforge.net>
00004  *
00005  * This software is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This software is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this software; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00018  * 02111-1307, USA
00019  *
00020  * RCS: $Id: Class.h,v 1.2 2003/04/18 01:41:07 elemings Exp $
00021  */
00022 
00023 #ifdef __cplusplus
00024 
00025 #  ifndef OGS_SUPPORT_CLASS_H
00026 #    define OGS_SUPPORT_CLASS_H
00027 
00028 #    include <string>
00029 #    include <typeinfo>
00030 
00031 #    include <ogs/support/Namespace.h>
00032 #    include <ogs/support/Object.h>
00033 
00034 OGS_BEGIN_SUPPORT_NAMESPACE
00035 
00041 class Class {
00042   public:
00043     template <class C>
00044     static Class getClass ();
00045 
00046     bool operator== (const Class& cls) const;
00047     bool operator!= (const Class& cls) const;
00048     std::string getName () const;
00049 
00050   private:
00051     const std::type_info& typeInfo;
00052 
00053     Class ();
00054     Class (const std::type_info& typeInfo);
00055 
00056     friend Class Object::getClass () const;
00057 };
00058 
00065 template <class C>
00066 inline Class Class::getClass () {
00067   Class c (typeid (C));
00068   return (c);
00069 }
00070 
00077 inline bool
00078 Class::operator== (const Class& cls) const {
00079   return (typeInfo == cls.typeInfo);
00080 }
00081 
00089 inline bool
00090 Class::operator!= (const Class& cls) const {
00091   return (typeInfo != cls.typeInfo);
00092 }
00093 
00099 inline std::string Class::getName () const {
00100   return (std::string (typeInfo.name ()));
00101 }
00102 
00108 inline Class
00109 Object::getClass () const {
00110   return (Class (typeid (*this)));
00111 }
00112 
00113 OGS_END_SUPPORT_NAMESPACE
00114 
00115 #  endif /* !defined OGS_SUPPORT_CLASS_H */
00116 
00117 #endif /* defined __cplusplus */
00118 

Generated on Sun Apr 20 03:36:15 2003 for Open Gaming System (OGS) by doxygen1.3