예제 #1
0
int main(int argc, char *argv[])
{
    int i, x;
    TList<int> L;

    for (i = 0; i < 10; ++i)
    {
        x = i*i;
        L.push_front(x); // mit Quadratzahlen füllen
    }

    TList<int>::Iterator ListIter(L);

    cout << "*ListIter = " << *ListIter << endl;
    cout << "ListIter++;" << endl;
    ListIter++;
    cout << "*ListIter = " << *ListIter << endl;

   // 36 löschen, falls vorhanden
   while(ListIter++ != L.end())
      if (*ListIter == 36)
      {
         cout << *ListIter << " wird geloescht\n";
         L.erase(ListIter);
         cout << *ListIter
              << " an aktueller Position\n";
         break;
      }

   int target = 3;
   int count = 0;

   TList<int>::Iterator it = L.begin();
   while (it != L.end()) {
       if (count == target) {
           std::cout << "bam" << *it << std::endl;
       }
       count++;
       it++;
   }

   //for (TList<int>::Iterator iter = L.begin(); iter != L.end(); i++) {
   //    std::cout << *iter << std::endl;
   //}

   //TList<int>::Iterator it = L.begin();
   //while (it != L.end()) {
   //    std::cout << *it << std::endl;
   //    it++;
   //}
   for (TList<int>::Iterator itt = L.begin(); itt != L.end(); ++itt) {
       std::cout << *itt << " ";
   }
   

    return 0;
}
예제 #2
0
파일: 03.cpp 프로젝트: filaPro/my
std::string DoTestSplice(size_t n) {
    TCounter::Reset();
    {
        TList<TCounter, std::allocator<TCounter>> lst;
        for (size_t i = 0; i < n; ++i) {
            lst.push_back(TCounter());
        }
        TList<TCounter, std::allocator<TCounter>> lst1;
        for (size_t i = 0; i < n; ++i) {
            lst1.push_back(TCounter());
        }
        TList<TCounter, std::allocator<TCounter>>::iterator from = lst1.begin(), to = lst1.end();
        ++from;
        --to;
        lst.splice(lst.end(), lst1, from, to);
        if (lst.size() != 2 * n - 2 || lst1.size() != 2)
            return "lst.splice() or lst.size(): wrong answer";
        lst.resize(n);
        if (lst.size() != n)
            return "lst.resize(): wrong answer";
        lst1.splice(lst1.end(), lst);
        if (lst1.size() != n + 2 || lst.size() != 0)
            return "lst.splice() or lst.size(): wrong answer";
    }
    TCounter::CheckTotalOperationsCount(n * 10 + 100, n * 2 + 100);
    return TCounter::GetAllErrors();
}
예제 #3
0
 TList(const TList<T, Allocator> &list) {
     begin_ = nullptr;
     end_ = nullptr;
     size_ = 0;
     for (TConstListIterator it = list.begin(); it != list.end(); ++it) {
         push_back(*it);
     }
 }
예제 #4
0
be_ArgumentList::be_ArgumentList(const TList<be_argument*>& oldlist)
{
   TList<be_argument*>::iterator iter;

   for (iter = oldlist.begin(); iter != oldlist.end(); ++iter)
   {
      const be_argument& arg = *(*iter);
      push_back(be_Argument(arg));
   }
}
예제 #5
0
int TimerMaster::CascadeTimers(TimerVec *v, int index) {
  TList *l = &(*v)[index];
  for (TList::iterator it = l->begin();
       it != l->end();) {
    TimerSlot *s = &*it;
    ++it;
    s->unlink();
    InternalAddTimer(s, s->weak_timer, s->jiffies);
  }
  CHECK(l->empty());
  return index;
}
예제 #6
0
void TimerMaster::DestroyAllTimers() {
  for (int i = 0; i < arraysize(vecs_); ++i) {
    for (int j = 0; j < kTVSize; ++j) {
      TList *l = &vecs_[i][j];
      for (TList::iterator it = l->begin(); it != l->end();) {
        TimerSlot *s = &*it;
        ++it;
        delete s;
      }
    }
  }
}
예제 #7
0
void TimerMaster::Update(int jiffies) {
  CHECK_GE(jiffies, timer_jiffies_);
  TimerVec &v0 = vecs_[0];
  while (jiffies - timer_jiffies_ >= 0) {
    vector<pair<TimerSlot*, boost::shared_ptr<Timer> > > timers;
    {
      boost::mutex::scoped_lock lock(mutex_);
      const int index = timer_jiffies_ & kTVMask;
      if (!index && !CascadeTimers(&vecs_[1], INDEX(1)) &&
          !CascadeTimers(&vecs_[2], INDEX(2))) {
        CascadeTimers(&vecs_[3], INDEX(3));
      }
      TList *l = &v0[index];
      for (TList::iterator it = l->begin();
           it != l->end();) {
        TimerSlot *s = &*it;
        ++it;
        s->unlink();
        boost::weak_ptr<Timer> weak_timer = s->weak_timer;
        boost::shared_ptr<Timer> timer = weak_timer.lock();
        if (weak_timer.expired()) {
          delete s;
          continue;
        }
        timers.push_back(make_pair(s, timer));
      }
    }
    const int old_timer_jiffies = timer_jiffies_;
    ++timer_jiffies_;
    for (vector<pair<TimerSlot*, boost::shared_ptr<Timer> > >::iterator it =
         timers.begin(); it != timers.end(); ++it) {
      it->second->Expired();
    }
    {
      for (int i = 0; i < timers.size(); ++i) {
        TimerSlot *s = timers[i].first;
        boost::shared_ptr<Timer> timer = timers[i].second;
        if (timer->period()) {
          boost::mutex::scoped_lock lock(mutex_);
          InternalAddTimer(s, timer, timer->timeout() + old_timer_jiffies);
        } else {
          delete s;
        }
      }
    }
  }
}
예제 #8
0
 void merge(TList<T, Allocator> &list) {
     if (&list == this) {
         return;
     }
     TListIterator firstIter = begin();
     TListIterator secondIter = list.begin();
     while (firstIter != end() && secondIter != list.end()) {
         if (*firstIter < *secondIter) {
             ++firstIter;
         } else {
             insert(firstIter, *secondIter);
             list.erase(secondIter);
             secondIter = list.begin();
         }
     }
     while (secondIter != end()) {
         insert(firstIter, *secondIter);
         list.erase(secondIter);
         secondIter = list.begin();
     }
 }