0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / Interface / Interface_Statics.hxx
1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
2 //
3 // This file is part of Open CASCADE Technology software library.
4 //
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
10 //
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
13
14 //  Macros to help static Handles not to be "constructed" before main run
15 //  In order to avoid it, the Handle to be statically reserved is encapsulated
16 //  in a structure itself designated through a Null Pointer :
17 //  Only the pointer is declared static, and initialized to NULL : then,
18 //  there is no routine to call for static construction
19
20 //  Remember that the objet designated by a static Handle should not be created
21 //  in the static declaration, but must anyway be created, during main run,
22 //  once before its first use : this is the initialization step.
23
24
25 //  This set of macros allows user to simply declare and use "static" Handles.
26 //  It is available once having included this file :
27 //  ***************************************************
28 //         #include <Interface_Statics.hxx>
29
30 //  Static construction is replaced by using the macro StaticHandle :
31 //  ***************************************************
32 //    Old statement  :  static Handle(pk_class) object;
33 //    Is replaced by :  StaticHandle(pk_class,object);
34 //    which creates a null pointer called 'object_s' and typed 'pk_class_struc'
35
36 //  For first initialisation and use, several ways are available, all of them
37 //  give an access to the Handle through a reference.
38 //  It is required to initialize the static structure once, the macros Init*
39 //  assume that it is created once and only once, even if they are called
40 //  more than once.
41 //  It is possible : to create the object at initialization time by a macro,
42 //  or to create it after the macro call through its reference :
43
44 //  ***************************************************
45 //  Old statement (in a routine, not static) :
46 //          if (object.IsNull()) object = new pk_class (..args if any..);
47 //  can be maintained, but preceeded by an initialization :
48 //          InitHandle(pk_class,object);         // -> Null Handle
49
50 //  ***************************************************
51 //  or it can be replaced by a direct formula (creation called only once) :
52 //          InitHandleVoid(pk_class,object);     // for a void constructor
53 //   or     InitHandleArgs(pk_class,object,(..args..));
54 //               (the arglist between embedded parentheses)
55 //   or     InitHandleVal(pk_class,object,val);  // i.e. object = val;
56
57 //  To simply use this pseudo-static object, consider
58 //  either the static variable  object_s->H
59 //  ***************************************************
60 //  or take it by the macro (which does not initialize it)
61 //          UseHandle(pk_class,object);
62
63
64 //  Declaration of a static Handle : first use for a given type
65 #define StaticHandle(type,var) static struct type##_struc { Handle(type) H; } *var##_s = NULL
66
67 //  Another declaration for an already declared type (with StaticHandle)
68 #define StaticHandleA(type,var) static struct type##_struc *var##_s = NULL
69
70 //  Using it (IT MUST HAVE BEEN FORMERLY INITIALIZED)
71 #define UseHandle(type,var) Handle(type)& var = var##_s->H
72
73 //  Initializing it (as Null Handle)
74 #define InitHandle(type,var) \
75 if(!var##_s) { var##_s=new type##_struc;  }\
76 Handle(type)& var = var##_s->H;
77
78 //  Initializing it and Creating it by a Void Constructor
79 #define InitHandleVoid(type,var) \
80 if(!var##_s) { var##_s=new type##_struc; var##_s->H=new type; }\
81 Handle(type)& var = var##_s->H;
82
83 //  Initializing it and Creating it by a Constructor with Arguments
84 //    (give them grouped in their parentheses)
85 #define InitHandleArgs(type,var,args) \
86 if(!var##_s) { var##_s=new type##_struc; var##_s->H=new type args; }\
87 Handle(type)& var = var##_s->H;
88
89 //  Initializing it from an already determined Value
90 #define InitHandleVal(type,var,value) \
91 if(!var##_s) { var##_s=new type##_struc; var##_s->H=value; }\
92 Handle(type)& var = var##_s->H;