gVirtualXRay  2.0.10
VirtualX-RayImagingLibraryonGPU
PythonSingleton.inl
Go to the documentation of this file.
1 /*
2 
3 Copyright (c) 2014, Dr Franck P. Vidal (franck.p.vidal@fpvidal.net),
4 http://www.fpvidal.net/
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without modification,
8 are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation and/or
15 other materials provided with the distribution.
16 
17 3. Neither the name of the Bangor University nor the names of its contributors
18 may be used to endorse or promote products derived from this software without
19 specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 
32 */
33 
34 
62 //******************************************************************************
63 // Include
64 //******************************************************************************
65 // #include <fstream>
66 // #include <sstream>
67 // #include <cfloat>
68 // #include <algorithm>
69 
70 // #ifndef __ElementSet_h
71 // #include "gVirtualXRay/ElementSet.h"
72 // #endif
73 
74 // #ifndef __FileDoesNotExistException_h
75 // #include "gVirtualXRay/FileDoesNotExistException.h"
76 // #endif
77 
78 // #ifndef __OutOfBoundsException_h
79 // #include "gVirtualXRay/OutOfBoundsException.h"
80 // #endif
81 
82 // #ifndef __Logger_h
83 // #include <gVirtualXRay/Logger.h>
84 // #endif
85 
86 // #ifndef __PythonSingleton_h
87 // #include <gVirtualXRay/PythonSingleton.h>
88 // #endif
89 
90 
91 //******************************************************************************
92 // namespace
93 //******************************************************************************
94 namespace gVirtualXRay {
95 
96 
97 
98 //--------------------------------------
100 //--------------------------------------
101 {
102  return m_has_spekpy;
103 }
104 
105 
106 //---------------------------------------
108 //---------------------------------------
109 {
110  return m_has_xpecgen;
111 }
112 
113 
114 #ifdef HAS_PythonLibs
115 //-------------------------------------------
116 inline PyObject* PythonSingleton::getModule()
117 //-------------------------------------------
118 {
119  return m_p_module;
120 }
121 #endif
122 
123 
124 //----------------------------------------
126 //----------------------------------------
127 {
128  releasePython();
129 }
130 
131 
132 //----------------------------------------
133 inline PythonSingleton::PythonSingleton():
134 //----------------------------------------
135  m_initialised(false),
136 #ifdef HAS_PythonLibs
137  m_p_global(0),
138  m_p_module(0),
139  m_p_local(0),
140 #endif
141  m_has_spekpy(false),
142  m_has_xpecgen(false)
143 //----------------------------------------
144 {}
145 
146 
147 //------------------------------------------
148 inline void PythonSingleton::releasePython()
149 //------------------------------------------
150 {
151  m_has_spekpy = false;
152  m_has_xpecgen = false;
153 
154 #ifdef HAS_PythonLibs
155  Py_CLEAR(m_p_local);
156  Py_CLEAR(m_p_module);
157  Py_CLEAR(m_p_global);
158 
159  if (m_initialised) Py_Finalize();
160  m_initialised = false;
161 #endif
162 }
163 
164 
165 } // namespace gVirtualXRay