Game Development Community

Gui Addition efficiency question

by Nathan Huffman · in Torque Game Engine · 05/28/2006 (1:01 am) · 1 replies

I'm rather new to C++, so I was wondering if what I did was 'sane' without 'going overboard' or creating security flaws... somehow...

I wanted to make sure all input into one of my GuiTextEditCtrl was only Alphanumeric A-Z 0-9

So I opened up the C++ code for this control and added a new persistance field which is boolean and toggles an mAlnumShield

Later down the code in the onkeydown function where it typically adds what you typed, or executes the correct command if you did a CTRL C or whatever, I found a good location and pasted

if ( mAlnumShield )
	  {
		  if ( !isalnum(event.ascii) )
		  {
			  return true;
		  }
	  }

Then in the GuiTextEditCtrl's includes I added ctype.h to have functionality with isalnum()

And it works just fine.

However, I'm happy that it works but is this inefficent? Is my executable now compiling with loads of extra code it doesn't need because of that new include? Am I permitted to use that new include in my project? Was there an easier way to do this?

Any input from someone who knows this stuff is appreciated :)

thanks.

#1
05/28/2006 (5:42 am)
Quote:
However, I'm happy that it works but is this inefficent?
If you are happy with how it works I would say its effiecent enough.

Quote:
Is my executable now compiling with loads of extra code it doesn't need because of that new include?
Most likely not. Did your exe get too big? My guess is that you can't even tell the difference.

Quote:
Am I permitted to use that new include in my project?
Of course!

Quote:
Was there an easier way to do this?
I don't know. Your solution seems pretty straight forward for your need.