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 | // |
d5f74e42 |
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 |
973c2be1 |
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 | |
42cf5bc1 |
14 | |
15 | #include <StepData_EnumTool.hxx> |
16 | #include <TCollection_AsciiString.hxx> |
7fd59977 |
17 | |
18 | static TCollection_AsciiString nulstr(""); |
19 | |
20 | StepData_EnumTool::StepData_EnumTool |
21 | (const Standard_CString e0, const Standard_CString e1, |
22 | const Standard_CString e2, const Standard_CString e3, |
23 | const Standard_CString e4, const Standard_CString e5, |
24 | const Standard_CString e6, const Standard_CString e7, |
25 | const Standard_CString e8, const Standard_CString e9, |
26 | const Standard_CString e10,const Standard_CString e11, |
27 | const Standard_CString e12,const Standard_CString e13, |
28 | const Standard_CString e14,const Standard_CString e15, |
29 | const Standard_CString e16,const Standard_CString e17, |
30 | const Standard_CString e18,const Standard_CString e19, |
31 | const Standard_CString e20,const Standard_CString e21, |
32 | const Standard_CString e22,const Standard_CString e23, |
33 | const Standard_CString e24,const Standard_CString e25, |
34 | const Standard_CString e26,const Standard_CString e27, |
35 | const Standard_CString e28,const Standard_CString e29, |
36 | const Standard_CString e30,const Standard_CString e31, |
37 | const Standard_CString e32,const Standard_CString e33, |
38 | const Standard_CString e34,const Standard_CString e35, |
39 | const Standard_CString e36,const Standard_CString e37, |
40 | const Standard_CString e38,const Standard_CString e39) |
41 | { |
42 | AddDefinition (e0); AddDefinition (e1); AddDefinition (e2); |
43 | AddDefinition (e3); AddDefinition (e4); AddDefinition (e5); |
44 | AddDefinition (e6); AddDefinition (e7); AddDefinition (e8); |
45 | AddDefinition (e9); AddDefinition (e10); AddDefinition (e11); |
46 | AddDefinition (e12); AddDefinition (e13); AddDefinition (e14); |
47 | AddDefinition (e15); AddDefinition (e16); AddDefinition (e17); |
48 | AddDefinition (e18); AddDefinition (e19); AddDefinition (e20); |
49 | AddDefinition (e21); AddDefinition (e22); AddDefinition (e23); |
50 | AddDefinition (e24); AddDefinition (e25); AddDefinition (e26); |
51 | AddDefinition (e27); AddDefinition (e28); AddDefinition (e29); |
52 | AddDefinition (e30); AddDefinition (e31); AddDefinition (e32); |
53 | AddDefinition (e33); AddDefinition (e34); AddDefinition (e35); |
54 | AddDefinition (e36); AddDefinition (e37); AddDefinition (e38); |
55 | AddDefinition (e39); |
56 | theinit = thetexts.Length(); theopt = Standard_True; |
57 | } |
58 | |
59 | void StepData_EnumTool::AddDefinition (const Standard_CString term) |
60 | { |
61 | char text[80]; |
62 | if (!term) return; |
63 | if (term[0] == '\0') return; |
64 | Standard_Integer n0 = 0, n1 = 0; |
65 | for (; term[n0] != '\0'; n0 ++) { |
66 | if (term[n0] <= 32) { |
67 | if (n1 == 0) continue; |
68 | if (n1 > 1 || text[0] != '$') { |
69 | if (text[n1-1] != '.') { text[n1] = '.'; n1 ++; } |
70 | text[n1] = '\0'; |
71 | } |
72 | thetexts.Append ( TCollection_AsciiString(text) ); |
73 | n1 = 0; |
74 | } |
75 | if (n1 == 0 && term[n0] != '.' && term[n0] != '$') { text[0] = '.'; n1 ++; } |
76 | text[n1] = term[n0]; n1 ++; |
77 | } |
78 | if (n1 > 0 || text[0] != '$') { |
79 | if (text[n1-1] != '.') { text[n1] = '.'; n1 ++; } |
80 | text[n1] = '\0'; |
81 | } |
82 | if (text[n1-1] != '.') { text[n1] = '.'; n1 ++; } |
83 | text[n1] = '\0'; |
84 | thetexts.Append ( TCollection_AsciiString(text) ); |
85 | } |
86 | |
87 | Standard_Boolean StepData_EnumTool::IsSet () const |
88 | { return (thetexts.Length() > theinit); } |
89 | |
90 | Standard_Integer StepData_EnumTool::MaxValue () const |
91 | { return thetexts.Length() - 1; } |
92 | |
93 | void StepData_EnumTool::Optional (const Standard_Boolean mode) |
94 | { theopt = mode; } |
95 | |
96 | Standard_Integer StepData_EnumTool::NullValue () const |
97 | { return (theopt ? Value("$") : Standard_False); } |
98 | |
99 | const TCollection_AsciiString& StepData_EnumTool::Text |
100 | (const Standard_Integer num) const |
101 | { |
102 | if (num < 0 || num >= thetexts.Length()) return nulstr; |
103 | return thetexts.Value (num+1); |
104 | } |
105 | |
106 | Standard_Integer StepData_EnumTool::Value |
107 | (const Standard_CString txt) const |
108 | { |
109 | Standard_Integer nb = thetexts.Length(); |
110 | for (Standard_Integer i = 1; i <= nb; i ++) { |
111 | if (thetexts.Value(i).IsEqual(txt)) return i-1; |
112 | } |
113 | return (-1); |
114 | } |
115 | |
116 | Standard_Integer StepData_EnumTool::Value |
117 | (const TCollection_AsciiString& txt) const |
118 | { |
119 | Standard_Integer nb = thetexts.Length(); |
120 | for (Standard_Integer i = 1; i <= nb; i ++) { |
121 | if (thetexts.Value(i).IsEqual(txt)) return i-1; |
122 | } |
123 | return (-1); |
124 | } |