M
ma740988
Say I've got source executing on 2 processors. The prime difference
in the source lies in select member variables
So now consider:
# include <iostream>
# include <bitset>
using namespace std;
struct open_struct
{ int val1; int val2; };
#if 0
class foo { // foo for processor 1
open_struct open;
public:
foo(open_struct os)
pen(os)
{}
void test(int val)
{
std::bitset<24> bs(val);
for ( int idx(0); idx < bs.size(); ++idx )
{
if (bs[idx])
{
switch ( idx ) // i want bits 0 .. 3 here
{
case 0: cout << " bit 0 set " << endl; break;
case 1: cout << " bit 1 set " << endl; break;
case 2: cout << " bit 2 set " << endl; break;
case 3: cout << " bit 3 set " << endl; break;
break;
}
}
}
}
void do_work( int val ) { if ( val == os.val1 ) {} };
};
int main() // processor 1 main
{
open_struct os;
os.val1 = 0x200000; os.val2 = 5;
foo f;
f.test(0xFF);
}
#endif
class foo { foo for processor 2
open_struct open;
public:
foo(open_struct os)
: open(os)
{}
void test(int val)
{
std::bitset<24> bs(val);
for ( int idx(4); idx < 8; ++idx ) // i want bits 4 .. 7 here
{
if (bs[idx])
{
switch ( idx )
{
case 4: cout << " bit 4 set " << endl; break;
case 5: cout << " bit 5 set " << endl; break;
case 6: cout << " bit 6 set " << endl; break;
case 7: cout << " bit 7 set " << endl; break;
break;
}
}
}
}
void do_work(int val) { if ( val == os.val1 ) {} };
};
int main() // processor 2 main
{
open_struct os;
os.val1 = 0x100000; os.val2 = 5;
foo f(os);
f.test(0xFF);
}
Currently I'm maintaing two foo - classes - which _quite frankly_ is a
maintanence nightmare. Notice the bit range in foo::test is different
for the two classes in addition. I'm seeking to generate a generic
solution such that I'll have 1 foo class that'll handle the unique
range for each foo class. A template solution I'm not sure will help
me here.
Thanks in advance.
in the source lies in select member variables
So now consider:
# include <iostream>
# include <bitset>
using namespace std;
struct open_struct
{ int val1; int val2; };
#if 0
class foo { // foo for processor 1
open_struct open;
public:
foo(open_struct os)
pen(os)
{}
void test(int val)
{
std::bitset<24> bs(val);
for ( int idx(0); idx < bs.size(); ++idx )
{
if (bs[idx])
{
switch ( idx ) // i want bits 0 .. 3 here
{
case 0: cout << " bit 0 set " << endl; break;
case 1: cout << " bit 1 set " << endl; break;
case 2: cout << " bit 2 set " << endl; break;
case 3: cout << " bit 3 set " << endl; break;
break;
}
}
}
}
void do_work( int val ) { if ( val == os.val1 ) {} };
};
int main() // processor 1 main
{
open_struct os;
os.val1 = 0x200000; os.val2 = 5;
foo f;
f.test(0xFF);
}
#endif
class foo { foo for processor 2
open_struct open;
public:
foo(open_struct os)
: open(os)
{}
void test(int val)
{
std::bitset<24> bs(val);
for ( int idx(4); idx < 8; ++idx ) // i want bits 4 .. 7 here
{
if (bs[idx])
{
switch ( idx )
{
case 4: cout << " bit 4 set " << endl; break;
case 5: cout << " bit 5 set " << endl; break;
case 6: cout << " bit 6 set " << endl; break;
case 7: cout << " bit 7 set " << endl; break;
break;
}
}
}
}
void do_work(int val) { if ( val == os.val1 ) {} };
};
int main() // processor 2 main
{
open_struct os;
os.val1 = 0x100000; os.val2 = 5;
foo f(os);
f.test(0xFF);
}
Currently I'm maintaing two foo - classes - which _quite frankly_ is a
maintanence nightmare. Notice the bit range in foo::test is different
for the two classes in addition. I'm seeking to generate a generic
solution such that I'll have 1 foo class that'll handle the unique
range for each foo class. A template solution I'm not sure will help
me here.
Thanks in advance.