/* 
 * Copyright 2010-2011 PathScale, Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright notice,
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef _LINUX_TYPEINFO_
#define _LINUX_TYPEINFO_

#include <stddef.h>
#include "exception"

namespace __cxxabiv1
{
	struct __class_type_info;
}
namespace std
{
	/**
	  * Standard type info class.  The layout of this class is specified by the
	  * ABI.  The layout of the vtable is not, but is intended to be
	  * compatible with the GNU ABI.
	  *
	  * Unlike the GNU version, the vtable layout is considered semi-private.
	  */
	class type_info
	{
		public:
		/**
		 * Virtual destructor.  This class must have one virtual function to
		 * ensure that it has a vtable.
		 */
		virtual ~type_info();
		bool operator==(const type_info &) const;
		bool operator!=(const type_info &) const;
		bool before(const type_info &) const;
		const char* name() const;
		type_info();
		private:
		type_info(const type_info& rhs);
		type_info& operator= (const type_info& rhs);
		const char *__type_name;
		/*
		 * The following functions are in this order to match the
		 * vtable layout of libsupc++.  This allows libcxxrt to be used
		 * with libraries that depend on this.
		 *
		 * These functions are in the public headers for libstdc++, so
		 * we have to assume that someone will probably call them and
		 * expect them to work.  Their names must also match the names used in
		 * libsupc++, so that code linking against this library can subclass
		 * type_info and correctly fill in the values in the vtables.
		 */
		public:
		/**
		 * Returns true if this is some pointer type, false otherwise.
		 */
		virtual bool __is_pointer_p() const { return false; }
		/**
		 * Returns true if this is some function type, false otherwise.
		 */
		virtual bool __is_function_p() const { return false; }
		/**
		 * Catch function.  Allows external libraries to implement
		 * their own basic types.  This is used, for example, in the
		 * GNUstep Objective-C runtime to allow Objective-C types to be
		 * caught in G++ catch blocks.
		 *
		 * The outer parameter indicates the number of outer pointers
		 * in the high bits.  The low bit indicates whether the
		 * pointers are const qualified.
		 */
		virtual bool __do_catch(const type_info *thrown_type,
		                        void **thrown_object,
		                        unsigned outer) const;
		/**
		 * Performs an upcast.  This is used in exception handling to
		 * cast from subclasses to superclasses.  If the upcast is
		 * possible, it returns true and adjusts the pointer.  If the
		 * upcast is not possible, it returns false and does not adjust
		 * the pointer.
		 */
		virtual bool __do_upcast(
		                const __cxxabiv1::__class_type_info *target,
		                void **thrown_object) const
		{
			(void)target, (void)thrown_object;
			return false;
		}
	};

    /**
	 * Bad cast exception.  Thrown by the __cxa_bad_cast() helper function.
	 */
	class bad_cast: public exception {
	public:
		bad_cast() throw();
		bad_cast(const bad_cast&) throw();
		bad_cast& operator=(const bad_cast&) throw();
		virtual ~bad_cast();
		virtual const char* what() const throw();
	};

	/**
	 * Bad typeidexception.  Thrown by the __cxa_bad_typeid() helper function.
	 */
	class bad_typeid: public exception
	{
	public:
		bad_typeid() throw();
		bad_typeid(const bad_typeid &__rhs) throw();
		virtual ~bad_typeid();
		bad_typeid& operator=(const bad_typeid &__rhs) throw();
		virtual const char* what() const throw();
	};

    class bad_array_new_length: public bad_alloc
    { 
        public:
            bad_array_new_length() throw();
            bad_array_new_length(const bad_array_new_length&) throw();
            bad_array_new_length& operator=(const bad_array_new_length&) throw();
            virtual ~bad_array_new_length();
            virtual const char *what() const throw();
    };
}

#endif /* _LINUX_TYPEINFO_ */
