>xabsl   The Extensible Agent Behavior Specification Language

XabslEngine Class Library Reference

 

XabslStatement.cpp

Go to the documentation of this file.
00001 /** 
00002 * @file XabslStatement.cpp
00003 *
00004 * Implementation of class Statement and helper classes
00005 *
00006 * @author <a href="http://www.sim.informatik.tu-darmstadt.de/pers/card/risler.html">Max Risler</a>
00007 */
00008 
00009 #include "XabslStatement.h"
00010 #include "XabslState.h"
00011 #include "XabslOption.h"
00012 
00013 namespace xabsl 
00014 {
00015 
00016 Statement* Statement::createStatement(InputSource& input,    
00017                                                   ErrorHandler& errorHandler,
00018                                                   Symbols& symbols,    
00019                                                   Option& option,
00020                                                   State& state)
00021 {
00022   char c[100]; 
00023   
00024   input.readString(c,1);
00025   
00026   switch (*c)
00027   {
00028   case 't':
00029     return new TransitionToState(input, errorHandler, option);
00030   case 'i':
00031     return new IfElseBlock(input, errorHandler, symbols, option, state);
00032   default:
00033     errorHandler.error("XabslStatement::create(): unknown type \"%c\"",*c);
00034     return 0;
00035   }
00036 }
00037 
00038 Statement::~Statement()
00039 {
00040 }
00041 
00042 IfElseBlock::IfElseBlock(InputSource& input,    
00043                                      ErrorHandler& errorHandler,
00044                                      Symbols& symbols,    
00045                                      Option& option,
00046                                      State& state) :
00047 ifCondition(0), ifStatement(0), elseStatement(0)
00048 {
00049   
00050   // if case
00051   XABSL_DEBUG_INIT(errorHandler.message("creating if statement"));
00052   
00053   ifCondition = BooleanExpression::create(input, errorHandler, symbols, option, state);
00054   if (errorHandler.errorsOccurred)
00055   {
00056     errorHandler.error("XabslIfElseBlock::IfElseBlock(): could not create if condition");
00057     return;
00058   }
00059   
00060   ifStatement = Statement::createStatement(input, errorHandler, symbols, option, state);
00061   if (errorHandler.errorsOccurred)
00062   {
00063     errorHandler.error("XabslIfElseBlock::IfElseBlock(): could not create if statement");
00064     return;
00065   }
00066     
00067   // else case
00068   XABSL_DEBUG_INIT(errorHandler.message("creating else statement"));
00069   
00070   elseStatement = Statement::createStatement(input, errorHandler, symbols, option, state);
00071   if (errorHandler.errorsOccurred)
00072     errorHandler.error("XabslIfElseBlock::IfElseBlock(): could not create else statement");
00073   
00074 }
00075 
00076 IfElseBlock::~IfElseBlock()
00077 {
00078   if (ifCondition != 0) delete ifCondition;
00079   if (ifStatement != 0) delete ifStatement;
00080   
00081   int i;
00082   for (i=0; i<elseIfStatements.getSize(); i++)
00083   {
00084     if (elseIfConditions[i] != 0)
00085       delete elseIfConditions[i];
00086     if (elseIfStatements[i] != 0) 
00087       delete elseIfStatements[i];
00088   }
00089   
00090   if (elseStatement != 0) delete elseStatement;
00091 }
00092 
00093 State* IfElseBlock::getNextState()
00094 {
00095   if (ifCondition->getValue()) return ifStatement->getNextState();
00096   
00097   for (int i=0; i<elseIfConditions.getSize(); i++)
00098   {
00099     if (elseIfConditions[i]->getValue()) return elseIfStatements[i]->getNextState();
00100   }
00101   
00102   return elseStatement->getNextState();
00103 }
00104 
00105 TransitionToState::TransitionToState(InputSource& input,    
00106                                                  ErrorHandler& errorHandler,
00107                                                  Option& option)
00108 {
00109   char buf[100];
00110   input.readString(buf,99);
00111   
00112   nextState = option.states[buf];
00113   
00114   XABSL_DEBUG_INIT(errorHandler.message("creating a transition to state \"%s\"",nextState->n));
00115 }
00116 
00117 } // namespace
00118 

Up | Main Page | Generated at Wed Aug 19 17:32:29 2009.