0025953: BRepMesh_PairOfIndex::Prepend - variable assigned twice
[occt.git] / src / BRepMesh / BRepMesh_PairOfIndex.hxx
1 // Created on: 2009-01-29
2 // Created by: Pavel TELKOV
3 // Copyright (c) 2009-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef BRepMesh_PairOfIndex_HeaderFile
17 #define BRepMesh_PairOfIndex_HeaderFile
18
19 #include <Standard_OutOfRange.hxx>
20
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
25 {
26 public:
27
28   //! Default constructor
29   Standard_EXPORT BRepMesh_PairOfIndex()
30   {
31     Clear();
32   }
33
34   //! Clears indices.
35   void Clear()
36   {
37     myIndex[0] = myIndex[1] = -1;
38   }
39
40   //! Appends index to the pair.
41   inline void Append(const Standard_Integer theIndex)
42   {
43     if (myIndex[0] < 0)
44       myIndex[0] = theIndex;
45     else
46     {
47       if (myIndex[1] >= 0)
48         Standard_OutOfRange::Raise("BRepMesh_PairOfIndex::Append, more than two index to store");
49
50       myIndex[1] = theIndex;
51     }
52   }
53
54   //! Prepends index to the pair.
55   inline void Prepend(const Standard_Integer theIndex)
56   {
57     if (myIndex[1] >= 0)
58       Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::Prepend, more than two index to store");
59
60     myIndex[1] = myIndex[0];
61     myIndex[0] = theIndex;
62   }
63
64   //! Returns is pair is empty.
65   inline Standard_Boolean IsEmpty() const
66   {
67     // Check only first index. It is impossible to update
68     // second index if the first one is empty.
69     return (myIndex[0] < 0);
70   }
71
72   //! Returns number of initialized indeces.
73   inline Standard_Integer Extent() const
74   {
75     return (myIndex[0] < 0 ? 0 : (myIndex[1] < 0 ? 1 : 2));
76   }
77
78   //! Returns first index of pair.
79   inline Standard_Integer FirstIndex() const
80   {
81     return myIndex[0];
82   }
83
84   //! Returns last index of pair
85   inline Standard_Integer LastIndex() const
86   {
87     return (myIndex[1] < 0 ? myIndex[0] : myIndex[1]);
88   }
89
90   //! Returns index corresponding to the given position in the pair.
91   //! @param thePairPos position of index in the pair (1 or 2).
92   inline Standard_Integer Index(const Standard_Integer thePairPos) const
93   {
94     if (thePairPos != 1 && thePairPos != 2)
95       Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::Index, requested index is out of range");
96
97     return myIndex[thePairPos - 1];
98   }
99
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   inline void SetIndex(const Standard_Integer thePairPos,
104                        const Standard_Integer theIndex)
105   {
106     if (thePairPos != 1 && thePairPos != 2)
107       Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::SetIndex, requested index is out of range");
108
109     myIndex[thePairPos - 1] = theIndex;
110   }
111
112   //! Remove index from the given position.
113   //! @param thePairPos position of index in the pair (1 or 2).
114   inline void RemoveIndex(const Standard_Integer thePairPos)
115   {
116     if (thePairPos != 1 && thePairPos != 2)
117       Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::RemoveIndex, requested index is out of range");
118
119     if ( thePairPos == 1 )
120       myIndex[0] = myIndex[1];
121
122     myIndex[1] = -1;
123   }
124
125 private:
126   Standard_Integer myIndex[2];
127 };
128
129 #endif