From 66b164cf532fcdb33477a5399f2e8fbcf8322410 Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 26 Sep 2002 17:51:59 +0000 Subject: [PATCH] Make constructors of the iterators private, to avoid them being used other than as temporaries, since this would generate problems with data integrity when the mother object goes out of scope. git-svn-id: https://svn.dealii.org/trunk@6532 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/base/include/base/table.h | 172 +++++++++++++++++++++++++++++- 1 file changed, 167 insertions(+), 5 deletions(-) diff --git a/deal.II/base/include/base/table.h b/deal.II/base/include/base/table.h index b6bd7c7259..304c62f076 100644 --- a/deal.II/base/include/base/table.h +++ b/deal.II/base/include/base/table.h @@ -14,6 +14,7 @@ #define __deal2__table_h #include +#include #include #include @@ -21,8 +22,16 @@ // forward declaration -template -class TableBase; +template class TableBase; +template class Table; +template class Table<1,T1>; +template class Table<2,T1>; +template class Table<3,T>; +template class Table<4,T>; +template class Table<5,T>; +template class Table<6,T>; + + /** @@ -346,7 +355,11 @@ namespace TableBaseAccessors * * As stated for the entire namespace, you will not usually have to do * with these classes directly, and should not try to use their - * interface directly as it may change without notice. + * interface directly as it may change without notice. In fact, since + * the constructors are made private, you will not even be able to + * generate objects of this class, as they are only thought as + * temporaries for access to elements of the table class, not for + * passing them around as arguments of functions, etc. * * @author Wolfgang Bangerth, 2002 */ @@ -361,6 +374,7 @@ namespace TableBaseAccessors typedef typename Types::value_type * pointer; typedef typename Types::TableType TableType; + private: /** * Constructor. Take a pointer * to the table object to know @@ -368,10 +382,39 @@ namespace TableBaseAccessors * 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 @p{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); + /** + * Default constructor. Not + * needed, and invisible, so + * private. + */ + Accessor (); + /** + * Copy constructor. Not + * needed, and invisible, so + * private. + */ + Accessor (const Accessor &a); + + public: + /** * Index operator. Performs a * range check. @@ -400,6 +443,19 @@ namespace TableBaseAccessors */ const TableType &table; const pointer data; + + // declare some other classes + // as friends. make sure to + // work around bugs in some + // compilers +#ifndef DEAL_II_NAMESP_TEMPL_FRIEND_BUG + template friend class Table; + template + friend class Accessor; +#else + friend class Accessor; + friend class Table; +#endif }; @@ -408,7 +464,8 @@ namespace TableBaseAccessors * Accessor class for tables. This is the specialization for the last * index, which actually allows access to the elements of the table, * rather than recursively returning access objects for further - * subsets. + * subsets. The same holds for this specialization as for the general + * template; see there for more information. * * @author Wolfgang Bangerth, 2002 */ @@ -440,6 +497,8 @@ namespace TableBaseAccessors * switch class above. */ typedef typename Types::TableType TableType; + + private: /** * Constructor. Take a pointer @@ -450,9 +509,39 @@ namespace TableBaseAccessors * data we may access (which in * this particular case is only * one row). + * + * The constructor is made + * private in order to prevent + * you having such objects + * around. The only way to + * create such objects is via + * the @p{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); + + /** + * Default constructor. Not + * needed, and invisible, so + * private. + */ + Accessor (); + + /** + * Copy constructor. Not + * needed, and invisible, so + * private. + */ + Accessor (const Accessor &a); + + public: /** * Index operator. Performs a @@ -504,6 +593,19 @@ namespace TableBaseAccessors */ const TableType &table; const pointer data; + + // declare some other classes + // as friends. make sure to + // work around bugs in some + // compilers +#ifndef DEAL_II_NAMESP_TEMPL_FRIEND_BUG + template friend class Table; + template + friend class Accessor; +#else + friend class Accessor; + friend class Table<2,T>; +#endif }; }; @@ -1627,6 +1729,36 @@ namespace TableBaseAccessors {}; + + template + inline + Accessor::Accessor (const Accessor &) + : + table (*static_cast(0)), + data (0) + { + // accessor objects are only + // temporary objects, so should + // not need to be copied around + Assert (false, ExcInternalError()); + }; + + + + template + inline + Accessor::Accessor () + : + table (*static_cast(0)), + data (0) + { + // accessor objects are only + // temporary objects, so should + // not need to be copied around + Assert (false, ExcInternalError()); + }; + + template inline @@ -1666,6 +1798,36 @@ namespace TableBaseAccessors {}; + + template + inline + Accessor::Accessor () + : + table (*static_cast(0)), + data (0) + { + // accessor objects are only + // temporary objects, so should + // not need to be copied around + Assert (false, ExcInternalError()); + }; + + + + template + inline + Accessor::Accessor (const Accessor &) + : + table (*static_cast(0)), + data (0) + { + // accessor objects are only + // temporary objects, so should + // not need to be copied around + Assert (false, ExcInternalError()); + }; + + template inline @@ -2001,7 +2163,7 @@ Table<1,T>::operator () (const unsigned int i) template -Table<2,T>::Table () +Table<2,T>::Table () {}; -- 2.39.5