/*----------------------------------------------------------------------------+
Copyright (c) 2007-2008: Joachim Faulhaber
+-----------------------------------------------------------------------------+
Copyright (c) 1999-2006: Cortex Software GmbH, Kantstrasse 57, Berlin
+-----------------------------------------------------------------------------+
Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
+----------------------------------------------------------------------------*/
#ifndef __ordered_type_h_JOFA_011005_H__
#define __ordered_type_h_JOFA_011005_H__

#include <string>

namespace boost{namespace itl
{

/// an enumeration ordered class type
/**  
    class template <b>ordered_type</b> defines objects
    that can be ordered by an enumeration type that
    is associated to the template parameter TypeDomain.
    Every object of this class exposes a value of
    that enumeration type by a function <b>type()</b>

    @author  Joachim Faulhaber
*/
template <class TypeDomain>
class ordered_type
{
public:
    typedef ordered_type* OrderedTypePIT;

public:
    /// virtual destructors to avoid memory leaks
    virtual ~ordered_type(){}
    /// the objects type
    virtual typename TypeDomain::DomainET type()const=0;

    /// the objects value
    virtual const typename TypeDomain::ValueBaseTD* value()const=0;

    /// Comparison on type level
    virtual bool isLessOnType(const ordered_type* x2)const=0;
    /// Equivalece relation <tt>this->type()==x2->type()</tt>
    virtual bool isTypeEquivalent(const ordered_type* x2)const=0;

    /// comparisons on value level
    virtual bool isEqual(const ordered_type* x2)const=0;  

    virtual bool isLess(const ordered_type* x2)const=0;  
    
    /// equality on value-level using == operator
    virtual bool operator == (const ordered_type& x2)const=0;
    
    //JODO Aufrufmechnismus für stl::container operator ==.verstehen
    //virtual bool operator == (const OrderedTypePIT& x2)const=0;

    //KEEP JODO einpflegen 
    // virtual bool isLess(const ordered_type* x2)const=0;  
    // virtual bool operator < (const ordered_type& x2)const=0;

    /// string representation
    virtual std::string as_string()const=0 ;
};


template <class TypeDomain>
class ordered_type_base : public ordered_type<TypeDomain>
{
public:
    typedef ordered_type<TypeDomain>* OrderedTypeOfDomPIT;

public:
    virtual bool isLessOnType (const ordered_type<TypeDomain>* x2)const 
    { return this->type() < x2->type(); }
    virtual bool isTypeEquivalent (const ordered_type<TypeDomain>* x2)const 
    { return this->type() == x2->type(); }

    // comparisons on value level
    bool isEqual(const ordered_type<TypeDomain>* x2)const
    { 
        return isTypeEquivalent(x2) && isValueEqual(x2); 
    }

    bool operator == (const ordered_type<TypeDomain>& x2)const 
    {
        return isEqual(&x2); 
    } 

    bool isLess(const ordered_type<TypeDomain>* x2)const
    { 
        return this < x2; 
    }

    /*JODO Aufrufmechnismus für stl::container operator ==.verstehen
    bool operator == (const OrderedTypeOfDomPIT& x2)const 
    {
        return isEqual(x2); 
    } 
    */

    /*KEEP JODO Einfplegen
    bool isLess(const ordered_type<TypeDomain>* x2)const
    { 
        return isLessOnType(x2) && isValueLess(x2); 
    }

    bool operator < (const ordered_type<TypeDomain>& x2)const 
    {
        return isLess(&x2);
    }
    */

protected:
    /// Gleichheit der Werte
    virtual bool isValueEqual(const ordered_type<TypeDomain>* x2)const=0;

    //KEEP JODO Einfplegen
    //virtual bool isValueLess(const ordered_type<TypeDomain>* x2)const=0;
};

}} // namespace itl boost

#endif // __ordered_type_h_JOFA_011005_H__


