Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

AIBase.h

Go to the documentation of this file.
00001 
00002 //      Copyright (C) 2004 Dylan Blair
00003 //
00004 //      email: dblair@alumni.cs.utexas.edu
00005 //
00006 //      This library is free software; you can redistribute it and/or
00007 //      modify it under the terms of the GNU Lesser General Public
00008 //      License as published by the Free Software Foundation; either
00009 //      version 2.1 of the License, or (at your option) any later version.
00010 //
00011 //      This library is distributed in the hope that it will be useful,
00012 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 //      Lesser General Public License for more details.
00015 //
00016 //      You should have received a copy of the GNU Lesser General Public
00017 //      License along with this library; if not, write to the Free Software
00018 //      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 #ifndef AIBASE_H
00022 #define AIBASE_H
00023 
00024 #include "AIConsts.h"
00025 
00037 class AIPremise {
00038 public:
00039         std::vector<int> params; 
00040         float entrytime;         
00041         bool negated;            
00042 
00047         AIPremise(std::vector<int> params_=std::vector<int>());
00048 
00053         virtual bool operator==(const AIPremise& rhs) const;
00054 
00059         virtual bool equals(const AIPremise& rhs, int numparamstocheck_) const;
00060 
00065         AIPremise& operator=(int param_) {
00066                 params.clear();
00067                 params.push_back(param_);
00068                 entrytime = -1.0f;
00069                 negated = false;
00070                 return *this;
00071         }
00072 
00077         AIPremise& operator+=(int param_) {
00078                 params.push_back(param_);
00079                 return *this;
00080         }
00081 
00087         virtual int serialize(std::ofstream& fout_) const;
00088 
00094         virtual int assemble(std::ifstream& fin_);
00095 
00096         virtual ~AIPremise() {} 
00097 };
00098 
00102 class AIAction : public AIPremise {
00103 public:
00104         AIAction(std::vector<int> params_=std::vector<int>());
00105 
00106         AIAction& operator=(int param_) {
00107                 AIPremise::operator=(param_);
00108                 return *this;
00109         }
00110 
00111         AIAction& operator+=(int param_) {
00112                 AIPremise::operator+=(param_);
00113                 return *this;
00114         }
00115 
00116         virtual ~AIAction() {} 
00117 };
00118 
00119 class AIWrapper;
00120 
00125 class AIException : public AIPremise {
00126 public:
00127         AIWrapper* n;               
00128         float badgoodscalevalue;    
00129         int stateIDduringexception; 
00130 
00131         AIException(std::vector<int> params_=std::vector<int>(), AIWrapper* n_=0, float badgoodscalevalue_=0.0f,
00132                 int stateIDduringexception_=-1);
00133 
00138         AIException& operator=(int param_) {
00139                 AIPremise::operator=(param_);
00140                 return *this;
00141         }
00142 
00143         AIException& operator+=(int param_) {
00144                 AIPremise::operator+=(param_);
00145                 return *this;
00146         }
00147 
00148         virtual ~AIException() {} 
00149 };
00150 
00154 namespace AIFileIO {
00161         template <class T>
00162         int serialize(std::ofstream& fout_, const std::vector<T>& vector_) {
00163                 static const unsigned int sizeoftype = sizeof(T);
00164                 unsigned int byteswritten = 0;
00165                 unsigned int vectorsize = vector_.size();
00166                 
00167                 fout_.write((char*)&vectorsize,sizeoftype);
00168                 byteswritten += sizeoftype;
00169 
00170                 for (int i = 0; i < vectorsize; i++)
00171                         fout_.write((char*)&(vector_[i]),sizeoftype);
00172                 byteswritten += vectorsize*sizeoftype;
00173 
00174                 return byteswritten;
00175         }
00176 
00183         template <class T>
00184         int assemble(std::ifstream& fin_, std::vector<T>& vector_) {
00185                 static const unsigned int sizeoftype = sizeof(T);
00186                 unsigned int bytesread = 0;
00187                 unsigned int vectorsize = 0;
00188                 vector_.clear();
00189 
00190                 fin_.read((char*)&vectorsize,sizeoftype);
00191                 bytesread += sizeoftype;
00192 
00193                 vector_.resize(vectorsize);
00194                 for (int i = 0; i < vectorsize; i++)
00195                         fin_.read((char*)&(vector_[i]),sizeoftype);
00196                 bytesread += vectorsize*sizeoftype;
00197 
00198                 return bytesread;
00199         }
00200 
00207         template <>
00208         int serialize(std::ofstream& fout_, const std::vector<AIPremise>& premVector_);
00209 
00216         template <>
00217         int assemble(std::ifstream& fin_, std::vector<AIPremise>& premVector_);
00218 
00225         template <>
00226         int serialize(std::ofstream& fout_, const std::vector<AIAction>& actVector_);
00227 
00234         template <>
00235         int assemble(std::ifstream& fin_, std::vector<AIAction>& actVector_);
00236 }
00237 
00238 #endif //AIBASE_H

Generated on Sun Apr 11 05:05:55 2004 for FSM_API by doxygen 1.3.6