Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

ruleatom.h

00001 // $Id: ruleatom_8h-source.html,v 1.2 2002/06/20 17:09:51 mkrohn5 Exp $
00002 
00003 // RuleAtom Header File
00004 // Written by: Marco Krohn <marco.krohn@gmx.de>
00005 
00006 // Copyright (C) 2001 - 2002, Marco Krohn <marco.krohn@gmx.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 1, or (at your option)
00011 // any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 
00018 #ifndef __RULEATOM_INCLUDED
00019 #define __RULEATOM_INCLUDED
00020 
00021 #include <list>
00022 #include <map>
00023 #include <string>
00024 
00025 #include "common/datapackage.h"
00026 #include "common/defs.h"
00027 #include "common/leakchecker.h"
00028 #include "common/prototype.h"
00029 #include "rulesystem.h"
00030 
00031 class TLinkable;
00032 class TRuleAtom;
00033 
00034 using namespace std;
00035 
00036 
00037 
00038 
00039 
00040 //----------------------------------------  tRuleAtomKey  ----------------------------------------
00041 
00047 typedef struct tRuleAtomKey
00048 {
00049   tRuleAtomKey( const string& name, const string& set ) : rule_name(name), rule_set(set) { };
00050   bool operator<( const tRuleAtomKey& key2 ) const
00051   {
00052     if ( rule_name == key2.rule_name )  return rule_set < key2.rule_set;
00053     return rule_name < key2.rule_name;
00054   }
00055   string rule_name;
00056   string rule_set;
00057 };
00058 
00059 
00060 
00061 
00062 
00063 //----------------------------------------  Some evil defines  ----------------------------------------
00064 // this makes writing actions a lot easier
00065 
00066 #define RuleAtomClass(a,b)          TRuleAtom##a##b
00067 #define RuleAtomProto(a,b)          RuleAtom##a##b##Proto
00068 #define RuleAtomName(a,b)           "TRA"#a#b
00069 
00070 #define DefineNewRuleAtom(a,b,c,d)  RuleAtomClass(a,b)* RuleAtomProto(a,b) = new RuleAtomClass(a,b)(c); \
00071                                     RuleAtomClass(a,b)::RuleAtomClass(a,b)(const string& name) \
00072                                       : TRuleAtom()                                            \
00073                                     {                                                          \
00074                                       setTypeName( name );                                     \
00075                                       initialize();                                            \
00076                                       TPrototypeManager<tRuleAtomKey,TRuleAtom>::instance().registerPrototype(tRuleAtomKey(c,d),this); \
00077                                     }                                                          \
00078                                     RuleAtomClass(a,b)::RuleAtomClass(a,b)() : TRuleAtom()     \
00079                                     { initialize(); }                                          \
00080                                     RuleAtomClass(a,b)::~RuleAtomClass(a,b)()                  \
00081                                     { uninitialize(); }
00082 
00083 #define DeclareNewRuleAtom(a,b)  class RuleAtomClass(a,b) : public TRuleAtom {                 \
00084                                    public:                                                     \
00085                                      RuleAtomClass(a,b)(const string& name);                   \
00086                                      virtual ~RuleAtomClass(a,b)();                            \
00087                                      virtual bool execute();                                   \
00088                                      virtual bool checkDependencies( list<TRuleSystem::tError>* errors ) const; \
00089                                      virtual bool validateInfo();                              \
00090                                    private:                                                    \
00091                                      RuleAtomClass(a,b)();                                     \
00092                                      void initialize();                                        \
00093                                      void uninitialize();                                      \
00094                                      TRuleAtom* clone() const { return new RuleAtomClass(a,b)(); }
00095 
00096 #define EndDeclareRuleAtom       }
00097 
00098 #define RAUnsupported(type)      Fatal( #type, "unsupported method", "an unsupported method was called for a rule atom "#type, -1)
00099 
00100 #define RAMember(a,b)            RuleAtomClass(a,b)
00101 
00102 
00103 
00104 
00105 
00106 //----------------------------------------  class TRuleAtom  ----------------------------------------
00107 
00315 class TRuleAtom : public TCanBePrototype
00316 {
00317   public:
00321     virtual ~TRuleAtom();
00322 
00331     void addInfo( const string& identifier, TLinkable* obj );
00332     void addInfo( const string& identifier, double data );
00333     void addInfo( const string& identifier, int2 data );
00337     virtual bool checkDependencies( list<TRuleSystem::tError>* errors ) const = 0;
00344     virtual bool execute() = 0;
00345 
00346     double getInfoDouble( const string& identifier ) const;
00353     int2 getInfoInt2( const string& identifier ) const;
00360     TLinkable* getInfoObject( const string& identifier ) const;
00364     const TDataPackageList* getResults() const;
00368     virtual bool validateInfo() = 0;
00369 
00370   protected:
00374     TDataPackageList* fInfo;
00381     map<string,TLinkable*> fInfoObj;
00386     TDataPackageList* fResults;
00387 
00391     TRuleAtom();
00392 
00393   private:
00394     #ifdef SECURE_MODE
00395 
00399       static TLeakChecker lc;
00400     #endif // SECURE_MODE
00401 };
00402 
00403 
00404 
00405 
00406 
00407 #endif        // __RULEATOM_INCLUDED
00408 
00409 
00410 
00411 
00412 

Generated on Thu Jun 20 18:13:16 2002 for Stellar Legacy by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001