Open Inventor Release 2024.2.0
 
Loading...
Searching...
No Matches
SoFieldData.h
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Paul S. Strauss (MMM yyyy)
25** Modified by : Nick Thompson (MMM yyyy)
26** Modified by : Gavin Bell (MMM yyyy)
27**=======================================================================*/
28/*=======================================================================
29 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
30 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
31 *** ***
32 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
33 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
34 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
35 *** ***
36 *** RESTRICTED RIGHTS LEGEND ***
37 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
38 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
39 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
40 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
41 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
42 *** ***
43 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, ***
44 *** BORDEAUX, FRANCE ***
45 *** ALL RIGHTS RESERVED ***
46**=======================================================================*/
47/*=======================================================================
48** Modified by : VSG (MMM YYYY)
49**=======================================================================*/
50
51
52
53#ifndef _SO_FIELD_DATA_
54#define _SO_FIELD_DATA_
55
56#include <Inventor/misc/SoBasic.h>
57#include <Inventor/SbPList.h>
58#include <Inventor/SbString.h>
59
60class SoField;
61class SoInput;
63class SoOutput;
64
66//
67// Class: SoFieldData
68//
69// The SoFieldData class holds data about fields of an object: the
70// number of fields the object has, the names of the fields, and a
71// pointer to a prototype instance of the field. (Typically, this
72// prototype field is contained within a prototype instance of the
73// node or engine.)
74//
75// All objects of a given class share the same field data. Therefore,
76// to get information about a particular field in a particular object
77// instance, it is necessary to pass that instance to the appropriate
78// method.
79//
81
82{
83 public:
84 // Constructor
85 SoFieldData() {}
86
87 // Copy constructors
88 SoFieldData(const SoFieldData &);
89 SoFieldData(const SoFieldData *);
90
91 // Constructor that takes number of fields as a hint
92 SoFieldData(int numFields) : fields(numFields) {}
93
94 // Destructor
95 ~SoFieldData();
96
97 // Adds a field to current data, given default value object, name of
98 // field and pointer to field within default value object. This is
99 // used to define fields of a FieldContainer (node or engine) class.
100 void addField(SoFieldContainer *defObject,
101 const char *fieldName,
102 const SoField *field);
103
104 // Copy values and flags of fields from one object to another (of
105 // the same type). If copyConnections is TRUE, any connections to
106 // the fields are copied as well
107 void overlay(SoFieldContainer *to,
108 const SoFieldContainer *from,
109 SbBool copyConnections) const;
110
111 // Returns number of fields
112 int getNumFields() const { return fields.getLength(); }
113
114 // Returns name of field with given index
115 const SbName & getFieldName(int index) const;
116
117 // Returns name of field with given adress
118 SbString getFieldName(const SoFieldContainer *object, const SoField* field) const;
119
120 // Returns pointer to field with given name
121 SoField* getField(const SoFieldContainer *object, const SbString& name) const;
122
123 // Returns pointer to field with given index within given object instance
124 SoField * getField(const SoFieldContainer *object,
125 int index) const;
126
127 // Returns index of field, given the field and the instance it is in
128 int getIndex(const SoFieldContainer *fc,
129 const SoField *field) const;
130
131 // Enum name/value mechanism
132 void addEnumValue(const char *typeName,
133 const char *valName, int val);
134 void getEnumData(char *typeName, int &num,
135 int *&vals, SbName *&names);
136 void getEnumValueName(char *typeName, int val, SbName *&name);
137
138 private:
139
140 // Reads into fields according to SoInput. The third
141 // parameter indicates whether an unknown field should be reported
142 // as an error; this can be FALSE for nodes that have children.
143 // The last argument will be set to TRUE if a description of the
144 // fields (using the "inputs" or "fields" keywords) was read.
145 SbBool read(SoInput *in, SoFieldContainer *object,
146 SbBool errorOnUnknownField,
147 SbBool &notBuiltIn) const;
148
149 // This function is used when the field name has already been
150 // read, and just the value needs to be read in. It is used by
151 // the above read() method and to read in GlobalFields. It
152 // returns TRUE if there were no problems reading, and will return
153 // FALSE in 'foundName' if the given name is not the name of one
154 // of the fields in the fieldData.
155 SbBool read(SoInput *in, SoFieldContainer *object,
156 const SbName &fieldName,
157 SbBool &foundName) const;
158
159 // Writes all fields of object according to SoOutput
160 void write(SoOutput *out,
161 const SoFieldContainer *object) const;
162
163 // Copies all fields from given field data into this one, creating
164 // new fields for them
165 void copy(const SoFieldData *from);
166
167 // Returns TRUE if the values in the fields of one container are
168 // the same as those in another (of the same type)
169 SbBool isSame(const SoFieldContainer *c1,
170 const SoFieldContainer *c2) const;
171
172 // Read field type information
173 SbBool readEventIn(
174 SoInput *in, SoFieldContainer *object ) const;
175
176 SbBool readEventOut(
177 SoInput *in, SoFieldContainer *object ) const;
178
179 // Read field type information
180 SbBool readVField(
181 SoInput *in, SoFieldContainer *object ) const;
182 // Read field type information
183 SbBool readVExposedField(
184 SoInput *in, SoFieldContainer *object ) const;
185
186 // Read field type information
187 SbBool readFieldDescriptions(
188 SoInput *in, SoFieldContainer *object,
189 int numDescriptionsExpected) const;
190
191 // Write field type information
192 void writeFieldDescriptions(
193 SoOutput *out,
194 const SoFieldContainer *object) const;
195
196 private:
197 // Used by binary reading to read in all the fields:
198 SbBool readFields(
199 SoInput *in, SoFieldContainer *object,
200 int numFieldsWritten) const;
201
202 SbPList fields; // List of fields (SoFieldEntry)
203 SbPList enums; // List of enums (SoEnumEntry)
204
211 struct SoFieldEntry
212 {
213 SbName name; // Name of field
214 int64_t offset; // Offset of field within object
215 bool noObj;
216 };
217
218 struct SoEnumEntry
219 {
220 SbName typeName; // Name of enum type
221 int num; // number of values
222 int arraySize; // size of arrays
223 int *vals; // array of values
224 SbName *names; // array of names
225
226 SoEnumEntry(const SbName &name);
227 SoEnumEntry(const SoEnumEntry &o);
228 ~SoEnumEntry();
229
230 static int growSize; // amount to grow arrays
231 };
232
233};
234
235#endif /* _SO_FIELD_DATA_ */
236
237
Character string stored in a hash table.
Definition SbName.h:162
List of generic (void *) pointers.
Definition SbPList.h:77
int getLength() const
Returns number of pointers in list.
Definition SbPList.h:125
Class for smart character strings.
Definition SbString.h:202
Abstract base class for objects that contain fields.
Base class for all fields.
Definition SoField.h:234
Used to read Open Inventor data files.
Definition SoInput.h:363
Used to write Open Inventor data files.
Definition SoOutput.h:186
int SbBool
Boolean type.
Definition SbBase.h:87