WinCond.h

Go to the documentation of this file.
00001 /* -*- Mode: c++ -*- */
00002 
00003 #ifndef _WINCOND_
00004 #define _WINCOND_
00005 
00006 #include <list>
00007 #include <map>
00008 #include <string>
00009 #include "VehicleSprite.h"
00010 
00011 struct _xmlNode;
00012 
00013 class CondData {
00014 public:
00015   struct Team {
00016     int teamNo;
00017     std::list<VehicleSprite*> vehicles;
00018   };
00019 
00020   static void Clear();
00021   static void Init(int nteams);
00022   static void AddVehicleForTeam(VehicleSprite* v, int team);
00023   static Team& GetTeam(int teamno) { return teams[teamno-1]; }
00024 
00025 private:
00026   static std::vector<Team> teams;
00027 };
00028 
00033 class Cond
00034 {
00035 public:
00036   class Bool {
00037   public:
00038     virtual ~Bool() {}
00039     
00040     virtual void evaluate() = 0;
00041     inline bool getValue() const { return value; }
00042 
00043   protected:
00044     bool value;
00045   };
00046 
00047   typedef std::string BoolOper;
00048   
00049   class BoolExpr {
00050   public:
00051     BoolExpr(Bool* boolVar) : var(boolVar), oper(0) {}
00052     BoolExpr(BoolOper *boolOper) : var(0), oper(boolOper) {}
00053     ~BoolExpr() { delete oper; oper = 0; delete var; var = 0; }
00054 
00055     const BoolOper* getOper() { return oper; }
00056     const Bool* getVariable() { return var; }
00057 
00058   private:
00059     Bool *var;
00060     BoolOper *oper;
00061   };
00062 
00063 public:
00064   virtual ~Cond();
00065 
00066   bool loadCond(const std::string &condPath, const std::string &exprPath);
00067   bool evaluate();
00068 
00069 protected:
00070   bool loadExpression(const std::string &path, 
00071                 std::map<std::string, Bool*> &lookup);
00072   bool parseCondition(_xmlNode* node, std::map<std::string, Bool*> &lookup);
00073   
00074 protected:
00075   std::list<Bool*> boolVariables;
00076   std::list<BoolExpr*> boolExpr;
00077 };
00078 
00079 #endif

Generated on Sun Mar 11 15:33:24 2007 for MetalWarriors by  doxygen 1.4.7