PythonMarshalTuple.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <Source/PythonMarshalComponent.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. namespace EditorPythonBindings
  12. {
  13. class TypeConverterTuple final : public PythonMarshalComponent::TypeConverter
  14. {
  15. public:
  16. TypeConverterTuple(
  17. [[maybe_unused]] AZ::GenericClassInfo* genericClassInfo,
  18. const AZ::SerializeContext::ClassData* classData,
  19. const AZ::TypeId& typeId)
  20. : m_classData(classData)
  21. , m_typeId(typeId)
  22. {
  23. }
  24. AZStd::optional<PythonMarshalTypeRequests::BehaviorValueResult> PythonToBehaviorValueParameter(
  25. PythonMarshalTypeRequests::BehaviorTraits traits, pybind11::object pyObj, AZ::BehaviorArgument& outValue) override;
  26. AZStd::optional<PythonMarshalTypeRequests::PythonValueResult> BehaviorValueParameterToPython(
  27. AZ::BehaviorArgument& behaviorValue) override;
  28. bool CanConvertPythonToBehaviorValue(PythonMarshalTypeRequests::BehaviorTraits traits, pybind11::object pyObj) const override;
  29. protected:
  30. const AZ::SerializeContext::ClassData* m_classData = nullptr;
  31. const AZ::TypeId m_typeId = {};
  32. bool IsValidList(pybind11::object pyObj) const;
  33. bool IsValidTuple(pybind11::object pyObj) const;
  34. bool IsCompatibleProxy(pybind11::object pyObj) const;
  35. static bool LoadPythonToTupleElement(
  36. PyObject* pyItem,
  37. PythonMarshalTypeRequests::BehaviorTraits traits,
  38. const AZ::SerializeContext::ClassElement* itemElement,
  39. AZ::SerializeContext::IDataContainer* tupleContainer,
  40. size_t index,
  41. AZ::SerializeContext* serializeContext,
  42. void* newTuple);
  43. };
  44. } // namespace EditorPythonBindings