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.

108 lines
3.0 KiB

8 months ago
9 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 LOCALE_IO;
  30. class KICOMMON_API DESIGN_BLOCK_INFO_IMPL : public DESIGN_BLOCK_INFO
  31. {
  32. public:
  33. DESIGN_BLOCK_INFO_IMPL( DESIGN_BLOCK_LIST* aOwner, const wxString& aNickname,
  34. const wxString& aDesignBlockName )
  35. {
  36. m_nickname = aNickname;
  37. m_dbname = aDesignBlockName;
  38. m_num = 0;
  39. m_owner = aOwner;
  40. m_loaded = false;
  41. load();
  42. }
  43. // A constructor for cached items
  44. DESIGN_BLOCK_INFO_IMPL( const wxString& aNickname, const wxString& aDesignBlockName,
  45. const wxString& aDescription, const wxString& aKeywords, int aOrderNum )
  46. {
  47. m_nickname = aNickname;
  48. m_dbname = aDesignBlockName;
  49. m_num = aOrderNum;
  50. m_doc = aDescription;
  51. m_keywords = aKeywords;
  52. m_owner = nullptr;
  53. m_loaded = true;
  54. }
  55. // A dummy constructor for use as a target in a binary search
  56. DESIGN_BLOCK_INFO_IMPL( const wxString& aNickname, const wxString& aDesignBlockName )
  57. {
  58. m_nickname = aNickname;
  59. m_dbname = aDesignBlockName;
  60. m_owner = nullptr;
  61. m_loaded = true;
  62. }
  63. protected:
  64. virtual void load() override;
  65. };
  66. class KICOMMON_API DESIGN_BLOCK_LIST_IMPL : public DESIGN_BLOCK_LIST
  67. {
  68. public:
  69. DESIGN_BLOCK_LIST_IMPL();
  70. virtual ~DESIGN_BLOCK_LIST_IMPL(){};
  71. bool ReadDesignBlockFiles( DESIGN_BLOCK_LIB_TABLE* aTable, const wxString* aNickname = nullptr,
  72. PROGRESS_REPORTER* aProgressReporter = nullptr ) override;
  73. protected:
  74. void loadDesignBlocks();
  75. private:
  76. /**
  77. * Call aFunc, pushing any IO_ERRORs and std::exceptions it throws onto m_errors.
  78. *
  79. * @return true if no error occurred.
  80. */
  81. bool CatchErrors( const std::function<void()>& aFunc );
  82. private:
  83. SYNC_QUEUE<wxString> m_queue;
  84. long long m_list_timestamp;
  85. PROGRESS_REPORTER* m_progress_reporter;
  86. std::atomic_bool m_cancelled;
  87. std::mutex m_join;
  88. };
  89. #endif // DESIGN_BLOCK_INFO_IMPL_H