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-2014 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 00119 class SoTranSender { 00120 public: 00121 00126 SoTranSender(SoOutput *output); 00127 00131 ~SoTranSender() {} 00132 00133 00137 SoOutput * getOutput() const { return out; } 00138 00143 void insert(SoNode *node); 00144 00150 void insert(SoNode *node, SoNode *parent, int n); 00151 00156 void remove(SoNode *parent, int n); 00157 00163 void replace(SoNode *parent, int n, SoNode *newNode); 00169 void modify(SoNode *node); 00170 00176 void prepareToSend(); 00177 00178 private: 00179 SoOutput *out; 00180 00181 // Adding items to send 00182 void addBytes(const void *bytes, size_t nBytes); 00183 void addCommand(int command); 00184 void addInt(int n); 00185 void addNode(SoNode *node, SbBool addNames = TRUE); 00186 void addNodeNames(const SoNode *root); 00187 void addNodeRef(const SoNode *node); 00188 void addString(const char *cmdString); 00189 00190 friend class SoTranReceiver; 00191 }; 00192 00194 // 00195 // Class: SoTranReceiver 00196 // 00197 // An SoTranReceiver is used on the receiving end to interpret the 00198 // data packaged up by an SoTranSender. It is given a root node that 00199 // is the default place to add incoming nodes. The input for the 00200 // receiver comes from an SoInput. 00201 // 00203 00223 class SoTranReceiver { 00224 00225 public: 00226 00233 SoTranReceiver(SoGroup *rootNode); 00234 00238 ~SoTranReceiver(); 00239 00245 SbBool interpret(SoInput *in); 00246 00247 private: 00248 SoGroup *root; 00249 SbDict nameToEntryDict; // Maps node keyname to SoTranDictEntry 00250 SbDict nodeToNameDict; // Maps node pointer to node keyname 00251 00252 // Interprets one database change command (with given code) from stream. 00253 // Sets done to TRUE if end command was found. Returns T/F error status. 00254 SbBool interpretCommand(int commandCode, SoInput *in, SbBool &done); 00255 00256 // Gets a node and node names from the input 00257 SbBool getNodeAndNames(SoInput *in, SoNode *&node); 00258 00259 // Gets node from input 00260 SbBool getNode(SoInput *in, SoNode *&root); 00261 00262 // Recursively gets node names and sets up dictionaries. 00263 SbBool getNodeNames(SoInput *in, SoNode *root, 00264 SbBool lookForNode, SoNode *&oldRoot); 00265 00266 // Gets reference to a node, looks it up in dictionary, returns 00267 // node pointer. 00268 SbBool getNodeReference(SoInput *in, SoNode *&node); 00269 00270 // Removes reference to node in dictionaries, recursively. 00271 void removeNodeReferences(SoNode *node); 00272 00273 // Adds an entry to the dictionaries 00274 void addEntry(SoNode *node, SbName &name); 00275 00276 // Deletes (frees up) an entry from the nodeDict 00277 static void deleteDictEntry(uintptr_t key, void *value); 00278 }; 00279 00280 #endif /* _SO_TRANSCRIBE_ */ 00281 00282 00283 00284