0024428: Implementation of LGPL license
[occt.git] / src / BRepMesh / BRepMesh_PairOfIndex.hxx
CommitLineData
b311480e 1// Created on: 2009-01-29
2// Created by: Pavel TELKOV
973c2be1 3// Copyright (c) 2009-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
973c2be1 7// This library is free software; you can redistribute it and / or modify it
8// under the terms of the GNU Lesser General Public 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
0d88155b
O
15
16/*
17* Purpose: This class represent pair of integer indices
18* It is restricted to store more than two indices in it
19* This pair uses to store element indices connected to link
20*/
21
22#ifndef BRepMesh_PairOfIndex_HeaderFile
23#define BRepMesh_PairOfIndex_HeaderFile
24
25#include <Standard_OutOfRange.hxx>
26
27class BRepMesh_PairOfIndex
28{
29public:
30 BRepMesh_PairOfIndex()
31 { myIndx1 = myIndx2 = -1; }
32
33 BRepMesh_PairOfIndex(const BRepMesh_PairOfIndex& theOther)
34 {
35 myIndx1 = theOther.myIndx1;
50e433aa 36 myIndx2 = theOther.myIndx2;
0d88155b
O
37 }
38
39 //! Clear indices
40 void Clear()
41 {
42 myIndx1 = myIndx2 = -1;
43 }
44
45 //! append index (store first of last index of pair)
46 void Append(const Standard_Integer theIndx)
47 {
48 if ( myIndx1 < 0 )
49 myIndx1 = theIndx;
50 else
51 {
52 if ( myIndx2 >= 0 )
53 Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::Append, more than two index to store");
54 myIndx2 = theIndx;
55 }
56 }
57
58 //! prepend index (store first index)
59 void Prepend(const Standard_Integer theIndx)
60 {
61 if ( myIndx2 >= 0 )
62 Standard_OutOfRange::Raise ("BRepMesh_PairOfIndex::Append, more than two index to store");
63 myIndx2 = myIndx1;
64 myIndx1 = theIndx;
65 }
66
67 //! returns is pair not initialized by index
68 Standard_Boolean IsEmpty() const
69 {
70 return (myIndx1 < 0 /*optimisation && myIndx2 < 0*/);
71 }
72
73 //! returns numner of initialized indeces
74 Standard_Integer Extent() const
75 {
76 return (myIndx1 < 0 ? 0 : (myIndx2 < 0 ? 1 : 2));
77 }
78
79 //! returns first index from pair
80 Standard_Integer FirstIndex() const
81 {
82 return myIndx1;
83 }
84
85 //! returns last index
86 Standard_Integer LastIndex() const
87 {
88 return (myIndx2 < 0 ? myIndx1 : myIndx2);
89 }
90
91 Standard_Integer Index(const Standard_Integer theNum) const
92 {
93 return (theNum == 1 ? myIndx1 : myIndx2 /*(theNum == 2 ? myIndx2 : -1 )*/);
94 }
95
96 void SetIndex(const Standard_Integer theNum,
97 const Standard_Integer theIndex)
98 {
99 theNum == 1 ? myIndx1 = theIndex : myIndx2 = theIndex;
100 }
101
102 //! remove indicated
103 void RemoveIndex (const Standard_Integer theNum)
104 {
105 if ( theNum == 1 )
106 myIndx1 = myIndx2;
107 myIndx2 = -1;
108 }
109 //! fields
110private:
111 Standard_Integer myIndx1;
112 Standard_Integer myIndx2;
113};
114
115#endif