Channel List

J

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.
 
J

John Harrison

Joe said:
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
 
M

Mike Wahler

Joe said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,431
Latest member
ElyseG3173

Latest Threads

Top