|
...
// ----------------------------------------------------------------------------
//
// Class_Insert
//
// This is the function that is called to insert a new element into
// the database tree.
//
// param: file (SliceO_File *) Pt to the file struct of the file to insert
// bunch (int) If the file has multiple groups
// slice (int) If the file has multiple slices
// parent (SliceO_Class *) Pt to the parent of this structure
// level (unsigned short) Current level in the database tree
//
// return: (int) NULL if error.
//
// ----------------------------------------------------------------------------
extern "C" __declspec(dllexport) int Class_Insert( SliceO_File *file, int bunch, int slice, SliceO_Class *parent, unsigned short level )
{
// --- The DB_Tree_Insert variable contain a list of "Class_Insert()" functions
// for all the classes used in the database tree. Each element in the list is a
// pointer to the function of the class at that level in the database tree.
// The first element is a pointer to the function of the "SliceO_Root" class, the
// last is a pointer to the function of the SliceO_Frame" class. The list is
// modified with the "DB Class" mode. ---
unsigned short *DB_Tree_Id = (unsigned short *) Fct_Variable_Value( "$DB_TREE_ID" ) ;
int (**DB_Tree_Insert)(SliceO_File *,int,int,SliceO_Class *,unsigned short)
= (int (**)(SliceO_File *,int,int,SliceO_Class *,unsigned short)) Fct_Variable_Value( "$DB_TREE_PT" ) ;
// ====================================================================
// Create the new element
// ====================================================================
SliceO_Series *series = new SliceO_Series( parent, DB_Tree_Id[level], file, bunch, slice ) ;
// ====================================================================
// Do we already have an equivalent element for this file?
// ====================================================================
// --- look at all the existing children of the parent ---
// If one of the children of the parent already match the same criteria,
// we do not need a new structure, instead we insert this slice in the
// existing structure.
for ( int k=0; k < parent->Child_Get_Nb(); k++ ) {
if ( ! series->Compare( parent->Child_Get_Pt(k) ) ) {
// --- we will use the already existing series, we do not need the
// new one anymore, so delete it. ---
delete series ;
// --- continue creating the tree using the already existing series
// as a parent for the next level ---
return( (DB_Tree_Insert[level+1])( file, bunch, slice, parent->Child_Get_Pt(k), level+1 ) ) ;
}
}
// ====================================================================
// this new element is placed in the parent's "child" structure
// ====================================================================
parent->Child_Add( (SliceO_Class *) series ) ;
// ====================================================================
// Mark this new structure for update
// ====================================================================
Fct_Update( UPDATE_DATA_GLI | UPDATE_DISPLAY_GLI | UPDATE_DATA_TAG | UPDATE_DISPLAY_TAG,
NULL, series, NULL ) ;
// ====================================================================
// Continue creating the tree until the leaf nodes. The parent of
// of the next level is the newly created "series" class.
// ====================================================================
return( (DB_Tree_Insert[level+1])( file, bunch, slice, series, level+1 ) ) ;
}
...
|