- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Executives/DeductiveController/Command/CommandDispatcherEntry.h

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00010
    00011 #if !defined(AFX_COMMANDDISPATCHERENTRY_H__CF596C4C_7484_4EBC_93D7_5D38C4D4C374__INCLUDED_)
    00012 #define AFX_COMMANDDISPATCHERENTRY_H__CF596C4C_7484_4EBC_93D7_5D38C4D4C374__INCLUDED_
    00013
    00014 #if _MSC_VER > 1000
    00015 #pragma once
    00016 #endif // _MSC_VER > 1000
    00017
    00018 #ifdef _MSC_VER
    00019 #pragma warning(disable:4786)
    00020 #endif
    00021
    00022 #include <vector>
    00023 #include <string>
    00024
    00025 #ifndef EMBEDDED
    00026 #include <iostream>
    00027 #endif
    00028
    00029 #include <Mers/Utils/Containers/DynamicArrayTemplate.h>
    00030
    00031 #include <Mers/Utils/Exceptions/IllegalArgumentException.h>
    00032 #include <Mers/Utils/Exceptions/RuntimeException.h>
    00033
    00034 namespace Mers {
    00035         namespace Executives {
    00036                 namespace DeductiveController {
    00037                         namespace Command {
    00038
    00056                                 class CommandDispatcherEntry :
    00057                                         public Mers::Utils::Lang::BaseModelObject
    00058                                 {
    00059                                 public:
    00075                                         CommandDispatcherEntry( const char * fromFunctionName,
    00076                                                 unsigned int numFromParams,
    00077                                                 const char * toFunctionName );
    00078
    00094                                         CommandDispatcherEntry(
    00095                                                 const Mers::Utils::Lang::String &fromFunctionName,
    00096                                                 unsigned int numFromParams,
    00097                                                 const Mers::Utils::Lang::String &toFunctionName );
    00098
    00102                                         virtual ~CommandDispatcherEntry();
    00103
    00113                                         void addToParameter( const char * str );
    00114
    00124                                         void addToParameter( const Mers::Utils::Lang::String &str );
    00125
    00138                                         void addToParameter( unsigned int index )
    00139                                                 throw(Mers::Utils::Exceptions::IllegalArgumentException *);
    00140
    00153                                         void setFromParameter( unsigned int index, const char * str );
    00154
    00166                                         void setFromParameter( unsigned int index,
    00167                                                 const Mers::Utils::Lang::String &str );
    00168
    00177                                         void clearFromParameter( unsigned int index );
    00178
    00183                                         unsigned int getNumFromParameters() const {
    00184                                                 return m_numFromParams;
    00185                                         }
    00186
    00200                                         bool matches( const Mers::Utils::Lang::String &funcName,
    00201                                                 const std::vector< const Mers::Utils::Lang::String * > &params )
    00202                                                 const;
    00203
    00220                                         void convertParameters(
    00221                                                 const std::vector< const Mers::Utils::Lang::String * > &fromParams,
    00222                                                 std::vector< const Mers::Utils::Lang::String * > &out_toParams ) const
    00223                                                 throw(Mers::Utils::Exceptions::IllegalArgumentException *);
    00224
    00228                                         const Mers::Utils::Lang::String &getFromFunctionName() const {
    00229                                                 return m_fromFuncName;
    00230                                         }
    00231
    00235                                         const Mers::Utils::Lang::String &getToFunctionName() const {
    00236                                                 return m_toFuncName;
    00237                                         }
    00238
    00239 #ifndef EMBEDDED
    00240
    00245                                         virtual void print(std::ostream &out) const;
    00246 #endif
    00247
    00257                                         virtual CommandDispatcherEntry * duplicate() const;
    00258
    00266                                         bool operator ==(CommandDispatcherEntry const &other) const;
    00267
    00268                                 protected:
    00273                                         class Parameter {
    00274                                         public:
    00279                                                 virtual bool isLiteral() const = 0;
    00280
    00284                                                 virtual const Mers::Utils::Lang::String & getLiteral() const = 0;
    00285
    00290                                                 virtual unsigned int getReference() const = 0;
    00291
    00292 #ifndef EMBEDDED
    00293
    00299                                                 virtual void print(std::ostream &out) const;
    00300
    00319                                                 virtual void print( std::ostream &out, const char * refVarName,
    00320                                                         const char * litPrefix, const char * litPostfix ) const;
    00321
    00326                                                 class PrintAll
    00327                                                 {
    00328                                                 public:
    00334                                                         PrintAll( const Parameter &param, const char * refVarName,
    00335                                                                 const char * litPrefix, const char * litPostfix )
    00336                                                                 : m_param( &param ), m_refVarName( refVarName ),
    00337                                                                         m_litPrefix( litPrefix ), m_litPostfix( litPostfix )
    00338                                                         {
    00339                                                         }
    00340
    00344                                                         void operator ()( const Parameter &param ) {
    00345                                                                 m_param = &param;
    00346                                                         }
    00347
    00348                                                         friend std::ostream &operator <<( std::ostream &out,
    00349                                                                 const PrintAll & obj )
    00350                                                         {
    00351                                                                 // Print our object and return the stream.
    00352                                                                 obj.m_param->print( out, obj.m_refVarName, obj.m_litPrefix,
    00353                                                                         obj.m_litPostfix );
    00354                                                                 return out;
    00355                                                         }
    00356
    00357                                                 protected:
    00360                                                         const Parameter * m_param;
    00361                                                         const char * m_refVarName;
    00362                                                         const char * m_litPrefix;
    00363                                                         const char * m_litPostfix;
    00364                                                 };
    00365
    00366 #endif
    00367
    00377                                                 virtual Parameter * duplicate() const {
    00378                                                         return NULL;
    00379                                                 }
    00380
    00388                                                 bool operator ==(Parameter const &other) const;
    00389                                         };
    00390
    00394                                         class ParameterLiteral : public Parameter
    00395                                         {
    00396                                         public:
    00402                                                 ParameterLiteral( const Mers::Utils::Lang::String &str )
    00403                                                         : m_stringLiteral( str )
    00404                                                 {
    00405                                                 }
    00406
    00412                                                 ParameterLiteral( const char * str )
    00413                                                         : m_stringLiteral( str )
    00414                                                 {
    00415                                                 }
    00416
    00420                                                 virtual ~ParameterLiteral() {
    00421                                                 }
    00422
    00427                                                 virtual bool isLiteral() const {
    00428                                                         return true;
    00429                                                 }
    00430
    00434                                                 virtual const Mers::Utils::Lang::String & getLiteral() const {
    00435                                                         return m_stringLiteral;
    00436                                                 }
    00437
    00442                                                 virtual unsigned int getReference() const
    00443                                                         throw(Mers::Utils::Exceptions::RuntimeException *);
    00444
    00445                                         protected:
    00447                                                 Mers::Utils::Lang::String m_stringLiteral;
    00448                                         };
    00449
    00453                                         class ParameterReference : public Parameter
    00454                                         {
    00455                                         public:
    00461                                                 ParameterReference( unsigned int index )
    00462                                                         : m_refIndex( index )
    00463                                                 {
    00464                                                 }
    00465
    00470                                                 virtual bool isLiteral() const {
    00471                                                         return false;
    00472                                                 }
    00473
    00477                                                 virtual const Mers::Utils::Lang::String & getLiteral() const
    00478                                                         throw(Mers::Utils::Exceptions::RuntimeException *);
    00479
    00484                                                 virtual unsigned int getReference() const {
    00485                                                         return m_refIndex;
    00486                                                 }
    00487
    00488                                         protected:
    00490                                                 unsigned int m_refIndex;
    00491                                         };
    00492
    00493                                 protected:
    00494                                         // The name of the calling function.
    00495                                         Mers::Utils::Lang::String m_fromFuncName;
    00496
    00497                                         // The number of parameters in the calling function.
    00498                                         unsigned int m_numFromParams;
    00499
    00500                                         // The name of the function that should be called.
    00501                                         Mers::Utils::Lang::String m_toFuncName;
    00502
    00503                                         // List of parameters for the second function.
    00504                                         Mers::Utils::Containers::DynamicArrayTemplate< Parameter >
    00505                                                 m_toFuncParams;
    00506
    00507                                         // List of parameters for the first function that must be matched.
    00508                                         Mers::Utils::Containers::DynamicArrayTemplate< ParameterLiteral >
    00509                                                 m_fromFuncParams;
    00510                                 };
    00511                         }
    00512                 }
    00513         }
    00514 }
    00515
    00516 #endif // !defined(AFX_COMMANDDISPATCHERENTRY_H__CF596C4C_7484_4EBC_93D7_5D38C4D4C374__INCLUDED_)