Connecting Tech Pros Worldwide Help | Site Map

Channel List

Joe
Guest
 
Posts: n/a
#1: Jul 22 '05
I'm quite new to object oriented programming, so this is probably a really
basic problem that there is an obvious solution to, but anyway...

I am looking for a little advice on a good way of storing a list of channels
for a video capture application. I have a channel class that contains
information such as the tuning frequency and the channel name. I then want
to have a channel list class which is used to store the channels and their
associated channel numbers (as defined by the user).

The ChannelList class will provide functionality such as:

bool RetrieveChannel (int ChanNumber, channel &Chan) - Finds the channel
specified by the number or returns false if there is no channel in that
position.
bool AddChannel (int ChanNumber, channel Chan) - Adds the given channel
in the specified position or returns false if there is already one there
bool MoveChannel (int OldChanNumber, int NewChannelNumber) - Moves the
channel from one position to another.

I also need some way of listing all the channels and this is where I start
to get stuck. How do I actually "store" each channel object in the
ChannelList? How should I associate the channel number with each channel
object? I suppose I could add a channel number entry to the channel class,
but this doesn't seem quite right to me (in terms of keeping a strict class
heirarchy) or am I wrong?

Any help is appreciated.

TIA,
Joe.




John Harrison
Guest
 
Posts: n/a
#2: Jul 22 '05

re: Channel List



"Joe" <anon@anon.com> wrote in message news:t_p_b.87$bJ1.16@newsfe1-win...[color=blue]
> I'm quite new to object oriented programming, so this is probably a really
> basic problem that there is an obvious solution to, but anyway...
>
> I am looking for a little advice on a good way of storing a list of[/color]
channels[color=blue]
> for a video capture application. I have a channel class that contains
> information such as the tuning frequency and the channel name. I then want
> to have a channel list class which is used to store the channels and their
> associated channel numbers (as defined by the user).
>
> The ChannelList class will provide functionality such as:
>
> bool RetrieveChannel (int ChanNumber, channel &Chan) - Finds the channel
> specified by the number or returns false if there is no channel in that
> position.
> bool AddChannel (int ChanNumber, channel Chan) - Adds the given channel
> in the specified position or returns false if there is already one there
> bool MoveChannel (int OldChanNumber, int NewChannelNumber) - Moves the
> channel from one position to another.
>
> I also need some way of listing all the channels and this is where I start
> to get stuck. How do I actually "store" each channel object in the
> ChannelList? How should I associate the channel number with each channel
> object? I suppose I could add a channel number entry to the channel class,
> but this doesn't seem quite right to me (in terms of keeping a strict[/color]
class[color=blue]
> heirarchy) or am I wrong?
>
> Any help is appreciated.
>
> TIA,
> Joe.
>[/color]

I would suggest that you use the std::map class, it seems tailor made for
your application.

#include <map>

std::map<int, Chan> channel_map;

// adding a channel
Chan some_channel;
channel_map.insert(make_pair(123, some_channel));

// finding a channel
Chan some_channel = channel_map.find(123);

Moving a channel is slightly more complex but not too difficult. Any good
book will tell you about the std::map class which is part of the C++
standard library (aka the STL).

john


Mike Wahler
Guest
 
Posts: n/a
#3: Jul 22 '05

re: Channel List



"Joe" <anon@anon.com> wrote in message news:t_p_b.87$bJ1.16@newsfe1-win...[color=blue]
> I'm quite new to object oriented programming, so this is probably a really
> basic problem that there is an obvious solution to, but anyway...
>
> I am looking for a little advice on a good way of storing a list of[/color]
channels[color=blue]
> for a video capture application. I have a channel class that contains
> information such as the tuning frequency and the channel name. I then want
> to have a channel list class which is used to store the channels and their
> associated channel numbers (as defined by the user).
>
> The ChannelList class will provide functionality such as:
>
> bool RetrieveChannel (int ChanNumber, channel &Chan) - Finds the channel
> specified by the number or returns false if there is no channel in that
> position.
> bool AddChannel (int ChanNumber, channel Chan) - Adds the given channel
> in the specified position or returns false if there is already one there
> bool MoveChannel (int OldChanNumber, int NewChannelNumber) - Moves the
> channel from one position to another.
>
> I also need some way of listing all the channels and this is where I start
> to get stuck. How do I actually "store" each channel object in the
> ChannelList? How should I associate the channel number with each channel
> object? I suppose I could add a channel number entry to the channel class,
> but this doesn't seem quite right to me (in terms of keeping a strict[/color]
class[color=blue]
> heirarchy) or am I wrong?
>
> Any help is appreciated.[/color]

Sounds like a job for a std::map.

For listing, see std::map::const_iterator.

-Mike


Closed Thread