RenamedNodesMap.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 <memory>
  10. #include <AzCore/std/containers/unordered_map.h>
  11. #include <AzCore/std/string/string.h>
  12. #include <SceneAPI/SceneCore/Containers/SceneGraph.h>
  13. #include <SceneAPI/SDKWrapper/NodeWrapper.h>
  14. namespace AZ
  15. {
  16. namespace SceneAPI
  17. {
  18. namespace SceneBuilder
  19. {
  20. class RenamedNodesMap
  21. {
  22. public:
  23. //! Checks if the provided name is valid for the position in the graph and makes corrections if
  24. //! problems are found.
  25. //! @param name The name of the node in the scene graph.
  26. //! @param graph The scene graph the node will be added to.
  27. //! @param parentNode The node that will be the intended parent for the the node who's name is being checked.
  28. //! @param defaultName If the provided name is empty, the defaultName will be used.
  29. //! @return True if the name was updated otherwise false.
  30. static bool SanitizeNodeName(AZStd::string& name, const Containers::SceneGraph& graph,
  31. Containers::SceneGraph::NodeIndex parentNode, const char* defaultName = "unnamed");
  32. //! Register the name for later reference. If the name needs to be sanitized, the sanitized name will be stored.
  33. //! @param node The node that's to be registered.
  34. //! @param graph The scene graph the node will be added to.
  35. //! @param parentNode The node that will be the intended parent for the the node who's name is being checked.
  36. //! @param defaultName If the provided name is empty, the defaultName will be used.
  37. //! @return True if the node was successfully registered.
  38. bool RegisterNode(const std::shared_ptr<SDKNode::NodeWrapper>& node, const Containers::SceneGraph& graph,
  39. Containers::SceneGraph::NodeIndex parentNode, const char* defaultName = "unnamed");
  40. bool RegisterNode(const std::shared_ptr<const SDKNode::NodeWrapper>& node, const Containers::SceneGraph& graph,
  41. Containers::SceneGraph::NodeIndex parentNode, const char* defaultName = "unnamed");
  42. bool RegisterNode(const SDKNode::NodeWrapper& node, const Containers::SceneGraph& graph,
  43. Containers::SceneGraph::NodeIndex parentNode, const char* defaultName = "unnamed");
  44. //! Returns the name of the given node, which may be sanitized if this was needed.
  45. const char* GetNodeName(const std::shared_ptr<SDKNode::NodeWrapper>& node) const;
  46. const char* GetNodeName(const std::shared_ptr<const SDKNode::NodeWrapper>& node) const;
  47. const char* GetNodeName(const AZStd::shared_ptr<SDKNode::NodeWrapper>& node) const;
  48. const char* GetNodeName(const AZStd::shared_ptr<const SDKNode::NodeWrapper>& node) const;
  49. const char* GetNodeName(const SDKNode::NodeWrapper& node) const;
  50. private:
  51. AZStd::unordered_map<u64, AZStd::string> m_idToName;
  52. };
  53. } // namespace SceneBuilder
  54. } // namespace SceneAPI
  55. } // namespace AZ