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...)
simple queue form Array(Vector...) [message #3547] Thu, 01 June 2006 11:00 Go to next message
qwerty is currently offline  qwerty
Messages: 130
Registered: May 2006
Experienced Member
some simple way(other than fundametnally Array && few C++ code:)) to set the size of array and if size of Array reach specified size_value, the first element will disapperar to keep size latest recently values in :> ???
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 next message
mr_ped is currently offline  mr_ped
Messages: 825
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

Re: simple queue form Array(Vector...) [message #3554 is a reply to message #3553] Thu, 01 June 2006 14:49 Go to previous message
qwerty is currently offline  qwerty
Messages: 130
Registered: May 2006
Experienced Member
yes, I have something like that, but with Array<String>, remove(0) if over etc... than you Very Happy
Previous Topic: appending to an existing file
Next Topic: binar files in String
Goto Forum:
  


Current Time: Sun Apr 28 11:21:54 CEST 2024

Total time taken to generate the page: 0.05061 seconds