0023024: Update headers of OCCT files
[occt.git] / src / Aspect / Aspect_TypeMap.cxx
1 // Created on: 1993-09-14
2 // Created by: GG
3 // Copyright (c) 1993-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 //
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
10 //
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 //
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
20
21
22
23 //-Version
24
25 //-Design       Declaration des variables specifiques aux Ensembles
26 //              de Type de traits
27
28 //-Warning      Une TypeMap est definie par un ensemble de TypeMapEntries
29
30 //-References
31
32 //-Language     C++ 2.0
33
34 //-Declarations
35
36 // for the class
37 #include <Aspect_TypeMap.ixx>
38
39 //-Aliases
40
41 //-Global data definitions
42
43 //      mydata       : SequenceOfTypeMapEntry from Aspect is protected
44
45 //-Constructors
46
47 //-Destructors
48
49 //-Methods, in order
50
51 Aspect_TypeMap::Aspect_TypeMap( ) {
52 Aspect_TypeMapEntry theDefaultEntry;
53
54         AddEntry(theDefaultEntry);
55 }
56
57 void Aspect_TypeMap::AddEntry (const Aspect_TypeMapEntry& AnEntry) {
58 Standard_Integer i,index = AnEntry.Index();
59 Aspect_TypeMapEntry theEntry;
60
61         for( i=1 ; i<=mydata.Length() ; i++ ) {
62             theEntry = mydata.Value(i);
63             if( index == theEntry.Index() ) break;
64         }
65
66         if( i > mydata.Length() ) {
67             mydata.Append( AnEntry );
68         } else {
69             mydata.SetValue(i,AnEntry);
70         }
71 }
72
73 Standard_Integer Aspect_TypeMap::AddEntry (const Aspect_LineStyle &aStyle) {
74 Aspect_TypeMapEntry theEntry ;
75 Standard_Integer i,maxindex = 0 ;
76  
77     for( i=1 ; i<=mydata.Length() ; i++ ) {
78         theEntry = mydata.Value(i) ;
79         maxindex = Max(maxindex,theEntry.Index()) ;
80         if( theEntry.Type() == aStyle ) return theEntry.Index() ;
81     }
82  
83     maxindex++ ;
84     theEntry.SetValue(maxindex,aStyle) ;
85     mydata.Append( theEntry ) ;
86     return maxindex ;
87 }
88
89 Standard_Integer     Aspect_TypeMap::Size() const {
90
91         return mydata.Length() ;
92 }
93
94 Standard_Integer     Aspect_TypeMap::Index(const Standard_Integer anIndex) const {
95
96         if( anIndex < 1 || anIndex > Size() ) {
97             Aspect_BadAccess::Raise ("Undefined typemap Index");
98         }
99
100         Aspect_TypeMapEntry theEntry = mydata.Value(anIndex) ;
101
102         return theEntry.Index() ;
103 }
104
105 const Aspect_TypeMapEntry& Aspect_TypeMap::Entry (const Standard_Integer AnIndex) const {
106
107         if( AnIndex < 1 || AnIndex > mydata.Length() )
108                 Aspect_BadAccess::Raise ("Aspect_TypeMap::Entry Bad Index");
109
110         return mydata.Value(AnIndex);
111 }
112
113 void Aspect_TypeMap::Dump () const {
114
115   Standard_Integer i ;
116
117   cout << "Typemap Dump-->\n" ;
118
119   for ( i = 1 ; i <= Size() ; i++ ) (Entry(i)).Dump() ;
120
121   cout << "<--End Typemap Dump\n" ;
122 }