00001 #ifndef _STATIC_MAILLAGE_HPP_
00002 #define _STATIC_MAILLAGE_HPP_
00003
00004 #include <map>
00005
00006 #include "kernel/jafarMacro.hpp"
00007
00008 namespace jafar {
00009 namespace facetsmap {
00010 class MaillagePoint {
00011 template<class _T1, class _T2>
00012 friend struct std::pair;
00013 private:
00014 MaillagePoint() : i(0), j(0) {}
00015 public:
00016 MaillagePoint(int ni, int nj) : i(ni), j(nj) { }
00017 int i,j;
00018 inline bool operator<(const MaillagePoint& m ) const
00019 {
00020 if( i < m.i) return true;
00021 if( i == m.i) return j < m.j;
00022 return false;
00023 }
00024 };
00025 template<typename T>
00026 class StaticMaillage {
00027 protected:
00028 typedef typename std::map<MaillagePoint, T> maillage;
00029 typedef typename maillage::const_iterator maillage_cit;
00030 public:
00031 StaticMaillage() { };
00032 inline T get(int i, int j) {
00033 typename maillage::iterator it;
00034 if( (it = m_maillage.find(MaillagePoint(i,j))) != m_maillage.end() )
00035 {
00036 return it->second;
00037 } else {
00038 return 0.;
00039 }
00040 }
00041 inline void set(int i, int j, T v)
00042 {
00043 m_maillage[MaillagePoint(i,j)] = v;
00044 }
00045 T totalValue()
00046 {
00047 T tv = 0;
00048 for(maillage_cit it = begin(); it != end(); it++)
00049 {
00050 tv += it->second;
00051 }
00052 return tv;
00053 }
00054 protected:
00055 inline maillage_cit begin() { return m_maillage.begin(); }
00056 inline maillage_cit end() { return m_maillage.end(); }
00057 private:
00058 maillage m_maillage;
00059 };
00060 };
00061 };
00062
00063 #endif