ViennaGrid - The Vienna Grid Library  2.1.0
viennagrid/element/element_orientation.hpp
Go to the documentation of this file.
00001 #ifndef VIENNAGRID_DETAIL_ELEMENT_ORIENTATION_HPP
00002 #define VIENNAGRID_DETAIL_ELEMENT_ORIENTATION_HPP
00003 
00004 /* =======================================================================
00005    Copyright (c) 2011-2014, Institute for Microelectronics,
00006                             Institute for Analysis and Scientific Computing,
00007                             TU Wien.
00008 
00009                             -----------------
00010                      ViennaGrid - The Vienna Grid Library
00011                             -----------------
00012 
00013    License:      MIT (X11), see file LICENSE in the base directory
00014 ======================================================================= */
00015 
00016 
00017 #include <vector>
00018 #include <iostream>
00019 
00020 #include "viennagrid/forwards.hpp"
00021 
00026 namespace viennagrid
00027 {
00028   namespace result_of
00029   {
00031     template<int num_elements>
00032     struct permutator_type
00033     {
00034       typedef typename permutator_type<num_elements+1>::type type;
00035     };
00036 
00038     template<>
00039     struct permutator_type<16>  //shortcut for not instantiating too many template specializations
00040     {
00041       typedef unsigned char type;
00042     };
00043 
00044     template<>
00045     struct permutator_type<256>
00046     {
00047       typedef unsigned char type;
00048     };
00049 
00050     template<>
00051     struct permutator_type<65536>
00052     {
00053       typedef unsigned short type;
00054     };
00056   }
00057 
00058 
00059 
00060   /************** Level 1: Elements contained by a higher-level element *******/
00061 
00068     template <typename container_type>
00069     class element_orientation : public container_type
00070     {
00071       typedef typename container_type::value_type  permutator_type;
00072       typedef typename container_type::size_type   size_type;
00073 
00074     public:
00075       void setDefaultOrientation()
00076       {
00077         unsigned int index = 0;
00078         for (typename container_type::iterator it = container_type::begin(); it != container_type::end(); ++it, ++index)
00079           *it = static_cast<permutator_type>(index);
00080       }
00081 
00082       size_type operator()(size_type in) const { return static_cast<size_type>( (*this)[in] ); }
00083 
00084       void setPermutation(size_type index, size_type mappedTo) { (*this)[index] = static_cast<permutator_type>(mappedTo); }
00085 
00086       void print() const
00087       {
00088         unsigned int index = 0;
00089         for (typename container_type::const_iterator it = container_type::begin(); it != container_type::end(); ++it, ++index)
00090           std::cout << index << "->" << *it << ",";
00091         std::cout << std::endl;
00092       }
00093     };
00094 
00095 }
00096 
00097 
00098 #endif
00099