Subversion Repositories gelsvn

Rev

Rev 511 | Rev 515 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/* ----------------------------------------------------------------------- *
 * This file is part of GEL, www.imm.dtu.dk/GEL
 * Copyright (C) the authors (see AUTHORS.txt) and DTU Informatics
 *
 * Principal authors:
 *  Christian Thode Larsen (thode2d@gmail.com)
 *  J. Andreas Baerentzen (jab@imm.dtu.dk)
 *
 * See LICENSE.txt for licensing information
 * ----------------------------------------------------------------------- */

#ifndef __HMESH_ITEMID_H__
#define __HMESH_ITEMID_H__

#include <cstdint>

namespace HMesh
{
    typedef uint32_t IndexType;  
    const IndexType NULL_INDEX =  UINT32_MAX;

    class ItemID
    {
    public:
        ItemID(IndexType _index = NULL_INDEX);

        bool operator ==(const ItemID& other) const;
        bool operator !=(const ItemID& other) const;
        bool operator >=(const ItemID& other) const;
        bool operator <=(const ItemID& other) const;
        bool operator <(const ItemID& other) const;
        bool operator >(const ItemID& other) const;

        ItemID& operator ++();
        ItemID& operator ++(int);
        ItemID& operator --();
        ItemID& operator --(int);

        bool valid() const;
        IndexType idx() const;
        void invalidate();

    private:
        IndexType index;
    };

    class VertexID : public ItemID
    {
    public:
        VertexID(IndexType _index = NULL_INDEX) : ItemID(_index){}
    };

    class FaceID : public ItemID
    {
    public:
        FaceID(IndexType _index = NULL_INDEX) : ItemID(_index){}
    };

    class HalfEdgeID : public ItemID
    {
    public:
        HalfEdgeID(IndexType _index = NULL_INDEX) : ItemID(_index){}
    };

    inline ItemID::ItemID(IndexType _index) : index(_index){}

    inline bool ItemID::operator ==(const ItemID& other) const
    { return index == other.index; }

    inline bool ItemID::operator !=(const ItemID& other) const
    { return index != other.index; }

    inline bool ItemID::operator >=(const ItemID& other) const
    { return index >= other.index; }

    inline bool ItemID::operator <=(const ItemID& other) const
    { return index <= other.index; }

    inline bool ItemID::operator <(const ItemID& other) const
    { return index < other.index; }

    inline bool ItemID::operator >(const ItemID& other) const
    { return index > other.index; }

    inline ItemID& ItemID::operator ++()
    { 
        ++index;
        return *this;
    }

    inline ItemID& ItemID::operator ++(int)
    {
        ++(*this);
        return *this;
    }

    inline ItemID& ItemID::operator --()
    { 
        --index; 
        return *this;
    }

    inline ItemID& ItemID::operator --(int)
    {
        --(*this);
        return *this;
    }

    inline bool ItemID::valid() const
    { return index != NULL_INDEX; }

    inline void ItemID::invalidate()
    { index = NULL_INDEX; }

    inline IndexType ItemID::idx() const
    { return index; }

}

#endif

Generated by GNU Enscript 1.6.6.