Channel List 
July 22nd, 2005, 07:47 AM
| | | |
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. | 
July 22nd, 2005, 07:48 AM
| | | | 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 | 
July 22nd, 2005, 07:48 AM
| | | | 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 |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,689 network members.
|