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

0001 // ct_lvtldr_graphloader.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_LVTLDR_GRAPHLOADER
0021 #define INCLUDED_CT_LVTLDR_GRAPHLOADER
0022 
0023 //@PURPOSE: Load data into an lvtshr::IGraphLoader such that parents are always
0024 //          loaded before children and things are not added multiple times
0025 
0026 #include <lvtldr_export.h>
0027 
0028 #include <ct_lvtldr_igraphloader.h>
0029 #include <ct_lvtshr_loaderinfo.h>
0030 
0031 #include <memory>
0032 
0033 namespace Codethink::lvtldr {
0034 
0035 class NodeStorage;
0036 class LakosianEdge;
0037 class LakosianNode;
0038 
0039 // ==========================
0040 // class IGraphLoader
0041 // ==========================
0042 
0043 class LVTLDR_EXPORT GraphLoader {
0044     // Loads data into an lvtshr::IGraphLoader
0045 
0046     // TYPES
0047     struct Private;
0048     struct LoaderVertex;
0049     struct LoaderEdge;
0050     struct VertexHash;
0051     struct EdgeHash;
0052 
0053     // DATA
0054     std::unique_ptr<Private> d;
0055 
0056     // PRIVATE MODIFIERS
0057     lvtqtc::LakosEntity *load(LakosianNode *node);
0058     lvtqtc::LakosEntity *load(const LoaderVertex& vertex);
0059     void load(const LoaderEdge& edge);
0060 
0061     void addEdge(LakosianNode *source, const LakosianEdge& edge, bool reverse);
0062     // Add an edge to the internal store. reverse should be true if this is
0063     // an edge for a reverse dependency
0064 
0065   public:
0066     explicit GraphLoader();
0067     ~GraphLoader() noexcept;
0068 
0069     // MODIFIERS
0070     void setGraph(IGraphLoader *graph);
0071     // Really this should be in the constructor, but that isn't how
0072     // lvtqtc::GraphicsScene works. Graph must live at least as long as this
0073     // object.
0074 
0075     void clear();
0076     // Empties the internal store of vertices and edges
0077 
0078     void addVertex(LakosianNode *node, bool withParent, lvtshr::LoaderInfo info);
0079     // add a vertex to our internal store. These may be added in any order
0080     // and it is safe to call this multiple times with the same node.
0081     // If we are ever called withParent = true, that node's parent will be
0082     // loaded no matter if other calls set withParent = true.
0083 
0084     void loadForwardEdges();
0085     // load all forward edges between the added vertices
0086 
0087     void loadReverseEdges();
0088     // load all reverse edges between the added vertices
0089 
0090     void unload(LakosianNode *node);
0091     // we need to be able to unload those when removing children from the view.
0092 
0093     // ACCESSORS
0094     void load();
0095     // Load everything into the lvtshr::IGraphLoader
0096 };
0097 
0098 } // namespace Codethink::lvtldr
0099 
0100 #endif // INCLUDED_CT_LVTLDR_GRAPHLOADER