File indexing completed on 2024-05-19 05:41:57

0001 // ct_lvtcgn_app_adapter.h                              -*-C++-*-
0002 
0003 /*
0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0005 // SPDX-License-Identifier: Apache-2.0
0006 //
0007 // Licensed under the Apache License, Version 2.0 (the "License");
0008 // you may not use this file except in compliance with the License.
0009 // You may obtain a copy of the License at
0010 //
0011 //     http://www.apache.org/licenses/LICENSE-2.0
0012 //
0013 // Unless required by applicable law or agreed to in writing, software
0014 // distributed under the License is distributed on an "AS IS" BASIS,
0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 // See the License for the specific language governing permissions and
0017 // limitations under the License.
0018 */
0019 
0020 #ifndef _CT_LVTCGN_APPADAPTER_H
0021 #define _CT_LVTCGN_APPADAPTER_H
0022 
0023 #include <QWidget>
0024 #include <ct_lvtcgn_generatecode.h>
0025 #include <ct_lvtldr_lakosiannode.h>
0026 #include <functional>
0027 #include <lvtcgn_adapter_export.h>
0028 #include <map>
0029 #include <memory>
0030 #include <optional>
0031 #include <vector>
0032 
0033 namespace Codethink::lvtcgn::app {
0034 
0035 class NodeStorageDataProvider;
0036 
0037 class LVTCGN_ADAPTER_EXPORT WrappedLakosianNode : public Codethink::lvtcgn::mdl::IPhysicalEntityInfo {
0038   public:
0039     WrappedLakosianNode(NodeStorageDataProvider& dataProvider, lvtldr::LakosianNode *node, bool isSelectedForCodegen);
0040     ~WrappedLakosianNode() override;
0041     std::string name() const override;
0042     std::string type() const override;
0043     std::optional<std::reference_wrapper<IPhysicalEntityInfo>> parent() const override;
0044     std::vector<std::reference_wrapper<IPhysicalEntityInfo>> children() const override;
0045     std::vector<std::reference_wrapper<IPhysicalEntityInfo>> fwdDependencies() const override;
0046     bool selectedForCodeGeneration() const override;
0047     void setSelectedForCodeGeneration(bool value) override;
0048 
0049   private:
0050     NodeStorageDataProvider& dataProvider;
0051     Codethink::lvtldr::LakosianNode *node;
0052     bool isSelectedForCodegen;
0053 };
0054 
0055 class LVTCGN_ADAPTER_EXPORT NodeStorageDataProvider : public Codethink::lvtcgn::mdl::ICodeGenerationDataProvider {
0056   public:
0057     explicit NodeStorageDataProvider(lvtldr::NodeStorage& sharedNodeStorage);
0058     NodeStorageDataProvider(NodeStorageDataProvider const& other) = delete;
0059     NodeStorageDataProvider(NodeStorageDataProvider&& other) = delete;
0060     ~NodeStorageDataProvider() override;
0061     [[nodiscard]] std::vector<std::reference_wrapper<mdl::IPhysicalEntityInfo>> topLevelEntities() override;
0062     [[nodiscard]] int numberOfPhysicalEntities() const override;
0063 
0064     friend class WrappedLakosianNode;
0065 
0066   private:
0067     [[nodiscard]] std::reference_wrapper<mdl::IPhysicalEntityInfo> getWrappedNode(lvtldr::LakosianNode *node);
0068 
0069     lvtldr::NodeStorage& ns;
0070     std::map<lvtldr::LakosianNode *, std::unique_ptr<mdl::IPhysicalEntityInfo>> nodeToInfo;
0071 };
0072 
0073 class LVTCGN_ADAPTER_EXPORT CodegenAppAdapter {
0074   public:
0075     static void run(QWidget *parent, Codethink::lvtldr::NodeStorage& sharedNodeStorage);
0076 };
0077 
0078 } // namespace Codethink::lvtcgn::app
0079 
0080 #endif