0023304: Copying constructor fails to copy both 'myIndx' variables.
[occt.git] / src / BRepMesh / BRepMesh_PairOfIndex.hxx
CommitLineData
b311480e 1// Created on: 2009-01-29
2// Created by: Pavel TELKOV
3// Copyright (c) 2009-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
0d88155b
O
20
21/*
22* Purpose: This class represent pair of integer indices
23* It is restricted to store more than two indices in it
24* This pair uses to store element indices connected to link
25*/
26
27#ifndef BRepMesh_PairOfIndex_HeaderFile
28#define BRepMesh_PairOfIndex_HeaderFile
29
30#include <Standard_OutOfRange.hxx>
31
32class BRepMesh_PairOfIndex
33{
34public:
35 BRepMesh_PairOfIndex()
36 { myIndx1 = myIndx2 = -1; }
37
38 BRepMesh_PairOfIndex(const BRepMesh_PairOfIndex& theOther)
39 {
40 myIndx1 = theOther.myIndx1;
50e433aa 41 myIndx2 = theOther.myIndx2;
0d88155b
O
42 }
43
44 //! Clear indices
45 void Clear()
46 {
47 myIndx1 = myIndx2 = -1;
48 }
49
50 //! append index (store first of last index of pair)
51 void Append(const Standard_Integer theIndx)
52 {
53 if ( myIndx1 < 0 )
54 myIndx1 = theIndx;
55 else
56 {
57 if ( myIndx2 >= 0 )
58 Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::Append, more than two index to store");
59 myIndx2 = theIndx;
60 }
61 }
62
63 //! prepend index (store first index)
64 void Prepend(const Standard_Integer theIndx)
65 {
66 if ( myIndx2 >= 0 )
67 Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::Append, more than two index to store");
68 myIndx2 = myIndx1;
69 myIndx1 = theIndx;
70 }
71
72 //! returns is pair not initialized by index
73 Standard_Boolean IsEmpty() const
74 {
75 return (myIndx1 < 0 /*optimisation && myIndx2 < 0*/);
76 }
77
78 //! returns numner of initialized indeces
79 Standard_Integer Extent() const
80 {
81 return (myIndx1 < 0 ? 0 : (myIndx2 < 0 ? 1 : 2));
82 }
83
84 //! returns first index from pair
85 Standard_Integer FirstIndex() const
86 {
87 return myIndx1;
88 }
89
90 //! returns last index
91 Standard_Integer LastIndex() const
92 {
93 return (myIndx2 < 0 ? myIndx1 : myIndx2);
94 }
95
96 Standard_Integer Index(const Standard_Integer theNum) const
97 {
98 return (theNum == 1 ? myIndx1 : myIndx2 /*(theNum == 2 ? myIndx2 : -1 )*/);
99 }
100
101 void SetIndex(const Standard_Integer theNum,
102 const Standard_Integer theIndex)
103 {
104 theNum == 1 ? myIndx1 = theIndex : myIndx2 = theIndex;
105 }
106
107 //! remove indicated
108 void RemoveIndex (const Standard_Integer theNum)
109 {
110 if ( theNum == 1 )
111 myIndx1 = myIndx2;
112 myIndx2 = -1;
113 }
114 //! fields
115private:
116 Standard_Integer myIndx1;
117 Standard_Integer myIndx2;
118};
119
120#endif