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

0001 // ct_lvtmdb_packageobject.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 INCLUDED_CT_LVTMDB_PACKAGEOBJECT
0021 #define INCLUDED_CT_LVTMDB_PACKAGEOBJECT
0022 
0023 #include <lvtmdb_export.h>
0024 
0025 #include <ct_lvtmdb_databaseobject.h>
0026 
0027 #include <string>
0028 #include <vector>
0029 
0030 namespace Codethink::lvtmdb {
0031 
0032 // Forward Declarations
0033 class RepositoryObject;
0034 class ComponentObject;
0035 class FileObject;
0036 class TypeObject;
0037 
0038 // ====================
0039 // class PackageObject
0040 // ====================
0041 
0042 class LVTMDB_EXPORT PackageObject : public DatabaseObject {
0043     // See locking discipline in superclass. That applies here.
0044 
0045   private:
0046     PackageObject *d_parent_p;
0047     // Null if this is a package group
0048 
0049     std::vector<PackageObject *> d_children;
0050     // Child packages (if this is a package group)
0051 
0052     // deliberately skip SourcePackage::sourceFiles()
0053     // because this isn't needed now wew have components
0054 
0055     std::vector<ComponentObject *> d_components;
0056 
0057     std::vector<PackageObject *> d_forwardDeps;
0058 
0059     std::vector<PackageObject *> d_reverseDeps;
0060 
0061     std::vector<TypeObject *> d_types;
0062 
0063     std::string d_diskPath;
0064 
0065     RepositoryObject *d_repository;
0066     // Null if inside no repository
0067 
0068   public:
0069     // CREATORS
0070     PackageObject(std::string qualifiedName,
0071                   std::string name,
0072                   std::string path,
0073                   PackageObject *parent,
0074                   RepositoryObject *repository);
0075 
0076     ~PackageObject() noexcept override;
0077 
0078     PackageObject(PackageObject&& other) noexcept;
0079 
0080     PackageObject& operator=(PackageObject&& other) noexcept;
0081 
0082     // ACCESSORS
0083     [[nodiscard]] RepositoryObject *repository() const;
0084 
0085     [[nodiscard]] PackageObject *parent() const;
0086 
0087     [[nodiscard]] const std::vector<PackageObject *>& children() const;
0088 
0089     [[nodiscard]] const std::vector<ComponentObject *>& components() const;
0090 
0091     [[nodiscard]] const std::vector<PackageObject *>& forwardDependencies() const;
0092 
0093     [[nodiscard]] const std::vector<PackageObject *>& reverseDependencies() const;
0094 
0095     [[nodiscard]] const std::vector<TypeObject *>& types() const;
0096 
0097     [[nodiscard]] const std::string& diskPath() const;
0098 
0099     // MANIPULATORS
0100     void addChild(PackageObject *pkg);
0101     void removeChild(PackageObject *pkg);
0102 
0103     // pkg->parent() should already point to this
0104     // an exclusive lock on this is required before calling this method
0105 
0106     void addComponent(ComponentObject *component);
0107     // adds component to this package
0108     // an exclusive lock on this is required before calling this method
0109 
0110     void removeComponent(ComponentObject *component);
0111 
0112     void addType(TypeObject *type);
0113     // adds a type to this package
0114     // an exclusive lock on this is required before calling this method
0115 
0116     void removeType(TypeObject *type);
0117 
0118     // CLASS METHODS
0119     static void addDependency(PackageObject *source, PackageObject *target);
0120     // On calling this function, neither source nor target should be locked
0121     // (readOnly or for writing). This function handles locking internally.
0122 };
0123 
0124 } // namespace Codethink::lvtmdb
0125 
0126 #endif // INCLUDED_CT_LVTMDB_PACKAGEOBJECT