$treeview $search $mathjax
Palabos  Version 1.1
$projectbrief
$projectbrief
$searchbox

metaStuffHelper.h

Go to the documentation of this file.
00001 /* This file is part of the Palabos library.
00002  *
00003  * Copyright (C) 2011 FlowKit Sarl
00004  * Avenue de Chailly 23
00005  * 1012 Lausanne, Switzerland
00006  * E-mail contact: contact@flowkit.com
00007  *
00008  * The most recent release of Palabos can be downloaded at 
00009  * <http://www.palabos.org/>
00010  *
00011  * The library Palabos is free software: you can redistribute it and/or
00012  * modify it under the terms of the GNU Affero General Public License as
00013  * published by the Free Software Foundation, either version 3 of the
00014  * License, or (at your option) any later version.
00015  *
00016  * The library is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU Affero General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU Affero General Public License
00022  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00023 */
00024 
00025 #ifndef META_STUFF_HELPER_H
00026 #define META_STUFF_HELPER_H
00027 
00028 #include "atomicBlock/atomicContainerBlock2D.h"
00029 #include <set>
00030 #include <map>
00031 
00032 namespace plb {
00033 
00034 struct VectorIsLess {
00035     bool operator()(std::vector<int> const& v1, std::vector<int> const& v2) const {
00036         pluint bound = std::max(v1.size(), v2.size());
00037         for (pluint i=0; i<bound; ++i) {
00038             int val1 = i<v1.size() ? v1[i] : 0;
00039             int val2 = i<v2.size() ? v2[i] : 0;
00040             if (val1<val2) {
00041                 return true;
00042             }
00043             else if (val1>val2) {
00044                 return false;
00045             }
00046         }
00047         return false;
00048     }
00049 };
00050 
00051 inline bool vectorEquals(std::vector<int> const& v1, std::vector<int> const& v2)
00052 {
00053     return !(VectorIsLess()(v1,v2) || VectorIsLess()(v2,v1));
00054 }
00055 
00057 class StoreDynamicsID : public ContainerBlockData
00058 {
00059 public:
00060     typedef std::set<std::vector<int>, VectorIsLess> ChainCollection;
00061 public:
00062     virtual StoreDynamicsID* clone() const {
00063         return new StoreDynamicsID(*this);
00064     }
00065     void addIdChain(std::vector<int> const& chain) {
00066         idChains.insert(chain);
00067     }
00068     ChainCollection const& getIds() const {
00069         return idChains;
00070     }
00071     void startIterations() {
00072         pos = idChains.rbegin();
00073     }
00074     std::vector<int> iterate() {
00075         ++pos;
00076         if (empty()) {
00077             std::vector<int> none;
00078             none.push_back(-1);
00079             return none;
00080         }
00081         else {
00082             return *pos;
00083         }
00084     }
00085     bool empty() const {
00086         return pos == idChains.rend();
00087     }
00088     std::vector<int> const& getCurrent() const {
00089         return *pos;
00090     }
00091 private:
00092     ChainCollection::const_reverse_iterator pos;
00093     ChainCollection idChains;
00094 };
00095 
00096 }  // namespace plb
00097 
00098 #endif  // META_STUFF_HELPER_H
00099