Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6455


Ignore:
Timestamp:
Jan 22, 2010, 3:49:23 PM (15 years ago)
Author:
scheusso
Message:

unregisterVariable reintroduced
some style changes

Location:
code/branches/network2/src/libraries/network/synchronisable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network2/src/libraries/network/synchronisable/Synchronisable.cc

    r6450 r6455  
    4949  * Initializes all Variables and sets the right objectID_
    5050  */
    51   Synchronisable::Synchronisable(BaseObject* creator ){
     51  Synchronisable::Synchronisable(BaseObject* creator )
     52  {
    5253    RegisterRootObject(Synchronisable);
    5354    static uint32_t idCounter=0;
     
    7374    else
    7475      this->creatorID_ = OBJECTID_UNKNOWN;
    75 
    76     /*searchcreatorID:
    77     if (creator)
    78     {
    79         Synchronisable* synchronisable_creator = orxonox_cast<Synchronisable*>(creator);
    80         if (synchronisable_creator && synchronisable_creator->objectMode_)
    81         {
    82             this->creatorID = synchronisable_creator->getScene()->getObjectID();
    83         }
    84         else if (creator != creator->getCreator())
    85         {
    86             creator = creator->getCreator();
    87             goto searchcreatorID;
    88         }
    89     }*/
    9076  }
    9177
     
    9480   * Delete all callback objects and remove objectID_ from the objectMap_
    9581   */
    96   Synchronisable::~Synchronisable(){
     82  Synchronisable::~Synchronisable()
     83  {
    9784    // delete callback function objects
    9885    if(!Identifier::isCreatingHierarchy()){
     
    118105   * @param b true if this object is located on a client or on a server
    119106   */
    120   void Synchronisable::setClient(bool b){
     107  void Synchronisable::setClient(bool b)
     108  {
    121109    if(b) // client
    122110      state_=0x2;
     
    191179   * @return true/false
    192180   */
    193   bool Synchronisable::deleteObject(uint32_t objectID_){
     181  bool Synchronisable::deleteObject(uint32_t objectID_)
     182  {
    194183    if(!getSynchronisable(objectID_))
    195184      return false;
     
    208197   * @return pointer to the Synchronisable with the objectID_
    209198   */
    210   Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_){
     199  Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_)
     200  {
    211201    std::map<uint32_t, Synchronisable*>::iterator it1;
    212202    it1 = objectMap_.find(objectID_);
    213203    if (it1 != objectMap_.end())
    214204      return it1->second;
    215 
    216 //     ObjectList<Synchronisable>::iterator it;
    217 //     for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    218 //       if( it->getObjectID()==objectID_ ){
    219 //         objectMap_[objectID_] = *it;
    220 //         return *it;
    221 //       }
    222 //     }
    223205    // if the objects not in the map it should'nt exist at all anymore
    224206    return NULL;
     
    240222   * @return true: if !doSync or if everything was successfully saved
    241223   */
    242   uint32_t Synchronisable::getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode){
     224  uint32_t Synchronisable::getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode)
     225  {
    243226    unsigned int test = 0;
    244227    if(mode==0x0)
     
    270253//     COUT(4) << "objectid: " << this->objectID_ << ":";
    271254    // copy to location
    272     for(i=syncList_.begin(); i!=syncList_.end(); ++i){
     255    for(i=syncList_.begin(); i!=syncList_.end(); ++i)
     256    {
    273257      uint32_t varsize = (*i)->getData( mem, mode );
    274258//       COUT(4) << " " << varsize;
     
    304288   * @return true/false
    305289   */
    306   bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback){
     290  bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback)
     291  {
    307292    if(mode==0x0)
    308293      mode=state_;
    309     if(syncList_.empty()){
     294    if(syncList_.empty())
     295    {
    310296      assert(0);
    311297      COUT(2) << "Synchronisable::updateData syncList_ is empty" << std::endl;
     
    356342  * @return amount of bytes
    357343  */
    358   uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){
     344  uint32_t Synchronisable::getSize(int32_t id, uint8_t mode)
     345  {
    359346    uint32_t tsize=SynchronisableHeader::getSize();
    360347    if (mode==0x0)
     
    365352    tsize += this->dataSize_;
    366353    std::vector<SynchronisableVariableBase*>::iterator i;
    367     for(i=stringList_.begin(); i!=stringList_.end(); ++i){
     354    for(i=stringList_.begin(); i!=stringList_.end(); ++i)
     355    {
    368356      tsize += (*i)->getSize( mode );
    369357    }
     
    376364   * @return true/false
    377365   */
    378   bool Synchronisable::doSync(int32_t id, uint8_t mode){
     366  bool Synchronisable::doSync(int32_t id, uint8_t mode)
     367  {
    379368    if(mode==0x0)
    380369      mode=state_;
     
    390379   * @param mode same as in registerVar
    391380   */
    392   void Synchronisable::setSyncMode(uint8_t mode){
     381  void Synchronisable::setSyncMode(uint8_t mode)
     382  {
    393383    assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3);
    394384    this->objectMode_=mode;
     
    406396  }
    407397
     398template <> void Synchronisable::unregisterVariable( std::string& variable )
     399  {
     400    bool unregistered_nonexistent_variable = true;
     401    std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin();
     402    while(it!=syncList_.end())
     403    {
     404      if( ((*it)->getReference()) == &variable )
     405      {
     406        delete (*it);
     407        syncList_.erase(it);
     408        unregistered_nonexistent_variable = false;
     409        break;
     410      }
     411      else
     412        ++it;
     413    }
     414    assert(unregistered_nonexistent_variable == false);
     415   
     416    it = stringList_.begin();
     417    while(it!=stringList_.end())
     418    {
     419      if( ((*it)->getReference()) == &variable )
     420      {
     421        delete (*it);
     422        stringList_.erase(it);
     423        return;
     424      }
     425      else
     426        ++it;
     427    }
     428    unregistered_nonexistent_variable = true;
     429    assert(unregistered_nonexistent_variable == false); //if we reach this point something went wrong:
     430    // the variable has not been registered before
     431  }
     432
    408433
    409434}
  • code/branches/network2/src/libraries/network/synchronisable/Synchronisable.h

    r6450 r6455  
    177177    Synchronisable(BaseObject* creator);
    178178    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
     179    template <class T> void unregisterVariable(T& var);
    179180
    180181    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
     
    219220    }
    220221  }
     222 
     223  template <class T> void Synchronisable::unregisterVariable(T& variable){
     224    std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin();
     225    while(it!=syncList_.end()){
     226      if( ((*it)->getReference()) == &variable ){
     227        delete (*it);
     228        syncList_.erase(it);
     229        return;
     230      }
     231      else
     232        it++;
     233    }
     234    bool unregistered_nonexistent_variable = false;
     235    assert(unregistered_nonexistent_variable); //if we reach this point something went wrong:
     236    // the variable has not been registered before
     237  }
    221238
    222239  template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional);
     240  template <> _NetworkExport void Synchronisable::unregisterVariable( std::string& variable );
    223241
    224242
Note: See TracChangeset for help on using the changeset viewer.