Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-29 09:20:24

0001 // Created on: 1995-10-25
0002 // Created by: Christian CAILLET
0003 // Copyright (c) 1995-1999 Matra Datavision
0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0005 //
0006 // This file is part of Open CASCADE Technology software library.
0007 //
0008 // This library is free software; you can redistribute it and/or modify it under
0009 // the terms of the GNU Lesser General Public License version 2.1 as published
0010 // by the Free Software Foundation, with special exception defined in the file
0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0012 // distribution for complete text of the license and disclaimer of any warranty.
0013 //
0014 // Alternatively, this file may be used under the terms of Open CASCADE
0015 // commercial license or contractual agreement.
0016 
0017 #ifndef _StepData_EnumTool_HeaderFile
0018 #define _StepData_EnumTool_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 #include <Standard_Handle.hxx>
0023 
0024 #include <TCollection_AsciiString.hxx>
0025 #include <NCollection_Sequence.hxx>
0026 #include <Standard_CString.hxx>
0027 class TCollection_AsciiString;
0028 
0029 //! This class gives a way of conversion between the value of an
0030 //! enumeration and its representation in STEP
0031 //! An enumeration corresponds to an integer with reserved values,
0032 //! which begin to 0
0033 //! In STEP, it is represented by a name in capital letter and
0034 //! limited by two dots, e.g. .UNKNOWN.
0035 //!
0036 //! EnumTool works with integers, it is just required to cast
0037 //! between an integer and an enumeration of required type.
0038 //!
0039 //! Its definition is intended to allow static creation in once,
0040 //! without having to recreate once for each use.
0041 //!
0042 //! It is possible to define subclasses on it, which directly give
0043 //! the good list of definition texts, and accepts a enumeration
0044 //! of the good type instead of an integer
0045 class StepData_EnumTool
0046 {
0047 public:
0048   DEFINE_STANDARD_ALLOC
0049 
0050   //! Creates an EnumTool with definitions given by e0 .. e<max>
0051   //! Each definition string can bring one term, or several
0052   //! separated by blanks. Each term corresponds to one value of the
0053   //! enumeration, if dots are not presents they are added
0054   //!
0055   //! Such a static constructor allows to build a static description
0056   //! as : static StepData_EnumTool myenumtool("e0","e1"...);
0057   //! then use it without having to initialise it
0058   //!
0059   //! A null definition can be input by given "$" :the corresponding
0060   //! position is attached to "null/undefined" value (as one
0061   //! particular item of the enumeration list)
0062   Standard_EXPORT StepData_EnumTool(const char* const e0  = "",
0063                                     const char* const e1  = "",
0064                                     const char* const e2  = "",
0065                                     const char* const e3  = "",
0066                                     const char* const e4  = "",
0067                                     const char* const e5  = "",
0068                                     const char* const e6  = "",
0069                                     const char* const e7  = "",
0070                                     const char* const e8  = "",
0071                                     const char* const e9  = "",
0072                                     const char* const e10 = "",
0073                                     const char* const e11 = "",
0074                                     const char* const e12 = "",
0075                                     const char* const e13 = "",
0076                                     const char* const e14 = "",
0077                                     const char* const e15 = "",
0078                                     const char* const e16 = "",
0079                                     const char* const e17 = "",
0080                                     const char* const e18 = "",
0081                                     const char* const e19 = "",
0082                                     const char* const e20 = "",
0083                                     const char* const e21 = "",
0084                                     const char* const e22 = "",
0085                                     const char* const e23 = "",
0086                                     const char* const e24 = "",
0087                                     const char* const e25 = "",
0088                                     const char* const e26 = "",
0089                                     const char* const e27 = "",
0090                                     const char* const e28 = "",
0091                                     const char* const e29 = "",
0092                                     const char* const e30 = "",
0093                                     const char* const e31 = "",
0094                                     const char* const e32 = "",
0095                                     const char* const e33 = "",
0096                                     const char* const e34 = "",
0097                                     const char* const e35 = "",
0098                                     const char* const e36 = "",
0099                                     const char* const e37 = "",
0100                                     const char* const e38 = "",
0101                                     const char* const e39 = "");
0102 
0103   //! Processes a definition, splits it according blanks if any
0104   //! empty definitions are ignored
0105   //! A null definition can be input by given "$" :the corresponding
0106   //! position is attached to "null/undefined" value (as one
0107   //! particular item of the enumeration list)
0108   //! See also IsSet
0109   Standard_EXPORT void AddDefinition(const char* const term);
0110 
0111   //! Returns True if at least one definition has been entered after
0112   //! creation time (i.e. by AddDefinition only)
0113   //!
0114   //! This allows to build a static description by a first pass :
0115   //! static StepData_EnumTool myenumtool("e0" ...);
0116   //! ...
0117   //! if (!myenumtool.IsSet()) {             for further inits
0118   //! myenumtool.AddDefinition("e21");
0119   //! ...
0120   //! }
0121   Standard_EXPORT bool IsSet() const;
0122 
0123   //! Returns the maximum integer for a suitable value
0124   //! Remark : while values begin at zero, MaxValue is the count of
0125   //! recorded values minus one
0126   Standard_EXPORT int MaxValue() const;
0127 
0128   //! Sets or Unsets the EnumTool to accept undefined value (for
0129   //! optional field). Ignored if no null value is defined (by "$")
0130   //! Can be changed during execution (to read each field),
0131   //! Default is True (if a null value is defined)
0132   Standard_EXPORT void Optional(const bool mode);
0133 
0134   //! Returns the value attached to "null/undefined value"
0135   //! If none is specified or if Optional has been set to False,
0136   //! returns -1
0137   //! Null Value has been specified by definition "$"
0138   Standard_EXPORT int NullValue() const;
0139 
0140   //! Returns the text which corresponds to a given numeric value
0141   //! It is limited by dots
0142   //! If num is out of range, returns an empty string
0143   Standard_EXPORT const TCollection_AsciiString& Text(const int num) const;
0144 
0145   //! Returns the numeric value found for a text
0146   //! The text must be in capitals and limited by dots
0147   //! A non-suitable text gives a negative value to be returned
0148   Standard_EXPORT int Value(const char* const txt) const;
0149 
0150   //! Same as above but works on an AsciiString
0151   Standard_EXPORT int Value(const TCollection_AsciiString& txt) const;
0152 
0153 private:
0154   NCollection_Sequence<TCollection_AsciiString> thetexts;
0155   int                                           theinit;
0156   bool                                          theopt;
0157 };
0158 
0159 #endif // _StepData_EnumTool_HeaderFile