PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > collections with items accessible by name?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
collections with items accessible by name?

Réponse
 
LinkBack Outils de la discussion
Vieux 18/01/2008, 13h23   #1
Lars Uffmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut collections with items accessible by name?

I've been looking into vector, deque and list documentation. None of
these have the nifty little feature that a VB collection has, and which
comes in very handy for code readability as soon as you are developing a
GUI. I'm thinking along the lines of
mywindow("lblLastChanged")->caption = "2008-01-18 14:13h";

Before I create my own template for this, based on list or vector class,
is there something that does this in any c++ libraries? I must have
missed it then.

And if there is an implementation, is it speed-optimized (with indexing
maybe)? Just so that it doesn't end up similar to the following?

element *collection::getElementByName (const char *name)
{
element *e = this->first;

do {
if (!strcmp (name, e->name))
return e;
e = e->next;
} while (e != this->first);

return NULL;
}

Thanks for any input!

Lars
  Réponse avec citation
Vieux 18/01/2008, 13h31   #2
jkherciueh@gmx.net
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: collections with items accessible by name?

Lars Uffmann wrote:

> I've been looking into vector, deque and list documentation. None of
> these have the nifty little feature that a VB collection has, and which
> comes in very handy for code readability as soon as you are developing a
> GUI. I'm thinking along the lines of
> mywindow("lblLastChanged")->caption = "2008-01-18 14:13h";
>
> Before I create my own template for this, based on list or vector class,
> is there something that does this in any c++ libraries? I must have
> missed it then.
>
> And if there is an implementation, is it speed-optimized (with indexing
> maybe)? Just so that it doesn't end up similar to the following?
>
> element *collection::getElementByName (const char *name)
> {
> element *e = this->first;
>
> do {
> if (!strcmp (name, e->name))
> return e;
> e = e->next;
> } while (e != this->first);
>
> return NULL;
> }


What about

std::map< std::string, whatever > mywindow;


Best

Kai-Uwe Bux
  Réponse avec citation
Vieux 18/01/2008, 13h45   #3
Lars Uffmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: collections with items accessible by name?

Hi Kai,

jkherciueh@gmx.net wrote:
> What about
> std::map< std::string, whatever > mywindow;


map - of course... doh! Thanks a lot - that's what I was looking for!

Lars
  Réponse avec citation
Vieux 18/01/2008, 17h04   #4
Erik Wikström
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: collections with items accessible by name?

On 2008-01-18 14:45, Lars Uffmann wrote:
> Hi Kai,
>
> jkherciueh@gmx.net wrote:
>> What about
>> std::map< std::string, whatever > mywindow;

>
> map - of course... doh! Thanks a lot - that's what I was looking for!


Just a few comments: std::map is what you would call "speed optimised"
so that a lookup takes O(log n) (usually implemented by a red-black
tree). Unlike a VB collection you can not access elements both by key
and index. Though you can get an iterator to the first element and
advance it to the desired element.

--
Erik Wikström
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h58.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10906 seconds with 12 queries