AutoPtr

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
CuteAlien
Admin
Posts: 9670
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: AutoPtr

Post by CuteAlien »

Thanks for posting the FAQ. Curiously browsed over it and found out that I'm using the ## feature wrong (the other case besides compile directives where macros are still necessary). Never knew it needs another macro to wrap that...
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
REDDemon
Developer
Posts: 1044
Joined: Tue Aug 31, 2010 8:06 pm
Location: Genova (Italy)

Re: AutoPtr

Post by REDDemon »

randomMesh wrote: No. Clean and maintainable C++ code doesn't use any macros.
Please do yourself a favour and read the C++ FAQ
disagree, and anyway the FAQS example shows why a macro doesn't work and why you should not use macros, but don't say anything about what I did (so just simple code expansion for save typing) wich is done also in other libraries and suggested in many books (books that usually people reccomends if you want book names in PM just tell so that you can verify. Most of them are free e-books so you can check yourself without having to buy them) ^^ and makes code more readable and clean:

few examples:
http://sparkengine.svn.sourceforge.net/ ... iew=markup
http://poco.svn.sourceforge.net/viewvc/ ... iew=markup

What I do (probably wrong) is not to read theory but is to learn from what others did before and from my mistakes, (started with Irrlicht few years ago) and AFTER that I read theory and compare with example's from others. If I see examples of when and where macros are usefull, why avoiding them in similiar situations? (ok take my snippet as bad example if you want but reinventing the wheel is always usefull, at least for learning. )
Junior Irrlicht Developer.
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
CuteAlien
Admin
Posts: 9670
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: AutoPtr

Post by CuteAlien »

They did both add prefixes to reduce the chance of name-collisions.

Also still check the FAQ, it will at least show you (when clicking through the evil examples) how to make your macro at least safer to use.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
fabs
Posts: 18
Joined: Sun Jun 25, 2006 1:41 pm

Re: AutoPtr

Post by fabs »

I suggest just using boost headers and intrusive_ptr. All you need to do is add the following to your main header file:

Code: Select all

#include <boost/intrusive_ptr.hpp>
 
namespace boost
{
        static inline void intrusive_ptr_add_ref(irr::IReferenceCounted *p)
        {
                p->grab();
        }
        static inline void intrusive_ptr_release(irr::IReferenceCounted *p)
        {
                p->drop();
        }
};
 
Makes it pretty easy doesn't it? :D Just remember that if you store irrlicht objects in an intrusive_ptr created from functions like createXXXX, you need to call drop() once to make the count correct, because the intrusive_ptr will grab it.
Post Reply