You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.0 KiB

8 months ago
8 months ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef DESIGN_BLOCK_INFO_IMPL_H
  20. #define DESIGN_BLOCK_INFO_IMPL_H
  21. #include <atomic>
  22. #include <functional>
  23. #include <memory>
  24. #include <thread>
  25. #include <vector>
  26. #include <kicommon.h>
  27. #include <design_block_info.h>
  28. #include <core/sync_queue.h>
  29. class KICOMMON_API DESIGN_BLOCK_INFO_IMPL : public DESIGN_BLOCK_INFO
  30. {
  31. public:
  32. DESIGN_BLOCK_INFO_IMPL( DESIGN_BLOCK_LIST* aOwner, const wxString& aNickname,
  33. const wxString& aDesignBlockName )
  34. {
  35. m_nickname = aNickname;
  36. m_dbname = aDesignBlockName;
  37. m_num = 0;
  38. m_owner = aOwner;
  39. m_loaded = false;
  40. load();
  41. }
  42. // A constructor for cached items
  43. DESIGN_BLOCK_INFO_IMPL( const wxString& aNickname, const wxString& aDesignBlockName,
  44. const wxString& aDescription, const wxString& aKeywords, int aOrderNum )
  45. {
  46. m_nickname = aNickname;
  47. m_dbname = aDesignBlockName;
  48. m_num = aOrderNum;
  49. m_doc = aDescription;
  50. m_keywords = aKeywords;
  51. m_owner = nullptr;
  52. m_loaded = true;
  53. }
  54. // A dummy constructor for use as a target in a binary search
  55. DESIGN_BLOCK_INFO_IMPL( const wxString& aNickname, const wxString& aDesignBlockName )
  56. {
  57. m_nickname = aNickname;
  58. m_dbname = aDesignBlockName;
  59. m_owner = nullptr;
  60. m_loaded = true;
  61. }
  62. protected:
  63. virtual void load() override;
  64. };
  65. class KICOMMON_API DESIGN_BLOCK_LIST_IMPL : public DESIGN_BLOCK_LIST
  66. {
  67. public:
  68. DESIGN_BLOCK_LIST_IMPL();
  69. virtual ~DESIGN_BLOCK_LIST_IMPL(){};
  70. bool ReadDesignBlockFiles( DESIGN_BLOCK_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
  71. PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
  72. protected:
  73. void loadDesignBlocks();
  74. private:
  75. /**
  76. * Call aFunc, pushing any IO_ERRORs and std::exceptions it throws onto m_errors.
  77. *
  78. * @return true if no error occurred.
  79. */
  80. bool CatchErrors( const std::function<void()>& aFunc );
  81. private:
  82. SYNC_QUEUE<wxString> m_queue;
  83. long long m_list_timestamp;
  84. PROGRESS_REPORTER* m_progress_reporter;
  85. std::atomic_bool m_cancelled;
  86. std::mutex m_join;
  87. };
  88. #endif // DESIGN_BLOCK_INFO_IMPL_H