From 8d65b021d5e5c7e6c852984f6bf903bbfc33492f Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 20 May 2008 03:16:54 +0000 Subject: [PATCH] Allow binding accessor objects to references. In fact, allow copying as well. git-svn-id: https://svn.dealii.org/trunk@16130 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/table.h | 79 +++++++++++++------------------ 1 file changed, 34 insertions(+), 45 deletions(-) diff --git a/deal.II/base/include/base/table.h b/deal.II/base/include/base/table.h index 6ac48a062d..ea9ac58a02 100644 --- a/deal.II/base/include/base/table.h +++ b/deal.II/base/include/base/table.h @@ -2,7 +2,7 @@ // $Id$ // Version: $Name$ // -// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 by the deal.II authors +// Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 by the deal.II authors // // This file is subject to QPL and may not be distributed // without copyright and license information. Please refer @@ -153,20 +153,6 @@ namespace internal * various dimensions, and a * pointer to the subset of * data we may access. - * - * The constructor is made - * private in order to prevent - * you having such objects - * around. The only way to - * create such objects is via - * the Table class, which - * only generates them as - * temporary objects. This - * guarantees that the accessor - * objects go out of scope - * earlier than the mother - * object, avoid problems with - * data consistency. */ Accessor (const TableType &table, const pointer data); @@ -178,15 +164,22 @@ namespace internal */ Accessor (); + public: + /** - * Copy constructor. Not - * needed, and invisible, so - * private. + * Copy constructor. This constructor + * is public so that one can pass + * sub-tables to functions as + * arguments, as in + * f(table[i]). + * + * Using this constructor is risky if + * accessors are stored longer than + * the table it points to. Don't do + * this. */ Accessor (const Accessor &a); - public: - /** * Index operator. Performs a * range check. @@ -305,20 +298,26 @@ namespace internal const pointer data); /** - * Default constructor. Not - * needed, and invisible, so - * private. + * Default constructor. Not needed, + * so private. */ Accessor (); + public: /** - * Copy constructor. Not - * needed, and invisible, so - * private. + * Copy constructor. This constructor + * is public so that one can pass + * sub-tables to functions as + * arguments, as in + * f(table[i]). + * + * Using this constructor is risky if + * accessors are stored longer than + * the table it points to. Don't do + * this. */ Accessor (const Accessor &a); - public: /** * Index operator. Performs a @@ -1769,16 +1768,11 @@ namespace internal template inline - Accessor::Accessor (const Accessor &) + Accessor::Accessor (const Accessor &a) : - table (*static_cast(0)), - data (0) - { - // accessor objects are only - // temporary objects, so should - // not need to be copied around - Assert (false, ExcInternalError()); - } + table (a.table), + data (a.data) + {} @@ -1853,16 +1847,11 @@ namespace internal template inline - Accessor::Accessor (const Accessor &) + Accessor::Accessor (const Accessor &a) : - table (*static_cast(0)), - data (0) - { - // accessor objects are only - // temporary objects, so should - // not need to be copied around - Assert (false, ExcInternalError()); - } + table (a.table), + data (a.data) + {} -- 2.39.5