escript  Revision_
IndexList.h
Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003 *
00004 * Copyright (c) 2003-2014 by University of Queensland
00005 * http://www.uq.edu.au
00006 *
00007 * Primary Business: Queensland, Australia
00008 * Licensed under the Open Software License version 3.0
00009 * http://www.opensource.org/licenses/osl-3.0.php
00010 *
00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
00012 * Development 2012-2013 by School of Earth Sciences
00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
00014 *
00015 *****************************************************************************/
00016 
00017 
00018 /****************************************************************************/
00019 
00020 /*   esysUtils: IndexList                                                   */
00021 
00022 /****************************************************************************/
00023 
00024 /*   Author: Lutz Gross, l.gross@uq.edu.au */
00025 
00026 /****************************************************************************/
00027 
00028 #ifndef __ESYSUTILS_INDEXLIST_H__
00029 #define __ESYSUTILS_INDEXLIST_H__
00030 
00031 #include "types.h"
00032 
00033 #include <algorithm>
00034 #include <list>
00035 #include <vector>
00036 
00037 namespace esysUtils {
00038 
00039 struct IndexList;
00040 typedef std::vector<IndexList> IndexListArray;
00041 
00042 struct IndexList {
00043     std::list<index_t> m_list;
00044 
00046     inline void insertIndex(index_t index)
00047     {
00048         if (std::find(m_list.begin(), m_list.end(), index) == m_list.end())
00049             m_list.push_back(index);
00050     }
00051 
00053     inline dim_t count(index_t range_min, index_t range_max) const
00054     {
00055         dim_t out=0;
00056         std::list<index_t>::const_iterator it;
00057         for (it=m_list.begin(); it != m_list.end(); it++) {
00058             if (*it >= range_min && range_max > *it)
00059                 ++out;
00060         }
00061         return out;
00062     }
00063 
00065     inline void toArray(index_t* array, index_t range_min, index_t range_max,
00066                         index_t index_offset) const
00067     {
00068         index_t idx = 0;
00069         std::list<index_t>::const_iterator it;
00070         for (it=m_list.begin(); it != m_list.end(); it++) {
00071             if (*it >= range_min && range_max > *it) {
00072                 array[idx] = (*it)+index_offset;
00073                 ++idx;
00074             }
00075         }
00076     }
00077 };
00078 
00079 } // namespace esysUtils
00080 
00081 #endif // __ESYSUTILS_INDEXLIST_H__
00082