opcode_python.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
  2. //
  3. // Permission to use, copy, modify, and/or distribute this software for any
  4. // purpose with or without fee is hereby granted, provided that the above
  5. // copyright notice and this permission notice appear in all copies.
  6. //
  7. // THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  8. // REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  9. // AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  10. // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  11. // LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  12. // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  13. // PERFORMANCE OF THIS SOFTWARE.
  14. #ifndef __PYTHON_OPCODE_H
  15. #define __PYTHON_OPCODE_H 1
  16. #include <Python.h>
  17. namespace isc {
  18. namespace dns {
  19. class Opcode;
  20. namespace python {
  21. extern PyTypeObject opcode_type;
  22. /// This is a simple shortcut to create a python Opcode object (in the
  23. /// form of a pointer to PyObject) with minimal exception safety.
  24. /// On success, it returns a valid pointer to PyObject with a reference
  25. /// counter of 1; if something goes wrong it throws an exception (it never
  26. /// returns a NULL pointer).
  27. /// This function is expected to be called within a try block
  28. /// followed by necessary setup for python exception.
  29. PyObject* createOpcodeObject(const Opcode& source);
  30. /// \brief Checks if the given python object is a Opcode object
  31. ///
  32. /// \exception PyCPPWrapperException if obj is NULL
  33. ///
  34. /// \param obj The object to check the type of
  35. /// \return true if the object is of type Opcode, false otherwise
  36. bool PyOpcode_Check(PyObject* obj);
  37. /// \brief Returns a reference to the Opcode object contained within the given
  38. /// Python object.
  39. ///
  40. /// \note The given object MUST be of type Opcode; this can be checked with
  41. /// either the right call to ParseTuple("O!"), or with PyOpcode_Check()
  42. ///
  43. /// \note This is not a copy; if the Opcode is needed when the PyObject
  44. /// may be destroyed, the caller must copy it itself.
  45. ///
  46. /// \param opcode_obj The opcode object to convert
  47. const Opcode& PyOpcode_ToOpcode(const PyObject* opcode_obj);
  48. } // namespace python
  49. } // namespace dns
  50. } // namespace isc
  51. #endif // __PYTHON_OPCODE_H
  52. // Local Variables:
  53. // mode: c++
  54. // End: