/* Copyright (c) 1997-2004
   Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
   http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de

   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 2, or (at your option) any
   later version: http://www.gnu.org/licenses/gpl.txt.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*/

#ident "$Project: polymake $$Id: read_str_args.tcc,v 1.2 2004/06/22 16:22:56 gawrilow Exp $"

#include <read_str_args.h>
#include <ext/hash_map>

namespace polymake { namespace topaz {

  template <typename Labels, typename Args>
  Set<int> transform_label_args (const Labels& L, const Args& labeled_args) {
    typedef std_ext::hash_map<std::string,int> vertex_map;
    vertex_map map(L.size());
    int count = 0;
    for (typename Entire< Labels >::const_iterator l=entire(L);
	 !l.at_end(); ++l, ++count)
      map[*l] = count;
    
    Set<int> F;
    for (typename Entire< Args >::const_iterator ll=entire(labeled_args);
	 !ll.at_end(); ++ll) {
      vertex_map::iterator v=map.find(*ll);
      if (v == map.end())
	throw std::runtime_error("Unknown vertex label '" + *ll + "'.");
      F += v->second;
    }
    
    return F;
  }
  
} };


// Local Variables:
// mode:C++
// c-basic-offset:3
// End:
