I put togrether a dll that takes a load off of drawing animations in basic API.
http://queatrix.awardspace.com/index/
I'm not an master or expert programmer, so please, don't laugh.
But still give me your honest opinion.
I put togrether a dll that takes a load off of drawing animations in basic API.
http://queatrix.awardspace.com/index/
I'm not an master or expert programmer, so please, don't laugh.
But still give me your honest opinion.
"structer" is spelled "structure". And the "weather"s should be "whether"s.
You could probably add lots of constness and maybe overloaded functions.
Code:BOOL index::LoadFromFile(char file_name[]); Loads the bitmap file_name from the hard disk into your structer. BOOL index::LoadFromResource(HINSTANCE instance, char resource_name[]); Loads the bitmap resource_name from instance's program into your structer.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Thanks for the reply.
I'll fix the typos.
What are overload functions?
EDIT:
Also, what do you mean by "constness"?
Last edited by Queatrix; 09-14-2006 at 06:01 PM.
Overloaded functions are a C++ feature that allows you to have two functions with the same name but different signatures. They are not allowed in C, but I assume you don't want to retain C compatibility because you're using classes/namespaces. A function has a different signature if its parameters are different. (The return value doesn't count. If two functions have the same parameters but a different return value, they still have the same signatures.) This is valid C++:
It makes it easier to program, because you don't have to remember so many names.Code:void load_file(const char *fn) {} void load_file(string fn) {} void load_file(FILE *fp) {} void load_file(ifstream i) {}
By "constness" I meant that you should use the const keyword whenever possible. Making something const means that you won't modify it (if you try to the compiler will complain). The advantage of this is that you won't modify something you shouldn't and you can pass the function const and non-const objects. (You can't pass a const object to a function that takes a non-const parameter, because the function could potentially modify that object *1).
Another thing you might want is default arguments. When a function has a default argument, you can leave it out when you call the function, and that function's parameter will get the defualt value.
For more detailed explanations, try the tutorials or a C++ book. (Overloaded functions might be under "Polymorphism".)Code:void print_number(int number, char c = ' '); /* the default value goes only in the prototype */ void print_number(int number, char c) {}
*1 You can use a const_cast to discard constness, but that's for bad designs where someone didn't make something const that they should have; you can avoid this by putting const in in the first place.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Here's a program that demonstrates polymorphism (function overloading), default arguments, and const parameters:
Note: I have not compiled or testing the above program.Code:#include <iostream> #include <cstddef> void print_chars(char c = ' ', int number = 1); /* default parameters must be the last parameters in the function; you can't have a default parameter argument followed by a non-default parameter argument */ void print_long(const char *str, int number = 1); void print_chars(char c, int number) { for(int x = 0; x < number; x ++) { std::cout << c; } } void print_long(const char *str, int number) { size_t len = std::strlen(str); for(int x = 0; x < len; x ++) { print_chars(str[x], number); } } int main(void) { const char *version = "1.00"; /* since print_long takes a const parameter, this variable can be passed to it */ char greeting[] = "hello!"; print_chars(); /* prints " " */ print_chars('A'); /* prints "A" */ print_chars('A', 3); /* prints "AAA" */ print_str(version); /* prints "1.00" */ print_str(greeting); /* prints "hello!" */ print_str(greeting, 3) /* prints "hhheeelllooo!!!" */ return 0; }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
I think I see what you mean, you are saying I should turn:
into:Code:BOOL index::LoadFromFile(char file_name[]); BOOL index::LoadFromResource(HINSTANCE instance, char resource_name[]);
???Code:BOOL index::LoadImage(char file_name[]); BOOL index::LoadImage(HINSTANCE instance, char resource_name[]);
I will make those consts too.
EDIT:
Thanks for the example. (You posted it when I was posting.)
Last edited by Queatrix; 09-14-2006 at 06:36 PM.
Exactly. And you could probably provide default values for some arguments.
[edit] You don't need to make ordinary variables const, because the calling function won't care if the function modifies the value. But if the variable is a reference or a pointer or you're just not sure, you should probably make it const if you don't modify it. [/edit]Code:BOOL index::Animate(int play, BOOL re_play = TRUE);
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
And for a name;
- queatrixGraphics
- QGL (queatrix graphics library); already taken: http://www.google.ca/search?hl=en&q=qgl&meta=
- QSGL (queatrix simple graphics library); posssibly taken
- QVSGL (queatrix very simple graphics library); posssibly taken
- Something else . . . maybe you don't want to name it yet. But at least call it "library".
[edit] Here's a more extensive document on const: http://www.icce.rug.nl/documents/cpl...lus03.html#l35 [/edit]
Last edited by dwks; 09-14-2006 at 08:58 PM.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Thanks for the advice.Originally Posted by dwks
How's this? (Other than the name of course.)
http://queatrix.awardspace.com/index/
Better, although this is somewhat ambiguous:
[edit] And as I mentioned in a previous edit, you don't have to make non-pointer and non-reference arguments constant:The following functions ALL return TRUE or FALSE depending on their success.
If you do you still gain the advantage of the compiler reinforcing no modifications; but it can be called with a const argument either way. [/edit]Code:BOOL index::Animate(const int play, const BOOL re_play);
Last edited by dwks; 09-15-2006 at 09:21 PM.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
I have upgraded both the documentation and DLL it's self.
It now has a class called indexSound.
After comparing a simple program (with simultaneouse sounds and animations) without the DLL and with the DLL, the script size is SO much bigger. It defenitly serves it's purpose.
>> If you do you still gain the advantage of the compiler
>> reinforcing no modifications; but it can be
>> called with a const argument either way.
For some reason it wouldn't work unless I added the const to those after upgrading it.