File indexing completed on 2024-05-19 05:42:09
0001 // ct_lvtldr_typenode.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_TYPENODE_H 0021 #define DIAGRAM_SERVER_CT_LVTLDR_TYPENODE_H 0022 0023 #include <ct_lvtldr_databasehandler.h> 0024 #include <ct_lvtldr_lakosiannode.h> 0025 #include <ct_lvtldr_typenodefields.h> 0026 0027 namespace Codethink::lvtldr { 0028 0029 // ========================== 0030 // class TypeNode 0031 // ========================== 0032 0033 class LVTLDR_EXPORT TypeNode : public LakosianNode { 0034 // Implementation of LakosianNode for UDTs 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 TypeNodeFields d_fields; 0041 std::vector<std::string> d_qualifiedNameParts; 0042 0043 protected: 0044 explicit TypeNode(NodeStorage& store); 0045 0046 // MODIFIERS 0047 void loadParent() override; 0048 void loadChildren() override; 0049 void loadProviders() override; 0050 void loadClients() override; 0051 void loadFields(); 0052 0053 public: 0054 explicit TypeNode(NodeStorage& store, 0055 std::optional<std::reference_wrapper<DatabaseHandler>> dbHandler = std::nullopt, 0056 std::optional<TypeNodeFields> d_fields = std::nullopt); 0057 0058 ~TypeNode() noexcept override; 0059 0060 static inline TypeNode *from(LakosianNode *other) 0061 { 0062 return dynamic_cast<TypeNode *>(other); 0063 } 0064 0065 inline TypeNodeFields const& getFields() 0066 { 0067 loadFields(); 0068 return d_fields; 0069 } 0070 0071 void invalidateFieldNames(); 0072 0073 void addFieldName(std::string fieldName); 0074 0075 // ACCESSORS 0076 void setParentPackageId(Codethink::lvtshr::UniqueId::RecordNumberType id); 0077 0078 [[nodiscard]] lvtshr::DiagramType type() const override; 0079 [[nodiscard]] lvtshr::UDTKind kind() const; 0080 cpp::result<void, AddChildError> addChild(LakosianNode *child) override; 0081 bool isA(TypeNode *other); 0082 bool usesInTheImplementation(TypeNode *other); 0083 bool usesInTheInterface(TypeNode *other); 0084 0085 [[nodiscard]] std::string qualifiedName() const override; 0086 [[nodiscard]] std::string parentName() override; 0087 [[nodiscard]] long long id() const override; 0088 [[nodiscard]] lvtshr::UniqueId uid() const override; 0089 0090 [[nodiscard]] IsLakosianResult isLakosian() override; 0091 0092 [[nodiscard]] bool hasClassNamespace() const; 0093 [[nodiscard]] lvtshr::UniqueId::RecordNumberType classNamespaceId() const; 0094 }; 0095 0096 template<> 0097 struct LakosianNodeType<Codethink::lvtldr::TypeNode> { 0098 static auto constexpr diagramType = lvtshr::DiagramType::ClassType; 0099 }; 0100 0101 } // namespace Codethink::lvtldr 0102 0103 #endif // DIAGRAM_SERVER_CT_LVTLDR_TYPENODE_H