Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10472


Ignore:
Timestamp:
May 25, 2015, 1:51:40 PM (10 years ago)
Author:
landauf
Message:

use the same interface for static an member functions

Location:
code/branches/core7/src/libraries/network
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core7/src/libraries/network/FunctionCall.cc

    r10471 r10472  
    4747
    4848bool FunctionCall::execute(){
    49   if( this->bIsStatic_ )
     49  NetworkFunctionBase* fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getFunction( this->functionID_ ));
     50  assert( this->nrOfArguments_==this->arguments_.size() );
     51  switch(this->nrOfArguments_)
    5052  {
    51     NetworkFunctionStatic *fct = static_cast<NetworkFunctionStatic*>(NetworkFunctionManager::getFunction( this->functionID_ ));
    52     assert( this->nrOfArguments_==this->arguments_.size() );
    53     switch(this->nrOfArguments_)
    54     {
    55       case 0:
    56         fct->call();
    57         break;
    58       case 1:
    59         fct->call(this->arguments_[0]);
    60         break;
    61       case 2:
    62         fct->call(this->arguments_[0], this->arguments_[1]);
    63         break;
    64       case 3:
    65         fct->call(this->arguments_[0], this->arguments_[1], this->arguments_[2]);
    66         break;
    67       case 4:
    68         fct->call(this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]);
    69         break;
    70       case 5:
    71         fct->call(this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]);
    72         break;
    73       default:
    74         assert(0);
    75     }
     53    case 0:
     54      return !fct->call(this->objectID_);
     55    case 1:
     56      return !fct->call(this->objectID_, this->arguments_[0]);
     57    case 2:
     58      return !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1]);
     59    case 3:
     60      return !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2]);
     61    case 4:
     62      return !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]);
     63    case 5:
     64      return !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]);
     65    default:
     66      assert(0);
     67      return true; // return true to avoid that this functions gets called over and over again
    7668  }
    77   else // not a static function, so also handle with the objectID
    78   {
    79     NetworkMemberFunctionBase *fct = static_cast<NetworkMemberFunctionBase*>(NetworkFunctionManager::getFunction( this->functionID_ ));
    80     switch(this->nrOfArguments_)
    81     {
    82       case 0:
    83         if( !fct->call(this->objectID_) )
    84           return false;
    85         break;
    86       case 1:
    87         if( !fct->call(this->objectID_, this->arguments_[0]) )
    88           return false;
    89         break;
    90       case 2:
    91         if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1]) )
    92           return false;
    93         break;
    94       case 3:
    95         if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2]) )
    96           return false;
    97         break;
    98       case 4:
    99         if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3]) )
    100           return false;
    101         break;
    102       case 5:
    103         if( !fct->call(this->objectID_, this->arguments_[0], this->arguments_[1], this->arguments_[2], this->arguments_[3], this->arguments_[4]) )
    104           return false;
    105         break;
    106       default:
    107         assert(0);
    108     }
    109   }
    110   return true;
    11169}
    11270
     
    148106  this->nrOfArguments_ = nrOfArguments;
    149107  this->size_ = callsize;
    150   this->bIsStatic_ = true;
    151108  this->functionID_ = networkID;
    152109}
     
    188145  }
    189146  this->nrOfArguments_ = nrOfArguments;
    190   this->bIsStatic_ = false;
    191147  this->functionID_ = networkID;
    192148  this->size_ = callsize;
     
    197153{
    198154  this->functionID_ = *(uint32_t*)mem;
    199   this->bIsStatic_ = *(uint8_t*)(mem+sizeof(uint32_t));
    200   this->nrOfArguments_ = *(uint32_t*)(mem+sizeof(uint32_t)+sizeof(uint8_t));
    201   if( this->bIsStatic_ )
    202   {
    203     mem += 2*sizeof(uint32_t)+sizeof(uint8_t);
    204   }
    205   else
    206   {
    207     this->objectID_ = *(uint32_t*)(mem+2*sizeof(uint32_t)+sizeof(uint8_t));
    208     mem += 3*sizeof(uint32_t)+sizeof(uint8_t);
    209   }
     155  this->nrOfArguments_ = *(uint32_t*)(mem+sizeof(uint32_t));
     156  this->objectID_ = *(uint32_t*)(mem+2*sizeof(uint32_t));
     157  mem += 3*sizeof(uint32_t);
    210158  for( unsigned int i=0; i<this->nrOfArguments_; ++i )
    211159  {
     
    219167  // now serialise the mt values and copy the function id and isStatic
    220168  *(uint32_t*)mem = this->functionID_;
    221   *(uint8_t*)(mem+sizeof(uint32_t)) = this->bIsStatic_;
    222   *(uint32_t*)(mem+sizeof(uint32_t)+sizeof(uint8_t)) = this->nrOfArguments_;
    223   if( this->bIsStatic_ )
    224   {
    225     mem += 2*sizeof(uint32_t)+sizeof(uint8_t);
    226   }
    227   else
    228   {
    229     *(uint32_t*)(mem+2*sizeof(uint32_t)+sizeof(uint8_t)) = this->objectID_;
    230     mem += 3*sizeof(uint32_t)+sizeof(uint8_t);
    231   }
     169  *(uint32_t*)(mem+sizeof(uint32_t)) = this->nrOfArguments_;
     170  *(uint32_t*)(mem+2*sizeof(uint32_t)) = this->objectID_;
     171  mem += 3*sizeof(uint32_t);
    232172  for( std::vector<MultiType>::iterator it = this->arguments_.begin(); it!=this->arguments_.end(); ++it )
    233173  {
  • code/branches/core7/src/libraries/network/FunctionCall.h

    r7495 r10472  
    5959private:
    6060  uint32_t                  nrOfArguments_;
    61   bool                      bIsStatic_;
    6261  uint32_t                  functionID_;
    6362  uint32_t                  objectID_;
  • code/branches/core7/src/libraries/network/NetworkFunction.h

    r10471 r10472  
    7676    inline const std::string& getName() const           { return name_; }
    7777
    78   private:
    79     uint32_t networkID_;
    80     std::string name_;
    81 
    82 };
    83 
    84 
    85 class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase {
    86   public:
    87     NetworkFunctionStatic(const FunctorStaticPtr& functor, const std::string& name, const NetworkFunctionPointer& p)
    88         : NetworkFunctionBase(name, p)
    89         , functor_(functor)
    90     { }
    91 
    92     inline void call(){ (*this->functor_)(); }
    93     inline void call(const MultiType& mt1){ (*this->functor_)(mt1); }
    94     inline void call(const MultiType& mt1, const MultiType& mt2){ (*this->functor_)(mt1, mt2); }
    95     inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3){ (*this->functor_)(mt1, mt2, mt3); }
    96     inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4){ (*this->functor_)(mt1, mt2, mt3, mt4); }
    97     inline void call(const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); }
    98 
    99   private:
    100     FunctorStaticPtr functor_;
    101 
    102 };
    103 
    104 
    105 class _NetworkExport NetworkMemberFunctionBase: public NetworkFunctionBase {
    106   public:
    107     NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p)
    108         : NetworkFunctionBase(name, p)
    109     { }
    110 
    111     //
    11278    virtual bool call(uint32_t objectID)=0;
    11379    virtual bool call(uint32_t objectID, const MultiType& mt1)=0;
     
    11682    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4)=0;
    11783    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5)=0;
     84
     85  private:
     86    uint32_t networkID_;
     87    std::string name_;
     88
     89};
     90
     91
     92class _NetworkExport NetworkFunctionStatic: public NetworkFunctionBase {
     93  public:
     94    NetworkFunctionStatic(const FunctorStaticPtr& functor, const std::string& name, const NetworkFunctionPointer& p)
     95        : NetworkFunctionBase(name, p)
     96        , functor_(functor)
     97    { }
     98
     99    // ignore the objectID because its a static function
     100    virtual bool call(uint32_t objectID){ (*this->functor_)(); return true; }
     101    virtual bool call(uint32_t objectID, const MultiType& mt1){ (*this->functor_)(mt1); return true; }
     102    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2){ (*this->functor_)(mt1, mt2); return true; }
     103    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3){ (*this->functor_)(mt1, mt2, mt3); return true; }
     104    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4){ (*this->functor_)(mt1, mt2, mt3, mt4); return true; }
     105    virtual bool call(uint32_t objectID, const MultiType& mt1, const MultiType& mt2, const MultiType& mt3, const MultiType& mt4, const MultiType& mt5){ (*this->functor_)(mt1, mt2, mt3, mt4, mt5); return true; }
     106
     107  private:
     108    FunctorStaticPtr functor_;
     109
     110};
     111
     112
     113class _NetworkExport NetworkMemberFunctionBase: public NetworkFunctionBase {
     114  public:
     115    NetworkMemberFunctionBase(const std::string& name, const NetworkFunctionPointer& p)
     116        : NetworkFunctionBase(name, p)
     117    { }
    118118};
    119119
Note: See TracChangeset for help on using the changeset viewer.