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

0001 // ct_lvtmdb_typeobject.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_TYPEOBJECT
0021 #define INCLUDED_CT_LVTMDB_TYPEOBJECT
0022 
0023 #include <lvtmdb_export.h>
0024 
0025 #include <ct_lvtshr_graphenums.h>
0026 
0027 #include <ct_lvtmdb_databaseobject.h>
0028 
0029 #include <string>
0030 #include <vector>
0031 
0032 namespace Codethink::lvtmdb {
0033 
0034 // Forward Declarations
0035 class ComponentObject;
0036 class FieldObject;
0037 class FileObject;
0038 class MethodObject;
0039 class NamespaceObject;
0040 class PackageObject;
0041 
0042 // ====================
0043 // class PackageObject
0044 // ====================
0045 
0046 class LVTMDB_EXPORT TypeObject : public DatabaseObject {
0047     // See locking discipline in superclass. That applies here.
0048 
0049   private:
0050     // DATA
0051     lvtshr::UDTKind d_kind;
0052     // What kind of type is this? e.g. class, struct, union, enum
0053 
0054     lvtshr::AccessSpecifier d_access;
0055 
0056     NamespaceObject *d_namespace_p;
0057     // Immediate parent namespace
0058 
0059     PackageObject *d_package_p;
0060     // Immediate parent package
0061 
0062     TypeObject *d_parent_p;
0063     // C++ type enclosing this type (or nullptr)
0064     // This maps to UserDefinedType::d_classNamespace_p **not** ::d_parents
0065 
0066     std::vector<TypeObject *> d_children;
0067     // C++ types nested inside this type
0068     // This maps to UserDefinedType::d_revClassnamespace **not** ::d_children
0069 
0070     std::vector<TypeObject *> d_subclasses;
0071     // subclasses of this type
0072     // Maps to UserDefinedType::d_children
0073 
0074     std::vector<TypeObject *> d_superclasses;
0075     // superclasses of this type
0076     // Maps to UserDefinedType::d_parents
0077 
0078     std::vector<TypeObject *> d_usesInTheInterface;
0079     std::vector<TypeObject *> d_revUsesInTheInterface;
0080 
0081     std::vector<TypeObject *> d_usesInTheImplementation;
0082     std::vector<TypeObject *> d_revUsesInTheImplementation;
0083 
0084     std::vector<FileObject *> d_files;
0085     // Soruce files in which this type is defined
0086 
0087     std::vector<ComponentObject *> d_components;
0088     // Components in which this type is defined
0089 
0090     std::vector<MethodObject *> d_methods;
0091     // Methods of this type
0092 
0093     std::vector<FieldObject *> d_fields;
0094     // Data members of this type
0095 
0096   public:
0097     // CREATORS
0098     TypeObject(std::string qualifiedName,
0099                std::string name,
0100                lvtshr::UDTKind kind,
0101                lvtshr::AccessSpecifier access,
0102                NamespaceObject *nmspc,
0103                PackageObject *package,
0104                TypeObject *parent);
0105 
0106     ~TypeObject() noexcept override;
0107 
0108     TypeObject(TypeObject&& other) noexcept;
0109 
0110     TypeObject& operator=(TypeObject&& other) noexcept;
0111 
0112     // ACCESSORS
0113     [[nodiscard]] lvtshr::UDTKind kind() const;
0114 
0115     [[nodiscard]] lvtshr::AccessSpecifier access() const;
0116 
0117     [[nodiscard]] NamespaceObject *parentNamespace() const;
0118 
0119     [[nodiscard]] PackageObject *package() const;
0120 
0121     [[nodiscard]] TypeObject *parent() const;
0122     [[nodiscard]] const std::vector<TypeObject *>& children() const;
0123 
0124     [[nodiscard]] const std::vector<TypeObject *>& subclasses() const;
0125     [[nodiscard]] const std::vector<TypeObject *>& superclasses() const;
0126 
0127     [[nodiscard]] const std::vector<TypeObject *>& usesInTheInterface() const;
0128     [[nodiscard]] const std::vector<TypeObject *>& revUsesInTheInterface() const;
0129 
0130     [[nodiscard]] const std::vector<TypeObject *>& usesInTheImplementation() const;
0131     [[nodiscard]] const std::vector<TypeObject *>& revUsesInTheImplementation() const;
0132 
0133     [[nodiscard]] const std::vector<FileObject *>& files() const;
0134 
0135     [[nodiscard]] const std::vector<ComponentObject *>& components() const;
0136 
0137     [[nodiscard]] const std::vector<MethodObject *>& methods() const;
0138 
0139     [[nodiscard]] const std::vector<FieldObject *>& fields() const;
0140 
0141     // MANIPULATORS
0142     void setPackage(PackageObject *package);
0143     void addChild(TypeObject *child);
0144     void addFile(FileObject *file);
0145     void setUniqueFile(FileObject *file);
0146 
0147     void removeFile(FileObject *file);
0148     void addComponent(ComponentObject *comp);
0149     void setUniqueComponent(ComponentObject *comp);
0150     void addMethod(MethodObject *method);
0151     void addField(FieldObject *field);
0152 
0153     // CLASS METHODS
0154     static void addIsARelationship(TypeObject *subclass, TypeObject *superclass);
0155     // On calling this function, neither subclass nor superclass should be
0156     // locked
0157 
0158     static void addUsesInTheInterface(TypeObject *source, TypeObject *target);
0159     // On calling this function, neither source nor target should be
0160     // locked
0161 
0162     static void addUsesInTheImplementation(TypeObject *source, TypeObject *target);
0163     // On calling this function, neither source nor target should be
0164     // locked
0165 };
0166 
0167 } // namespace Codethink::lvtmdb
0168 
0169 #endif // INCLUDED_CT_LVTMDB_TYPEOBJECT