0024023: Revamp the OCCT Handle -- ambiguity
[occt.git] / src / StepData / StepData_Simple.cxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 #include <StepData_Simple.ixx>
15 #include <Interface_InterfaceMismatch.hxx>
16 #include <StepData_ESDescr.hxx>
17
18 StepData_Simple::StepData_Simple (const Handle(StepData_ESDescr)& descr)
19     : StepData_Described (descr) , thefields (descr->NbFields())    {  }
20
21     Handle(StepData_ESDescr)  StepData_Simple::ESDescr () const
22       {  return Handle(StepData_ESDescr)::DownCast (Description());  }
23
24     Standard_CString  StepData_Simple::StepType () const
25       {  return ESDescr()->TypeName();  }
26
27
28     Standard_Boolean  StepData_Simple::IsComplex () const
29       {  return Standard_False;  }
30
31     Standard_Boolean  StepData_Simple::Matches (const Standard_CString steptype) const
32       {  return ESDescr()->Matches (steptype);  }
33
34     Handle(StepData_Simple)  StepData_Simple::As (const Standard_CString steptype) const
35 {
36   Handle(StepData_Simple) nulent;
37   if (Matches(steptype)) return this;
38   return nulent;
39 }
40
41
42     Standard_Boolean  StepData_Simple::HasField (const Standard_CString name) const
43 {
44   Standard_Integer num = ESDescr()->Rank (name);
45   return (num > 0);
46 }
47
48     const StepData_Field&  StepData_Simple::Field (const Standard_CString name) const
49 {
50   Standard_Integer num = ESDescr()->Rank (name);
51   if (num == 0) Interface_InterfaceMismatch::Raise("StepData_Simple : Field");
52   return FieldNum (num);
53 }
54
55     StepData_Field&  StepData_Simple::CField (const Standard_CString name)
56 {
57   Standard_Integer num = ESDescr()->Rank (name);
58   if (num == 0) Interface_InterfaceMismatch::Raise("StepData_Simple : Field");
59   return CFieldNum (num);
60 }
61
62     Standard_Integer  StepData_Simple::NbFields () const
63       {  return thefields.NbFields();  }
64
65     const StepData_Field&  StepData_Simple::FieldNum (const Standard_Integer num) const
66       {  return thefields.Field(num);  }
67
68     StepData_Field&  StepData_Simple::CFieldNum (const Standard_Integer num)
69       {  return thefields.CField(num);  }
70
71     const StepData_FieldListN&  StepData_Simple::Fields () const
72       {  return thefields;  }
73
74     StepData_FieldListN&  StepData_Simple::CFields ()
75       {  return thefields;  }
76
77
78 void StepData_Simple::Check(Handle(Interface_Check)& /*ach*/) const
79 {
80 }  // qq chose ? cf la description
81
82
83     void  StepData_Simple::Shared (Interface_EntityIterator& list) const
84 {
85   Standard_Integer i, nb = thefields.NbFields();
86   for (i = 1; i <= nb; i ++) {
87     const StepData_Field& fi = thefields.Field(i);
88     Standard_Integer j1,j2,l1,l2;  l1 = l2 = 1;
89     if (fi.Arity() >= 1) l1 = fi.Length(1);
90     if (fi.Arity() >  1) l2 = fi.Length(2);
91     for (j1 = 1; j1 <= l1; j1 ++) {
92       for (j2 = 1; j2 <= l2; j2 ++) {
93         Handle(Standard_Transient) ent = fi.Entity(j1,j2);
94         if (!ent.IsNull()) list.AddItem(ent);
95       }
96     }
97   }
98 }