Vinzenz Feenstra’s WebLog

July 25, 2006

German Developers

by @ 6:44 pm. Filed under News, Code, Programming

I am now 14 month in a keystroke - collecting team and I have already collected More than 14 million keystrokes :)

Our team has already more than 78 Million strokes collected. :)
http://whatpulse.org/stats/teams/7250/

:P

Regards,
Vinzenz



July 4, 2006

GTKmm Tutorial Part 2

by @ 3:48 pm. Filed under Code, Articles, GTKmm, C++, Programming

Hi,

Part two of my german GTKmm Tutorial can be found here

Regards,

Vinzenz



Tags: , , , , ,

July 1, 2006

C++ Container Clean Help Function

by @ 1:39 am. Filed under Code, C++, Programming

#include <cstdlib>
#include <string>
#include <iostream>
#include <vector>
#include <list>
#include <set>
namespace container_utils
{
    namespace helper
    {
        template < typename T >
        struct isPointer
        {
            enum { Result = 0 };
            typedef T Type;
            typedef T* Pointer;
        };
 
        template< typename T>
        struct isPointer<T*>
        {
            enum { Result = 1 };
            typedef T Type;
            typedef T* Pointer;
        };
 
        template< class Container ,
        class Type = typename Container::value_type,
            bool Ptr = isPointer<Type>::Result
        >
        struct container_cleanup
        {
            container_cleanup(Container & cont)
            {
                cont.clear(); // erasing all elements
            }
        };
 
        template< class Container ,
        class Type
        >
        struct container_cleanup<Container,Type,true>
        {
            container_cleanup( Container & cont)
            {
                typename Container::iterator it;
                for (it = cont.begin(); it != cont.end(); ++it)
                    delete *it;
                cont.clear(); // erasing all elements
            }
        };
    } // namespace container_utils::helper
 
    /** This is the function will be called by us
    * It will be decided at compile time which clear type will be used
    */
    template < class Container >
        void clean( Container & cont )
    {
        helper::container_cleanup<Container> tmp(cont);
    }
} //namespace container_utils
 
 
struct A
{
    A()
    {
        std::cout << “A Constructed” << std::endl;
    }
    ~A()
    {
        std::cout << “A Destructed “ << std::endl;
    }
};
struct B
{
    static int num;
    int value;
    B()
    {
        std::cout << “B Constructed” << std::endl;
        value = ++num;
    }
    ~B()
    {
        std::cout << “B Destructed “ << std::endl;
    }
    bool operator< ( B const & rhs ) const
    {
        return this->value < rhs.value;
    }
};
int B::num = 0;
 
int main()
{
    // Test mit std::list<>
    std::list<B> a_list;
 
    for(unsigned i = 0; i < 10 ; ++i)
        a_list.push_back(B());
 
    container_utils::clean(a_list);
 
    std::cout << “############################################” << std::endl;
    // Test mit std::set<>
    std::set<B> a_set;
    for(unsigned i = 0; i < 10 ; ++i)
        a_set.insert(B());
 
    container_utils::clean(a_set);
 
    std::cout << “############################################” << std::endl;
    // Test mit std::vector<>
    std::vector<A*> vec_ptr;
    for(unsigned i = 0; i < 10 ; ++i)
        vec_ptr.push_back(new A);
 
    container_utils::clean(vec_ptr);
 
    std::cout << “############################################” << std::endl;
}
 
 

Download this code: container_clean.cpp



C++ Container Choice Image

by @ 12:41 am. Filed under C++, Programming

C++ Container Choice helper

Thanks to http://www.linuxsoftware.co.nz for providing such a helpful image for all C++ programmers :)



archives:

January 2009
M T W T F S S
« Mar    
 1234
567891011
12131415161718
19202122232425
262728293031  

internal links:

categories:

Search

other:

Advertisement