/***********************************************************************

  File:   typeinfo
  Author: Jeffrey Oldham
  Date:   08/18/2000

  Contents:
    Type Identification.

***  Copyright  (C) 2000-2001 Intel Corporation. All rights reserved.
***
*** The information and source code contained herein is the exclusive
*** property of Intel Corporation and may not be disclosed, examined
*** or reproduced in whole or in part without explicit written authorization
*** from the company.


***********************************************************************/

#ifndef _CSL_TYPEINFO_HPP
#define _CSL_TYPEINFO_HPP

/***********************************************************************
  Notes
***********************************************************************/

/* C++ Standard \S 18.5 Type Identification.  */

/***********************************************************************
  Included Files
***********************************************************************/

#include <exception>
#include <cstring>

/***********************************************************************
  Macros
***********************************************************************/

namespace std {

/***********************************************************************
  Forward Declarations
***********************************************************************/

/***********************************************************************
  Type Declarations
***********************************************************************/

class type_info {

public:

  virtual	~type_info ();

  bool 		operator== (const type_info& _rhs) const;
			/* C++ standard \S 18.5.1/2.
			   Effects:
			     Compares the current object with rhs.
			   Returns:
			     true if the two values describe the same
			     type.  */

  bool		operator!= (const type_info& _rhs) const;
			/* C++ standard \S 18.5.1/4.
			   Returns:
			     !(THIS == _RHS).  */

  bool		before (const type_info& _rhs) const;
			/* C++ standard \S 18.5.1/5.
			   Effects:
			     Compares the current object with rhs.
			   Returns: 
			     true if *THIS precedes _RHS in the
			     implementation's collation order.  */

  const char*	name () const;
			/* C++ standard \S 18.5.1/7.
			   Returns:
			     an implementation-defined NTBS.  */

  const char*	__type_name;
			/* __type_name is a pointer to a NTBS
			   representing the name of the type.  */

  virtual bool	_eh_match (const type_info& _caught_type,
			   const void*      _object,
			   const void**	    _adjusted_object,
			   const bool	    _const_so_far,
			   const unsigned   _pointer_level) const;
			/* Preconditions:
			     _CONST_SO_FAR is true iff all previous
			     calls had const cv-qualifiers for
			     _caught_type.  _POINTER_LEVEL indicates
			     how many levels of pointers exist.
			   Returns:
			     True iff the _OBJECT (whose static
			     type is _THROWN_TYPE) can be caught in a
			     catch clause whose type is *THIS.
			   Effects:
			     If the return value is non-zero,
			     *_ADJUSTED_OBJECT points to the address
			     of the object when it is caught.  */

private:

		type_info (const type_info& _rhs);

  type_info&	operator= (const type_info& _rhs);
			/* C++ standard \S 18.5.1/9.
			   Effects:
			     Copies a type_info object.
			   Notes: 
			     Since the copy constructor and assignment
			     operator for type_info are private to the
			     class, objects of this type cannot be
			     copied.  */
protected:
    type_info() { } ;
};

/* C++ standard \S 18.5.2.  The class bad_cast defines the type of
   objects thrown as exceptions by the implementation to report the
   execution of an invalid dynamic_cast expression.  */

class bad_cast 
  : public exception
{
};

/* C++ standard \S 18.5.3.  The class bad_typeid defines the type of
   objects thrown as exceptions by the implementation to report a
   null pointer in a typeid expression (\S 5.2.8).  */

class bad_typeid
  : public exception
{
};

/***********************************************************************
  Class Declarations
***********************************************************************/

/***********************************************************************
  Variable Declarations
***********************************************************************/

/***********************************************************************
  Function Declarations
***********************************************************************/

/***********************************************************************
  Inline Function Definitions
***********************************************************************/

// type_info
/* C++ standard \S 18.5.1.  */

inline
type_info::~type_info ()
{
}

inline bool
type_info::operator== (const type_info& _rhs) const
{
  return __type_name == _rhs.__type_name;
}

inline bool 
type_info::operator!= (const type_info& _rhs) const
{
  return !(*this == _rhs);
}

inline bool 
type_info::before (const type_info& _rhs) const
{
  return strcmp (__type_name, _rhs.__type_name) < 0;
}
 
inline const char* 
type_info::name () const
{
  return __type_name;
}

inline bool
type_info::_eh_match (const type_info& _caught_type,
		      const void*      _object,
		      const void**     _adjusted_object,
		      const bool       ,
		      const unsigned   ) const
{
  // If the two types are not identical, there is no match.
  // _adjusted_object has already been set to _object.
  return _caught_type == *this;
}

} // Namespace std

#endif // _CSL_TYPEINFO_HPP
