1 // Created on: 2009-01-29
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2009-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #ifndef BRepMesh_PairOfIndex_HeaderFile
17 #define BRepMesh_PairOfIndex_HeaderFile
19 #include <Standard_OutOfRange.hxx>
21 //! This class represents a pair of integer indices to store
22 //! element indices connected to link. It is restricted to
23 //! store more than two indices in it.
24 class BRepMesh_PairOfIndex
28 //! Default constructor
29 BRepMesh_PairOfIndex()
37 myIndex[0] = myIndex[1] = -1;
40 //! Appends index to the pair.
41 void Append(const Standard_Integer theIndex)
44 myIndex[0] = theIndex;
48 throw Standard_OutOfRange("BRepMesh_PairOfIndex::Append, more than two index to store");
50 myIndex[1] = theIndex;
54 //! Prepends index to the pair.
55 void Prepend(const Standard_Integer theIndex)
58 throw Standard_OutOfRange("BRepMesh_PairOfIndex::Prepend, more than two index to store");
60 myIndex[1] = myIndex[0];
61 myIndex[0] = theIndex;
64 //! Returns is pair is empty.
65 Standard_Boolean IsEmpty() const
67 // Check only first index. It is impossible to update
68 // second index if the first one is empty.
69 return (myIndex[0] < 0);
72 //! Returns number of initialized indices.
73 Standard_Integer Extent() const
75 return (myIndex[0] < 0 ? 0 : (myIndex[1] < 0 ? 1 : 2));
78 //! Returns first index of pair.
79 Standard_Integer FirstIndex() const
84 //! Returns last index of pair
85 Standard_Integer LastIndex() const
87 return (myIndex[1] < 0 ? myIndex[0] : myIndex[1]);
90 //! Returns index corresponding to the given position in the pair.
91 //! @param thePairPos position of index in the pair (1 or 2).
92 Standard_Integer Index(const Standard_Integer thePairPos) const
94 if (thePairPos != 1 && thePairPos != 2)
95 throw Standard_OutOfRange("BRepMesh_PairOfIndex::Index, requested index is out of range");
97 return myIndex[thePairPos - 1];
100 //! Sets index corresponding to the given position in the pair.
101 //! @param thePairPos position of index in the pair (1 or 2).
102 //! @param theIndex index to be stored.
103 void SetIndex(const Standard_Integer thePairPos,
104 const Standard_Integer theIndex)
106 if (thePairPos != 1 && thePairPos != 2)
107 throw Standard_OutOfRange("BRepMesh_PairOfIndex::SetIndex, requested index is out of range");
109 myIndex[thePairPos - 1] = theIndex;
112 //! Remove index from the given position.
113 //! @param thePairPos position of index in the pair (1 or 2).
114 void RemoveIndex(const Standard_Integer thePairPos)
116 if (thePairPos != 1 && thePairPos != 2)
117 throw Standard_OutOfRange("BRepMesh_PairOfIndex::RemoveIndex, requested index is out of range");
119 if ( thePairPos == 1 )
120 myIndex[0] = myIndex[1];
126 Standard_Integer myIndex[2];