Click here to Skip to main content
15,893,668 members
Articles / Desktop Programming / ATL

2D Water Effect in WTL

Rate me:
Please Sign up or sign in to vote.
4.66/5 (22 votes)
28 Apr 2011CPOL4 min read 144.4K   3.7K   55  
A WTL control class to add water effect to an image, like what's done in the TortoiseSVN About dialog
// TortoiseSVN - a Windows shell extension for easy version control

// Copyright (C) 2009 - TortoiseSVN

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#pragma once

/**
 * A simplified analog to std::auto_ptr<> that encapsulates
 * an array allocated dynamically via new[].
 *
 * Use this where you could not use a std::auto_ptr<> (works
 * for single elements only) nor a std::vector<> (no guarantees
 * w.r.t. to internal organization, i.e. no access to mem buffer).
 */

template<class T>
class auto_buffer
{
private:

    T* buffer;

    /// no copy nor assignment

    auto_buffer(const auto_buffer&);
    auto_buffer& operator=(const auto_buffer&);

public:

	explicit auto_buffer (size_t size = 0) throw()
        : buffer (size == 0 ? NULL : new T[size])
	{	
	}

	~auto_buffer()
	{	
		delete[] buffer;
	}

	operator T*() const throw()
    {	
		return buffer;
	}

	operator void*() const throw()
    {	
		return buffer;
	}

    operator bool() const throw()
    {
        return buffer != NULL;
    }

	T* operator->() const throw()
	{
		return buffer;
    }

	T *get() const throw()
	{
		return buffer;
    }

    T* release() throw()
    {
        T* temp = buffer;
        buffer = NULL;
        return temp;
    }

    void reset (size_t newSize = 0)
    {
        delete[] buffer;
        buffer = (newSize == 0 ? NULL : new T[newSize]);
    }
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions