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 **=======================================================================*/ 00026 /*======================================================================= 00027 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), *** 00028 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. *** 00029 *** *** 00030 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS *** 00031 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR *** 00032 *** WRITTEN AUTHORIZATION OF FEI S.A.S. *** 00033 *** *** 00034 *** RESTRICTED RIGHTS LEGEND *** 00035 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS *** 00036 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN *** 00037 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT *** 00038 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN *** 00039 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. *** 00040 *** *** 00041 *** COPYRIGHT (C) 1996-2020 BY FEI S.A.S, *** 00042 *** BORDEAUX, FRANCE *** 00043 *** ALL RIGHTS RESERVED *** 00044 **=======================================================================*/ 00045 /*======================================================================= 00046 ** Modified by : VSG (MMM YYYY) 00047 **=======================================================================*/ 00048 00049 00050 #ifndef _SO_TRANSCRIBE_ 00051 #define _SO_TRANSCRIBE_ 00052 00053 #include <Inventor/misc/SoBasic.h> 00054 #include <Inventor/SbString.h> 00055 #include <Inventor/SbDict.h> 00056 00057 class SoGroup; 00058 class SoInput; 00059 class SoNode; 00060 class SoOutput; 00061 00063 // 00064 // Class: SoTranSender 00065 // 00066 // This stores database changes that are to be transcribed. The 00067 // changes are written to an SoOutput instance allocated and managed 00068 // by the caller. 00069 // 00070 // These database change routines are supported: 00071 // 00072 // INSERT node [parent n] 00073 // Creates and adds a node to other database. With 1 argument, 00074 // the node is added as the last child of the root of the 00075 // database. With 3 arguments, the node is added as the nth 00076 // child of the given parent. (The parent may be NULL to 00077 // indicate the root.) Note that if the inserted node is already 00078 // in the graph, a link is made from the parent to the existing 00079 // version of the node. (Therefore, if the new node is different 00080 // from the old one, any changes are lost.) 00081 // 00082 // REMOVE parent n 00083 // Removes nth child from the given parent node. (The parent may 00084 // be NULL to indicate the root.) 00085 // 00086 // REPLACE parent n newNode 00087 // This is exactly equivalent to "REMOVE parent n" followed by 00088 // "INSERT newNode parent n". 00089 // 00090 // MODIFY node 00091 // Updates the field data for the given node to the new 00092 // contents. Note that this changes only field data; children of 00093 // groups are not affected, nor is any non-field instance data. 00094 // 00096 00120 class SoTranSender { 00121 public: 00122 00127 SoTranSender(SoOutput *output); 00128 00132 ~SoTranSender() {} 00133 00134 00138 SoOutput * getOutput() const { return out; } 00139 00144 void insert(SoNode *node); 00145 00151 void insert(SoNode *node, SoNode *parent, int n); 00152 00157 void remove(SoNode *parent, int n); 00158 00164 void replace(SoNode *parent, int n, SoNode *newNode); 00170 void modify(SoNode *node); 00171 00177 void prepareToSend(); 00178 00179 private: 00180 SoOutput *out; 00181 00182 // Adding items to send 00183 void addBytes(const void *bytes, size_t nBytes); 00184 void addCommand(int command); 00185 void addInt(int n); 00186 void addNode(SoNode *node, SbBool addNames = TRUE); 00187 void addNodeNames(const SoNode *root); 00188 void addNodeRef(const SoNode *node); 00189 void addString(const char *cmdString); 00190 00191 friend class SoTranReceiver; 00192 }; 00193 00195 // 00196 // Class: SoTranReceiver 00197 // 00198 // An SoTranReceiver is used on the receiving end to interpret the 00199 // data packaged up by an SoTranSender. It is given a root node that 00200 // is the default place to add incoming nodes. The input for the 00201 // receiver comes from an SoInput. 00202 // 00204 00225 class SoTranReceiver { 00226 00227 public: 00228 00235 SoTranReceiver(SoGroup *rootNode); 00236 00240 ~SoTranReceiver(); 00241 00247 SbBool interpret(SoInput *in); 00248 00249 private: 00250 SoGroup *root; 00251 SbDict nameToEntryDict; // Maps node keyname to SoTranDictEntry 00252 SbDict nodeToNameDict; // Maps node pointer to node keyname 00253 00254 // Interprets one database change command (with given code) from stream. 00255 // Sets done to TRUE if end command was found. Returns T/F error status. 00256 SbBool interpretCommand(int commandCode, SoInput *in, SbBool &done); 00257 00258 // Gets a node and node names from the input 00259 SbBool getNodeAndNames(SoInput *in, SoNode *&node); 00260 00261 // Gets node from input 00262 SbBool getNode(SoInput *in, SoNode *&root); 00263 00264 // Recursively gets node names and sets up dictionaries. 00265 SbBool getNodeNames(SoInput *in, SoNode *root, 00266 SbBool lookForNode, SoNode *&oldRoot); 00267 00268 // Gets reference to a node, looks it up in dictionary, returns 00269 // node pointer. 00270 SbBool getNodeReference(SoInput *in, SoNode *&node); 00271 00272 // Removes reference to node in dictionaries, recursively. 00273 void removeNodeReferences(SoNode *node); 00274 00275 // Adds an entry to the dictionaries 00276 void addEntry(SoNode *node, SbName &name); 00277 00278 // Deletes (frees up) an entry from the nodeDict 00279 static void deleteDictEntry(uintptr_t key, void *value); 00280 }; 00281 00282 #endif /* _SO_TRANSCRIBE_ */ 00283 00284 00285 00286