JsObject.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file JsObject.h
22 
23  \brief An auxiliary data structure for helping to control the garbage collection of wrapped C++ objects associated to JavaScript objects in Google's V8 engine.
24  */
25 
26 #ifndef __TERRALIB_BINDING_V8_COMMON_INTERNAL_JSOBJECT_H
27 #define __TERRALIB_BINDING_V8_COMMON_INTERNAL_JSOBJECT_H
28 
29 // TerraLib
30 #include "Config.h"
31 
32 namespace te
33 {
34  namespace v8
35  {
36  namespace common
37  {
38  /*!
39  \struct JsObject
40 
41  \brief An auxiliary data structure for helping to control the garbage collection of wrapped C++ objects associated to JavaScript objects in Google's V8 engine.
42  */
43  template<class T> struct JsObject
44  {
45  T* m_handle; //!< A pointer to a C++ object.
46  bool m_isOwner; //!< If true it specifies that JsObject has the ownership of the C++ handle.
47 
48  /*!
49  \brief Initializes a new garbage collection helper object.
50 
51  \param handle A pointer to a C++ object.
52  \param isOwner If true the JsObject will have the ownership of the pointer.
53  */
54  JsObject(T* handle, bool isOwner)
55  : m_handle(handle),
56  m_isOwner(isOwner)
57  {
58  }
59 
60  /*! \brief The destructor will check if it is necessary to release the C++ object handle. */
62  {
63  if(m_isOwner)
64  delete m_handle;
65  }
66  };
67 
68  } // end namespace common
69  } // end namespace v8
70 } // end namespace te
71 
72 #endif // __TERRALIB_BINDING_V8_COMMON_INTERNAL_JSOBJECT_H
T * m_handle
A pointer to a C++ object.
Definition: JsObject.h:45
~JsObject()
The destructor will check if it is necessary to release the C++ object handle.
Definition: JsObject.h:61
JsObject(T *handle, bool isOwner)
Initializes a new garbage collection helper object.
Definition: JsObject.h:54
An auxiliary data structure for helping to control the garbage collection of wrapped C++ objects asso...
Definition: JsObject.h:43
bool m_isOwner
If true it specifies that JsObject has the ownership of the C++ handle.
Definition: JsObject.h:46
URI C++ Library.
Definition: Attributes.h:37