Subversion Repositories gelsvn

Rev

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

/*
* Written by Christian Thode Larsen 2009-2010
* Contact: thode2d@gmail.com
* Based on original work by J. Andreas Baerentzen
* Inspired by OpenMesh (www.openmesh.org)
*/

#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.