Bonmin  1.7
BonColReader.hpp
Go to the documentation of this file.
00001 // (C) Copyright Carnegie Mellon University 2005
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Pierre Bonami, Carnegie Mellon University,
00007 //
00008 // Date : 26/05/2005
00009 
00010 #ifndef NameReader_HPP
00011 #define NameReader_HPP
00012 #include <string>
00013 #include <vector>
00014 #include <list>
00015 #include <fstream>
00016 #include <iostream>
00017 #include <CoinHelperFunctions.hpp>
00018 #include "OsiSolverInterface.hpp"
00019 //#include <tr1/unordered_map>
00020 #include <map>
00021 
00022 namespace Bonmin{
00025 class NamesReader
00026 {
00027 public:
00029   NamesReader(const char * fileName, const char * suffix);
00031   NamesReader(const std::string & fileName="", const std::string& suffix=".col");
00033   bool readFile();
00035   bool readFile(const std::string &file)
00036   {
00037     file_=file;
00038     return readFile();
00039   }
00040 
00042   void copyNames(OsiSolverInterface::OsiNameVec& Names);
00043 
00045   const std::string& name(int i){
00046    return names_[i];
00047   }
00048 
00050   int index(const char * str){
00051     return indices_[str];
00052   }
00053 private:
00055   std::string file_;
00056 
00058   std::string suffix_;
00059 
00061   struct ltstr
00062   {
00063     bool operator()(const char* s1, const char* s2) const
00064     {
00065       return strcmp(s1, s2) < 0;
00066     }
00067   };
00068 
00070   typedef std::map<const char *, int, ltstr> namesHash;
00072   namesHash indices_;
00074   std::vector<std::string> names_;
00075 };
00076 }
00077 #endif