0024530: TKMesh - remove unused package IntPoly
[occt.git] / src / StepData / StepData_EnumTool.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
973c2be1 5// This library is free software; you can redistribute it and / or modify it
6// under the terms of the GNU Lesser General Public 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 14#include <StepData_EnumTool.ixx>
15
16static TCollection_AsciiString nulstr("");
17
18StepData_EnumTool::StepData_EnumTool
19 (const Standard_CString e0, const Standard_CString e1,
20 const Standard_CString e2, const Standard_CString e3,
21 const Standard_CString e4, const Standard_CString e5,
22 const Standard_CString e6, const Standard_CString e7,
23 const Standard_CString e8, const Standard_CString e9,
24 const Standard_CString e10,const Standard_CString e11,
25 const Standard_CString e12,const Standard_CString e13,
26 const Standard_CString e14,const Standard_CString e15,
27 const Standard_CString e16,const Standard_CString e17,
28 const Standard_CString e18,const Standard_CString e19,
29 const Standard_CString e20,const Standard_CString e21,
30 const Standard_CString e22,const Standard_CString e23,
31 const Standard_CString e24,const Standard_CString e25,
32 const Standard_CString e26,const Standard_CString e27,
33 const Standard_CString e28,const Standard_CString e29,
34 const Standard_CString e30,const Standard_CString e31,
35 const Standard_CString e32,const Standard_CString e33,
36 const Standard_CString e34,const Standard_CString e35,
37 const Standard_CString e36,const Standard_CString e37,
38 const Standard_CString e38,const Standard_CString e39)
39{
40 AddDefinition (e0); AddDefinition (e1); AddDefinition (e2);
41 AddDefinition (e3); AddDefinition (e4); AddDefinition (e5);
42 AddDefinition (e6); AddDefinition (e7); AddDefinition (e8);
43 AddDefinition (e9); AddDefinition (e10); AddDefinition (e11);
44 AddDefinition (e12); AddDefinition (e13); AddDefinition (e14);
45 AddDefinition (e15); AddDefinition (e16); AddDefinition (e17);
46 AddDefinition (e18); AddDefinition (e19); AddDefinition (e20);
47 AddDefinition (e21); AddDefinition (e22); AddDefinition (e23);
48 AddDefinition (e24); AddDefinition (e25); AddDefinition (e26);
49 AddDefinition (e27); AddDefinition (e28); AddDefinition (e29);
50 AddDefinition (e30); AddDefinition (e31); AddDefinition (e32);
51 AddDefinition (e33); AddDefinition (e34); AddDefinition (e35);
52 AddDefinition (e36); AddDefinition (e37); AddDefinition (e38);
53 AddDefinition (e39);
54 theinit = thetexts.Length(); theopt = Standard_True;
55}
56
57 void StepData_EnumTool::AddDefinition (const Standard_CString term)
58{
59 char text[80];
60 if (!term) return;
61 if (term[0] == '\0') return;
62 Standard_Integer n0 = 0, n1 = 0;
63 for (; term[n0] != '\0'; n0 ++) {
64 if (term[n0] <= 32) {
65 if (n1 == 0) continue;
66 if (n1 > 1 || text[0] != '$') {
67 if (text[n1-1] != '.') { text[n1] = '.'; n1 ++; }
68 text[n1] = '\0';
69 }
70 thetexts.Append ( TCollection_AsciiString(text) );
71 n1 = 0;
72 }
73 if (n1 == 0 && term[n0] != '.' && term[n0] != '$') { text[0] = '.'; n1 ++; }
74 text[n1] = term[n0]; n1 ++;
75 }
76 if (n1 > 0 || text[0] != '$') {
77 if (text[n1-1] != '.') { text[n1] = '.'; n1 ++; }
78 text[n1] = '\0';
79 }
80 if (text[n1-1] != '.') { text[n1] = '.'; n1 ++; }
81 text[n1] = '\0';
82 thetexts.Append ( TCollection_AsciiString(text) );
83}
84
85 Standard_Boolean StepData_EnumTool::IsSet () const
86 { return (thetexts.Length() > theinit); }
87
88 Standard_Integer StepData_EnumTool::MaxValue () const
89 { return thetexts.Length() - 1; }
90
91 void StepData_EnumTool::Optional (const Standard_Boolean mode)
92 { theopt = mode; }
93
94 Standard_Integer StepData_EnumTool::NullValue () const
95 { return (theopt ? Value("$") : Standard_False); }
96
97 const TCollection_AsciiString& StepData_EnumTool::Text
98 (const Standard_Integer num) const
99{
100 if (num < 0 || num >= thetexts.Length()) return nulstr;
101 return thetexts.Value (num+1);
102}
103
104 Standard_Integer StepData_EnumTool::Value
105 (const Standard_CString txt) const
106{
107 Standard_Integer nb = thetexts.Length();
108 for (Standard_Integer i = 1; i <= nb; i ++) {
109 if (thetexts.Value(i).IsEqual(txt)) return i-1;
110 }
111 return (-1);
112}
113
114 Standard_Integer StepData_EnumTool::Value
115 (const TCollection_AsciiString& txt) const
116{
117 Standard_Integer nb = thetexts.Length();
118 for (Standard_Integer i = 1; i <= nb; i ++) {
119 if (thetexts.Value(i).IsEqual(txt)) return i-1;
120 }
121 return (-1);
122}