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

0001 // ct_lvtmdb_namespaceobject.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_namespaceobject.h>
0021 
0022 #include <ct_lvtmdb_util.h>
0023 
0024 #include <algorithm>
0025 
0026 namespace Codethink::lvtmdb {
0027 
0028 NamespaceObject::NamespaceObject(std::string qualifiedName, std::string name, NamespaceObject *parent):
0029     DatabaseObject(std::move(qualifiedName), std::move(name)), d_parent_p(parent)
0030 {
0031 }
0032 
0033 NamespaceObject::~NamespaceObject() noexcept = default;
0034 
0035 NamespaceObject::NamespaceObject(NamespaceObject&&) noexcept = default;
0036 
0037 NamespaceObject& NamespaceObject::operator=(NamespaceObject&&) noexcept = default;
0038 
0039 NamespaceObject *NamespaceObject::parent() const
0040 {
0041     assertReadable();
0042     return d_parent_p;
0043 }
0044 
0045 const std::vector<NamespaceObject *>& NamespaceObject::children() const
0046 {
0047     assertReadable();
0048     return d_children;
0049 }
0050 
0051 const std::vector<TypeObject *>& NamespaceObject::typeChildren() const
0052 {
0053     assertReadable();
0054     return d_typeChildren;
0055 }
0056 
0057 const std::vector<FileObject *>& NamespaceObject::files() const
0058 {
0059     assertReadable();
0060     return d_files;
0061 }
0062 
0063 const std::vector<FunctionObject *>& NamespaceObject::functions() const
0064 {
0065     assertReadable();
0066     return d_functions;
0067 }
0068 
0069 const std::vector<VariableObject *>& NamespaceObject::variables() const
0070 {
0071     assertReadable();
0072     return d_variables;
0073 }
0074 
0075 void NamespaceObject::addChild(NamespaceObject *child)
0076 {
0077     assertWritable();
0078     MdbUtil::pushBackUnique(d_children, child);
0079 }
0080 
0081 void NamespaceObject::removeChild(NamespaceObject *child)
0082 {
0083     assertWritable();
0084     d_children.erase(std::remove(d_children.begin(), d_children.end(), child), d_children.end());
0085 }
0086 
0087 void NamespaceObject::addType(TypeObject *type)
0088 {
0089     assertWritable();
0090     MdbUtil::pushBackUnique(d_typeChildren, type);
0091 }
0092 
0093 void NamespaceObject::removeType(TypeObject *type)
0094 {
0095     assertWritable();
0096     d_typeChildren.erase(std::remove(d_typeChildren.begin(), d_typeChildren.end(), type), d_typeChildren.end());
0097 }
0098 
0099 void NamespaceObject::addFile(FileObject *file)
0100 {
0101     assertWritable();
0102     MdbUtil::pushBackUnique(d_files, file);
0103 }
0104 
0105 void NamespaceObject::removeFile(FileObject *file)
0106 {
0107     assertWritable();
0108     d_files.erase(std::remove(d_files.begin(), d_files.end(), file), d_files.end());
0109 }
0110 
0111 void NamespaceObject::addFunction(FunctionObject *function)
0112 {
0113     assertWritable();
0114     MdbUtil::pushBackUnique(d_functions, function);
0115 }
0116 
0117 void NamespaceObject::removeFunction(FunctionObject *function)
0118 {
0119     assertWritable();
0120     d_functions.erase(std::remove(d_functions.begin(), d_functions.end(), function), d_functions.end());
0121 }
0122 
0123 void NamespaceObject::addVariable(VariableObject *variable)
0124 {
0125     assertWritable();
0126     MdbUtil::pushBackUnique(d_variables, variable);
0127 }
0128 
0129 void NamespaceObject::removeVariable(VariableObject *var)
0130 {
0131     assertWritable();
0132     d_variables.erase(std::remove(d_variables.begin(), d_variables.end(), var), d_variables.end());
0133 }
0134 
0135 } // namespace Codethink::lvtmdb