Palabos  Version 1.0
basicDataTypes.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 BASIC_DATA_TYPES_H
00026 #define BASIC_DATA_TYPES_H
00027 
00028 #include "core/globalDefs.h"
00029 #include <set>
00030 #include <typeinfo>
00031 
00032 namespace plb {
00033 
00034 
00035 template<typename T>
00036 class EnumeratedUniqueObjects {
00037 public:
00038     pluint operator[] (T const& object) {
00039         typename std::set<T>::iterator pos = objects.insert(object).first;
00040         return distance(objects.begin(), pos);
00041     }
00042 private:
00043     std::set<T> objects;
00044 };
00045 
00046 struct TypeInfoComparator
00047 {
00048     bool operator () (std::type_info const* t1, std::type_info const* t2) const {
00049         return t1->before(*t2);
00050     }
00051 };
00052 
00053 
00054 class EnumeratedUniqueTypeIds {
00055 public:
00056     pluint operator[] (std::type_info const& object) {
00057         std::set<std::type_info const*, TypeInfoComparator>::iterator pos = objects.insert(&object).first;
00058         return std::distance(objects.begin(), pos);
00059     }
00060 private:
00061     std::set<std::type_info const*, TypeInfoComparator> objects;
00062 };
00063 
00064 } // namespace plb
00065 
00066 #endif  // BASIC_DATA_TYPES_H