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

0001 // ct_lvtmdb_fileobject.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_FILEOBJECT
0021 #define INCLUDED_CT_LVTMDB_FILEOBJECT
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 ComponentObject;
0034 class NamespaceObject;
0035 class PackageObject;
0036 class TypeObject;
0037 class FunctionObject;
0038 
0039 // ===================
0040 // class FileObject
0041 // ===================
0042 
0043 class LVTMDB_EXPORT FileObject : public DatabaseObject {
0044     // See locking discipline in superclass. That applies here.
0045 
0046   private:
0047     bool d_isHeader;
0048 
0049     std::string d_hash;
0050     // MD5 hash of the file at the time it was added to the database
0051 
0052     std::vector<FileObject *> d_forwardIncludes;
0053     // Files included by this file
0054     // Pointers owned by ObjectStore
0055 
0056     std::vector<FileObject *> d_reverseIncludes;
0057     // Files which include this file
0058     // Pointers owned by ObjectStore
0059 
0060     PackageObject *d_package_p;
0061     ComponentObject *d_component_p;
0062 
0063     std::vector<NamespaceObject *> d_namespaces;
0064 
0065     std::vector<TypeObject *> d_types;
0066 
0067     std::vector<FunctionObject *> d_globalfunctions;
0068 
0069   public:
0070     // CREATORS
0071     // TODO: Component already has "package", remove this from the constructor.
0072     FileObject(std::string qualifiedName,
0073                std::string name,
0074                bool isHeader,
0075                std::string hash,
0076                PackageObject *package,
0077                ComponentObject *component);
0078 
0079     ~FileObject() noexcept override;
0080 
0081     FileObject(FileObject&& other) noexcept;
0082 
0083     FileObject& operator=(FileObject&& other) noexcept;
0084 
0085     // ACCESSORS
0086     [[nodiscard]] bool isHeader() const;
0087 
0088     [[nodiscard]] const std::string& hash() const;
0089 
0090     [[nodiscard]] const std::vector<FileObject *>& forwardIncludes() const;
0091 
0092     [[nodiscard]] const std::vector<FileObject *>& reverseIncludes() const;
0093 
0094     [[nodiscard]] PackageObject *package() const;
0095 
0096     [[nodiscard]] ComponentObject *component() const;
0097 
0098     [[nodiscard]] const std::vector<NamespaceObject *>& namespaces() const;
0099 
0100     [[nodiscard]] const std::vector<FunctionObject *>& globalFunctions() const;
0101 
0102     [[nodiscard]] const std::vector<TypeObject *>& types() const;
0103 
0104     // MANIPULATORS
0105     void setHash(std::string hash);
0106     // Update the stored hash for a file
0107 
0108     void addNamespace(NamespaceObject *nmspc);
0109     // An exclusive lock on this is required before calling this method
0110 
0111     void addGlobalFunction(FunctionObject *fnc);
0112     // An exclusive lock on this is required before calling this method
0113 
0114     void addType(TypeObject *type);
0115     // An exclusive lock on this is required before calling this method
0116 
0117     // CLASS METHODS
0118     static void addIncludeRelation(FileObject *source, FileObject *target);
0119     // On calling this function, neither source nor target should be locked
0120     // (readOnly or for writing). This function handles locking internally.
0121 
0122     static void removeIncludeRelation(FileObject *source, FileObject *target);
0123 };
0124 
0125 } // namespace Codethink::lvtmdb
0126 
0127 #endif // INCLUDED_CT_LVTMDB_FILEOBJECT