#ifndef REF_H
#define REF_H

#ifndef FLAW_H
#include "Flaw.h"
#endif

namespace MM
{

template < class T >
class Ref
{
public:
    typedef T element_type;

    Ref() { p_ = 0; }  //fix remove?
    ~Ref()
    {
        p_ = 0;
    }

    void destroy() //fix test
    {
        p_ = 0;
    }

//    explicit Ref( T & p )                   : p_( &p ) { }
    Ref( T & p )                   : p_( &p ) { }
//    Ref( const Ref & );
//    const Ref & operator == ( const Ref & );

    T &                 operator () () const
    {
        #ifndef NDEBUG
        invariant();
        #endif
        return * p_;
    }

    bool                was_initialized() const { return p_ != 0; }
    bool                is_valid       () const { return p_ != 0; }

/*    bool operator == ( const T & item ) //fix test
    {
        return item == *p_;
    }

    bool operator != ( const T & item ) //fix test
    {
        return item != *p_;
    }//*/

private:

    void                invariant() const
    {
        if( p_ == 0 )
            FLAW( "Class Ref invariant violation: p_ == 0" );
    }

protected:
    T                   * p_;
};

}//MM

#endif //REF_H

