$extrastylesheet
mesh_inserter_iterator.h
Go to the documentation of this file.
00001 
00002 // The libMesh Finite Element Library.
00003 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
00004 
00005 // This library is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 
00010 // This library is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this library; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 
00020 
00021 #ifndef LIBMESH_MESH_INSERTER_ITERATOR_H
00022 #define LIBMESH_MESH_INSERTER_ITERATOR_H
00023 
00024 // Local includes
00025 #include "libmesh/elem.h"
00026 #include "libmesh/mesh_base.h"
00027 #include "libmesh/node.h"
00028 
00029 // C++ includes
00030 #include <iterator>
00031 
00032 namespace libMesh
00033 {
00034 
00035 // A class for templated methods that expect output iterator
00036 // arguments, which adds objects to the Mesh.
00037 // Although any mesh_inserter_iterator can add any object, we
00038 // template it around object type so that type inference and
00039 // iterator_traits will work.
00040 template <typename T>
00041 struct mesh_inserter_iterator
00042   : std::iterator<std::output_iterator_tag, T>
00043 {
00044   mesh_inserter_iterator (MeshBase& m) : mesh(m) {}
00045 
00046   void operator=(Elem* e) { mesh.add_elem(e); }
00047 
00048   void operator=(Node* n) { mesh.insert_node(n); }
00049 
00050   void operator=(Point* p) { mesh.add_point(*p); }
00051 
00052   mesh_inserter_iterator& operator++() {
00053     return *this;
00054   }
00055 
00056   mesh_inserter_iterator operator++(int) {
00057     return mesh_inserter_iterator(*this);
00058   }
00059 
00060   // We don't return a reference-to-T here because we don't want to
00061   // construct one or have any of its methods called.  We just want
00062   // to allow the returned object to be able to do mesh insertions
00063   // with operator=().
00064   mesh_inserter_iterator& operator*() { return *this; }
00065 private:
00066 
00067   MeshBase& mesh;
00068 };
00069 
00070 } // namespace libMesh
00071 
00072 
00073 #endif // LIBMESH_MESH_INSERTER_ITERATOR_H