📄 cond.h
字号:
// -*-c++-*-/*************************************************************************** cond.h Clang conditions ------------------- begin : 18-MAR-2002 copyright : (C) 2002 by The RoboCup Soccer Server Maintenance Group. email : sserver-admin@lists.sourceforge.net***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU LGPL as published by the Free Software * * Foundation; either version 2 of the License, or (at your option) any * * later version. * * * ***************************************************************************/#ifndef CLANG_COND_H#define CLANG_COND_H#include "clangutil.h"#include "region.h"#include "compop.h"#include "rcssexceptions.h"#include <iosfwd>#include <memory>namespace rcss {namespace clang {/******** Conditions ********************/class CondBool;class CondPlayerPos;class CondBallPos;class CondBallOwner;class CondPlayMode;class CondAnd;class CondOr;class CondNot;class CondNamed;class CondTime;class CondOppGoal;class CondOurGoal;class CondGoalDiff;class CondUNum;class Cond {public: class Context { public: Context() { } virtual ~Context() { } virtual bool lookup( const CondPlayerPos & cond ) const = 0; virtual bool lookup( const CondBallPos & cond ) const = 0; virtual bool lookup( const CondBallOwner & cond ) const = 0; virtual bool lookup( const CondPlayMode & cond ) const = 0; virtual bool lookup( const CondNamed & cond ) const = 0; virtual bool lookup( const CondTime & cond ) const = 0; virtual bool lookup( const CondOppGoal & cond ) const = 0; virtual bool lookup( const CondOurGoal & cond ) const = 0; virtual bool lookup( const CondGoalDiff & cond ) const = 0; virtual bool lookup( const CondUNum & cond ) const = 0; }; // end Context Cond() { } virtual ~Cond() { } virtual std::ostream & print( std::ostream & out ) const = 0; virtual std::ostream & printPretty( std::ostream & out, const std::string & line_header ) const = 0; virtual bool eval( const Context & context ) const = 0; virtual std::auto_ptr< Cond > deepCopy() const = 0;};inlinestd::ostream &operator<<( std::ostream & os, const Cond & c ){ return c.print( os );}class CondBool : public Cond {public: CondBool() : Cond(), M_state( false ) { } CondBool( bool state ) : Cond(), M_state( state ) { } ~CondBool() { } virtual std::ostream & print( std::ostream & out ) const; virtual std::ostream & printPretty( std::ostream & out, const std::string & line_header ) const; virtual bool eval( const Context & ) const { return M_state; } bool getState() const { return M_state; } virtual std::auto_ptr< Cond > deepCopy() const { return std::auto_ptr< Cond >( new CondBool( *this ) ); }private: bool M_state;};class CondPlayerPos : public Cond {private: CondPlayerPos() : Cond(), M_our_side( false ), M_min_match( 1 ), M_max_match( 11 ) {}public: CondPlayerPos( const bool & our_side, const UNumSet & players, const int & min_match, const int & max_match, std::auto_ptr< Region > reg ) : Cond(), M_our_side( our_side ), M_min_match( min_match ), M_max_match( max_match ), M_players( players ), M_reg( reg ) {} virtual ~CondPlayerPos() { } virtual std::auto_ptr< Cond > deepCopy() const; virtual std::ostream & print( std::ostream & out ) const; virtual std::ostream & printPretty( std::ostream & out, const std::string & line_header ) const; virtual bool eval( const Context & context ) const { return context.lookup( *this ); } /* class specific stuff */ bool isOurSide() const { return M_our_side; } bool isTheirSide() const { return !M_our_side; } int getMinMatch() const { return M_min_match; } int getMaxMatch() const { return M_max_match; } const Region * getRegion() const { return M_reg.get(); } UNumSet getPlayerSet() { return M_players; } void setMinMatch( int x ) { M_min_match = x; } void setMaxMatch( int x ) { M_max_match = x; } void set( std::auto_ptr< Region > reg ) { M_reg = reg; } std::auto_ptr< Region > detachRegion() { return M_reg; } void setOurSide( const bool & our_side ) { M_our_side = our_side; } void set( const UNumSet & players ) { M_players = players; } void addPlayer( const UNum & i ) { M_players.add( i ); } void clearPlayers() { M_players.clear(); }private: bool M_our_side; int M_min_match; int M_max_match; UNumSet M_players; std::auto_ptr< Region > M_reg;};class CondBallPos : public Cond {private: CondBallPos() : Cond() { }public: CondBallPos( std::auto_ptr< Region > reg ) : Cond(), M_reg( reg ) { } ~CondBallPos() { } virtual std::auto_ptr< Cond > deepCopy() const; virtual std::ostream & print( std::ostream & out ) const; virtual std::ostream & printPretty( std::ostream & out, const std::string & line_header ) const; virtual bool eval( const Context & context ) const { return context.lookup( *this ); } const Region * getRegion() const { return M_reg.get(); } std::auto_ptr< Region > detachRegion() { return M_reg; }private: std::auto_ptr< Region > M_reg;};class CondBallOwner : public Cond {private: CondBallOwner() : Cond(), M_our_side( false ) {}public: CondBallOwner( const bool & our_side, const UNumSet & players ) : Cond(), M_our_side( our_side ), M_players( players ) {} ~CondBallOwner() {} virtual std::auto_ptr< Cond > deepCopy() const { return std::auto_ptr< Cond >( new CondBallOwner( *this ) ); } virtual std::ostream & print( std::ostream & out ) const; virtual std::ostream & printPretty( std::ostream & out, const std::string & line_header ) const; virtual bool eval( const Context & context ) const { return context.lookup( *this ); } /* class specific stuff */ bool isOurSide() const { return M_our_side; } bool isTheirSide() const { return ! M_our_side; } UNumSet & getPlayerSet() { return M_players; } const UNumSet & getPlayerSet() const { return M_players; } void setOurSide( const bool & our_side ) { M_our_side = our_side; } void setPlayers( const UNumSet & players ) { M_players = players; } void addPlayer( const UNum & i ) { M_players.add( i ); } void clearPlayers() { M_players.clear(); }private: bool M_our_side; UNumSet M_players;};class CondPlayMode : public Cond {public: static const char * MODE_STRINGS[];private: CondPlayMode() : Cond(), M_pm( PM_None ) { }public: CondPlayMode( const PlayMode& pm ) : Cond(), M_pm( pm ) { } ~CondPlayMode() { } virtual std::auto_ptr< Cond > deepCopy() const { return std::auto_ptr< Cond >( new CondPlayMode( *this ) ); } virtual std::ostream & print( std::ostream & out ) const; virtual std::ostream & printPretty( std::ostream & out, const std::string & line_header ) const; virtual
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -