Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » simple queue form Array(Vector...)
Re: simple queue form Array(Vector...) [message #3553 is a reply to message #3547] Thu, 01 June 2006 14:03 Go to previous messageGo to previous message
mr_ped is currently offline  mr_ped
Messages: 826
Registered: November 2005
Location: Czech Republic - Praha
Experienced Contributor
qwerty: what you are looking for is some sort of FIFO queue, which is not directly part of U++ core (AFAIK).
(well, actually the BiVector *IS* FIFO queue, but it lacks some auto-size guard, etc.. i.e. some higher logic of some queue, but there's no point to add such logic into basic container class IMHO).

What's wrong with BiVector and few lines of C++ code?

As the AddHead(const T& x) and AddTail(const T& x) and few others are not virtual, you can't simply derive new BiVector class and add automatic guard of number of elements with "AutoDrop" feature, yet I think the classic "few C++ code" solution is a good choice here.

  BiVector<element> myQueue;
  int myQueueMaxLength = 40;

  void AddAndKeepSize(const element & el) {
      while ( myQueue.GetCount() >= myQueueMaxLength )
          myQueue.DropHead();
      myQueue.AddTail(el);
  }

  //to add new element use:
  AddAndKeepSize(element);



That's basically it. It would be nice to embed it into some class ... depends where and how you need it and how much you dislike globals + globals functions outside of any class.

[Updated on: Thu, 01 June 2006 14:04]

Report message to a moderator

 
Read Message
Read Message
Read Message
Previous Topic: appending to an existing file
Next Topic: binar files in String
Goto Forum:
  


Current Time: Fri Jul 18 03:14:56 CEST 2025

Total time taken to generate the page: 0.02927 seconds