473,698 Members | 2,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C++ Event Coding Questions

C++ Event Coding Questions

I have done some simple programs in C++ and read a lot of good C++
books (Including The C++ Programing Language, and C++ Primer) I am
trying to understand and implement an Event based program and Message
system. I have a very basic event engine that I'm feeling works a bit
backwards. I'm looking for documents, source code, and books that may
help me better understand how to implement this type of code. I am not
a student and this is not homework, just a hobby at the moment.

I have a few requirements that are making my search difficult.

1. I'm trying to develop some cross platform programming skills so I
want the code to be as generic as possible. (No MFC)

2. I'm happy to use the STL but no other external libraries

3. I am coding this on a Linux Box but that should not matter because
of point 1

4. Simpler is better. I understand and am able to read most code and
have many samples but they are very poorly documented and are so
ingrained with some external framework (like MFC) that I am having a
bear of a time trying to make heads or tails of it.

5. I have a very archaic but working garbage collector and memory
management system. After I get this all figured out I'll be happy to
let you all rip it to shreds and tell me how evil and silly I am. (It's
creative but not necessarily in a good way)

6. I'm not using threads. I hear that they are not dependable for
execution speed and time and can be problematic and in many cases are
unnecessary.

I keep reading about Event handlers and Dispatchers and I don't think
that is what I am doing

My code is a bit long and not commented well so I will spare you all
reading it at this point.

In general I have an Event Controller that all events are sent to.
When it receives an event it determines if it runs now or is on hold.
If it runs now it gets added to the end of the NOW link list. If it
runs later it gets sorted into the HOLD list. Once a cycle the
Controller checks the front of the HOLD lists for things that should
run now (and pulls off the events and pushes them onto the front of the
NOW list) Then it executes every event in the NOW list. Events are
deleted after they return from execution by the Controller.

The Events work by calling a function pointer that points to a static
function of the object or factory that created it. These then do
something and usually generate a new event. The Function Pointers
ActionFunction( Object* Me,int Action) for what the object (Me) is doing
(Action) and InteractFunctio n(Object* Me,Object* You, int Action) for
Object (Me) doing (Action) to Object(You)

I have some great casting in these functions that just shout out EVIL
and I'm certain I can get rid of them by changing the way either the
function Pointers work or the way the Events work.

Also I think this will need a better State Machine because using an
enumerated Type cast on an int is EVIL and using a raw int and trying
to keep track of what it means is EVIL and making the base objects and
events use a pre-defined enumerated Type is inflexible and therefor
EVIL.

Please help me get rid of the EVIL.

Thanks

Nov 2 '06 #1
4 6695

AzizMandar wrote:
I have a few requirements that are making my search difficult.

1. I'm trying to develop some cross platform programming skills so I
want the code to be as generic as possible. (No MFC)

2. I'm happy to use the STL but no other external libraries
You are usinllg the word "difficult" in a rather euphemistic way.
Events are neither part of the C++ language, nor of the STL. This means
you'll either grab your events directly from your OS, which is not
portable. Or you are using a portable external framework, which is not
standard sustained any more. There is no such thing as "pure language
cross plattform event programming Skillz" in C++.

Let's face it, the requirements you are describing show one thing very
clearly. You are concerned about productivity, ease of use and
portability, as opposed to MIPS or FLOPS. C++ should not be your weapon
of choice. Consider using a language that actually focusses on things
like portable GUI's, like Tcl/TK, Python/TK, Ruby or even evil Java.
Part of being a good C++ programmer is knowing when NOT to use C++ ;-)

Have fun, FJK

Nov 3 '06 #2
F.J.K. wrote:
AzizMandar wrote:
**** original post reinserted *********
>C++ Event Coding Questions

I have done some simple programs in C++ and read a lot of good C++
books (Including The C++ Programing Language, and C++ Primer) I am
trying to understand and implement an Event based program and Message
system. I have a very basic event engine that I'm feeling works a bit
backwards. I'm looking for documents, source code, and books that may
help me better understand how to implement this type of code. I am not
a student and this is not homework, just a hobby at the moment.

I have a few requirements that are making my search difficult.

1. I'm trying to develop some cross platform programming skills so I
want the code to be as generic as possible. (No MFC)

2. I'm happy to use the STL but no other external libraries
STL is not an external library. Its a standardised part of a conforming

C++ implementation.

>3. I am coding this on a Linux Box but that should not matter because
of point 1

4. Simpler is better. I understand and am able to read most code and
have many samples but they are very poorly documented and are so
ingrained with some external framework (like MFC) that I am having a
bear of a time trying to make heads or tails of it.

5. I have a very archaic but working garbage collector and memory
management system. After I get this all figured out I'll be happy to
let you all rip it to shreds and tell me how evil and silly I am. (It's
creative but not necessarily in a good way)

6. I'm not using threads. I hear that they are not dependable for
execution speed and time and can be problematic and in many cases are
unnecessary.

You are usinllg the word "difficult" in a rather euphemistic way.
Events are neither part of the C++ language, nor of the STL. This means
you'll either grab your events directly from your OS, which is not
portable. Or you are using a portable external framework, which is not
standard sustained any more.
or roll your own. An event can simply be a class.

There is no such thing as "pure language
cross plattform event programming Skillz" in C++.

Let's face it, the requirements you are describing show one thing very
clearly. You are concerned about productivity, ease of use and
portability, as opposed to MIPS or FLOPS. C++ should not be your weapon
of choice. Consider using a language that actually focusses on things
like portable GUI's, like Tcl/TK, Python/TK, Ruby or even evil Java.
Part of being a good C++ programmer is knowing when NOT to use C++ ;-)
um. I never saw the word "GUI" in his post. He said he was interested
in
an event or message driven system. That doesn't mean it's a GUI.
eg. telecomms
--
Nick Keighley

As I recall, OSI dealt with TCP/IP by just admitting it into the spec
as a variation of existing levels. This is akin to dealing with an
Alien face hugger by allowing it to implant its embryo in your body.

Nov 3 '06 #3
Nick Keighley wrote:
F.J.K. wrote:
AzizMandar wrote:

**** original post reinserted *********
C++ Event Coding Questions

I have done some simple programs in C++ and read a lot of good C++
books (Including The C++ Programing Language, and C++ Primer) I am
trying to understand and implement an Event based program and Message
system. I have a very basic event engine that I'm feeling works a bit
backwards. I'm looking for documents, source code, and books that may
help me better understand how to implement this type of code. I am not
a student and this is not homework, just a hobby at the moment.

I have a few requirements that are making my search difficult.

1. I'm trying to develop some cross platform programming skills so I
want the code to be as generic as possible. (No MFC)

2. I'm happy to use the STL but no other external libraries

STL is not an external library. Its a standardised part of a conforming

C++ implementation.

3. I am coding this on a Linux Box but that should not matter because
of point 1

4. Simpler is better. I understand and am able to read most code and
have many samples but they are very poorly documented and are so
ingrained with some external framework (like MFC) that I am having a
bear of a time trying to make heads or tails of it.

5. I have a very archaic but working garbage collector and memory
management system. After I get this all figured out I'll be happy to
let you all rip it to shreds and tell me how evil and silly I am. (It's
creative but not necessarily in a good way)

6. I'm not using threads. I hear that they are not dependable for
execution speed and time and can be problematic and in many cases are
unnecessary.
You are usinllg the word "difficult" in a rather euphemistic way.
Events are neither part of the C++ language, nor of the STL. This means
you'll either grab your events directly from your OS, which is not
portable. Or you are using a portable external framework, which is not
standard sustained any more.

or roll your own. An event can simply be a class.
Sure. But where's the point? You can define pretty much anything as a
class. But events as general data structures are of rather limited use,
unless you want to respond to external triggers. In this case, you'll
need to interface the external "trigger-giving" software-layer. This
interface is not defined by the C++ language, you'll have to either use
abstraction libraries or use nonstandard constructs. Which is what the
OP wanted to avoid.

IMHO events/messages only make sense in the context of asynchronous
communication. Which again, is not part of the standard (yet, see
boost::asio)."P ure" C++ programs to my knowledge can only communicate
synchronously.
>
There is no such thing as "pure language
cross plattform event programming Skillz" in C++.

Let's face it, the requirements you are describing show one thing very
clearly. You are concerned about productivity, ease of use and
portability, as opposed to MIPS or FLOPS. C++ should not be your weapon
of choice. Consider using a language that actually focusses on things
like portable GUI's, like Tcl/TK, Python/TK, Ruby or even evil Java.
Part of being a good C++ programmer is knowing when NOT to use C++ ;-)

um. I never saw the word "GUI" in his post. He said he was interested
in
an event or message driven system. That doesn't mean it's a GUI.
eg. telecomms
Right. But if you read carefully, I used the words "like portable
GUI's" to give a nonexclusive example of an important, if not the most
important, area of application for event based programming. Your
example "telecomms" is another important area. That doesn't make GUIs
any less valid though ;-)

There's a reason, a std::event does not exist. The current standard
language does not allow you to portably do anything useful with events.
Period. You do have input and output streams, that's it. These can be
handled without events and easier. You need to use external libraries
and/or system specific headers for events to become useful in C++.

If you want the "batteries included" you need to use a different
language. Perl, Python, Java, Tcl/TK all of them are good choices in
that sense. C/C++ needs its external libraries.

Greets, FJK

Nov 3 '06 #4


On Nov 3, 9:56 am, "F.J.K." <felix.koeh...@ gmail.comwrote:
Nick Keighley wrote:
F.J.K. wrote:
>AzizMandarwrot e:
**** original post reinserted *********
>C++ Event Coding Questions
>I have done some simple programs in C++ and read a lot of good C++
>books (Including The C++ Programing Language, and C++ Primer) I am
>trying to understand and implement an Event based program and Message
>system. I have a very basic event engine that I'm feeling works a bit
>backwards. I'm looking for documents, source code, and books that may
>help me better understand how to implement this type of code. I am not
>a student and this is not homework, just a hobby at the moment.
>I have a few requirements that are making my search difficult.
>1. I'm trying to develop some cross platform programming skills so I
>want the code to be as generic as possible. (No MFC)
>2. I'm happy to use the STL but no other external libraries
STL is not an external library. Its a standardised part of a conforming
C++ implementation.
>3. I am coding this on a Linux Box but that should not matter because
>of point 1
>4. Simpler is better. I understand and am able to read most code and
>have many samples but they are very poorly documented and are so
>ingrained with some external framework (like MFC) that I am having a
>bear of a time trying to make heads or tails of it.
>5. I have a very archaic but working garbage collector and memory
>management system. After I get this all figured out I'll be happy to
>let you all rip it to shreds and tell me how evil and silly I am. (It's
>creative but not necessarily in a good way)
>6. I'm not using threads. I hear that they are not dependable for
>execution speed and time and can be problematic and in many cases are
>unnecessary.
You are usinllg the word "difficult" in a rather euphemistic way.
Events are neither part of the C++ language, nor of the STL. This means
you'll either grab your events directly from your OS, which is not
portable. Or you are using a portable external framework, which is not
standard sustained any more.
or roll your own. An event can simply be a class.Sure. But where's the point? You can define pretty much anything as a
class. But events as general data structures are of rather limited use,
unless you want to respond to external triggers. In this case, you'll
need to interface the external "trigger-giving" software-layer. This
interface is not defined by the C++ language, you'll have to either use
abstraction libraries or use nonstandard constructs. Which is what the
OP wanted to avoid.

IMHO events/messages only make sense in the context of asynchronous
communication. Which again, is not part of the standard (yet, see
boost::asio)."P ure" C++ programs to my knowledge can only communicate
synchronously.


There is no such thing as "pure language
cross plattform event programming Skillz" in C++.
Let's face it, the requirements you are describing show one thing very
clearly. You are concerned about productivity, ease of use and
portability, as opposed to MIPS or FLOPS. C++ should not be your weapon
of choice. Consider using a language that actually focusses on things
like portable GUI's, like Tcl/TK, Python/TK, Ruby or even evil Java.
Part of being a good C++ programmer is knowing when NOT to use C++ ;-)
um. I never saw the word "GUI" in his post. He said he was interested
in
an event or message driven system. That doesn't mean it's a GUI.
eg. telecommsRight. But if you read carefully, I used the words "like portable
GUI's" to give a nonexclusive example of an important, if not the most
important, area of application for event based programming. Your
example "telecomms" is another important area. That doesn't make GUIs
any less valid though ;-)

There's a reason, a std::event does not exist. The current standard
language does not allow you to portably do anything useful with events.
Period. You do have input and output streams, that's it. These can be
handled without events and easier. You need to use external libraries
and/or system specific headers for events to become useful in C++.

If you want the "batteries included" you need to use a different
language. Perl, Python, Java, Tcl/TK all of them are good choices in
that sense. C/C++ needs its external libraries.

Greets, FJK
If you have a copy of The C++ Programming Language 3rd Edition please
check out Chapter 12 Problem 11 (I think the only dificulty 5 excersise
in the book)

This is what I am looking for more information on. I got the Task.h
from Stroustrup and most of the concept is abstract classes and
containers. I've made some simple working event programs but I know
there is more out there. Event Driven programming is more than
multithreaded MFC and GUI code. I'm not looking for tools or code that
will use events I want to write an event driven engine. The concept of
Event driven code is that the event can interupt the code at any time
and many languages and tools let you program in a seemingly
asynchronous way. However at some level it's all synchronous. I want
to write a Synchronous Event Engine.

My goal is to write an Event/message engine that will be:
1. Easy to document and debug (Primary advantages of OO programing)
2. fast (C/C++ advantages)
3. Platform independant (C/C++ advantages)

Why? Fun and learning

What use would it be? OS design, real time monitoring or
communications , entertainment applications(ga mes).

To get any of these to run at an acceptable speed I will most likely
have to use a lot of non-OO code (abstract classes have a tendency to
slow down the main loop because of the extra pointer calls) but that
again is a great advantage of C++ (You don't have to use OO code when
you don't need it) C++ is not C with OOP.

I have a decent amount of C examples but I know a lot of people use C++
to do this as well. But most of what I have seen is either proprietary
code (MFC) or C with OOP code (someone who added abstract classes to a
C concept but sacrifices type safety, uses 8 tons of Macros, and 2-3
pages of global variables).

one last thing
STL is not an external library. Its a standardized part of a conforming
C++ implementation.
STL: Standard Template Library. Requires #include statements because
it is EXTERNAL to C++. Therefor an external library. Yes it is a
standardized part of C++ implementation and controlled by a standards
comities but it is not a part of C++ just a very good set of
standardized templates and tools that are cross platform and type safe
for 'GOOD' C++ programming standards. If you don't have STL installed
on your computer you can't use it. But most computers with a C++
compiler have it (either installed by the compiler or the OS)

and no it doesn't have an Event class or GUI elements but it does have
good containers and tools for making the basic elements of these. As I
stated previously I am using an external I/O class and wrapping it into
an external class so I can keep the main engine completely independent
of this. Therefor I don't need any I/O specific code. (One of the
weakest part of C++ is the I/O but wrapped out of the main code I am
free to use the strengths of C++ and use external solutions for the
I/O)

Nov 9 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

55
5172
by: Jonas Smithson | last post by:
I've seen a few attractive multi-column sites whose geometry is based on pure CSS-P, but they're what you might call "code afficionado" sites, where the subject matter of the site is "coding practices." (One example of this is alistapart.com.) However, the project/development realities for small boutique sites are completely different from those of large commercial or institutional sites -- and I was curious to see what coding approaches...
4
2291
by: dotNetDave | last post by:
About three weeks ago I released the first .NET coding standards book titled "VSDN Tips & Tricks .NET Coding Standards". Here is what the famous author/ speaker Deborah Kurata says about it: "David McCarter once again demonstrates his knack for pulling best practices into one cohesive unit with his new book "VSDN Tips and Tricks: .NET Coding Standards". This book includes everything from how to set up your project to how to declare...
4
11033
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons to: if one is clicked, its corresponding information will become available on another document, if it's not clicked no information will be provided. If multiple buttons are clicked their information will available on the same document. I'm not...
3
10404
by: John Baro | last post by:
I need to implement an event to notify when a property has changed. Method 1. If I use a generic PropertyChanged event from System.ComponentModel then it will be raised for every property if 1 or more properties changed events are consumed. (more overhead, less coding) i.e PropertyChanged(object sender, PropertyChangedEventArgs e); Method 2.
2
1940
by: Wavemaker | last post by:
The canonical way of declaring delegates for events is to include a parameter representing the sender as well as an EventArgs derived class (or EventArgs itself) as the second parameter representing the data that accompanies the event. For example: public delegate void MessageReceivedHandler(object sender, MessageReceivedArgs e); // ...
17
10205
by: dan_williams | last post by:
I have the following test web page:- <html> <head><title>Test</title> <script language="Javascript"> <!-- function fnTR() { alert("TR"); }
5
3944
by: EManning | last post by:
I'm developing an unbound form with a series of questions on it. Each question is either a text box or an option group. I have coding in the AfterUpdate event of each control to highlight the next question to be answered, as a visual cue for the user. After the user has answered all questions, they click on the "Save" button to save their answers. My problem is that they have to click on "Save" twice because the AfterUpdate event...
3
4300
by: win | last post by:
when the cursor is in a textbox, only coding in the keydown event of the textbox triggered, the coding in the keydown event of the form does not triggered! Problem: I need to change a VB6 program to .Net. It uses function key(e.g. F12) to close the form, now i need to write the coding in the keydown event of all controls form. Can anyone help me? Thanks a lot.
1
108746
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back button anyways, if the user ventures away from your page then they wouldn't have this button at their disposal. The main reason people ask how to control or disable the back button is because they have a need to control sensitive (and/or) dynamic web...
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.