Class_Insert

 

The "Class_Insert()" function is used to insert files, using your class in the database structure.

 

It is called when a new file is read, or when the user ask sliceOmatic to update the database structure.

 

Once the image files have been read in sliceOmatic, it need to create a database of classes that will be used to manipulate the images from the files. This is the function that place the images in the database.

 

The function is recursive.  Once you have created your class, you use it as the parent of the call to the next level of the function.  The DB_Tree_Insert variable give you the "Class_Insert()" pointers you need for each level.

 

 

Syntax

 

extern "C" __declspec(dllexport) int          Class_Insert(

          SliceO_File *file,

          int bunch,

          int slice,

          SliceO_Class *parent,

          unsigned short level

)

 

 

Parameters

 

file

Pointer to the file structure of the file to insert

 

bunch

bunch number if the file has multiple bunches (groups of slices)

 

slice

slice number if the file has multiple slices

 

parent

Pointer to the parent of this structure

 

level

Current level in the database tree

 

 

Return value

 

The function returns "0" if an error occurred, "1" otherwise.

 

 

Remarks

 

 

 

Requirements

 

Header:

          sliceO_include.hpp

 

Library:

          sliceO_Structures.lib

 

 

Example

 

The "Series" class

 

...

 

// ----------------------------------------------------------------------------

//

//          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 ) ) ;

}

...

 

See also

 

Class File