0031481: Data Exchange - provide parser of STEP EXPRESS schema for generation of...
[occt.git] / src / Express / Express_Select.cxx
1 // Created:     Tue Nov  2 14:40:06 1999
2 // Author:      Andrey BETENEV
3 // Copyright (c) 1999-2020 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License 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.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #include <Express_Select.hxx>
17
18 #include <Express.hxx>
19 #include <Express_Alias.hxx>
20 #include <Express_ComplexType.hxx>
21 #include <Express_Entity.hxx>
22 #include <Express_Enum.hxx>
23 #include <Express_HSequenceOfItem.hxx>
24 #include <Express_Type.hxx>
25 #include <Message.hxx>
26 #include <OSD_Directory.hxx>
27 #include <OSD_FileSystem.hxx>
28 #include <OSD_Path.hxx>
29 #include <OSD_Protection.hxx>
30 #include <TColStd_HSequenceOfHAsciiString.hxx>
31
32 IMPLEMENT_STANDARD_RTTIEXT(Express_Select, Express_Item)
33
34 //=======================================================================
35 // function : Express_Select
36 // purpose  :
37 //=======================================================================
38
39 Express_Select::Express_Select ( const Standard_CString theName,
40                                  const Handle(TColStd_HSequenceOfHAsciiString)& theNames)
41 : Express_Item (theName), myNames (theNames)
42 {
43   myItems = new Express_HSequenceOfItem;
44 }
45
46 //=======================================================================
47 // function : Names
48 // purpose  :
49 //=======================================================================
50
51 const Handle(TColStd_HSequenceOfHAsciiString)& Express_Select::Names() const
52 {
53   return myNames;
54 }
55
56 //=======================================================================
57 // function : Items
58 // purpose  :
59 //=======================================================================
60
61 const Handle(Express_HSequenceOfItem)& Express_Select::Items() const
62 {
63   return myItems;
64 }
65
66 //=======================================================================
67 // function : GenerateClass
68 // purpose  :
69 //=======================================================================
70
71 Standard_Boolean Express_Select::GenerateClass() const
72 {
73   const TCollection_AsciiString aCPPName = CPPName();
74
75   Handle(TColStd_HSequenceOfInteger) aSeqMember = new TColStd_HSequenceOfInteger;
76   Handle(TColStd_HSequenceOfInteger) aSeqEntities = new TColStd_HSequenceOfInteger;
77   for (Standard_Integer i = 1; i <= myItems->Length(); i++)
78   {
79     Handle(Express_Item) anItem = myItems->Value (i);
80     if (anItem->IsKind (STANDARD_TYPE(Express_Entity)) || anItem->IsKind (STANDARD_TYPE(Express_Select))
81         || anItem->IsKind (STANDARD_TYPE(Express_Alias)) || anItem->IsKind (STANDARD_TYPE(Express_ComplexType)))
82     {
83       aSeqEntities->Append (i);
84     }
85     else
86     {
87       aSeqMember->Append (i);
88     }
89   }
90   Message::SendInfo() << "Generating SELECT " << aCPPName;
91   if (!aSeqMember->IsEmpty())
92   {
93     Message::SendInfo() << "Generating SELECTMember " << aCPPName << "Member";
94     generateSelectMember (aSeqMember);
95   }
96   // create a package directory (if not yet exist)
97   OSD_Protection aProt (OSD_RWXD, OSD_RWXD, OSD_RX, OSD_RX);
98   TCollection_AsciiString aPack = GetPackageName();
99   OSD_Path aPath (aPack);
100   OSD_Directory aDir (aPath);
101   aDir.Build (aProt);
102   aPack += "/";
103   aPack += aCPPName;
104   const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
105
106   //===============================
107   // Step 1: generating HXX
108   {
109     // Open HXX file
110     std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aPack.Cat (".hxx"), std::ios::out | std::ios::binary);
111     Standard_OStream& anOS = *aStreamPtr;
112
113     // write header
114     Express::WriteFileStamp (anOS);
115
116     // write start define
117     anOS << "#ifndef _" << aCPPName << "_HeaderFile\n"
118             "#define _" << aCPPName << "_HeaderFile\n"
119             "\n";
120
121     // write common includes
122     anOS << "#include <Standard.hxx>\n"
123             "#include <Standard_DefineAlloc.hxx>\n"
124             "#include <Standard_Handle.hxx>\n"
125             "#include <StepData_SelectType.hxx>\n"
126             "#include <Standard_Integer.hxx>\n"
127             "\n";
128
129     anOS << "class Standard_Transient;\n";
130     if (!aSeqMember->IsEmpty())
131       anOS << "class StepData_SelectMember;\n";
132
133     Standard_Integer jj = 1;
134     for (Standard_Integer i = 1; i <= myItems->Length(); i++)
135     {
136       Handle(Express_Item) anItem = myItems->Value (i);
137       anItem->Use();
138       if (anItem->IsKind (STANDARD_TYPE(Express_Alias)))
139       {
140         Handle(Express_Type) aType = Handle(Express_Alias)::DownCast (anItem)->Type();
141         if (aType->IsStandard())
142         {
143           continue;
144         }
145       }
146       anOS << "class " << anItem->CPPName() << ";\n";
147       jj++;
148     }
149     anOS << "\n";
150
151     // class declaration
152     anOS << "//! Representation of STEP SELECT type " << Name() << "\n"
153             "class " << aCPPName << " : public StepData_SelectType\n"
154             "{\n"
155             "\n"
156             "public:\n"
157             "\n"
158             "  DEFINE_STANDARD_ALLOC\n"
159             "\n";
160
161     // default constructor
162     anOS << "  //! Empty constructor\n"
163             "  Standard_EXPORT " << aCPPName << "();\n"
164             "\n";
165
166     // write common methods section
167     anOS << "  //! Recognizes a kind of " << Name() << " select type\n";
168     for (Standard_Integer i = 1; i <= aSeqEntities->Length(); i++)
169     {
170       Standard_Integer anIdx = aSeqEntities->Value (i);
171       anOS << "  //! -- " << i << " -> " << myNames->Value (anIdx)->String() << "\n";
172     }
173     anOS << "  Standard_EXPORT Standard_Integer CaseNum (const Handle(Standard_Transient)& theEnt) const Standard_OVERRIDE;\n"
174             "\n";
175
176     if (!aSeqMember->IsEmpty())
177     {
178       anOS << "  //! Recognizes items of select member " << Name() << "Member\n";
179       for (Standard_Integer i = 1; i <= aSeqMember->Length(); i++)
180       {
181         Standard_Integer anIdx = aSeqMember->Value (i);
182         anOS << "  //! -- " << i << " -> " << myNames->Value (anIdx)->String() << "\n";
183       }
184       anOS << "  //! -- 0 else\n"
185               "  Standard_EXPORT virtual Standard_Integer CaseMem (const Handle(StepData_SelectMember)& theEnt) const Standard_OVERRIDE;\n"
186               "\n"
187               "  //! Returns a new select member the type " << Name() << "Member\n"
188               "  Standard_EXPORT virtual Handle(StepData_SelectMember) NewMember() const Standard_OVERRIDE;\n"
189               "\n";
190     }
191
192     // write methods get for entities
193     for (Standard_Integer i = 1; i <= aSeqEntities->Length(); i++)
194     {
195       Standard_Integer anIdx = aSeqEntities->Value (i);
196       Handle(Express_Item) anItem = myItems->Value (anIdx);
197       const TCollection_AsciiString& aName = anItem->Name();
198       anOS << "  //! Returns Value as " << aName << " (or Null if another type)\n"
199               "  Standard_EXPORT Handle(" << anItem->CPPName() << ") " << aName << "() const;\n"
200               "\n";
201     }
202
203     // writes method set and get for enum , integer, real and string.
204     for (Standard_Integer i = 1; i <= aSeqMember->Length(); i++)
205     {
206       Standard_Integer anIdx = aSeqMember->Value (i);
207       Handle(Express_Item) anItem = myItems->Value (anIdx);
208       const TCollection_AsciiString& aName = anItem->Name();
209       const TCollection_AsciiString& anItemCPPName = anItem->CPPName();
210       anOS << "  //! Set Value for " << aName << "\n"
211               "  Standard_EXPORT void Set" << aName << " (const " << anItemCPPName << " theVal);\n"
212               "\n"
213               "  //! Returns Value as " << aName << " (or Null if another type)\n"
214               "  " << anItemCPPName << " " << aName << "() const;\n"
215               "\n";
216     }
217
218     // write end
219     anOS << "};\n"
220             "#endif // _" << aCPPName << "_HeaderFile\n";
221     aStreamPtr.reset();
222   }
223   //===============================
224   // Step 2: generating CXX
225   {
226     // Open CXX file
227     std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aPack.Cat (".cxx"), std::ios::out | std::ios::binary);
228     Standard_OStream& anOS = *aStreamPtr;
229
230     // write header
231     Express::WriteFileStamp (anOS);
232
233     // write include section
234     anOS << "#include <" << aCPPName << ".hxx>\n";
235     if (!aSeqMember->IsEmpty())
236     {
237       anOS << "#include <" << aCPPName << "Member.hxx>\n"
238               "#include <TCollection_HAsciiString.hxx>\n";
239     }
240     for (Standard_Integer i = 1; i <= aSeqEntities->Length(); i++)
241     {
242       Standard_Integer anIdx = aSeqEntities->Value (i);
243       anOS << "#include <" << myItems->Value (anIdx)->CPPName() << ".hxx>\n";
244     }
245
246     // write constructor
247     Express::WriteMethodStamp (anOS, aCPPName);
248     anOS << aCPPName << "::" << aCPPName << "()\n"
249            "{\n"
250            "}\n";
251
252     // write CaseNum method
253     Express::WriteMethodStamp (anOS, "CaseNum");
254     anOS << "Standard_Integer " << aCPPName << "::CaseNum (const Handle(Standard_Transient)& theEnt) const\n"
255             "{\n";
256
257     if (!aSeqEntities->IsEmpty())
258     {
259       anOS << "  if (theEnt.IsNull()) return 0;\n";
260       for (Standard_Integer i = 1; i <= aSeqEntities->Length(); i++)
261       {
262         Standard_Integer anIdx = aSeqEntities->Value (i);
263         anOS << "  if (theEnt->IsKind (STANDARD_TYPE(" << myItems->Value (anIdx)->CPPName() << "))) return " << i << ";\n";
264       }
265       anOS << "  return 0;\n"
266               "}\n";
267     }
268     else
269     {
270       anOS << "  return 0;\n"
271               "}\n";
272     }
273
274     if (!aSeqMember->IsEmpty())
275     {
276       // write CaseMem method
277       Express::WriteMethodStamp (anOS, "CaseMem");
278       anOS << "Standard_Integer " << aCPPName << "::CaseMem (const Handle(StepData_SelectMember)& theEnt) const\n"
279               "{\n"
280               "  if (theEnt.IsNull()) return 0;\n";
281       for (int j = 1; j <= aSeqMember->Length(); j++)
282       {
283         Standard_Integer anIdx = aSeqMember->Value (j);
284         if (j == 1)
285         {
286           anOS << "  if (theEnt->Matches (\"" << myNames->Value (anIdx)->String() << "\")) return " << j << ";\n";
287         }
288         else
289         {
290           anOS << "  else if (theEnt->Matches (\"" << myNames->Value (anIdx)->String() << "\")) return " << j << ";\n";
291         }
292       }
293       anOS << "  else return 0;\n"
294               "}\n";
295
296       // write NewMember method
297       Express::WriteMethodStamp (anOS, "NewMember");
298       anOS << "Handle(StepData_SelectMember) " << aCPPName << "::NewMember() const\n"
299               "{\n"
300               "  return new " << aCPPName << "Member;\n"
301               "}\n";
302     }
303
304     // write methods Get for entities.
305     for (Standard_Integer i = 1; i <= aSeqEntities->Length(); i++)
306     {
307       Standard_Integer anIdx = aSeqEntities->Value (i);
308       Handle(Express_Item) anItem = myItems->Value (anIdx);
309       const TCollection_AsciiString& aName = anItem->Name();
310       const TCollection_AsciiString& anItemCPPName = anItem->CPPName();
311       Express::WriteMethodStamp (anOS, aName);
312       anOS << "Handle(" << anItemCPPName << ") " << aCPPName << "::" << aName << "() const\n"
313               "{\n"
314               "  return Handle(" << anItemCPPName << ")::DownCast(Value());\n"
315               "}\n";
316     }
317
318     // write methods Set and Get for Integer, Real, String and Enum
319     for (Standard_Integer i = 1; i <= aSeqMember->Length(); i++)
320     {
321       Standard_Integer anIdx = aSeqMember->Value (i);
322       Handle(Express_Item) anItem = myItems->Value (anIdx);
323       const TCollection_AsciiString& aName = anItem->Name();
324       const TCollection_AsciiString& anItemCPPName = anItem->CPPName();
325       TCollection_AsciiString aStamp = "Set";
326       aStamp += aName;
327       Express::WriteMethodStamp (anOS, aStamp);
328
329       Standard_Boolean isString = (anItemCPPName.Location ("HAsciiString", 1, anItemCPPName.Length()) > 0);
330       TCollection_AsciiString aNameFunc;
331       TCollection_AsciiString aFunc;
332       Standard_Boolean isEnum = anItem->IsKind (STANDARD_TYPE(Express_Enum));
333       if (!isEnum)
334       {
335         if (isString)
336         {
337           aFunc += "String";
338         }
339         else
340         {
341           aNameFunc += anItemCPPName;
342           aFunc = aNameFunc;
343           Standard_Integer aSplitInd = aNameFunc.Location ("_", 1, anItemCPPName.Length());
344           if (aSplitInd)
345           {
346             aFunc = aNameFunc.Split (aSplitInd);
347           }
348         }
349       }
350
351       // write method set
352       if (isString)
353       {
354         anOS << "void " << aCPPName << "::Set" << aName << " (const Handle(" << anItemCPPName << ") &theVal)\n";
355       }
356       else
357       {
358         anOS << "void " << aCPPName << "::Set" << aName << " (const " << anItemCPPName << " theVal)\n";
359       }
360
361       anOS << "{\n"
362               "  Handle(" << aCPPName << "Member) SelMem = Handle(" << aCPPName << "Member)::DownCast(Value());\n"
363               "  if (SelMem.IsNull()) return;\n"
364               "  Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString(\"" << aName << "\");\n"
365               "  SelMem->SetName (aName->ToCString());\n";
366       if (isEnum)
367       {
368         anOS << "  SelMem->SetEnum ((Standard_Integer)theVal);\n";
369       }
370       else if (isString)
371       {
372         anOS << "  SelMem->Set" << aFunc << " (theVal->ToCString());\n";
373       }
374       else
375       {
376         anOS << "  SelMem->Set" << aFunc << " (theVal);\n";
377       }
378       anOS << "}\n";
379
380       // write method get
381       Express::WriteMethodStamp (anOS, aName);
382       if (isString)
383       {
384         anOS << "Handle(" << anItemCPPName << ") " << aCPPName << "::" << aName << "() const\n";
385       }
386       else
387       {
388         anOS << anItemCPPName << " " << aCPPName << "::" << aName << "() const\n";
389       }
390
391       anOS << "{\n"
392               "  Handle(" << aCPPName << "Member) SelMem = Handle(" << aCPPName << "Member)::DownCast (Value());\n"
393               "  if (SelMem.IsNull()) return 0;\n"
394               "  Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString;\n"
395               "  aName->AssignCat (SelMem->Name());\n"
396               "  Handle(TCollection_HAsciiString) aNameItem = new TCollection_HAsciiString(\"" << aName << "\");\n"
397               "  if (aName->IsDifferent (aNameItem)) return 0;\n";
398       if (isEnum)
399       {
400         anOS << "  Standard_Integer aNumIt = SelMem->Enum();\n"
401                 "  " << anItemCPPName << " aVal;\n"
402                 "  switch (aNumIt)\n"
403                 "  {\n";
404         Handle(Express_Enum) anEnum = Handle(Express_Enum)::DownCast (anItem);
405         Handle(TColStd_HSequenceOfHAsciiString) anEnItems = anEnum->Names();
406         TCollection_AsciiString aPrefix = Express::EnumPrefix (aName);
407         for (Standard_Integer k = 1; k <= anEnItems->Length(); k++)
408         {
409           anOS << "    case " << k << " : aVal = " << aName << "_" << aPrefix << anEnItems->Value (k)->String() << "; break;\n";
410         }
411         anOS << "    default : return 0; break;\n"
412                 "  }\n";
413       }
414       else if (isString)
415       {
416         anOS << "  Handle(TCollection_HAsciiString) aVal = new TCollection_HAsciiString;\n"
417                 "  aVal->AssignCat (SelMem->String());\n";
418       }
419       else
420       {
421         anOS << "  " << anItemCPPName << " aVal = SelMem->" << aFunc << "();\n";
422       }
423
424       anOS << "  return aVal;\n"
425               "}\n";
426
427     }
428     aStreamPtr.reset();
429   }
430
431   return Standard_True;
432 }
433
434 //=======================================================================
435 // function : PropagateUse
436 // purpose  :
437 //=======================================================================
438
439 void Express_Select::PropagateUse() const
440 {
441   const TCollection_AsciiString& aPack = GetPackageName();
442   const TCollection_AsciiString& aName = Name();
443
444   for (Standard_Integer i = 1; i <= myItems->Length(); i++)
445   {
446     Handle(Express_Item) anItem = myItems->Value (i);
447     anItem->Use2 (aName, aPack);
448   }
449 }
450
451 //=======================================================================
452 // function : GenerateSelectMember
453 // purpose  :
454 //=======================================================================
455
456 Standard_Boolean Express_Select::generateSelectMember (const Handle(TColStd_HSequenceOfInteger)& theSeqMember) const
457 {
458   TCollection_AsciiString aCPPname = CPPName();
459   aCPPname += "Member";
460
461   // create a package directory (if not yet exist)
462   OSD_Protection aProt (OSD_RWXD, OSD_RWXD, OSD_RX, OSD_RX);
463   TCollection_AsciiString aPack = GetPackageName();
464   OSD_Path aPath (aPack);
465   OSD_Directory aDir (aPath);
466   aDir.Build (aProt);
467   aPack += "/";
468   aPack += aCPPname;
469   const Handle(OSD_FileSystem)& aFileSystem = OSD_FileSystem::DefaultFileSystem();
470
471   // Step 1: generating HXX
472   {
473     // Open HXX file
474     std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aPack.Cat (".hxx"), std::ios::out | std::ios::binary);
475     Standard_OStream& anOS = *aStreamPtr;
476     // write header
477     Express::WriteFileStamp (anOS);
478
479     // write start define
480     anOS << "#ifndef _" << aCPPname << "_HeaderFile\n"
481                                        "#define _" << aCPPname << "_HeaderFile\n"
482                                                                   "\n";
483
484     // includes
485     anOS << "#include <Standard.hxx>\n"
486             "#include <Standard_Type.hxx>\n"
487             "#include <Standard_Boolean.hxx>\n"
488             "#include <Standard_CString.hxx>\n"
489             "#include <Standard_Integer.hxx>\n"
490             "#include <StepData_SelectNamed.hxx>\n"
491             "\n"
492             "DEFINE_STANDARD_HANDLE(" << aCPPname << ", StepData_SelectNamed)\n"
493                                                      "\n";
494
495     // write start of declaration (inheritance)
496     anOS << "  //! Representation of member for STEP SELECT type " << Name() << "\n"
497             "class " << aCPPname << " : public StepData_SelectNamed\n"
498             "{\n"
499             "public:\n";
500
501     // write methods
502     anOS << "  //! Empty constructor\n"
503             "  Standard_EXPORT " << aCPPname << "();\n"
504             "\n"
505             "  //! Returns True if has name\n"
506             "  Standard_EXPORT virtual Standard_Boolean HasName() const Standard_OVERRIDE;\n"
507             "\n"
508             "  //! Returns name\n"
509             "  Standard_EXPORT virtual Standard_CString Name() const Standard_OVERRIDE;\n"
510             "\n"
511             "  //! Set name\n"
512             "  Standard_EXPORT virtual Standard_Boolean SetName(const Standard_CString name) Standard_OVERRIDE;\n"
513             "\n"
514             "  //! Tells if the name of a SelectMember matches a given one;\n"
515             "  Standard_EXPORT virtual Standard_Boolean Matches (const Standard_CString name) const Standard_OVERRIDE;\n"
516             "\n";
517
518     // write fields
519     anOS << "private:\n"
520             "  Standard_Integer myCase;\n"
521             "\n";
522     // write end
523     anOS << "};\n"
524             "#endif // _" << aCPPname << "_HeaderFile\n";
525     aStreamPtr.reset();
526   }
527   //===============================
528   // Step 2: generating CXX
529   {
530     // Open CXX file
531     std::shared_ptr<std::ostream> aStreamPtr = aFileSystem->OpenOStream (aPack.Cat (".cxx"), std::ios::out | std::ios::binary);
532     Standard_OStream& anOS = *aStreamPtr;
533
534     // write header
535     Express::WriteFileStamp (anOS);
536
537     // write include section
538     anOS << "#include <" << aCPPname << ".hxx>\n"
539             "#include <TCollection_HAsciiString.hxx>\n";
540     // write constructor
541     Express::WriteMethodStamp (anOS, aCPPname);
542     anOS << aCPPname << "::" << aCPPname << "() : myCase(0) \n"
543             "{\n"
544             "}\n";
545
546     // write method HasName
547     Express::WriteMethodStamp (anOS, "HasName");
548     anOS << "Standard_Boolean " << aCPPname << "::HasName() const\n"
549             "{\n"
550             "  return myCase > 0;\n"
551             "}\n";
552
553     Standard_Boolean hasEnum = Standard_False;
554     // write method Name
555     Express::WriteMethodStamp (anOS, "Name");
556     anOS << "Standard_CString " << aCPPname << "::Name() const\n"
557             "{\n"
558             "  Handle(TCollection_HAsciiString) aName = new TCollection_HAsciiString;\n"
559             "  switch (myCase)"
560             "  {\n";
561     for (Standard_Integer i = 1; i <= theSeqMember->Length(); i++)
562     {
563       Standard_Integer anIdx = theSeqMember->Value (i);
564       Handle(Express_Item) anItem = myItems->Value (anIdx);
565       if (anItem->IsKind (STANDARD_TYPE(Express_Enum)))
566       {
567         hasEnum = Standard_True;
568       }
569       anOS << "    case " << i << " : aName->AssignCat (\"" << myNames->Value (anIdx)->String() << "\"); break;\n";
570     }
571     anOS << "    default : break;\n"
572             "  }\n"
573             "  return aName->String();\n"
574             "}\n";
575
576     // write static method for compare name
577     Express::WriteMethodStamp (anOS, "CompareNames");
578     anOS << "static Standard_Integer CompareNames (const Standard_CString theName";
579     if (hasEnum)
580     {
581       anOS << ", Standard_Integer &theNumEn)\n";
582     }
583     else
584     {
585       anOS << ")\n";
586     }
587     anOS << "{\n"
588             "  Standard_Integer aCase = 0;\n"
589             "  if (!theName || theName[0] == \'/0\') aCase = 0;\n";
590     for (Standard_Integer i = 1; i <= theSeqMember->Length(); i++)
591     {
592       Standard_Integer anIdx = theSeqMember->Value (i);
593       Handle(Express_Item) anItem = myItems->Value (anIdx);
594       if (anItem->IsKind (STANDARD_TYPE(Express_Enum)))
595       {
596         Handle(Express_Enum) en = Handle(Express_Enum)::DownCast (anItem);
597         for (Standard_Integer k = 1; k <= en->Names()->Length(); k++)
598         {
599           anOS << "  else if (!strcmp (theName, \"" << en->Names()->Value (k)->String() << "\"))\n"
600                   "  {\n"
601                   "    aCase = " << i << ";\n"
602                   "    theNumEn = " << k << ";\n"
603                   "  }\n";
604         }
605       }
606       else
607       {
608         anOS << "  else if (!strcmp (theName, \"" << myNames->Value (anIdx)->String() << "\")) aCase = " << i << ";\n";
609       }
610     }
611     anOS << "  return aCase;\n"
612             "}\n";
613
614     // write method SetName
615     Express::WriteMethodStamp (anOS, "SetName");
616     anOS << "Standard_Boolean " << aCPPname << "::SetName (const Standard_CString theName) \n"
617              "{\n";
618     if (hasEnum)
619     {
620       anOS << "  Standard_Integer aNumIt = 0;\n"
621               "  myCase = CompareNames (theName, aNumIt);\n"
622               "  if (aNumIt) SetInteger (aNumIt);\n";
623     }
624     else
625     {
626       anOS << "  myCase = CompareNames (theName);\n";
627     }
628     anOS << "  return (myCase > 0);\n"
629             "}\n";
630
631     // write method Matches
632     Express::WriteMethodStamp (anOS, "Matches");
633     anOS << "Standard_Boolean " << aCPPname << "::Matches (const Standard_CString theName) const\n"
634             "{\n";
635     if (hasEnum)
636     {
637       anOS << "  Standard_Integer aNumIt = 0;\n"
638               "  Standard_Integer aCase = CompareNames (theName, aNumIt);\n";
639     }
640     else
641     {
642       anOS << "  Standard_Integer aCase = CompareNames (theName);\n";
643     }
644     anOS << "  return (aCase > 0);\n"
645             "}\n";
646     aStreamPtr.reset();
647   }
648
649   return Standard_True;
650 }