xc
TripletMap.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //TripletMap.h
22 
23 #ifndef TRIPLETMAP_H
24 #define TRIPLETMAP_H
25 
26 #include <map>
27 #include <iostream>
28 #include "boost/tuple/tuple.hpp"
29 #include "boost/tuple/tuple_comparison.hpp"
30 
31 typedef boost::tuple<size_t,size_t,size_t> Triplete;
32 
33 inline void printTriplete(std::ostream &os,const Triplete &t)
34  {
35  os << "[" << t.get<0>() << ","
36  << t.get<1>() << ","
37  << t.get<2>() << "]";
38  }
39 
41 template<class T>
42 class TripletMap:public std::map<Triplete,T>
43  {
44  public:
45  typedef std::map<Triplete,T> map_Ts;
46  typedef typename map_Ts::const_iterator const_iterator;
47  typedef typename map_Ts::iterator iterator;
48  TripletMap(void): map_Ts() {}
49  void PrintMember(std::ostream &os,const_iterator &) const;
50  void Print(std::ostream &) const;
51  };
52 
53 template<class T>
54 void TripletMap<T>::PrintMember(std::ostream &os,const_iterator &i) const
55  {
56  printTriplete(os,(*i).first);
57  os << "; " << (*i).second;
58  }
59 
60 template<class T>
61 void TripletMap<T>::Print(std::ostream &os) const
62  {
63  for(const_iterator i=this->begin();i!=this->end();i++)
64  {
65  PrintMember(os,i);
66  os << std::endl;
67  }
68  }
69 template<class T>
70 std::ostream &operator<<(std::ostream &os,const TripletMap<T> &tm)
71  {
72  tm.Print(os);
73  return os;
74  }
75 
76 
77 #endif
Mapa tipo «tensor disperso».
Definition: TripletMap.h:42