|
Bernhard wrote:
is there any neat solution doing this with templates ?
What you might have been thinking of was template specialisation based on an integer constant - it's a possiblity, but it's unlikely that it would work. Most of the time you want to dispatch the function based on a number specified at compile time run time.
Bernhard wrote:
it is function based, so no chance in using a class
Ryan's solution might be the best in this case, but consider the alternative of using a standard map to dispatch the functions
#pragma warning(disable:4786)
#include <iostream>
#include <map>
#include <functional>
using namespace std;
typedef void (*func)();
void fun1()
{
cout << "a" << endl;
}
void fun2()
{
cout << "b" << endl;
}
int main()
{
std::map<int,func> m;
m[1] = &fun1;
m[2] = &fun2;
m[1]();
m[2]();
return 0;
}
If you can keep you head when all about you
Are losing theirs and blaming it on you;
If you can dream - and not make dreams your master;
If you can think - and not make thoughts you aim;
Yours is the Earth and everything that's in it.
Rudyard Kipling
|
|
|
|
|
well, this could really be a solution..
but the problem is somewhere different:
i have got 2 sets of functions, doing the same thing..
it depends on 1 parameter which function i have to chose (from set a or set b)
!! WARNING PSEUDOCODE !!
!! this is not intended to run, just to show the concept !!
void a_get();
void b_get();
void a_set();
void b_set();
void get()
{
if (a)
a_get();
else
b_get();
}
void set()
{
if (a)
a_set();
else
b_set();
}
now it is very cumbersome to write this for every function and i wanted to know if there isn't any possibility to write something like:
template <fun1, fun2>
{
if (a)
fun1;
if (b)
fun2;
}
template<&a_get, &b_get> get;
template<&a_set, &b_set> set;
yeah.. and this was what it was all about.
thanks for your efforts (both of you, altough i write you back)
bernhard
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
well.. after writing the pseudocode (thinking again about this problem), i found out this solution by myself..
template <void f1(), void f2>
class call_fun
{
call_fun () {};
public:
call_fun (char c)
{
if('A' == c)
{
cout << "call_fun: A selected" << endl;
f1();
}
else
{
cout << "call_fun: not A selected" << endl;
f2();
}
};
};
void fun11()
{
cout << "Hello from fun11" << endl;
}
void fun12()
{
cout << "Hello from fun12" << endl;
}
void fun21()
{
cout << "Hello from fun21" << endl;
}
void fun22()
{
cout << "Hello from fun22" << endl;
}
int main()
{
call_fun<&fun11, &fun12> a ('A');
call_fun<&fun11, &fun12> b ('B');
cout << endl;
call_fun<&fun21, &fun22> c('A');
call_fun<&fun21, &fun22> d('B');
return 0;
}
"I'm from the South Bronx, and I don't care what you say: those cows look dangerous." U.S. Secretary of State Colin Powell at George Bush's ranch in Texas
|
|
|
|
|
I have two questions.
1. Is there any way to check to see if there is a device on the other end of the serial port. The device itself does not have anything that will send out "yes i am here".
2. The device i am connecting to constantly send data unless a stop command is issued, how do i keep receiving the incoming data? Right now I execute the following code using a receive button, but I have to keep pressign the receive button to keep getting the code:
// Receive on the Serial Port
if( m_MySerialPort.IsOpen() )
{
m_bytesRead = m_MySerialPort.Read( m_readBuffer, 100 );
m_ctrlTextIn.SetWindowText(m_readBuffer);
}
else AfxMessageBox(" Compass not responding in Recieve function!");
|
|
|
|
|
1) If the device is constantly sending data unless a stop command is issued then you already know if it is attached (or that something is attached). Just send a start command, if you receive any data it is attached.
2) You could start a timer (StartTimer(), KillTimer()) or use a seperate thread to poll the serial port.
INTP
|
|
|
|
|
Hey,
I've got one question. I need to display an AutoCAD or Microstation drawings within a SDI frame. But I don't know how to do this. Is it possible with DirectX or OpenGL??
It would be nice to bet some helpfull informations.
Thanks for any replies!!!
|
|
|
|
|
Check www.opendwg.org[^]. There's a toolkit and a viewkit which put together should help. It's members-only downloads, but thats the most I can think of at the moment. There are a couple of articles here, but they are for writing DXF, not reading it.
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I would like to edit a Russian (Cyryllic) string in MFC's Edit/RichEdit box, then DDX it and write it to file... of course to be read again and put into the edit box.
Should I use Unicode (i.e. compile my application for Unicode)? Will it work with Win9x? How do I setup Edit box for cyryllic font?
Regards,
BB
|
|
|
|
|
My inclination would be to use Unicode, but I haven't worked with a non-english version of Windows, so I don't know if it's absolutely necessary. If you want it to work on an english version of Windows, then yes, you'll have to use Unicode. In this case, it won't work with Win9x, unless you link with the Microsoft Layer for Unicode (check the MSDN docs for this). You should be able to use any font that supports cyrillic characters. I think the Arial Unicode font does - you'll have to check, and distribute one with your app if necessary.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Is there a way to get the number of logical processors in a Windows XP system? If I see that the application is running on Windows XP and that hyperthreading is enabled (how do I do that?) I guess I could just divide by two?
Are there any api calls for this? I found something about GetLogicalProcessorInformation , but that didn't seem to be what I need.
Thanks,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
What is the difference between normal CPU and logical CPU? One solution is GetSystemInfo().
Kuphryn
|
|
|
|
|
With Hyperthreading you have physical processors and logical processors. Example, let's say:
I have to physical processors each one is also a logical processor. I then enable hyperthreading on both CPUs. Windows now thinks that I have 4 logical processors, that being each physical processor now represents two logical.
I wish to be able to get the number of physical processors and then also the number of logical processors. The reason for this is that if I were to have 4 real physical processors I might then spin out 8 threads. On the other hand, if I have only two physical processors that each are hyperthreaded I would only spin out 6 threads (logical processors aren't as capable as a physical processor).
Hope this offers some explanation.
-Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Try GetSystemInfo. I believe that the SYSTEM_INFO.dwNumberOfProcessors returns the number of logical processors (although I could be wrong).
onwards and upwards...
|
|
|
|
|
see answer to kuphryn...
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
I found the answer on Intel's site:
CPU Counting Utility[^]
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
I need 2 structures that have references to eachother. In this situation I need to do some forward declaring. I know how to do this when using a reference (pointer) to the other structure, but I don't want to use pointers so I don't have to create the structure with new and destroying them with delete when I don't need them anymore.
So what my question basically comes down to, is it possible to have circular references without using pointers? e.g. something like:
<br />
typedef std::list<struct TParamValue> TParamValues;<br />
typedef std::list<struct TParamField> TParamFields;<br />
<br />
typedef struct TParamValue<br />
{<br />
CString value;
CString description;
TParamFields fields;
} TParamValue;<br />
<br />
typedef struct TParamField<br />
{<br />
unsigned long index;
unsigned long bits;
CString description;
CString currentValue;
TParamValues values;
} TParamField;<br />
|
|
|
|
|
Brian van der Beek wrote:
So what my question basically comes down to, is it possible to have circular references without using pointers?
No. To fully specify a structure, the compiler has to know the size of every member, which means they have to be fully specified. If you have a circular reference, neither of the structures are fully specified, so neither can be compiled because they rely on the other one.
It's a never-ending loop which the compiler can not sort out. The only way to solve this problem is using pointers or references.
However, your situation may work (I'm not sure what the compiler might complain about). std::list internally uses pointers, so the compiler might accept it. You can try, but don't be surprised if it doesn't work.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
It's a never-ending loop which the compiler can not sort out. The only way to solve this problem is using pointers or references.
I was afraid of that.
Ryan Binns wrote:
However, your situation may work (I'm not sure what the compiler might complain about). std::list internally uses pointers, so the compiler might accept it. You can try, but don't be surprised if it doesn't work.
I doesn't work. I do have a question about your remark though. Does std::list use pointers? I always though it just stored the specified type, i.e. <T> instead of <T*> .
|
|
|
|
|
Brian van der Beek wrote:
I do have a question about your remark though. Does std::list use pointers? I always though it just stored the specified type, i.e. <t> instead of <t*>.
I was wrong It stores the object as a member of a private structure - which it stores pointers of. I forgot about that . So no, your situation won't work.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I've searched on how to remove the scrollbars on a CWebbrowser2 component, and the only thing I've found was to modify the HTML file itself by adding scroll=no to the <BODY> tag.
Is there another way that I missed ?
Thanks.
Maximilien Lincourt
"Never underestimate the bandwidth of a station wagon filled with backup tapes." ("Computer Networks" by Andrew S Tannenbaum )
|
|
|
|
|
I am working now on my own shell wich substitutes explorer.exe. Why do I need ths? - For security reasons
I am having problems with language switching in WinXP. When I press Ctrl+Shift, the keyborad language supposed to change, but It does not.
In Win9x/2000 there is no such problems since keyboard indicator is placed automatically into systray, But this does not work in WinXP!
Where can I get info about how to write own keyboard indicator or (even better) find the source code of working sample?
Thanks.
|
|
|
|
|
Hi,
I want to use OnCtlColor message to change the backgroung color of a Dialog. I use it like this :
CBrush m_Brush;<br />
<br />
m_Brush.CreateSolidBrush(RGB(212,212,226));<br />
<br />
HBRUSH MyClass::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) <br />
{<br />
return m_brush;<br />
}
It work, BUT THE BACKGROUNG COLOR OF ALL MY EDIT CONTROL ON THIS DIALOG are paint also by the bush.
Is There any way to keep the back color of an edit control to white by default ?
Thanks in advance
|
|
|
|
|
pWnd points to the control being coloured. Use this to determine whether you want to do the colouring or not.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
check the nCtlColor param.....
|
|
|
|
|
Hi, is there any effective way to know a process is dead?
Qin An
|
|
|
|