综合平台编程器项目的远程存储
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

71 linhas
1.6 KiB

  1. #include "project_model.h"
  2. #include <algorithm>
  3. namespace integrated_platform::domain {
  4. namespace {
  5. void setError(std::string *error, const std::string &message)
  6. {
  7. if (error != nullptr)
  8. {
  9. *error = message;
  10. }
  11. }
  12. template <typename TItem>
  13. bool containsDuplicateId(const std::vector<TItem> &items)
  14. {
  15. for (auto current = items.cbegin(); current != items.cend(); ++current)
  16. {
  17. const auto duplicate = std::find_if(
  18. current + 1,
  19. items.cend(),
  20. [&current](const TItem &item) { return item.id == current->id; });
  21. if (duplicate != items.cend())
  22. {
  23. return true;
  24. }
  25. }
  26. return false;
  27. }
  28. } // namespace
  29. bool Project::validate(std::string *error) const
  30. {
  31. if (metadata.id.empty() || metadata.name.empty() || metadata.formatVersion.empty())
  32. {
  33. setError(error, "project id, name and format version must not be empty");
  34. return false;
  35. }
  36. if (containsDuplicateId(hmiPages))
  37. {
  38. setError(error, "HMI page ids must be unique within a project");
  39. return false;
  40. }
  41. if (containsDuplicateId(controlLogics))
  42. {
  43. setError(error, "control logic ids must be unique within a project");
  44. return false;
  45. }
  46. for (const HmiPage &page : hmiPages)
  47. {
  48. if (!page.validate(error))
  49. {
  50. return false;
  51. }
  52. }
  53. for (const ControlLogic &logic : controlLogics)
  54. {
  55. if (!logic.validate(error))
  56. {
  57. return false;
  58. }
  59. }
  60. return true;
  61. }
  62. } // namespace integrated_platform::domain