K
Key9
Question about basic input output.
HI All
I am a new C++er
Suppose I am designing a i/o device .
system have screens .
system have keyboards.
=======================
class char_signal;
class Input;
class Output;
class Keyboard : public Input{
public:
virtual void operation>>(char_signal&) ;
virtual void pressed_actions();
protected:
void keyPress(char_signal);
};
class Screen : public Output{
public:
virtual void operation<<(char_signal&);
};
****
//may be later
class Tcp_Keyboard : public Keyboard;
class Tcp_Screen : public Screen;
Q1 : So what I need is associate these class with std's istream / ostream.
but how?
especially may be I will use a TCP connection or a file as i/o source?
sorry for my std zero experience.
Q2 : Suppose I want input a key and display to both of screen :
//<----file main.cpp
Screen SCR1;
Screen SCR2;
Keyboard Kbd1;
int main(){
"cycle step"{
input_char = read_a_char(device); //
input_char >> Kbd1;
//Kbd1 can do his action;
SCR1 << input_char;
SCR2 << input_char;
}
}
how can I use such a "cycle step" to monitor keyboard with better
performance?
I DON'T want a "while(true)" structure here, so I should use a thread based
keyboard? or better idea?
How I can keep program "cycle" will not exit?
Does design a monitor(watch dog) thread works? and what's the roadmap?
Q3 : Any similar source code you known ?
Thank you very much.
your
key9
HI All
I am a new C++er
Suppose I am designing a i/o device .
system have screens .
system have keyboards.
=======================
class char_signal;
class Input;
class Output;
class Keyboard : public Input{
public:
virtual void operation>>(char_signal&) ;
virtual void pressed_actions();
protected:
void keyPress(char_signal);
};
class Screen : public Output{
public:
virtual void operation<<(char_signal&);
};
****
//may be later
class Tcp_Keyboard : public Keyboard;
class Tcp_Screen : public Screen;
Q1 : So what I need is associate these class with std's istream / ostream.
but how?
especially may be I will use a TCP connection or a file as i/o source?
sorry for my std zero experience.
Q2 : Suppose I want input a key and display to both of screen :
//<----file main.cpp
Screen SCR1;
Screen SCR2;
Keyboard Kbd1;
int main(){
"cycle step"{
input_char = read_a_char(device); //
input_char >> Kbd1;
//Kbd1 can do his action;
SCR1 << input_char;
SCR2 << input_char;
}
}
how can I use such a "cycle step" to monitor keyboard with better
performance?
I DON'T want a "while(true)" structure here, so I should use a thread based
keyboard? or better idea?
How I can keep program "cycle" will not exit?
Does design a monitor(watch dog) thread works? and what's the roadmap?
Q3 : Any similar source code you known ?
Thank you very much.
your
key9