EnumDictionary.h

00001 //***************************************************************************************
00002 //
00003 // File supervisor: Crosswalk team
00004 //
00005 // Copyright 2008 Autodesk, Inc.  All rights reserved.
00006 // Use of this software is subject to the terms of the Autodesk license agreement
00007 // provided at the time of installation or download, or which otherwise accompanies
00008 // this software in either electronic or hard copy form.
00009 //
00010 //***************************************************************************************
00011 
00012 #ifndef __ENUMDICTIONNARY_H__
00013 #define __ENUMDICTIONNARY_H__
00014 
00015 #include <SIBCUtil.h>   // SI_Char, _SI_STRCMP
00016 
00017 #include "StrMap.h"     // StrMap
00018 
00047 template
00048 <
00049     class Enum,
00050     size_t size
00051 >
00052 class CEnumDictionary
00053 {
00054 public:
00056 
00071     inline CEnumDictionary( SI_Char const* * in_ppStringArray )
00072     {
00073         m_ppArray = in_ppStringArray;
00074     }
00075 
00076     ~CEnumDictionary()
00077     {
00078     }
00079 
00081 
00092     inline const SI_Char* ToString( Enum in_Value ) const
00093     {
00094         return (m_ppArray)[(size_t)in_Value];
00095     }
00096 
00098 
00114     inline SI_Bool ToEnum( Enum &out_rEnum, const SI_Char* in_pValue ) const
00115     {
00116         if ( !in_pValue )
00117             return SI_FALSE;
00118 
00119         for (int v=0;v<=size;v++)
00120         {
00121             if ( !_SI_STRCMP( m_ppArray[v], in_pValue ) )
00122             {
00123                 out_rEnum = (Enum)v;
00124                 return SI_TRUE;
00125             }
00126         }
00127         return SI_FALSE;
00128     }
00129 private:
00130     SI_Char const** m_ppArray;
00131 };
00132 
00133 #endif //__ENUMDICTIONNARY_H__