mirror of
https://github.com/opnsense/src.git
synced 2026-02-28 12:20:54 -05:00
(A number of files not required for the FreeBSD build have been removed.) Sponsored by: DARPA, AFRL
73 lines
1.5 KiB
C++
73 lines
1.5 KiB
C++
//===---------------------PythonPointer.h ------------------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef utility_PythonPointer_h_
|
|
#define utility_PythonPointer_h_
|
|
|
|
#include <algorithm>
|
|
|
|
#include "lldb/lldb-python.h"
|
|
|
|
namespace lldb_private {
|
|
|
|
template<class T>
|
|
class PythonPointer
|
|
{
|
|
public:
|
|
typedef PyObject* element_type;
|
|
private:
|
|
element_type* ptr_;
|
|
bool my_ref;
|
|
public:
|
|
|
|
PythonPointer(element_type p, bool steal_ref = false) :
|
|
ptr_(p),
|
|
my_ref(!steal_ref)
|
|
{
|
|
if (my_ref)
|
|
Py_INCREF(ptr_);
|
|
}
|
|
|
|
PythonPointer(const PythonPointer& r, bool steal_ref = false) :
|
|
ptr_(r.ptr_),
|
|
my_ref(!steal_ref)
|
|
{
|
|
if (my_ref)
|
|
Py_INCREF(ptr_);
|
|
}
|
|
|
|
~PythonPointer()
|
|
{
|
|
if (my_ref)
|
|
Py_XDECREF(ptr_);
|
|
}
|
|
|
|
PythonPointer
|
|
StealReference()
|
|
{
|
|
return PythonPointer(ptr_,true);
|
|
}
|
|
|
|
PythonPointer
|
|
DuplicateReference()
|
|
{
|
|
return PythonPointer(ptr_, false);
|
|
}
|
|
|
|
element_type get() const {return ptr_;}
|
|
|
|
bool IsNull() { return ptr_ == NULL; }
|
|
bool IsNone() { return ptr_ == Py_None; }
|
|
|
|
operator PyObject* () { return ptr_; }
|
|
};
|
|
|
|
} // namespace lldb
|
|
|
|
#endif // utility_PythonPointer_h_
|