/* CSE 333 Su12 lecture 12 demo: mapexample.cc */
/* Gribble/Perkins */

// Store several pairs of Printer objects in a map, then print
// the table, and print some individual values using table lookup.

#include <iostream>
#include <map>
#include <algorithm>

#include "Printer.h"

using namespace std;

void PrintOut(const pair<Printer,Printer> &p) {
  cout << "printout [" << p.first << "," << p.second << "]" << endl;
}

int main(int argc, char **argv) {
  Printer a, b, c, d, e, f;
  map<Printer,Printer> table;
  map<Printer,Printer>::iterator it;

  cout << "About to do insert (a,b)" << endl;
  table.insert(pair<Printer,Printer>(a, b));
  cout << "About to do table[c] = d" << endl;
  table[c] = d;
  cout << "About to do table[e] = f" << endl;
  table[e] = f;

  cout << "table[e]:" << table[e] << endl;
  it = table.find(c);
  cout << "PrintOut(*it), where it = table.find(c)" << endl;
  PrintOut(*it);

  cout << "iterating:" << endl;
  for_each(table.begin(), table.end(), &PrintOut);

  cout << "About to do table[f]..." << endl;
  cout << "table[f]:" << table[f] << endl;
  return 0;
}