/* 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
   GNU General Public License for more details.
*/

#ident "$Project: polymake $$Id: read_str_args.cc,v 1.3 2004/06/22 16:22:54 gawrilow Exp $"

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

namespace polymake {
namespace topaz {

std::list<std::string> read_str_args (const int argc, const char* argv[], const int start_index) {
   std::list<std::string> L;
   for (int i=start_index; i<argc; ++i)
      L.push_back(argv[i]); 
   
   return L;  
}

Set<int> read_label_args (const Array<std::string>& L, const int argc, const char* argv[], const int start_index) {
   typedef std_ext::hash_map<std::string,int> vertex_map;
   vertex_map map(L.size());
   int count = 0;
   for (Entire< Array<std::string> >::const_iterator l=entire(L);
	!l.at_end(); ++l, ++count)
      map[*l] = count;
	
   Set<int> F;
   for (int i=start_index; i<argc; ++i) {
      vertex_map::iterator v=map.find(argv[i]);
      if (v == map.end())
	 throw std::runtime_error(std::string(argv[0]) + ": unknown vertex label '" + argv[i] + "'");
      F += v->second;
   }
   
   return F;
}
   
} }


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