00001
00002
00003
00004
00005
00006
00007
00008 #ifndef OPTFRAMEMODULE_HPP_
00009 #define OPTFRAMEMODULE_HPP_
00010
00011 #include <iostream>
00012 #include <ostream>
00013
00014 #include <vector>
00015 #include <map>
00016
00017 #include "Util/Scanner++/Scanner.h"
00018
00019 #include "HeuristicFactory.hpp"
00020
00021 #include <algorithm>
00022
00023 template<class R, class M>
00024 class OptFrameModule
00025 {
00026 protected:
00027 void run_module(string mod, vector<OptFrameModule<R,M>*> v, HeuristicFactory<R,M>* f, map<string,string>* dictionary, string input)
00028 {
00029 for(int i=0;i<v.size();i++)
00030 if(mod==v[i]->id())
00031 {
00032 v[i]->run(v,f,dictionary,input);
00033 return;
00034 }
00035 cout << "Module '"<<mod<<"' not found." << endl;
00036 }
00037
00038 public:
00039 virtual string id() = 0;
00040 virtual string usage() = 0;
00041
00042 virtual void run(vector<OptFrameModule<R,M>*>, HeuristicFactory<R,M>*, map<string,string>* dictionary, string) = 0;
00043
00044 virtual string preprocess(map<string,string>* dictionary, string input)
00045 {
00046 return defaultPreprocess(dictionary,input);
00047 }
00048
00049 static string defaultPreprocess(map<string,string>* dictionary, string input)
00050 {
00051 Scanner scanner(input);
00052
00053
00054
00055 string input2 = "";
00056
00057 while(scanner.hasNextChar())
00058 {
00059 char c = scanner.nextChar();
00060 if(c != '%')
00061 input2 += c;
00062 else
00063 break;
00064 }
00065
00066 scanner = Scanner(input2);
00067
00068
00069
00070 string input3 = "";
00071
00072 while(scanner.hasNext())
00073 {
00074 string new_word = scanner.next();
00075
00076 if(dictionary->count(new_word) == 0)
00077 {
00078 if(input3=="")
00079 input3+=new_word;
00080 else
00081 input3 = input3+" "+new_word;
00082 }
00083 else
00084 {
00085 string found = dictionary->find(new_word)->second;
00086 scanner = Scanner(input3+" "+found+" "+scanner.rest());
00087 input3 = "";
00088 }
00089 }
00090
00091 return input3;
00092 }
00093 };
00094
00095 #endif