- Main Page
- Classes
- Files

- File List

# OptFrame/Modules/ReadModule.hpp

    00001 #ifndef READMODULE_HPP_
    00002 #define READMODULE_HPP_
    00003
    00004 #include "../OptFrameModule.hpp"
    00005
    00006 template<class R, class M>
    00007 class ReadModule : public OptFrameModule<R,M>
    00008 {
    00009 public:
    00010         string id()
    00011         {
    00012                 return "read";
    00013         }
    00014         string usage()
    00015         {
    00016                 return "read filename";
    00017         }
    00018
    00019         void run(vector<OptFrameModule<R,M>*> all_modules, HeuristicFactory<R,M>* factory, map<string,string>* dictionary, string input)
    00020         {
    00021                 Scanner trim(input);
    00022                 if(!trim.hasNext()) // no file
    00023                 {
    00024                         cout << "Usage: " << usage() << endl;
    00025                         return;
    00026                 }
    00027
    00028                 // Open file
    00029                 Scanner* scanner;
    00030
    00031                 try
    00032                 {
    00033                         scanner = new Scanner(new File(input));
    00034                 }
    00035                 catch (FileNotFound e)
    00036                 {
    00037                         cout << "File '"<< e.getFile() << "' not found!" << endl;
    00038                         cout << "Usage: " << usage() << endl;
    00039                         return;
    00040                 }
    00041
    00042                 while(scanner->hasNext())
    00043                 {
    00044                         string line = scanner->nextLine();
    00045
    00046                         line = OptFrameModule<R,M>::defaultPreprocess(dictionary,line);
    00047
    00048                         Scanner s2(line);
    00049
    00050                         if(!s2.hasNext()) // no command found in the line
    00051                                 continue;
    00052
    00053                         string command = s2.next();
    00054
    00055                         bool notfound = true;
    00056
    00057                         for(int i=0;i<all_modules.size();i++)
    00058                                 if(command == all_modules[i]->id())
    00059                                 {
    00060                                         all_modules[i]->run(all_modules, factory, dictionary, s2.rest());
    00061                                         notfound = false;
    00062                                         break;
    00063                                 }
    00064
    00065                         if(notfound)
    00066                                 cout << "Warning: command '"<<command<<"' not found!"<<endl;
    00067                 }
    00068
    00069                 delete scanner;
    00070         }
    00071
    00072 };
    00073
    00074 #endif /* READMODULE_HPP_ */

All Classes Functions