0023148: Error in stepstrcmp
[occt.git] / src / StepData / StepData_UndefinedEntity.cxx
1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
2 //
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
7 //
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10 //
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
17
18 #include <StepData_UndefinedEntity.ixx>
19 #include <Interface_ParamType.hxx>
20 #include <TCollection_AsciiString.hxx>
21 #include <Interface_Macros.hxx>
22
23
24
25 StepData_UndefinedEntity::StepData_UndefinedEntity ()
26       {  thecont = new Interface_UndefinedContent;  thesub = Standard_False;  }
27
28     StepData_UndefinedEntity::StepData_UndefinedEntity
29   (const Standard_Boolean issub)
30       { thesub = issub;  thecont = new Interface_UndefinedContent;  }
31
32     Handle(Interface_UndefinedContent)
33       StepData_UndefinedEntity::UndefinedContent () const
34       {  return thecont;  }
35
36     Standard_Boolean StepData_UndefinedEntity::IsSub () const
37       {  return thesub;  }
38
39     Standard_Boolean StepData_UndefinedEntity::IsComplex () const
40       {  return (!thenext.IsNull());  }
41
42     Handle(StepData_UndefinedEntity) StepData_UndefinedEntity::Next () const
43       {  return thenext;  }
44
45     Standard_CString StepData_UndefinedEntity::StepType () const
46       {  if (thetype.IsNull()) return "";  return thetype->ToCString();  }
47
48
49 void StepData_UndefinedEntity::ReadRecord(const Handle(StepData_StepReaderData)& SR,
50                                           const Standard_Integer num,
51                                           Handle(Interface_Check)& ach)
52 {
53   thetype = new TCollection_HAsciiString(SR->RecordType(num));
54   Standard_Integer nb = SR->NbParams(num);
55
56   thecont->Reservate (nb,4);
57   for (Standard_Integer i = 1; i <= nb; i ++) {
58     Handle(Standard_Transient) anent;
59     Handle(TCollection_HAsciiString) hval;
60     Standard_CString val = SR->ParamCValue(num,i);
61     Interface_ParamType partyp = SR->ParamType(num,i);
62     Standard_Integer nume = 0;
63     if (partyp == Interface_ParamIdent) {
64       nume = SR->ParamNumber(num,i);
65       if (nume <= 0) {
66         ach->AddFail("A reference to another entity is unresolved");
67         partyp = Interface_ParamVoid;
68       }
69       else {
70         anent = SR->BoundEntity(nume);
71       }
72     }
73     else if (partyp == Interface_ParamSub) {
74       nume = SR->ParamNumber(num,i);
75       Handle(StepData_UndefinedEntity) und = new StepData_UndefinedEntity (Standard_True);
76       anent = und;
77       und->ReadRecord(SR,nume,ach);
78     }
79     else if (partyp == Interface_ParamText) {
80       //    Return integre a supprimer silya
81       Standard_Integer lval = strlen(val);  Standard_Integer mval = -1;
82       for (Standard_Integer j = 0; j < lval; j ++) {
83         if (val[j] == '\n') { mval = i; break; }
84       }
85       if (mval > 0) {
86         nume = -1;
87         hval = new TCollection_HAsciiString (val);
88         hval->RemoveAll('\n');
89       }
90     }
91     if (nume == 0) hval = new TCollection_HAsciiString (val);
92     if (nume >  0) thecont->AddEntity(partyp,anent);
93     else           thecont->AddLiteral (partyp,hval);
94   }
95   Standard_Integer nextyp = SR->NextForComplex(num);
96   if (nextyp == 0) return;
97   thenext = new StepData_UndefinedEntity;
98   thenext->ReadRecord(SR,nextyp,ach);
99 }
100
101
102 void StepData_UndefinedEntity::WriteParams (StepData_StepWriter& SW) const
103 {
104   if (!IsSub()) SW.StartEntity(TCollection_AsciiString(StepType()));
105   Standard_Integer nb = thecont->NbParams();
106   Handle(Standard_Transient) anent;
107   for (Standard_Integer i = 1; i <= nb; i ++) {
108     Interface_ParamType partyp = thecont->ParamType(i);
109     if (partyp == Interface_ParamSub) {
110       DeclareAndCast(StepData_UndefinedEntity,und,thecont->ParamEntity(i));
111       und->StepType(); //svv #2
112       if (und->IsSub()) SW.OpenTypedSub (und->StepType());
113       und->WriteParams(SW);
114       if (und->IsSub()) SW.CloseSub();
115     }
116     else if (partyp == Interface_ParamIdent) {
117       anent = thecont->ParamEntity(i);
118       SW.Send(anent);
119     }
120     else SW.SendString (thecont->ParamValue(i)->ToCString());
121   }
122 //  if (IsSub()) return;
123 //  SW.NewLine(Standard_True);
124   if (thenext.IsNull()) return;
125   thenext->WriteParams(SW);
126 }
127
128     void  StepData_UndefinedEntity::GetFromAnother
129   (const Handle(StepData_UndefinedEntity)& another,
130    Interface_CopyTool& TC)
131 {
132 //  DeclareAndCast(StepData_UndefinedEntity,another,other);
133   thetype = new TCollection_HAsciiString (another->StepType());
134   thecont = new Interface_UndefinedContent;
135   thecont->GetFromAnother(another->UndefinedContent(),TC);
136
137   thesub = another->IsSub();
138   if (another->IsComplex()) thenext =
139     GetCasted(StepData_UndefinedEntity,TC.Transferred(another->Next()));
140   else thenext.Nullify();
141 }
142
143
144     void  StepData_UndefinedEntity::FillShared
145   (Interface_EntityIterator& list) const
146 {
147   Standard_Integer i, nb = thecont->NbParams();
148   for (i = 1; i <= nb; i ++) {
149     Interface_ParamType ptype = thecont->ParamType(i);
150     if (ptype == Interface_ParamSub) {
151       DeclareAndCast(StepData_UndefinedEntity,subent,thecont->ParamEntity(i));
152       subent->FillShared (list);
153     } else if (ptype == Interface_ParamIdent) {
154       list.AddItem(thecont->ParamEntity(i));
155     }
156   }
157   if (!thenext.IsNull()) thenext->FillShared (list);
158 }