List:MySQL++« Previous MessageNext Message »
From:Alex Burton Date:August 15 2007 8:42am
Subject:Re: Eyeballs needed on new reference counted pointer template
View as plain text  
Warren,

Looks all right - haven't tested it.
Slight improvements might be made by only testing counted_ to know if  
it is a non null pointer instead of checking ref_ is set all the time.
Like below.
Untested - but if it doesn't work you get the idea.
As mentioned by others it is probably not exception safe in assign(T  
* c) this is best handled using the .swap idiom that is in boost  
pointers and standard library.

Alex
	void assign(T* c)
	{
		detach();

		counted_ = c;
		if (c) {
			refs_ = new size_t(1);
		}
	}

	void assign(const ThisType& other)
	{
		detach();
		
		counted_ = other.counted_
		if (counted_ ) {
			refs_ = other.refs_;
			++(*refs_);
		}
	}
	void detach()
	{
		if (counted_)
		 if (--(*refs_) == 0))
		{
			delete counted_;
			delete refs_;
		}
	}

Thread
Eyeballs needed on new reference counted pointer templateWarren Young15 Aug
  • Re: Eyeballs needed on new reference counted pointer templateChris Frey15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
  • Re: Eyeballs needed on new reference counted pointer templateAlex Burton15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
  • Re: Eyeballs needed on new reference counted pointer templateJoseph Artsimovich15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateJonathan Wakely16 Aug
      • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
        • Re: Eyeballs needed on new reference counted pointer templateJonathan Wakely18 Aug
          • Re: Eyeballs needed on new reference counted pointer templateJonathan Wakely18 Aug
          • Re: Eyeballs needed on new reference counted pointer templateWarren Young20 Aug
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
  • RE: Eyeballs needed on new reference counted pointer templateJoel Fielder15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
  • Re: Eyeballs needed on new reference counted pointer templateRobert Mecklenburg15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateGraham Reitz15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateGraham Reitz15 Aug
    • Re: Eyeballs needed on new reference counted pointer templateWarren Young16 Aug
  • Re: Eyeballs needed on new reference counted pointer templateGraham Reitz15 Aug