Hi all,
I have the following being defined in a A.cxx file.
// define in source file. Not exported to the outside world (this
cannot be
// moved to the header file [restriction])
#define CHANNEL_0 0
#define CHANNEL_1 1
#define CHANNEL_2 2
#define CHANNEL_3 3
#define CHANNEL_4 4
#define CHANNEL_5 5
However, in another file B.cxx, I have a fucntion called:
registerChannel (int channelNumber_)
{
// perform registration via channel number (valid range 0 - 5)
register(channe lNumber_);
}
It works fine. However, now there is a new requirements: Channel
0,2,4 must maps to 0, 1, 2. Other channel maps to an invalid value.
I was wondering what is the best way to implements the mapping
function. My idea is as follows:
// 255 is an invalid value
#define INVALID_CHANNEL 255
int ChannelMapArray[] =
{0, INVALID_CHANNEL , 1, INVALID_CHANNEL , 2, INVALID_VALUE, };
So I could just use it in registerChannel () as follows:
registerChannel (int channelNumber_)
{
// perform registration via channel number (valid range 0 - 5)
register(Channe lMapArray[channelNumber_]);
}
Is there a better way to implement a mapping function. The array
implementation seems unclear. Also, is it possible to implement it as
a 2 ways mapping function (i.e given 1-6 -> 0,1,2,invalid or vice
versa)? Is there a commonly known technique for this? Is it possible
to reference the mapping to the #define in A.cxx?
Thanks All,
Naruto
I have the following being defined in a A.cxx file.
// define in source file. Not exported to the outside world (this
cannot be
// moved to the header file [restriction])
#define CHANNEL_0 0
#define CHANNEL_1 1
#define CHANNEL_2 2
#define CHANNEL_3 3
#define CHANNEL_4 4
#define CHANNEL_5 5
However, in another file B.cxx, I have a fucntion called:
registerChannel (int channelNumber_)
{
// perform registration via channel number (valid range 0 - 5)
register(channe lNumber_);
}
It works fine. However, now there is a new requirements: Channel
0,2,4 must maps to 0, 1, 2. Other channel maps to an invalid value.
I was wondering what is the best way to implements the mapping
function. My idea is as follows:
// 255 is an invalid value
#define INVALID_CHANNEL 255
int ChannelMapArray[] =
{0, INVALID_CHANNEL , 1, INVALID_CHANNEL , 2, INVALID_VALUE, };
So I could just use it in registerChannel () as follows:
registerChannel (int channelNumber_)
{
// perform registration via channel number (valid range 0 - 5)
register(Channe lMapArray[channelNumber_]);
}
Is there a better way to implement a mapping function. The array
implementation seems unclear. Also, is it possible to implement it as
a 2 ways mapping function (i.e given 1-6 -> 0,1,2,invalid or vice
versa)? Is there a commonly known technique for this? Is it possible
to reference the mapping to the #define in A.cxx?
Thanks All,
Naruto
Comment