1 #ifndef STEPATTRIBUTE_H
2 #define STEPATTRIBUTE_H 1
3 
4 /*
5 * NIST STEP Core Class Library
6 * clstepcore/STEPattribute.h
7 * April 1997
8 * K. C. Morris
9 * David Sauder
10 
11 * Development of this software was funded by the United States Government,
12 * and is not subject to copyright.
13 */
14 
15 
16 #include <sc_export.h>
17 #include <stdio.h>
18 #include <errordesc.h>
19 #include <baseType.h>
20 
21 #include <sdai.h>
22 
23 /** \def REAL_NUM_PRECISION
24  * this is used to set a const int Real_Num_Precision
25  * in STEPaggregate.cc and STEPattribute.cc
26  */
27 #define REAL_NUM_PRECISION 15
28 
29 typedef double real;
30 
31 class InstMgrBase;
32 class SDAI_Application_instance;
33 class STEPaggregate;
34 class SCLundefined;
35 
36 class TypeDescriptor;
37 class AttrDescriptor;
38 class EntityDescriptor;
39 
40 #include <sstream>
41 
42 extern SC_CORE_EXPORT int SetErrOnNull( const char * attrValue, ErrorDescriptor * error );
43 
44 extern SC_CORE_EXPORT SDAI_Application_instance * ReadEntityRef( istream & in, ErrorDescriptor * err, const char * tokenList,
45         InstMgrBase * instances, int addFileId );
46 
47 extern SC_CORE_EXPORT SDAI_Application_instance * ReadEntityRef( const char * s, ErrorDescriptor * err, const char * tokenList,
48         InstMgrBase * instances, int addFileId );
49 
50 extern SC_CORE_EXPORT Severity EntityValidLevel( SDAI_Application_instance * se,
51         const TypeDescriptor * ed, ///< entity type that entity se needs to match. (this must be an EntityDescriptor)
52         ErrorDescriptor * err );
53 
54 extern SC_CORE_EXPORT Severity EntityValidLevel( const char * attrValue, ///< string containing entity ref
55         const TypeDescriptor * ed, /**< entity type that entity in attrValue (if it exists) needs
56                                              *  to match. (this must be an EntityDescriptor)
57                                              */
58         ErrorDescriptor * err, InstMgrBase * im, int clearError );
59 
60 ////////////////////
61 ////////////////////
62 
63 extern SC_CORE_EXPORT SDAI_Application_instance * STEPread_reference( const char * s, ErrorDescriptor * err,
64         InstMgrBase * instances, int addFileId );
65 ////////////////////
66 
67 extern SC_CORE_EXPORT int QuoteInString( istream & in );
68 
69 extern SC_CORE_EXPORT void AppendChar( char c, int & index, char *& s, int & sSize );
70 
71 extern SC_CORE_EXPORT void PushPastString( istream & in, std::string & s, ErrorDescriptor * err );
72 
73 extern SC_CORE_EXPORT void PushPastImbedAggr( istream & in, std::string & s, ErrorDescriptor * err );
74 
75 extern SC_CORE_EXPORT void PushPastAggr1Dim( istream & in, std::string & s, ErrorDescriptor * err );
76 
77 class SC_CORE_EXPORT STEPattribute {
78         friend ostream & operator<< ( ostream &, STEPattribute & );
79         friend class SDAI_Application_instance;
80     protected:
81         bool _derive;
82         bool _mustDeletePtr; ///if a member uses new to create an object in ptr
83         ErrorDescriptor _error;
84         STEPattribute * _redefAttr;
85         const AttrDescriptor * aDesc;
86         int refCount;
87 
88         /** \union ptr
89         ** You know which of these to use based on the return value of
90         ** NonRefType() - see below. BASE_TYPE is defined in baseType.h
91         ** This variable points to an appropriate member variable in the entity
92         ** class in the generated schema class library (the entity class is
93         ** inherited from SDAI_Application_instance)
94         */
95         union attrUnion {
96             SDAI_String * S;                 // STRING_TYPE
97             SDAI_Integer * i;                // INTEGER_TYPE (Integer is a long int)
98             SDAI_Binary * b;                 // BINARY_TYPE
99             SDAI_Real * r;                   // REAL_TYPE and NUMBER_TYPE (Real is a double)
100             SDAI_Application_instance * * c; // ENTITY_TYPE
101             STEPaggregate * a;               // AGGREGATE_TYPE
102             SDAI_Enum * e;                   // ENUM_TYPE, BOOLEAN_TYPE, and LOGICAL_TYPE
103             SDAI_Select * sh;                // SELECT_TYPE
104             SCLundefined * u;                // UNKNOWN_TYPE
105             void * p;
106         } ptr;
107 
108         char SkipBadAttr( istream & in, char * StopChars );
109         void AddErrorInfo();
110         void STEPwriteError( ostream& out, unsigned int line, const char* desc );
111 
112     public:
incrRefCount()113         void incrRefCount() {
114             ++ refCount;
115         }
decrRefCount()116         void decrRefCount() {
117             -- refCount;
118         }
getRefCount()119         int getRefCount() {
120             return refCount;
121         }
getADesc()122         const AttrDescriptor * getADesc() {
123             return aDesc;
124         }
125         void Derive( bool n = true )  {
126             _derive = n;
127         }
128 
RedefiningAttr(STEPattribute * a)129         void RedefiningAttr( STEPattribute * a ) {
130             _redefAttr = a;
131         }
132 
133 ///////////// Read, Write, Assign attr value
134 
135         Severity StrToVal( const char * s, InstMgrBase * instances = 0,
136                            int addFileId = 0 );
137         Severity STEPread( istream & in = cin, InstMgrBase * instances = 0,
138                            int addFileId = 0, const char * currSch = NULL, bool strict = true );
139 
140         /// return the attr value as a string
141         string asStr( const char * currSch = 0 ) const;
142 
143         /// put the attr value in ostream
144         void STEPwrite( ostream & out = cout, const char * currSch = 0 );
145         void ShallowCopy( const STEPattribute * sa );
146 
147         Severity set_null();
148 
149         /**
150          * These functions verify that the attribute contains the requested type and
151          * returns a pointer. The pointer is null if the requested type does not match.
152          *
153          * \sa Raw()
154          * \sa NonRefType()
155          * \sa is_null()
156          */
157         ///@{
158         SDAI_Integer              * Integer();
159         SDAI_Real                 * Real();
160         SDAI_Real                 * Number();
161         SDAI_String               * String();
162         SDAI_Binary               * Binary();
163         SDAI_Application_instance * Entity();
164         STEPaggregate             * Aggregate();
165         SDAI_Enum                 * Enum();
166         SDAI_LOGICAL              * Logical();
167         SDAI_BOOLEAN              * Boolean();
168         SDAI_Select               * Select();
169         SCLundefined              * Undefined();
170         ///@}
171 
172         /// allows direct access to the union containing attr data (dangerous!)
Raw()173         attrUnion * Raw() {
174             return & ptr;
175         }
176 
177         /**
178          * These functions allow setting the attribute value.
179          * Attr type is verified using an assertion.
180          *
181          * TODO should they check that the pointer was null?
182          * what about ptr.c, which is ( SDAI_Application_instance ** ) ?
183          */
184         ///@{
185         void Integer( SDAI_Integer * n );
186         void Real( SDAI_Real * n );
187         void Number( SDAI_Real * n );
188         void String( SDAI_String * str );
189         void Binary( SDAI_Binary * bin );
190         void Entity( SDAI_Application_instance * ent );
191         void Aggregate( STEPaggregate * aggr );
192         void Enum( SDAI_Enum * enu );
193         void Logical( SDAI_LOGICAL * log );
194         void Boolean( SDAI_BOOLEAN * boo );
195         void Select( SDAI_Select * sel );
196         void Undefined( SCLundefined * undef );
197         ///@}
198 
199 ////////////// Return info on attr
200 
201         bool Nullable() const; // may this attribute be null?
202         bool is_null() const;  // is this attribute null?
IsDerived()203         bool IsDerived() const  {
204             return _derive;
205         }
RedefiningAttr()206         STEPattribute * RedefiningAttr() {
207             return _redefAttr;
208         }
209 
210         const char  *  Name() const;
211         const char  *  TypeName() const;
212         BASE_TYPE   Type() const;
213         BASE_TYPE   NonRefType() const;
214         BASE_TYPE   BaseType() const;
215 
216         const TypeDescriptor * ReferentType() const;
217 
Error()218         ErrorDescriptor & Error()    {
219             return _error;
220         }
ClearErrorMsg()221         void ClearErrorMsg()    {
222             _error.ClearErrorMsg();
223         }
224 
225         Severity ValidLevel( const char* attrValue, ErrorDescriptor* error, InstMgrBase * im, bool clearError = true );
226 
227 ////////////////// Constructors
228 
229         STEPattribute( const STEPattribute & a );
STEPattribute()230         STEPattribute(): _derive( false ), _mustDeletePtr( false ),
231                          _redefAttr( 0 ), aDesc( 0 ), refCount( 0 )  {
232             memset( & ptr, 0, sizeof( ptr ) );
233         }
234         ~STEPattribute();
235         //  INTEGER
236         STEPattribute( const class AttrDescriptor & d, SDAI_Integer * p );
237         //  BINARY
238         STEPattribute( const class AttrDescriptor & d, SDAI_Binary * p );
239         //  STRING
240         STEPattribute( const class AttrDescriptor & d, SDAI_String * p );
241         //  REAL & NUMBER
242         STEPattribute( const class AttrDescriptor & d, SDAI_Real * p );
243         //  ENTITY
244         STEPattribute( const class AttrDescriptor & d, SDAI_Application_instance* *p );
245         //  AGGREGATE
246         STEPattribute( const class AttrDescriptor & d, STEPaggregate * p );
247         //  ENUMERATION  and Logical
248         STEPattribute( const class AttrDescriptor & d, SDAI_Enum * p );
249         //  SELECT
250         STEPattribute( const class AttrDescriptor & d, SDAI_Select * p );
251         //  UNDEFINED
252         STEPattribute( const class AttrDescriptor & d, SCLundefined * p );
253 
254         /// return true if attr types and values match
255         SC_CORE_EXPORT friend bool operator == ( const STEPattribute & a1, const STEPattribute & a2 );
256         SC_CORE_EXPORT friend bool operator != ( const STEPattribute & a1, const STEPattribute & a2 );
257 
258         /// return true if aDesc's match (behavior of old operator==)
259         SC_CORE_EXPORT friend bool sameADesc ( const STEPattribute & a1, const STEPattribute & a2 );
260 };
261 
262 #endif
263