|
|
|||
File indexing completed on 2026-09-25 09:20:22
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 // This set of macros allows user to simply declare and use "static" Handles. 0028 // It is available once having included this file : 0029 // *************************************************** 0030 // #include <Interface_Statics.hxx> 0031 0032 // Static construction is replaced by using the macro StaticHandle : 0033 // *************************************************** 0034 // Old statement : static Handle(pk_class) object; 0035 // Is replaced by : StaticHandle(pk_class,object); 0036 // which creates a null pointer called 'object_s' and typed 'pk_class_struc' 0037 0038 // For first initialisation and use, several ways are available, all of them 0039 // give an access to the Handle through a reference. 0040 // It is required to initialize the static structure once, the macros Init* 0041 // assume that it is created once and only once, even if they are called 0042 // more than once. 0043 // It is possible : to create the object at initialization time by a macro, 0044 // or to create it after the macro call through its reference : 0045 0046 // *************************************************** 0047 // Old statement (in a routine, not static) : 0048 // if (object.IsNull()) object = new pk_class (..args if any..); 0049 // can be maintained, but preceded by an initialization : 0050 // InitHandle(pk_class,object); // -> Null Handle 0051 0052 // *************************************************** 0053 // or it can be replaced by a direct formula (creation called only once) : 0054 // InitHandleVoid(pk_class,object); // for a void constructor 0055 // or InitHandleArgs(pk_class,object,(..args..)); 0056 // (the arglist between embedded parentheses) 0057 // or InitHandleVal(pk_class,object,val); // i.e. object = val; 0058 0059 // To simply use this pseudo-static object, consider 0060 // either the static variable object_s->H 0061 // *************************************************** 0062 // or take it by the macro (which does not initialize it) 0063 // UseHandle(pk_class,object); 0064 0065 // Declaration of a static Handle : first use for a given type 0066 #define StaticHandle(type, var) \ 0067 static struct type##_struc \ 0068 { \ 0069 Handle(type) H; \ 0070 }* var##_s = NULL 0071 0072 // Another declaration for an already declared type (with StaticHandle) 0073 #define StaticHandleA(type, var) static struct type##_struc* var##_s = NULL 0074 0075 // Using it (IT MUST HAVE BEEN FORMERLY INITIALIZED) 0076 #define UseHandle(type, var) Handle(type)& var = var##_s->H 0077 0078 // Initializing it (as Null Handle) 0079 #define InitHandle(type, var) \ 0080 if (!var##_s) \ 0081 { \ 0082 var##_s = new type##_struc; \ 0083 } \ 0084 Handle(type)& var = var##_s->H; 0085 0086 // Initializing it and Creating it by a Void Constructor 0087 #define InitHandleVoid(type, var) \ 0088 if (!var##_s) \ 0089 { \ 0090 var##_s = new type##_struc; \ 0091 var##_s->H = new type; \ 0092 } \ 0093 Handle(type)& var = var##_s->H; 0094 0095 // Initializing it and Creating it by a Constructor with Arguments 0096 // (give them grouped in their parentheses) 0097 #define InitHandleArgs(type, var, args) \ 0098 if (!var##_s) \ 0099 { \ 0100 var##_s = new type##_struc; \ 0101 var##_s->H = new type args; \ 0102 } \ 0103 Handle(type)& var = var##_s->H; 0104 0105 // Initializing it from an already determined Value 0106 #define InitHandleVal(type, var, value) \ 0107 if (!var##_s) \ 0108 { \ 0109 var##_s = new type##_struc; \ 0110 var##_s->H = value; \ 0111 } \ 0112 Handle(type)& var = var##_s->H; 0113 0114 #endif
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|