irr_ptr
irr_ptr
Hey.
Just a thing I am using to manage reference-counted Irrlicht objects.
It's a small smartpointer class which caries about deletion, copy + move semantics and therefore adds exception safety and safes you from remembering to call grab + drop directly.
http://pastebin.com/NjiEaHA3
Nothing special, but maybe there are people out there, which didn't wrap it yet.
Regards,
Ethon
Just a thing I am using to manage reference-counted Irrlicht objects.
It's a small smartpointer class which caries about deletion, copy + move semantics and therefore adds exception safety and safes you from remembering to call grab + drop directly.
http://pastebin.com/NjiEaHA3
Nothing special, but maybe there are people out there, which didn't wrap it yet.
Regards,
Ethon
Last edited by Ethon on Sun Apr 08, 2012 3:53 pm, edited 1 time in total.
Re: irr_ptr
There is something to do this in irrlicht -
http://irrlicht.sourceforge.net/docu/cl ... unted.html
I'm not sure i your class differ so much maybe do it as an extension to IReferenceCounted
http://irrlicht.sourceforge.net/docu/cl ... unted.html
I'm not sure i your class differ so much maybe do it as an extension to IReferenceCounted
Re: irr_ptr
Jup, it's a RAII wrapper around IReferenceCounted with an STL-Smartpointer adapted style.
Re: irr_ptr
It seems you are missing tests if you assign the pointer to itself as well as if you assign that irr_ptr to itself. For example you drop the old pointer before you grab a new one - if it's the same pointer and this is the last reference you just killed your pointer.
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
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Re: irr_ptr
I didn't wrap it.. I made a game engine, or making. I simply ripped off reference counter and added it to my engine which I plan to rewrite. Now you've provided some code I can use to expand, appreciated!
Re: irr_ptr
Code: Select all
irr_ptr<element_type>& operator=(irr_ptr<element_type>&& other)
{
drop();
m_ptr = other.m_ptr();
other.m_ptr = 0;
}
Re: irr_ptr
Yeah, I know.
Just in case people don't know how to fix it, I fixed it. New version uploaded.
http://pastebin.com/NjiEaHA3
Just in case people don't know how to fix it, I fixed it. New version uploaded.
http://pastebin.com/NjiEaHA3
Re: irr_ptr
I'm guessing how many irr_ptr will be posted in future
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
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
Re: irr_ptr
Well, I think I was the first one, so don't blame me for another one.REDDemon wrote:I'm guessing how many irr_ptr will be posted in future
Re: irr_ptr
I can understand if there are no similiar snippets in the same page anyway nice snippet. Is always nice to see 100+1 different ways for doing almost the same thing.
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
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me
-
- Competition winner
- Posts: 688
- Joined: Mon Sep 10, 2012 8:51 am
Re: irr_ptr
I had a look at the code. I'm thinking this isn't going to work for things you get from the engine that you aren't supposed to drop (despite the fact that they inherit IReferenceCounted) - For example, images and things loaded from file - unless the first pointer used to store them is not of this pointer type.
Otherwise nice work.
EDIT: It'd be nice if there was a "quiet drop" - some way of setting the pointer to null without deleting the data.
Otherwise nice work.
EDIT: It'd be nice if there was a "quiet drop" - some way of setting the pointer to null without deleting the data.
Re: irr_ptr
I'm considering a new type of "smart pointer". maybe i'll post the snippet. nor boost or other frameworks have this so probably is useless xD
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
Real value in social networks is not about "increasing" number of followers, but about getting in touch with Amazing people.
- by Me