By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,974 Members | 1,913 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,974 IT Pros & Developers. It's quick & easy.

Channel List

P: n/a
Joe
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.


Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Joe" <an**@anon.com> wrote in message news:t_p_b.87$bJ1.16@newsfe1-win...
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.


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
Jul 22 '05 #2

P: n/a

"Joe" <an**@anon.com> wrote in message news:t_p_b.87$bJ1.16@newsfe1-win...
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.


Sounds like a job for a std::map.

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

-Mike
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.