Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:08

0001 // Copyright (c) 1999-2014 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef Interface_Statics_HeaderFile
0015 #define Interface_Statics_HeaderFile
0016 
0017 //  Macros to help static Handles not to be "constructed" before main run
0018 //  In order to avoid it, the Handle to be statically reserved is encapsulated
0019 //  in a structure itself designated through a Null Pointer :
0020 //  Only the pointer is declared static, and initialized to NULL : then,
0021 //  there is no routine to call for static construction
0022 
0023 //  Remember that the object designated by a static Handle should not be created
0024 //  in the static declaration, but must anyway be created, during main run,
0025 //  once before its first use : this is the initialization step.
0026 
0027 
0028 //  This set of macros allows user to simply declare and use "static" Handles.
0029 //  It is available once having included this file :
0030 //  ***************************************************
0031 //         #include <Interface_Statics.hxx>
0032 
0033 //  Static construction is replaced by using the macro StaticHandle :
0034 //  ***************************************************
0035 //    Old statement  :  static Handle(pk_class) object;
0036 //    Is replaced by :  StaticHandle(pk_class,object);
0037 //    which creates a null pointer called 'object_s' and typed 'pk_class_struc'
0038 
0039 //  For first initialisation and use, several ways are available, all of them
0040 //  give an access to the Handle through a reference.
0041 //  It is required to initialize the static structure once, the macros Init*
0042 //  assume that it is created once and only once, even if they are called
0043 //  more than once.
0044 //  It is possible : to create the object at initialization time by a macro,
0045 //  or to create it after the macro call through its reference :
0046 
0047 //  ***************************************************
0048 //  Old statement (in a routine, not static) :
0049 //          if (object.IsNull()) object = new pk_class (..args if any..);
0050 //  can be maintained, but preceded by an initialization :
0051 //          InitHandle(pk_class,object);         // -> Null Handle
0052 
0053 //  ***************************************************
0054 //  or it can be replaced by a direct formula (creation called only once) :
0055 //          InitHandleVoid(pk_class,object);     // for a void constructor
0056 //   or     InitHandleArgs(pk_class,object,(..args..));
0057 //               (the arglist between embedded parentheses)
0058 //   or     InitHandleVal(pk_class,object,val);  // i.e. object = val;
0059 
0060 //  To simply use this pseudo-static object, consider
0061 //  either the static variable  object_s->H
0062 //  ***************************************************
0063 //  or take it by the macro (which does not initialize it)
0064 //          UseHandle(pk_class,object);
0065 
0066 
0067 //  Declaration of a static Handle : first use for a given type
0068 #define StaticHandle(type,var) static struct type##_struc { Handle(type) H; } *var##_s = NULL
0069 
0070 //  Another declaration for an already declared type (with StaticHandle)
0071 #define StaticHandleA(type,var) static struct type##_struc *var##_s = NULL
0072 
0073 //  Using it (IT MUST HAVE BEEN FORMERLY INITIALIZED)
0074 #define UseHandle(type,var) Handle(type)& var = var##_s->H
0075 
0076 //  Initializing it (as Null Handle)
0077 #define InitHandle(type,var) \
0078 if(!var##_s) { var##_s=new type##_struc;  }\
0079 Handle(type)& var = var##_s->H;
0080 
0081 //  Initializing it and Creating it by a Void Constructor
0082 #define InitHandleVoid(type,var) \
0083 if(!var##_s) { var##_s=new type##_struc; var##_s->H=new type; }\
0084 Handle(type)& var = var##_s->H;
0085 
0086 //  Initializing it and Creating it by a Constructor with Arguments
0087 //    (give them grouped in their parentheses)
0088 #define InitHandleArgs(type,var,args) \
0089 if(!var##_s) { var##_s=new type##_struc; var##_s->H=new type args; }\
0090 Handle(type)& var = var##_s->H;
0091 
0092 //  Initializing it from an already determined Value
0093 #define InitHandleVal(type,var,value) \
0094 if(!var##_s) { var##_s=new type##_struc; var##_s->H=value; }\
0095 Handle(type)& var = var##_s->H;
0096 
0097 #endif