/home/coin/SVN-release/OS-2.1.0/Bonmin/src/Interfaces/BonColReader.cpp

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 #include "BonColReader.hpp"
00010 #include <fstream>
00011 #include <iostream>
00012 
00013 namespace Bonmin{
00014 
00015 NamesReader::NamesReader(const char * file, const char * suffix)
00016     :
00017     file_(), suffix_(suffix), indices_(), names_()
00018 {
00019   assert(file!= NULL);
00020   file_=file;
00021   if (suffix!=NULL)
00022     suffix_ = suffix;
00023 }
00024 NamesReader::NamesReader(const std::string & file, const std::string & suffix)
00025     :
00026     file_(file), suffix_(suffix), indices_(), names_()
00027 {}
00028 
00029 bool NamesReader::readFile()
00030 {
00031   std::string colFileName = file_;
00032   int size = colFileName.size();
00033   bool hasNlExtension =  (colFileName.size()>4) && (colFileName[size - 1] =='l') && (colFileName[size - 2] =='n') && (colFileName[size - 3] =='.');
00034   if(hasNlExtension)
00035     colFileName.erase(size-3,3);
00036   colFileName+=suffix_;
00037   std::ifstream inFile(colFileName.c_str());
00038   if(!inFile.is_open()) {
00039     return false;
00040   }
00041   std::string name;
00042   int nVar = 0;
00043   do {
00044     name="";
00045     inFile>>name;
00046     if(name.size()==0)
00047       continue;
00048     names_.push_back(name);
00049     indices_[names_[nVar].c_str()] = nVar;
00050     nVar++;
00051   }
00052   while(!inFile.eof());
00053 
00054   //  names_ = new std::string[nVar];
00055   for(int i = 0 ; i < nVar ; i++) {
00056     assert(i==indices_ [ names_ [i].c_str()]);
00057   }
00058   return true;
00059 }
00060 
00061 void
00062 NamesReader::copyNames(OsiSolverInterface::OsiNameVec& names)
00063 {
00064   names_ = names;
00065 }
00066 }

Generated on Tue Mar 30 03:04:35 2010 by  doxygen 1.4.7