ActionOutput.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #pragma once
  2. /*
  3. * Copyright (c) Contributors to the Open 3D Engine Project.
  4. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. *
  6. * SPDX-License-Identifier: Apache-2.0 OR MIT
  7. *
  8. */
  9. #include <AzCore/std/string/string.h>
  10. #include <AzCore/std/containers/map.h>
  11. #include <AzCore/std/containers/vector.h>
  12. #include <AzCore/std/smart_ptr/shared_ptr.h>
  13. #include <EditorCommonAPI.h>
  14. namespace AZ
  15. {
  16. // Stores the error output from save actions. Pairs error messages with a "details" context. That way if you could
  17. // do something like:
  18. // output->AddError("Failed to save file", fileName);
  19. //
  20. // Then if that error gets added a few times with different files, the final error message will be aggregated as
  21. // follows:
  22. // Failed to save file:
  23. // thing1.cdf
  24. // thing2.chr
  25. class EDITOR_COMMON_API ActionOutput
  26. {
  27. public:
  28. using DetailList = AZStd::vector<AZStd::string>;
  29. using IssueToDetails = AZStd::map<AZStd::string, DetailList>;
  30. ActionOutput();
  31. void AddError(const AZStd::string& error);
  32. void AddError(const AZStd::string& error, const AZStd::string& details);
  33. bool HasAnyErrors() const;
  34. AZStd::string BuildErrorMessage() const;
  35. void AddWarning(const AZStd::string& error);
  36. void AddWarning(const AZStd::string& error, const AZStd::string& details);
  37. bool HasAnyWarnings() const;
  38. AZStd::string BuildWarningMessage() const;
  39. private:
  40. AZStd::string BuildMessage(const IssueToDetails& issues) const;
  41. AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
  42. IssueToDetails m_errorToDetails;
  43. IssueToDetails m_warningToDetails;
  44. AZ_POP_DISABLE_DLL_EXPORT_MEMBER_WARNING
  45. int m_errorCount;
  46. int m_warningCount;
  47. };
  48. }