File indexing completed on 2024-05-19 05:42:10
0001 // ct_lvtmdb_fileobject.cpp -*-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 #include <ct_lvtmdb_fileobject.h> 0021 0022 #include <ct_lvtmdb_util.h> 0023 0024 #include <cassert> 0025 #include <iostream> 0026 0027 namespace Codethink::lvtmdb { 0028 0029 FileObject::FileObject(std::string qualifiedName, 0030 std::string name, 0031 bool isHeader, 0032 std::string hash, 0033 PackageObject *package, 0034 ComponentObject *component): 0035 DatabaseObject(std::move(qualifiedName), std::move(name)), 0036 d_isHeader(isHeader), 0037 d_hash(std::move(hash)), 0038 d_package_p(package), 0039 d_component_p(component) 0040 { 0041 } 0042 0043 FileObject::~FileObject() noexcept = default; 0044 0045 FileObject::FileObject(FileObject&&) noexcept = default; 0046 0047 FileObject& FileObject::operator=(FileObject&&) noexcept = default; 0048 0049 bool FileObject::isHeader() const 0050 { 0051 assertReadable(); 0052 return d_isHeader; 0053 } 0054 0055 const std::string& FileObject::hash() const 0056 { 0057 assertReadable(); 0058 return d_hash; 0059 } 0060 0061 const std::vector<FileObject *>& FileObject::forwardIncludes() const 0062 { 0063 assertReadable(); 0064 return d_forwardIncludes; 0065 } 0066 0067 const std::vector<FileObject *>& FileObject::reverseIncludes() const 0068 { 0069 assertReadable(); 0070 return d_reverseIncludes; 0071 } 0072 0073 PackageObject *FileObject::package() const 0074 { 0075 assertReadable(); 0076 return d_package_p; 0077 } 0078 0079 ComponentObject *FileObject::component() const 0080 { 0081 assertReadable(); 0082 return d_component_p; 0083 } 0084 0085 const std::vector<NamespaceObject *>& FileObject::namespaces() const 0086 { 0087 assertReadable(); 0088 return d_namespaces; 0089 } 0090 0091 const std::vector<FunctionObject *>& FileObject::globalFunctions() const 0092 { 0093 assertReadable(); 0094 return d_globalfunctions; 0095 } 0096 0097 const std::vector<TypeObject *>& FileObject::types() const 0098 { 0099 assertReadable(); 0100 return d_types; 0101 } 0102 0103 void FileObject::setHash(std::string hash) 0104 { 0105 assertWritable(); 0106 d_hash = std::move(hash); 0107 } 0108 0109 void FileObject::addNamespace(NamespaceObject *nmspc) 0110 { 0111 assertWritable(); 0112 MdbUtil::pushBackUnique(d_namespaces, nmspc); 0113 } 0114 0115 void FileObject::addGlobalFunction(FunctionObject *fnc) 0116 { 0117 assertWritable(); 0118 MdbUtil::pushBackUnique(d_globalfunctions, fnc); 0119 } 0120 0121 void FileObject::addType(TypeObject *type) 0122 { 0123 assertWritable(); 0124 MdbUtil::pushBackUnique(d_types, type); 0125 } 0126 0127 void FileObject::addIncludeRelation(FileObject *source, FileObject *target) 0128 { 0129 assert(source); 0130 assert(target); 0131 addPeerRelationship(source, target, source->d_forwardIncludes, target->d_reverseIncludes); 0132 } 0133 0134 void FileObject::removeIncludeRelation(FileObject *source, FileObject *target) 0135 { 0136 assert(source); 0137 assert(target); 0138 addPeerRelationship(source, target, source->d_forwardIncludes, target->d_reverseIncludes); 0139 } 0140 0141 } // namespace Codethink::lvtmdb