GarethLewin.Com

Programming

Welcome to my programming page. I plan on putting coding snippets, tips, ideas, or anything related to programming here. Everything I put on here will be totally free for use; I'll work out a proper license soon, but for now, assume everything is placed in the public domain.

Visual Studio.net stupidity

I really need to put the following on a seperate page:

Visual Studio .NET 2003 is the environment that I have to work in. There are a lot of good things in the .NET programming stuff, including how much better the C++ compiler is.

The following list is the list of problems I have with the IDE itself, not with the programming languages or compilers. All of these issues are things that Microsoft made worse than Visual Studio 6. I'm not asking for new features, or anything like that, just for old stuff. I'm also not going to go into the BRIEF keyboard layout issue, as I don't use it.

Character Animation

A few links I saw go buy on the GD-Algo mailing list, and I'm putting them here so I can find them again in the future :)

http://grail.cs.washington.edu/projects/
http://www.cs.wisc.edu/graphics/Gallery/Kovar/

Singleton Class

Here is my singleton class, I really like it, but it's nothing ground breaking. The main reason I'm putting it here is to play with the program I use to syntax hi-light C++ code and so I can get the CSS stuff setup correctly. Sadly the tool doesn't generate fully compliant code, but I'll fix that and give a patch back to the guy that wrote it. Hmm, after looking at the resulting code, I think I might need to find a better tool :)


////////////////////////////////////////////////////////////////////////////////

/**
    Declare a class as a singleton.

\param  __class        Class name of the singleton

\remark
    This class sets Singleton<__class> as a friend class. We need this so that
    CreateInst() and DestroyInst() can use new and delete on the singleton class
    even tho they are declared protected or private.

*/
////////////////////////////////////////////////////////////////////////////////

#define DECLARESINGLETON(__class) friend class Singleton<__class>
 

////////////////////////////////////////////////////////////////////////////////

/**
    Singleton base class.

*/
////////////////////////////////////////////////////////////////////////////////

template <class _TDerivedClass> class Singleton
{
friend class Singleton<_TDerivedClass>;
private:
    static _TDerivedClass *ms_pInstance;
public:
    ////////////////////////////////////////////////////////////////////////////

    /**
        Get a pointer to the created instance.

    \return         Pointer to the created instance.

    \remark
        In debug builds this method will assert if the instance was not created. It
        is a logical error to call this on a non created instance.
    \sa
        CreateInst()
        RemoveInst()
        IsInstanced()

    */
    ////////////////////////////////////////////////////////////////////////////
    static _TDerivedClass *GetInst () 
    {
        ASSERT (ms_pInstance); return ms_pInstance;
    }

    ////////////////////////////////////////////////////////////////////////////
    /**
        Create the singleton Instance

    \return         <b>true</b> if the instance was created.<br>
                    <b>false</b> if the instance was already created or on error.

    \remark
        In debug build this function will assert if the instance was already created.
        It is a logical error to call this function more than once.

    \sa
        GetInst()
        DestroyInst()
        IsInstanced()

    */
    ////////////////////////////////////////////////////////////////////////////
    static bool    CreateInst    ()
    {
        // Make sure we are creating the first instance.

        ASSERT (!IsInstanced());

        // In release builds the assert will not happen, so return 

        // false if the instance exists.

        if (IsInstanced())
            return false;

        // Create the Instance

        ms_pInstance = new _TDerivedClass();

        return IsInstanced();
    }

    ////////////////////////////////////////////////////////////////////////////
    /**
        Destroy the singleton instance.

    \return         <b>true</b> if the instance was destroyed.<br>
                    <b>false</b> if the instance was not initialized before this 
                    method was called.

    \remark
        In debug builds this function will assert if the method was already destroyed 
        or never created. It is a logical error to call this function on a non-created
        instance.

    \sa
        CreateInst()
        GetInst()
        IsInstanced()

    */
    ////////////////////////////////////////////////////////////////////////////
    static bool    DestroyInst ()
    {
        // Make sure the instance was created.

        ASSERT (IsInstanced ());

        // In release builds, the above assert will not happen, so return false

        // if there is no instance.


        if (!IsInstanced ())
            return false;

        SAFE_DELETE (ms_pInstance);
        return true;
    }

    ////////////////////////////////////////////////////////////////////////////
    /**
        Query if the singleton instance has been created.

    \return         <b>true</b> if the singleton instance has been created.<br>
                    <b>false</b> if the singleton instance has not been created <br>

    \sa
        CreateInst()
        GetInst()
        DestroyInst()
    */
    ////////////////////////////////////////////////////////////////////////////
    static bool IsInstanced ()
    {
        return (0 != ms_pInstance);
    }
};

Programming related links

#winprog homepage Fluid Studios