- Main Page
- Classes
- Files

- File List

# OptFrame/Modules/DefineModule.hpp

    00001 #ifndef DEFINEMODULE_HPP_
    00002 #define DEFINEMODULE_HPP_
    00003
    00004 #include "../OptFrameModule.hpp"
    00005
    00006 template<class R, class M>
    00007 class DefineModule : public OptFrameModule<R,M>
    00008 {
    00009 public:
    00010         string id()
    00011         {
    00012                 return "define";
    00013         }
    00014         string usage()
    00015         {
    00016                 return "define new_name string_to_be_substituted_from_the_new_name";
    00017         }
    00018
    00019         void run(vector<OptFrameModule<R,M>*>, HeuristicFactory<R,M>*, map<string,string>* dictionary, string rest)
    00020         {
    00021                 Scanner scanner(rest);
    00022
    00023                 string new_name = scanner.next();
    00024
    00025                 if(new_name != "")
    00026                 {
    00027                         string second_word = scanner.rest();
    00028
    00029                         Scanner s2(second_word);
    00030
    00031                         while(s2.hasNext())
    00032                                 if(new_name==s2.next())
    00033                                 {
    00034                                         cout << "Recursive definitions are not allowed!" << endl;
    00035                                         return;
    00036                                 }
    00037
    00038                         (*dictionary)[new_name] = second_word;
    00039                         cout << "Word '"<<new_name<<"' now means:"<<(*dictionary)[new_name]<<endl;
    00040                 }
    00041                 else
    00042                         cout << "Usage: "<<usage()<<endl;
    00043         }
    00044
    00045         virtual string preprocess(map<string,string>*, string input)
    00046         {
    00047                 Scanner scanner(input);
    00048
    00049                 // First, remove the comments '%'
    00050
    00051                 string input2 = "";
    00052
    00053                 while(scanner.hasNextChar())
    00054                 {
    00055                         char c = scanner.nextChar();
    00056                         if(c != '%')
    00057                                 input2 += c;
    00058                         else
    00059                                 break;
    00060                 }
    00061
    00062                 return input2;
    00063         }
    00064
    00065 };
    00066
    00067 #endif /* DEFINEMODULE_HPP_ */

All Classes Functions