// Copyright (C) 1991 - 1999 Rational Software Corporation

#if defined (_MSC_VER) && (_MSC_VER >= 1000)
#pragma once
#endif
#ifndef _INC_RIBBLE_471BB47802AF_INCLUDED
#define _INC_RIBBLE_471BB47802AF_INCLUDED
//////////////////////////////////////////////////////////////////////////
//ребро графа

template<class T>
class Ribble 
{
public:
	
	void set__vertex1(T* value)
	{
        // проверка нужна, чтобы избежать неожиданностей 
        //  при сериализации
        if ( value != NULL && _vertex1 != NULL )
        {
            _vertex1 = value;
        } 
        else
        {
            throw new GraphException("Nillable vertices are not allowed!");
        }
	}

	
	void set__vertex2(T* value)
	{
        // проверка нужна, чтобы избежать неожиданностей 
        //  при сериализации
        if ( value != NULL && _vertex2 != NULL )
        {
            _vertex2 = value;
        } 
        else
        {
            throw new GraphException("Nillable vertices are not allowed!");
        }
    }

    
    virtual ~Ribble()
    {
        // вершины по указателям не удаляем, т.к. возможны ещё
        //  указатели на эти вершины, которые (указатели) нам
        //  не доступны
        cout<<"[ribble] ribble destroyed\n";
    }

    
    bool operator==(const Ribble<T>& rhs) const
    {
        return rhs.equals(this);
    }

    //сравннение по указателю
	
    bool equals(const Ribble<T>* ribble)
    {
        return (*_vertex1 == *(ribble->_vertex1)) && 
               (*_vertex2 == *(ribble->_vertex2));
    }

    // является ли ребро петлей
	
    bool isLoop()
    {
        return *_vertex1 == *_vertex2;
    }

    //принадлежит ли вершина ребру
    
    bool contains(const T* vertex) const
    {
        return (_vertex1 == vertex) || (_vertex2 == vertex);
    }

    
    T* get__vertex2() const
    {
        if (_vertex2 != NULL)
        {
            return _vertex2;
        } 
        else
        {
            throw new GraphException("Nillable vertices are not allowed!");
        }
    }

    
    T* get__vertex1() const
    {
        if (_vertex1 != NULL)
        {
            return _vertex1;
        } 
        else
        {
            throw new GraphException("Nillable vertices are not allowed!");
        }
    }

    //получить вершину, отличную от заданной
	
    T* getAnotherVertex(T* vertex)
    {
        if (isLoop())
        {
            return NULL;
        } 
        else
        {
            if (*_vertex1 == *vertex )
            {
                return _vertex2;
            }
            else
            {
                return _vertex1;
            }
        }
    }

    
    Ribble(T* vertex1, T* vertex2): _vertex1(vertex1), _vertex2(vertex2)
    {
        if (_vertex1 == NULL || _vertex2 == NULL)
        {
            throw new GraphException("Nillable vertices are not allowed!");
        }
        cout<<"[ribble] ribble created\n";
    }

private:
    
    T* _vertex1;

    
    T* _vertex2;
};

//////////////////////////////////////////////////////////////////////////
#endif /* _INC_RIBBLE_471BB47802AF_INCLUDED */
Соседние файлы в папке container