/usr/include/dolfin/common/Hierarchical.h is in libdolfin1.0-dev 1.0.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | // Copyright (C) 2011 Anders Logg
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// First added: 2011-01-30
// Last changed: 2011-10-04
#ifndef __HIERARCHICAL_H
#define __HIERARCHICAL_H
#include <boost/shared_ptr.hpp>
#include <dolfin/log/dolfin_log.h>
#include "NoDeleter.h"
namespace dolfin
{
/// This class provides storage and data access for hierarchical
/// classes; that is, classes where an object may have a child
/// and a parent.
///
/// Note to developers: each subclass of Hierarchical that
/// implements an assignment operator must call the base class
/// assignment operator at the *end* of the subclass assignment
/// operator. See the Mesh class for an example.
template <typename T>
class Hierarchical
{
public:
/// Constructor
Hierarchical(T& self) : _self(reference_to_no_delete_pointer(self)) {}
/// Destructor
~Hierarchical() {}
/// Return depth of the hierarchy; that is, the total number of
/// objects in the hierarchy linked to the current object via
/// child-parent relationships, including the object itself.
///
/// *Returns*
/// uint
/// The depth of the hierarchy.
uint depth() const
{
uint d = 1;
for (boost::shared_ptr<const T> it = root_node_shared_ptr();
it->_child; it = it->_child)
d++;
return d;
}
/// Check if the object has a parent.
///
/// *Returns*
/// bool
/// The return value is true iff the object has a parent.
bool has_parent() const
{ return _parent; }
/// Check if the object has a child.
///
/// *Returns*
/// bool
/// The return value is true iff the object has a child.
bool has_child() const
{ return _child; }
/// Return parent in hierarchy. An error is thrown if the object
/// has no parent.
///
/// *Returns*
/// _Object_
/// The parent object.
T& parent()
{
if (!_parent)
dolfin_error("Hierarchical.h",
"extract parent of hierarchical object",
"Object has no parent in hierarchy");
return *_parent;
}
/// Return parent in hierarchy (const version).
const T& parent() const
{
if (!_parent)
dolfin_error("Hierarchical.h",
"extract parent of hierarchical object",
"Object has no parent in hierarchy");
return *_parent;
}
/// Return shared pointer to parent. A zero pointer is returned if
/// the object has no parent.
///
/// *Returns*
/// shared_ptr<T>
/// The parent object.
boost::shared_ptr<T> parent_shared_ptr()
{ return _parent; }
/// Return shared pointer to parent (const version).
boost::shared_ptr<const T> parent_shared_ptr() const
{ return _parent; }
/// Return child in hierarchy. An error is thrown if the object
/// has no child.
///
/// *Returns*
/// _T_
/// The child object.
T& child()
{
if (!_child)
dolfin_error("Hierarchical.h",
"extract child of hierarchical object",
"Object has no child in hierarchy");
return *_child;
}
/// Return child in hierarchy (const version).
const T& child() const
{
if (!_child)
dolfin_error("Hierarchical.h",
"extract child of hierarchical object",
"Object has no child in hierarchy");
return *_child;
}
/// Return shared pointer to child. A zero pointer is returned if
/// the object has no child.
///
/// *Returns*
/// shared_ptr<T>
/// The child object.
boost::shared_ptr<T> child_shared_ptr()
{ return _child; }
/// Return shared pointer to child (const version).
boost::shared_ptr<const T> child_shared_ptr() const
{ return _child; }
/// Return root node object in hierarchy.
///
/// *Returns*
/// _T_
/// The root node object.
T& root_node()
{
return *root_node_shared_ptr();
}
/// Return root node object in hierarchy (const version).
const T& root_node() const
{
return *root_node_shared_ptr();
}
/// Return shared pointer to root node object in hierarchy.
///
/// *Returns*
/// _T_
/// The root node object.
boost::shared_ptr<T> root_node_shared_ptr()
{
boost::shared_ptr<T> it = _self;
for (; it->_parent; it = it->_parent);
return it;
}
/// Return shared pointer to root node object in hierarchy (const version).
boost::shared_ptr<const T> root_node_shared_ptr() const
{
boost::shared_ptr<const T> it = _self;
for (; it->_parent; it = it->_parent);
return it;
}
/// Return leaf node object in hierarchy.
///
/// *Returns*
/// _T_
/// The leaf node object.
T& leaf_node()
{
return *leaf_node_shared_ptr();
}
/// Return leaf node object in hierarchy (const version).
const T& leaf_node() const
{
return *leaf_node_shared_ptr();
}
/// Return shared pointer to leaf node object in hierarchy.
///
/// *Returns*
/// _T_
/// The leaf node object.
boost::shared_ptr<T> leaf_node_shared_ptr()
{
boost::shared_ptr<T> it = _self;
for (; it->_child; it = it->_child);
return it;
}
/// Return shared pointer to leaf node object in hierarchy (const version).
boost::shared_ptr<const T> leaf_node_shared_ptr() const
{
boost::shared_ptr<const T> it = _self;
for (; it->_child; it = it->_child);
return it;
}
/// Set parent
void set_parent(boost::shared_ptr<T> parent)
{ _parent = parent; }
/// Set child
void set_child(boost::shared_ptr<T> child)
{ _child = child; }
/// Assignment operator
const Hierarchical& operator= (const Hierarchical& hierarchical)
{
// Destroy any previous parent-child relations
_parent.reset();
_child.reset();
return *this;
}
/// Function useful for debugging the hierarchy
void _debug() const
{
info("Debugging hierarchical object:");
cout << " depth = " << depth() << endl;
cout << " has_parent() = " << has_parent() << endl;
info(" _parent.get() = %x", _parent.get());
info(" _parent.count() = %d", _parent.use_count());
cout << " has_child() = " << has_parent() << endl;
info(" _child.get() = %x", _parent.get());
info(" _child.count() = %d", _parent.use_count());
}
private:
// The object itself
boost::shared_ptr<T> _self;
// Parent and child in hierarchy
boost::shared_ptr<T> _parent;
boost::shared_ptr<T> _child;
};
}
#endif
|