22using System ;
33using System . Runtime . InteropServices ;
44
5- public class SofaBaseAPI : IDisposable
5+ namespace SofaUnityAPI
66{
7- /// Name of the Sofa 3D Object mapped to this Object.
8- protected string m_name ;
9-
10- /// Pointer to the SofaPhysicsAPI
11- protected IntPtr m_simu = IntPtr . Zero ;
7+ public class SofaBaseAPI : IDisposable
8+ {
9+ /// Name of the Sofa 3D Object mapped to this Object.
10+ protected string m_name ;
1211
13- protected bool m_isReady = false ;
12+ /// Pointer to the SofaPhysicsAPI
13+ protected IntPtr m_simu = IntPtr . Zero ;
1414
15- protected bool m_isCustom = false ;
15+ protected bool m_isReady = false ;
1616
17- // TODO: check if needed
18- bool m_isDisposed ;
17+ protected bool m_isCustom = false ;
1918
20- /// Parameter to activate internal logging
21- protected bool displayLog = false ;
19+ // TODO: check if needed
20+ bool m_isDisposed ;
2221
23- /// <summary> Default constructor, will call impl method: @see createObject() </summary>
24- /// <param name="simu">Pointer to the SofaPhysicsAPI</param>
25- /// <param name="nameID">Name of this Object</param>
26- public SofaBaseAPI ( IntPtr simu , string nameID , bool isCustom )
27- {
28- m_isReady = false ;
29- m_simu = simu ;
30- m_name = nameID ;
31- m_isCustom = isCustom ;
22+ /// Parameter to activate internal logging
23+ protected bool displayLog = false ;
3224
33- if ( m_simu == IntPtr . Zero )
25+ /// <summary> Default constructor, will call impl method: @see createObject() </summary>
26+ /// <param name="simu">Pointer to the SofaPhysicsAPI</param>
27+ /// <param name="nameID">Name of this Object</param>
28+ public SofaBaseAPI ( IntPtr simu , string nameID , bool isCustom )
3429 {
35- Debug . LogError ( "SBaseAPI created with null SofaContextAPI pointer." ) ;
3630 m_isReady = false ;
37- return ;
38- }
31+ m_simu = simu ;
32+ m_name = nameID ;
33+ m_isCustom = isCustom ;
34+
35+ if ( m_simu == IntPtr . Zero )
36+ {
37+ Debug . LogError ( "SBaseAPI created with null SofaContextAPI pointer." ) ;
38+ m_isReady = false ;
39+ return ;
40+ }
3941
40- m_isReady = Init ( ) ;
41- }
42-
43- /// method to be overriden by cildren
44- virtual protected bool Init ( )
45- {
46- //Debug.Log("SBaseAPI::Init() " + m_name);
42+ m_isReady = Init ( ) ;
43+ }
4744
48- return true ;
49- }
45+ /// method to be overriden by cildren
46+ virtual protected bool Init ( )
47+ {
48+ //Debug.Log("SBaseAPI::Init() " + m_name);
5049
51- /// Memory free method
52- public void Dispose ( )
53- {
54- Dispose ( true ) ;
55- GC . SuppressFinalize ( this ) ;
56- }
50+ return true ;
51+ }
5752
58- /// Memory free method
59- protected virtual void Dispose ( bool disposing )
60- {
61- if ( ! m_isDisposed )
53+ /// Memory free method
54+ public void Dispose ( )
6255 {
63- m_isDisposed = true ;
56+ Dispose ( true ) ;
57+ GC . SuppressFinalize ( this ) ;
6458 }
65- }
66-
6759
68- protected bool checkNativePointer ( )
69- {
70- if ( m_simu == IntPtr . Zero ) // use native pointer?? m_native
60+ /// Memory free method
61+ protected virtual void Dispose ( bool disposing )
7162 {
72- Debug . LogError ( "Can't access Sofa native API for: " + m_name ) ;
73- return false ;
63+ if ( ! m_isDisposed )
64+ {
65+ m_isDisposed = true ;
66+ }
7467 }
75- else
76- return true ;
77- }
78-
7968
8069
70+ protected bool checkNativePointer ( )
71+ {
72+ if ( m_simu == IntPtr . Zero ) // use native pointer?? m_native
73+ {
74+ Debug . LogError ( "Can't access Sofa native API for: " + m_name ) ;
75+ return false ;
76+ }
77+ else
78+ return true ;
79+ }
8180
82- }
81+ }
82+ }
0 commit comments