00001 /*======================================================================= 00002 * Copyright 1991-1996, Silicon Graphics, Inc. 00003 * ALL RIGHTS RESERVED 00004 * 00005 * UNPUBLISHED -- Rights reserved under the copyright laws of the United 00006 * States. Use of a copyright notice is precautionary only and does not 00007 * imply publication or disclosure. 00008 * 00009 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND: 00010 * Use, duplication or disclosure by the Government is subject to restrictions 00011 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights 00012 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or 00013 * in similar or successor clauses in the FAR, or the DOD or NASA FAR 00014 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc., 00015 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311. 00016 * 00017 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY 00018 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, 00019 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY 00020 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON 00021 * GRAPHICS, INC. 00022 **=======================================================================*/ 00023 /*======================================================================= 00024 ** Author : Paul S. Strauss (MMM yyyy) 00025 ** Modified by : Nick Thompson (MMM yyyy) 00026 ** Modified by : Gavin Bell (MMM yyyy) 00027 **=======================================================================*/ 00028 /*======================================================================= 00029 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00030 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00031 *** *** 00032 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00033 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00034 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00035 *** *** 00036 *** RESTRICTED RIGHTS LEGEND *** 00037 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00038 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00039 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00040 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00041 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00042 *** *** 00043 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, *** 00044 *** BORDEAUX, FRANCE *** 00045 *** ALL RIGHTS RESERVED *** 00046 **=======================================================================*/ 00047 /*======================================================================= 00048 ** Modified by : VSG (MMM YYYY) 00049 **=======================================================================*/ 00050 00051 00052 00053 #ifndef _SO_FIELD_DATA_ 00054 #define _SO_FIELD_DATA_ 00055 00056 #include <Inventor/misc/SoBasic.h> 00057 #include <Inventor/SbPList.h> 00058 #include <Inventor/SbString.h> 00059 00060 class SoField; 00061 class SoInput; 00062 class SoFieldContainer; 00063 class SoOutput; 00064 00066 // 00067 // Class: SoFieldData 00068 // 00069 // The SoFieldData class holds data about fields of an object: the 00070 // number of fields the object has, the names of the fields, and a 00071 // pointer to a prototype instance of the field. (Typically, this 00072 // prototype field is contained within a prototype instance of the 00073 // node or engine.) 00074 // 00075 // All objects of a given class share the same field data. Therefore, 00076 // to get information about a particular field in a particular object 00077 // instance, it is necessary to pass that instance to the appropriate 00078 // method. 00079 // 00081 00082 { 00083 public: 00084 // Constructor 00085 SoFieldData() {} 00086 00087 // Copy constructors 00088 SoFieldData(const SoFieldData &); 00089 SoFieldData(const SoFieldData *); 00090 00091 // Constructor that takes number of fields as a hint 00092 SoFieldData(int numFields) : fields(numFields) {} 00093 00094 // Destructor 00095 ~SoFieldData(); 00096 00097 // Adds a field to current data, given default value object, name of 00098 // field and pointer to field within default value object. This is 00099 // used to define fields of a FieldContainer (node or engine) class. 00100 void addField(SoFieldContainer *defObject, 00101 const char *fieldName, 00102 const SoField *field); 00103 00104 // Copy values and flags of fields from one object to another (of 00105 // the same type). If copyConnections is TRUE, any connections to 00106 // the fields are copied as well 00107 void overlay(SoFieldContainer *to, 00108 const SoFieldContainer *from, 00109 SbBool copyConnections) const; 00110 00111 // Returns number of fields 00112 int getNumFields() const { return fields.getLength(); } 00113 00114 // Returns name of field with given index 00115 const SbName & getFieldName(int index) const; 00116 00117 // Returns name of field with given adress 00118 SbString getFieldName(const SoFieldContainer *object, const SoField* field) const; 00119 00120 // Returns pointer to field with given name 00121 SoField* getField(const SoFieldContainer *object, const SbString& name) const; 00122 00123 // Returns pointer to field with given index within given object instance 00124 SoField * getField(const SoFieldContainer *object, 00125 int index) const; 00126 00127 // Returns index of field, given the field and the instance it is in 00128 int getIndex(const SoFieldContainer *fc, 00129 const SoField *field) const; 00130 00131 // Enum name/value mechanism 00132 void addEnumValue(const char *typeName, 00133 const char *valName, int val); 00134 void getEnumData(char *typeName, int &num, 00135 int *&vals, SbName *&names); 00136 void getEnumValueName(char *typeName, int val, SbName *&name); 00137 00138 private: 00139 00140 // Reads into fields according to SoInput. The third 00141 // parameter indicates whether an unknown field should be reported 00142 // as an error; this can be FALSE for nodes that have children. 00143 // The last argument will be set to TRUE if a description of the 00144 // fields (using the "inputs" or "fields" keywords) was read. 00145 SbBool read(SoInput *in, SoFieldContainer *object, 00146 SbBool errorOnUnknownField, 00147 SbBool ¬BuiltIn) const; 00148 00149 // This function is used when the field name has already been 00150 // read, and just the value needs to be read in. It is used by 00151 // the above read() method and to read in GlobalFields. It 00152 // returns TRUE if there were no problems reading, and will return 00153 // FALSE in 'foundName' if the given name is not the name of one 00154 // of the fields in the fieldData. 00155 SbBool read(SoInput *in, SoFieldContainer *object, 00156 const SbName &fieldName, 00157 SbBool &foundName) const; 00158 00159 // Writes all fields of object according to SoOutput 00160 void write(SoOutput *out, 00161 const SoFieldContainer *object) const; 00162 00163 // Copies all fields from given field data into this one, creating 00164 // new fields for them 00165 void copy(const SoFieldData *from); 00166 00167 // Returns TRUE if the values in the fields of one container are 00168 // the same as those in another (of the same type) 00169 SbBool isSame(const SoFieldContainer *c1, 00170 const SoFieldContainer *c2) const; 00171 00172 // Read field type information 00173 SbBool readEventIn( 00174 SoInput *in, SoFieldContainer *object ) const; 00175 00176 SbBool readEventOut( 00177 SoInput *in, SoFieldContainer *object ) const; 00178 00179 // Read field type information 00180 SbBool readVField( 00181 SoInput *in, SoFieldContainer *object ) const; 00182 // Read field type information 00183 SbBool readVExposedField( 00184 SoInput *in, SoFieldContainer *object ) const; 00185 00186 // Read field type information 00187 SbBool readFieldDescriptions( 00188 SoInput *in, SoFieldContainer *object, 00189 int numDescriptionsExpected) const; 00190 00191 // Write field type information 00192 void writeFieldDescriptions( 00193 SoOutput *out, 00194 const SoFieldContainer *object) const; 00195 00196 private: 00197 // Used by binary reading to read in all the fields: 00198 SbBool readFields( 00199 SoInput *in, SoFieldContainer *object, 00200 int numFieldsWritten) const; 00201 00202 SbPList fields; // List of fields (SoFieldEntry) 00203 SbPList enums; // List of enums (SoEnumEntry) 00204 00211 struct SoFieldEntry 00212 { 00213 SbName name; // Name of field 00214 int64_t offset; // Offset of field within object 00215 bool noObj; 00216 }; 00217 00218 struct SoEnumEntry 00219 { 00220 SbName typeName; // Name of enum type 00221 int num; // number of values 00222 int arraySize; // size of arrays 00223 int *vals; // array of values 00224 SbName *names; // array of names 00225 00226 SoEnumEntry(const SbName &name); 00227 SoEnumEntry(const SoEnumEntry &o); 00228 ~SoEnumEntry(); 00229 00230 static int growSize; // amount to grow arrays 00231 }; 00232 00233 }; 00234 00235 #endif /* _SO_FIELD_DATA_ */ 00236 00237 00238