[ogs-changes] dist/c++/ogs/support Class.h,1.2,1.3
Status: Alpha
Brought to you by:
elemings
From: <ele...@us...> - 2003-11-26 01:44:18
|
Update of /cvsroot/ogs/dist/c++/ogs/support In directory sc8-pr-cvs1:/tmp/cvs-serv18323 Modified Files: Class.h Log Message: Modeled after TypeInfo from Loki library. Index: Class.h =================================================================== RCS file: /cvsroot/ogs/dist/c++/ogs/support/Class.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Class.h 18 Apr 2003 01:41:07 -0000 1.2 --- Class.h 26 Nov 2003 01:44:11 -0000 1.3 *************** *** 1,4 **** /* ! * Class.h -- class interface for class identification * Copyright (C) 2002 Eric Lemings <ele...@us...> * --- 1,4 ---- /* ! * Class.h -- class interface for type information * Copyright (C) 2002 Eric Lemings <ele...@us...> * *************** *** 26,113 **** # define OGS_SUPPORT_CLASS_H ! # include <string> # include <typeinfo> # include <ogs/support/Namespace.h> - # include <ogs/support/Object.h> OGS_BEGIN_SUPPORT_NAMESPACE /** ! * An object representing the class of another object. This class is ! * actually a thin wrapper for the type_info class declared in the ! * @<typeinfo@> header of the standard C++ library. */ class Class { public: template <class C> static Class getClass (); - bool operator== (const Class& cls) const; - bool operator!= (const Class& cls) const; - std::string getName () const; - private: ! const std::type_info& typeInfo; ! Class (); ! Class (const std::type_info& typeInfo); ! friend Class Object::getClass () const; ! }; /** ! * Determine the class of a type. The type is given as a template ! * argument. * ! * @return Class of type. */ ! template <class C> ! inline Class Class::getClass () { ! Class c (typeid (C)); ! return (c); } /** ! * Determine if this object describes the same class as another object. * ! * @param cls Class to be compared to. ! * @return True if the two objects describe the same class. */ inline bool ! Class::operator== (const Class& cls) const { ! return (typeInfo == cls.typeInfo); } /** ! * Determine if this object does not describe the same class as another ! * object. * ! * @param cls Class to be compared to. ! * @return True if each object describes a different class. */ ! inline bool ! Class::operator!= (const Class& cls) const { ! return (typeInfo != cls.typeInfo); } /** ! * Determine the name of this class. * ! * @return Name of class. */ ! inline std::string Class::getName () const { ! return (std::string (typeInfo.name ())); } /** ! * Determine the class of this object. * ! * @return Class of this object. */ ! inline Class ! Object::getClass () const { ! return (Class (typeid (*this))); } OGS_END_SUPPORT_NAMESPACE --- 26,158 ---- # define OGS_SUPPORT_CLASS_H ! # include <cassert> # include <typeinfo> # include <ogs/support/Namespace.h> OGS_BEGIN_SUPPORT_NAMESPACE /** ! * An object that represents the class of another object. This class is ! * actually a thin wrapper for the <code>type_info</code> class declared ! * in the @<typeinfo@> header of the standard C++ library. */ class Class { public: + Class (); + Class (const std::type_info& typeInfo); + + const std::type_info& getInfo () const; + const char* getName () const; + bool isBefore (const Class& rhs) const; + template <class C> static Class getClass (); private: ! const std::type_info* _typeInfo; ! }; ! /** ! * Create a new class object. This constructor is provided for ! * containers that require default constructors. ! */ ! inline ! Class::Class () { ! class Nil { }; ! _typeInfo = &(typeid (Nil)); ! assert (_typeInfo); ! } ! ! /** ! * Create a new class object from type info. ! * ! * @param typeInfo A type info object. ! */ ! inline ! Class::Class (const std::type_info& typeInfo): ! _typeInfo (&typeInfo) { ! assert (_typeInfo); ! } ! /** ! * Determine the type info contained in this class. ! * ! * @return Type info. ! */ ! inline const std::type_info& ! Class::getInfo () const { ! assert (_typeInfo); ! return (*_typeInfo); ! } /** ! * Determine the name of this class. * ! * @return Name of class. */ ! inline const char* ! Class::getName () const { ! assert (_typeInfo); ! return (_typeInfo->name ()); } /** ! * Determine if this class is before another class in logical order. * ! * @param rhs Another class object. ! * @return True if this class is before the other class. */ inline bool ! Class::isBefore (const Class& rhs) const { ! assert (_typeInfo); ! // type_info::before return type is int in some VC libraries ! return (_typeInfo->before (*(rhs._typeInfo)) != 0); } /** ! * Determine the class of a type. The type is given as a template ! * argument. * ! * @return Class of type. */ ! template <class C> ! inline Class ! Class::getClass () { ! Class c (typeid (C)); ! return (c); } /** ! * Determine if this class is equivalent to another class. * ! * @param lhs Class on left-hand side of operator. ! * @param rhs Class on right-hand side of operator. ! * @return True if the two classes are equivalewnt. */ ! inline bool ! operator== (const Class& lhs, const Class& rhs) { ! // type_info::operator== return type is int in some VC libraries ! return (lhs.getInfo () == rhs.getInfo ()) != 0; } /** ! * Determine if this class is less than another class. This operator is ! * used for imposing an order on class objects for operations like ! * sorting * ! * @param lhs Class on left-hand side of operator. ! * @param rhs Class on right-hand side of operator. ! * @return True if @c lhs is less than @c rhs. */ ! inline bool ! operator< (const Class& lhs, const Class& rhs) { ! return (lhs.isBefore (rhs)); } + + /* + * Portions of this file adapted from The Loki Library + * Copyright (c) 2001 by Andrei Alexandrescu + */ OGS_END_SUPPORT_NAMESPACE |