0026936: Drawbacks of inlining in new type system in OCCT 7.0 -- automatic
[occt.git] / src / StepData / StepData_EnumTool.hxx
1 // Created on: 1995-10-25
2 // Created by: Christian CAILLET
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _StepData_EnumTool_HeaderFile
18 #define _StepData_EnumTool_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <TColStd_SequenceOfAsciiString.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Boolean.hxx>
27 #include <Standard_CString.hxx>
28 class TCollection_AsciiString;
29
30
31 //! This class gives a way of conversion between the value of an
32 //! enumeration and its representation in STEP
33 //! An enumeration corresponds to an integer with reserved values,
34 //! which begin to 0
35 //! In STEP, it is represented by a name in capital letter and
36 //! limited by two dots, e.g. .UNKNOWN.
37 //!
38 //! EnumTool works with integers, it is just required to cast
39 //! between an integer and an enumeration of required type.
40 //!
41 //! Its definition is intended to allow static creation in once,
42 //! without having to recreate once for each use.
43 //!
44 //! It is possible to define subclasses on it, which directly give
45 //! the good list of definition texts, and accepts a enumeration
46 //! of the good type instead of an integer
47 class StepData_EnumTool 
48 {
49 public:
50
51   DEFINE_STANDARD_ALLOC
52
53   
54   //! Creates an EnumTool with definitions given by e0 .. e<max>
55   //! Each definition string can bring one term, or several
56   //! separated by blanks. Each term corresponds to one value of the
57   //! enumeration, if dots are not presents they are added
58   //!
59   //! Such a static constructor allows to build a static description
60   //! as : static StepData_EnumTool myenumtool("e0","e1"...);
61   //! then use it without having to initialise it
62   //!
63   //! A null definition can be input by given "$" :the corresponding
64   //! position is attached to "null/undefined" value (as one
65   //! particular item of the enumeration list)
66   Standard_EXPORT StepData_EnumTool(const Standard_CString e0 = "", const Standard_CString e1 = "", const Standard_CString e2 = "", const Standard_CString e3 = "", const Standard_CString e4 = "", const Standard_CString e5 = "", const Standard_CString e6 = "", const Standard_CString e7 = "", const Standard_CString e8 = "", const Standard_CString e9 = "", const Standard_CString e10 = "", const Standard_CString e11 = "", const Standard_CString e12 = "", const Standard_CString e13 = "", const Standard_CString e14 = "", const Standard_CString e15 = "", const Standard_CString e16 = "", const Standard_CString e17 = "", const Standard_CString e18 = "", const Standard_CString e19 = "", const Standard_CString e20 = "", const Standard_CString e21 = "", const Standard_CString e22 = "", const Standard_CString e23 = "", const Standard_CString e24 = "", const Standard_CString e25 = "", const Standard_CString e26 = "", const Standard_CString e27 = "", const Standard_CString e28 = "", const Standard_CString e29 = "", const Standard_CString e30 = "", const Standard_CString e31 = "", const Standard_CString e32 = "", const Standard_CString e33 = "", const Standard_CString e34 = "", const Standard_CString e35 = "", const Standard_CString e36 = "", const Standard_CString e37 = "", const Standard_CString e38 = "", const Standard_CString e39 = "");
67   
68   //! Processes a definition, splits it according blanks if any
69   //! empty definitions are ignored
70   //! A null definition can be input by given "$" :the corresponding
71   //! position is attached to "null/undefined" value (as one
72   //! particular item of the enumeration list)
73   //! See also IsSet
74   Standard_EXPORT void AddDefinition (const Standard_CString term);
75   
76   //! Returns True if at least one definition has been entered after
77   //! creation time (i.e. by AddDefinition only)
78   //!
79   //! This allows to build a static description by a first pass :
80   //! static StepData_EnumTool myenumtool("e0" ...);
81   //! ...
82   //! if (!myenumtool.IsSet()) {             for further inits
83   //! myenumtool.AddDefinition("e21");
84   //! ...
85   //! }
86   Standard_EXPORT Standard_Boolean IsSet() const;
87   
88   //! Returns the maximum integer for a suitable value
89   //! Remark : while values begin at zero, MaxValue is the count of
90   //! recorded values minus one
91   Standard_EXPORT Standard_Integer MaxValue() const;
92   
93   //! Sets or Unsets the EnumTool to accept undefined value (for
94   //! optional field). Ignored if no null value is defined (by "$")
95   //! Can be changed during execution (to read each field),
96   //! Default is True (if a null value is defined)
97   Standard_EXPORT void Optional (const Standard_Boolean mode);
98   
99   //! Returns the value attached to "null/undefined value"
100   //! If none is specified or if Optional has been set to False,
101   //! returns -1
102   //! Null Value has been specified by definition "$"
103   Standard_EXPORT Standard_Integer NullValue() const;
104   
105   //! Returns the text which corresponds to a given numeric value
106   //! It is limited by dots
107   //! If num is out of range, returns an empty string
108   Standard_EXPORT const TCollection_AsciiString& Text (const Standard_Integer num) const;
109   
110   //! Returns the numeric value found for a text
111   //! The text must be in capitals and limited by dots
112   //! A non-suitable text gives a negative value to be returned
113   Standard_EXPORT Standard_Integer Value (const Standard_CString txt) const;
114   
115   //! Same as above but works on an AsciiString
116   Standard_EXPORT Standard_Integer Value (const TCollection_AsciiString& txt) const;
117
118
119
120
121 protected:
122
123
124
125
126
127 private:
128
129
130
131   TColStd_SequenceOfAsciiString thetexts;
132   Standard_Integer theinit;
133   Standard_Boolean theopt;
134
135
136 };
137
138
139
140
141
142
143
144 #endif // _StepData_EnumTool_HeaderFile