Main Page | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals

rulesystem.cpp

Go to the documentation of this file.
00001 #include "rulesystem.h"
00002 #include <stdio.h>
00003 #include <dirent.h>
00004 
00005 #include "stree.h"
00006 #include "streeconstant.h"
00007 #include "streepin.h"
00008 #include "streevariable.h"
00009 #include "treeparser.h"
00010 #include "rtreenamedcontextrule.h"
00011 #include "namedcontext.h"
00012 
00019 void RuleSystem::execute(const string &phpFileName, StatementList *phpIn, StatementList *phpOut, StatementList *tplOut) {
00020   NamedContextRule mainRule(new Constant(MAINCONTEXTNAME), runRules[MAINCONTEXTNAME],
00021                             NULL, NULL, NULL, NULL, NULL);
00022   NameSpace fileNameSpace(&mainNameSpace);
00023   Node::Assignment assign;
00024   mainRule.runRules(fileNameSpace, phpIn, phpOut, tplOut, assign);
00025   mainNameSpace.importLocals(phpFileName, fileNameSpace);
00026 };
00027 
00028 
00029 RuleSystem::RuleSystem(int debug) {
00030 //  debug = 1;
00031   DIR *rulesDir = opendir(MYRULES);
00032   struct dirent *rulesFile; 
00033   
00034   readdir(rulesDir);
00035   readdir(rulesDir);
00036 
00037   while ((rulesFile = readdir(rulesDir))){
00038     if (strcmp(rulesFile->d_name + strlen(rulesFile->d_name) - 3,"txt")==0){
00039       cout << "Parsing rules - " << rulesFile->d_name << endl;
00040       NamedRuleList* namedRuleList = 
00041         ruleParser->parse(string(MYRULES)+string(rulesFile->d_name),this, debug);
00042       
00043       runRules[namedRuleList->name][namedRuleList->runTime].append(namedRuleList->rules);
00044       ruleRunTimes.insert(namedRuleList->runTime);
00045     };
00046   };
00047   courrentRunTime = ruleRunTimes.begin();
00048 };
00049 
00050 bool RuleSystem::stepTime(){
00051   courrentRunTime++;
00052   if (courrentRunTime!=ruleRunTimes.end()){
00053     mainNameSpace.setRuleRunTime(*courrentRunTime);
00054     return true;
00055   } else 
00056     return false;
00057 };
00058 
00059 RuleSystem::~RuleSystem(){
00060   /*    NamedRunRuleList::iterator rulesIt = runRules.begin();
00061     NamedRunRuleList::iterator rulesEnd = runRules.end();
00062     while (rulesIt!=rulesEnd){
00063       delete rulesIt->second;
00064       rulesIt++;
00065       };    */
00066 };
00067 
00068 /*
00069 void RuleSystem::insert(const string &contextName, int priority, Rule *rule){
00070     rules[contextName].insert(PriorityRulePair(priority,rule));
00071     };*/
00072 
00073 /*
00074 RunRuleList& RuleSystem::getRunRuleList(const string &contextName) { 
00075   NamedRunRuleList::iterator found = runRules.find(contextName);
00076   if (found != runRules.end())
00077     throw "ERROR: RuleSystem:getRunRuleList - context name " + contextName + " is not defined";
00078   else
00079     return found->second; 
00080     };*/ 

Generated on Fri Nov 21 17:54:03 2003 for PHPX by doxygen 1.3.3