L
Leslaw Bieniasz
Cracow, 8.09.2009
Hi,
I am writing a C++ program that does a job similar to a typical compiler:
It reads some source text, analyses it for errors, and performs some
conversion to a target format. I have a problem how to design the
communication between my code and user interfaces, to achieve
the following goals:
1) The code should be able to run either in the console mode, or
within a Windows GUI, but the kernel part of the code should be designed
in such a way so that it is independent on the interface.
2) The code should make available to the program user a list of
errors detected during its operation, with some additional information
about the location of the errors in the source text analysed.
Also, the user should be informed about the current status of
the program operation, by suitable messages.
3) The operation of the code is rather fast, so that it seems that
it is not necessary to run it in a separate thread (but who knows
what will be needed in the future?)
Owing to these features, I notice an analogy of my code to some of the
commercial C++ compilers, such as, for example, Borland compilers,
like C++ Builder. They can also run either in the console or Windows mode,
and send appropriate error and status messages. In the case of the Windows
GUI, the Builder displays status messages in a small Dialog-type window,
opened for the time of the compilation, and error messages are
added to a ListBox-type window. Later on, a user can click on any
of the error messages, which causes that a part of the
source text, containing the particular error, is displayed in another window.
In the case of the console mode, the messages are sent to the console.
I would like to have a similar behaviour in my code, so that if anybody
knows how such things are designed, please help me.
In the case of console programs, the easiest thing to do is to send
various messages to an output stream, during the program operation, for example:
cout << "Error detected: missing right parenthesis".
However, this solution does not seem the best if the same code is to run
also under graphical GUI, because there is no direct way to connect the output
stream to the various windows. It therefore seems that the interface-independent
kernel of my code should not send the messages but only keep a list of them somewhere.
The interface would later display the messages in this or other way. But this solution
is also not perfect, because then there would be a time shift between the actual
events and the information about the events, revealed to the user.
A related issue is how the code should behave internally when it detects
an error. Is this a good idea to use exceptions in such cases? If yes,
which part of the code (or interface?) should be responsible for
catching the exceptions?
I have to say I have already asked many programmers over the years,
about the above problems, and I have never obtained any real help.
This seems strange, as I can imagine these problems frequently arise
in the design of any serious large applications.
I would appreciate very much your help, ideally together with
some examples, using OOP and C++.
Leslaw
Hi,
I am writing a C++ program that does a job similar to a typical compiler:
It reads some source text, analyses it for errors, and performs some
conversion to a target format. I have a problem how to design the
communication between my code and user interfaces, to achieve
the following goals:
1) The code should be able to run either in the console mode, or
within a Windows GUI, but the kernel part of the code should be designed
in such a way so that it is independent on the interface.
2) The code should make available to the program user a list of
errors detected during its operation, with some additional information
about the location of the errors in the source text analysed.
Also, the user should be informed about the current status of
the program operation, by suitable messages.
3) The operation of the code is rather fast, so that it seems that
it is not necessary to run it in a separate thread (but who knows
what will be needed in the future?)
Owing to these features, I notice an analogy of my code to some of the
commercial C++ compilers, such as, for example, Borland compilers,
like C++ Builder. They can also run either in the console or Windows mode,
and send appropriate error and status messages. In the case of the Windows
GUI, the Builder displays status messages in a small Dialog-type window,
opened for the time of the compilation, and error messages are
added to a ListBox-type window. Later on, a user can click on any
of the error messages, which causes that a part of the
source text, containing the particular error, is displayed in another window.
In the case of the console mode, the messages are sent to the console.
I would like to have a similar behaviour in my code, so that if anybody
knows how such things are designed, please help me.
In the case of console programs, the easiest thing to do is to send
various messages to an output stream, during the program operation, for example:
cout << "Error detected: missing right parenthesis".
However, this solution does not seem the best if the same code is to run
also under graphical GUI, because there is no direct way to connect the output
stream to the various windows. It therefore seems that the interface-independent
kernel of my code should not send the messages but only keep a list of them somewhere.
The interface would later display the messages in this or other way. But this solution
is also not perfect, because then there would be a time shift between the actual
events and the information about the events, revealed to the user.
A related issue is how the code should behave internally when it detects
an error. Is this a good idea to use exceptions in such cases? If yes,
which part of the code (or interface?) should be responsible for
catching the exceptions?
I have to say I have already asked many programmers over the years,
about the above problems, and I have never obtained any real help.
This seems strange, as I can imagine these problems frequently arise
in the design of any serious large applications.
I would appreciate very much your help, ideally together with
some examples, using OOP and C++.
Leslaw