File indexing completed on 2024-05-19 05:42:08

0001 // ct_lvtldr_packagenode.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 DIAGRAM_SERVER_CT_LVTLDR_PACKAGENODE_H
0021 #define DIAGRAM_SERVER_CT_LVTLDR_PACKAGENODE_H
0022 
0023 #include <ct_lvtldr_databasehandler.h>
0024 #include <ct_lvtldr_lakosiannode.h>
0025 #include <ct_lvtldr_packagenodefields.h>
0026 
0027 namespace Codethink::lvtldr {
0028 
0029 // ==========================
0030 // class PackageNode
0031 // ==========================
0032 
0033 class LVTLDR_EXPORT PackageNode : public LakosianNode {
0034     // Implementation of LakosianNode for packages and package groups
0035 
0036   private:
0037     // DATA
0038     // TODO: Decide if optional should be removed after refactoring is done.
0039     std::optional<std::reference_wrapper<DatabaseHandler>> d_dbHandler = std::nullopt;
0040     PackageNodeFields d_fields;
0041     std::vector<std::string> d_qualifiedNameParts;
0042 
0043   protected:
0044     // MODIFIERS
0045     void loadParent() override;
0046     void loadChildren() override;
0047     void loadProviders() override;
0048     void loadClients() override;
0049 
0050   public:
0051     explicit PackageNode(NodeStorage& store,
0052                          std::optional<std::reference_wrapper<DatabaseHandler>> dbHandler = std::nullopt,
0053                          std::optional<PackageNodeFields> fields = std::nullopt);
0054     static inline PackageNode *from(LakosianNode *other)
0055     {
0056         return dynamic_cast<PackageNode *>(other);
0057     }
0058 
0059     inline PackageNodeFields const& getFields()
0060     {
0061         return d_fields;
0062     }
0063 
0064     ~PackageNode() noexcept override;
0065 
0066     cpp::result<void, AddChildError> addChild(LakosianNode *child) override;
0067     void removeChild(LakosianNode *child);
0068     void setName(std::string const& newName) override;
0069 
0070     void invalidateChildren() override
0071     {
0072         LakosianNode::invalidateChildren();
0073         d->innerPackages.clear();
0074     }
0075 
0076     // ACCESSORS
0077     void removeChildPackage(PackageNode *child);
0078     void addConcreteDependency(PackageNode *other);
0079     void removeConcreteDependency(PackageNode *other);
0080     [[nodiscard]] bool hasConcreteDependency(LakosianNode *other);
0081     [[nodiscard]] lvtshr::DiagramType type() const override;
0082     [[nodiscard]] bool isPackageGroup() override;
0083     [[nodiscard]] std::string qualifiedName() const override;
0084     [[nodiscard]] std::string parentName() override;
0085     [[nodiscard]] long long id() const override;
0086     [[nodiscard]] lvtshr::UniqueId uid() const override;
0087     [[nodiscard]] IsLakosianResult isLakosian() override;
0088     [[nodiscard]] std::string canonicalName() const;
0089     [[nodiscard]] bool isStandalone() const;
0090     [[nodiscard]] std::string dirPath() const;
0091     [[nodiscard]] bool hasRepository() const;
0092 };
0093 
0094 template<>
0095 struct LakosianNodeType<Codethink::lvtldr::PackageNode> {
0096     static auto constexpr diagramType = lvtshr::DiagramType::PackageType;
0097 };
0098 
0099 } // namespace Codethink::lvtldr
0100 
0101 #endif