dune-common  2.2.0
geometrytypeindex.hh
Go to the documentation of this file.
00001 // -*- tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002 // vi: set et ts=8 sw=2 sts=2:
00003 
00004 #ifndef DISABLE_GEOMETRYTYPEINDEX_DEPRECATION_WARNING
00005 #warning #include <dune/common/geometrytypeindex.hh> is deprecated. Use
00006 #warning #include <dune/geometry/typeindex.hh> instead. You may need the new
00007 #warning Dune-Geometry core module.
00008 #warning NOTE: <dune/common/geometrytypeindex.hh> was never part of a release,
00009 #warning so this compatibility mechanism should be removed before the 2.2
00010 #warning release.
00011 #endif // DISABLE_GEOMETRYTYPEINDEX_DEPRECATION_WARNING
00012 
00013 #ifndef DUNE_COMMON_GEOMETRYTYPEINDEX_HH
00014 #define DUNE_COMMON_GEOMETRYTYPEINDEX_HH
00015 
00021 #include <cstddef>
00022 
00023 #define DISABLE_GEOMETRYTYPE_DEPRECATION_WARNING
00024 #include <dune/common/geometrytype.hh>
00025 #undef DISABLE_GEOMETRYTYPE_DEPRECATION_WARNING
00026 
00027 namespace Dune {
00028 
00030   class LocalGeometryTypeIndex {
00032 
00036     inline static std::size_t regular_size(std::size_t dim) {
00037       // The following expression is derived from the expression for
00038       // GlobalGeometryTypeIndex::regular_base().  Substracting
00039       // regular_base(dim+1)-regular_base(dim) we get:
00040       //
00041       //   ((1 << dim+1) >> 1) - ((1 << dim) >> 1)
00042       //
00043       // We always have
00044       //
00045       //   dim >= 0,
00046       //
00047       // so
00048       //
00049       //   (1 << dim+1) >= 2   and   (1 << dim+2) % 2 == 0.
00050       //
00051       // So if we apply a single right-shift to that, we will never lose any
00052       // set bits, thus
00053       //
00054       //   ((1 << dim+1) >> 1) == (1 << dim)
00055       return (1 << dim) - ((1 << dim) >> 1);
00056     }
00057 
00058   public:
00060 
00063     inline static std::size_t size(std::size_t dim) {
00064       // one for "none"
00065       return regular_size(dim) + 1;
00066     }
00067 
00069 
00074     inline static std::size_t index(const GeometryType &gt) {
00075       if(gt.isNone())
00076         return regular_size(gt.dim());
00077       else
00078         return gt.id() >> 1;
00079     }
00080   };
00081 
00083   class GlobalGeometryTypeIndex {
00086 
00090     inline static std::size_t regular_base(std::size_t dim) {
00091       // The number of regular geometry types in a given dimension is
00092       // 2^(dim-1).  For dim==0 this would yield 1/2 geometry types (which is
00093       // obviously bogus, dim==0 has one regular geometry type, the point).
00094       // The following expression relies on 1 >> 1 == 0 to treat dim==0
00095       // specially.
00096       return (1 << dim) >> 1;
00097     }
00098 
00101     inline static std::size_t base(std::size_t dim) {
00102       // dim times "none"
00103       return regular_base(dim) + dim;
00104     }
00105 
00106   public:
00109 
00112     inline static std::size_t size(std::size_t maxdim)
00113     { return base(maxdim+1); }
00114 
00116 
00122     inline static std::size_t index(const GeometryType &gt) {
00123       return base(gt.dim()) + LocalGeometryTypeIndex::index(gt);
00124     }
00125   };
00126 
00127 } // namespace Dune
00128 
00129 #endif // DUNE_COMMON_GEOMETRYTYPEINDEX_HH