///////////////////////////////////////////////////////////////////////////////////////////
// ActionMap.cpp
//
//  Implementation of the ActionMap class, which handles DirectInput action maps.
//
//  ActionMap is a typed specialisation of System.Collections.CollectionBase, being a
// list of ActionMap.Entry objects.

#include "StdAfx.h"
#include "ActionMap.h"

namespace Sunlight
{
    namespace DirectX
    {
        namespace Input
        {
            ActionMap::Entry::Entry() : 
                ID(0), 
                Semantic(Actions::None), 
                Name(NULL)
            {
            }

            ActionMap::Entry::Entry(int nID, Actions nSemantic, String *pName) :
                ID(nID),
                Semantic(nSemantic),
                Name(pName)
            {
            }

            ActionMap::ActionMap(void)
            {
            }

            ActionMap::~ActionMap(void)
            {
            }

            // Add a new entry to this action map.
            void ActionMap::Add(Entry *EntryObject)
            {
                List->Add(EntryObject);
            }

            // Remove a numbered entry from this action map.
            void ActionMap::Remove(int index)
            {
                // Check to see if there is an Entry at the supplied index.
                if ((index > (Count - 1)) || (index < 0))
                    throw new ArgumentOutOfRangeException(S"index");

                List->RemoveAt(index);
            }

            // Look up a numbered entry from this action map.
            ActionMap::Entry *ActionMap::Item(int index)
            {
#ifdef __DEBUG
                // __try_cast will throw an exception in the unlikely event
                //  that a non-Entry Object has entered the list.
                return __try_cast<Entry *>(List->get_Item(index));
#else
                return static_cast<Entry *>(List->get_Item(index));
#endif
            }
        }
    }
}