Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

attach_new_node.C

Go to the documentation of this file.
00001 local INLINE void attach_new_node(worldbundle *wb, worldline *ww,
00002                                   pdyn *root, tdyn *top, tdyn *bb,
00003                                   bool debug)
00004 {
00005     // Create and attach a new node corresponding to worldline ww.
00006     // The root node for the interpolated tree is root; bb is the base
00007     // node for worldline ww; top is its top-level base node (at the
00008     // start of the segment).
00009 
00010     // The traversal of the tree is such that parents are always seen
00011     // before children and elder sisters are always seen before younger
00012     // sisters.
00013 
00014     if (debug)
00015         cerr << "base node " << bb << " "
00016              << bb->get_time() << " "
00017              << bb->format_label() << endl;
00018 
00019     pdyn *curr = new pdyn(NULL, NULL, false);
00020 
00021     // Replace by alloc_pdyn() if we do our own memory management.
00022 
00023     // Attach curr to the tree.  Don't use add_node except for the first
00024     // node, as it will create a tree with nodes in reverse order!
00025 
00026     if (bb == top) {
00027 
00028         // Attach the top-level node.
00029         // Add curr to the end of the top-level list.
00030 
00031         pdyn *n = root->get_oldest_daughter();
00032 
00033         if (!n)
00034             add_node(*curr, *root);
00035 
00036         else {
00037             while (n->get_younger_sister())
00038                 n = n->get_younger_sister();
00039             n->set_younger_sister(curr);
00040             curr->set_elder_sister(n);
00041             curr->set_parent(root);
00042         }
00043 
00044     } else {
00045 
00046         // Attach a low-level node.
00047 
00048         // Parent and elder sister pointers are derived
00049         // (awkwardly!) from the existing tree structures.
00050 
00051         pdyn *par = wb->find_worldline(bb->get_parent())
00052                       ->get_tree_node();
00053         curr->set_parent(par);
00054 
00055         tdyn * bb_sis = bb->get_elder_sister();
00056 
00057         if (!bb_sis)
00058             par->set_oldest_daughter(curr);
00059         else {
00060             pdyn *sis = wb->find_worldline(bb_sis)
00061                           ->get_tree_node();
00062             curr->set_elder_sister(sis);
00063             sis->set_younger_sister(curr);
00064         }
00065     }
00066 
00067     if (NEW == 1) {
00068 
00069         //-----------------------------------------------------------------
00070         // The following "static" quantities should be constant within a
00071         // segment, and thus need only be set when node curr is created.
00072         // Should not be necessary to copy these data at each update.
00073         //
00074         //              name/index
00075         //              worldline index
00076         //-----------------------------------------------------------------
00077 
00078         // Moved here from update_node.C (Steve, 5/30/01):
00079 
00080         // Very helpful to attach the worldline ID as an index to the pdyn,
00081         // but then we lose the connection between the index seen by the
00082         // display program and the index in the original data.  Save both!
00083 
00084         // Index is the original index; worldline ID is worldline_index.
00085 
00086         // Moved here from update_node.C (Steve, 5/30/01):
00087 
00088         if (bb->get_name()) {
00089             curr->set_name(bb->get_name());
00090             curr->set_index(atoi(bb->get_name()));
00091         }
00092         if (bb->get_index() >= 0)
00093             curr->set_index(bb->get_index());
00094 
00095         // Cleanest way to get the worldline index:
00096 
00097         int i = wb->find_index(bb);
00098         if (i < 0) {
00099             PRL(wb->find_index(bb));
00100             PRC(bb); PRL(bb->format_label());
00101         }
00102         curr->set_worldline_index(wb->find_index(bb));
00103 
00104         curr->set_mass(bb->get_mass());
00105     }
00106 
00107     ww->set_tree_node(curr);
00108 
00109     // Set standard values for some quantities:
00110 
00111     ww->set_t_curr(-VERY_LARGE_NUMBER);
00112     ww->set_current_event(NULL);
00113 }

Generated at Sun Feb 24 09:56:55 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001