~ubuntu-branches/ubuntu/oneiric/libclaw/oneiric

« back to all changes in this revision

Viewing changes to examples/multi_type_map/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Julien Jorge
  • Date: 2010-12-23 20:55:14 UTC
  • mfrom: (4.2.1 sid)
  • Revision ID: james.westby@ubuntu.com-20101223205514-s10m6ywla7s4ttqf
Tags: 1.6.1-3
UploadĀ inĀ sid

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <claw/meta/type_list.hpp>
1
2
#include <claw/multi_type_map.hpp>
2
3
#include <fstream>
3
4
#include <iostream>
21
22
  return os << "(" << c.a << ", " << c.s << ")";
22
23
}
23
24
 
24
 
 
 
25
using namespace claw;
25
26
using namespace claw::meta;
26
27
 
 
28
template<typename Map>
 
29
struct print_map;
 
30
 
 
31
template<typename Key>
 
32
struct print_map< multi_type_map<Key, no_type> >
 
33
{
 
34
  std::ostream& operator()
 
35
    ( std::ostream& os, const multi_type_map<Key, no_type>& ) const
 
36
  { return os; }
 
37
}; // print_map [no_type]
 
38
 
 
39
template<typename Key, typename Head, typename Queue>
 
40
struct print_map< multi_type_map< Key, type_list<Head, Queue> > >
 
41
{
 
42
  typedef multi_type_map< Key, type_list<Head, Queue> > map_type;
 
43
 
 
44
  std::ostream& operator()( std::ostream& os, const map_type& m ) const
 
45
  {
 
46
    typename map_type::template iterator<Head>::const_type it;
 
47
 
 
48
    for (it=m.template begin<Head>(); it!=m.template end<Head>(); ++it)
 
49
      os << "(" << it->first << ", " << it->second << ") ";
 
50
 
 
51
    os << std::endl;
 
52
 
 
53
    print_map< multi_type_map<Key, Queue> > rec;
 
54
    return rec( os, m );
 
55
  }
 
56
}; // print_map [no_type]
 
57
 
27
58
typedef type_list
28
59
<float,
29
60
 type_list<bool,
83
114
void read( std::istream& is )
84
115
{
85
116
  std::string line;
86
 
  claw::multi_type_map<int, my_type_list> map;
 
117
  typedef claw::multi_type_map<int, my_type_list> map_type;
 
118
 
 
119
  map_type map;
87
120
 
88
121
  std::cout << sizeof(map) << std::endl;
89
122
 
99
132
      else if ( action == "set" )
100
133
        set( iss, map );
101
134
    }
 
135
 
 
136
  print_map< map_type > p;
 
137
  p( std::cout, map );
102
138
} // read()
103
139
 
104
140
int main( int argc, char* argv[] )