1 /* 2 * Copyright (C) 2004-2021 Edward F. Valeev 3 * 4 * This file is part of Libint. 5 * 6 * Libint is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Libint is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with Libint. If not, see <http://www.gnu.org/licenses/>. 18 * 19 */ 20 21 #ifndef _libint2_src_bin_libint_drtree_h_ 22 #define _libint2_src_bin_libint_drtree_h_ 23 24 #include <smart_ptr.h> 25 26 namespace libint2 { 27 28 class DGVertex; 29 30 /// This is a directed rooted tree 31 class DRTree : 32 public EnableSafePtrFromThis<DRTree> 33 { 34 public: 35 typedef DRTree this_type; 36 37 /// If v is not on a DRTree, make a new one using v as root 38 static SafePtr<DRTree> CreateRootedAt(const SafePtr<DGVertex>& v); 39 ~DRTree(); 40 41 /// number of vertices nvertices()42 unsigned int nvertices() const { return nvertices_; } 43 /// the root of the tree 44 const SafePtr<DGVertex>& root() const; 45 /// remove all references from vertices to the tree and vice versa 46 void detach(); 47 /// will try to add v to this subtree. Should not be used by the user 48 void add_vertex(const SafePtr<DGVertex>& v); 49 /// recurively detach v from this 50 void detach_from(const SafePtr<DGVertex>& v); 51 52 private: 53 /// Create a tree starting at root 54 DRTree(const SafePtr<DGVertex>& root); 55 /// grows the tree from the root. Must be called after the constructor 56 void grow(); 57 58 unsigned int nvertices_; 59 SafePtr<DGVertex> root_; 60 }; 61 62 } 63 64 #endif // ifndef 65 66