Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

SpellList.h

00001 /*
00002  * SpellList.h -- class declaration for spell lists
00003  * Copyright (C) 2003  Eric Lemings <elemings@users.sourceforge.net>
00004  *
00005  * This software is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This software is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this software; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00018  * 02111-1307, USA
00019  *
00020  * RCS: $Id: SpellList.h,v 1.2 2003/04/15 16:58:47 elemings Exp $
00021  */
00022 
00023 #ifdef __cplusplus
00024 
00025 #  ifndef OGS_MAGIC_SPELL_LIST_H
00026 #    define OGS_MAGIC_SPELL_LIST_H
00027 
00028 #    include <map>
00029 
00030 #    include <ogs/support/Class.h>
00031 #    include <ogs/magic/Namespace.h>
00032 #    include <ogs/magic/Spell.h>
00033 
00034 OGS_BEGIN_MAGIC_NAMESPACE
00035 
00036 using ogs::support::Class;
00037 
00044 class SpellList {
00045   public:
00046     template <class CasterClass, class SpellClass>
00047     int getLevel () const;
00048 
00049     template <class CasterClass, class SpellClass>
00050     int getLevel (const SpellClass& spell) const;
00051 
00052   protected:
00057     typedef std::map<Class, int> SpellMap;
00058 
00063     typedef std::map<Class, SpellMap> CasterMap;
00064 
00070     CasterMap casterMap;
00071 
00072     SpellList ();
00073 
00074   private:
00075     template <class CasterClass>
00076     void checkCasterClass ();
00077 };
00078 
00082 inline SpellList::SpellList ():
00083   casterMap () {
00084   // empty constructor body
00085 }
00086 
00098 template <class CasterClass, class SpellClass>
00099 int SpellList::getLevel () const {
00100 
00101   // Throw bad_cast if casterClass is not derived from CClass or Domain.
00102   checkCasterClass<CasterClass> ();
00103 
00104   // Throw bad_cast if spellClass is not derived from Spell.
00105   SpellClass spell;
00106   dynamic_cast<Spell&> (spell);
00107 
00108   Class casterClass = Class::getClass<CasterClass> ();
00109   CasterMap::iterator casterItor = casterMap.find (casterClass);
00110   if (casterItor == casterMap.end ()) {
00111     //throw NotFound ();
00112   }
00113 
00114   SpellMap spellMap = *casterItor;
00115   SpellMap::iterator spellItor = spellMap.find (spellClass);
00116   if (spellItor == spellMap.end ()) {
00117     //throw NotFound ();
00118   }
00119 
00120   return (*spellItor);
00121 }
00122 
00123 template <class CasterClass>
00124 void SpellList::checkCasterClass () {
00125   // TODO: Implement.
00126 }
00127 
00142 template <class CasterClass, class SpellClass>
00143 int SpellList::getLevel (const SpellClass& spell) const {
00144   int spellLevel = getLevel<CasterClass, SpellClass> ();
00145   //spelLevel += spell.getMetamagicSlots ();
00146   return (spellLevel);
00147 }
00148 
00149 OGS_END_MAGIC_NAMESPACE
00150 
00151 #  endif /* !defined OGS_MAGIC_SPELL_LIST_H */
00152 
00153 #endif /* defined __cplusplus */
00154 

Generated on Sun Apr 20 03:36:26 2003 for Open Gaming System (OGS) by doxygen1.3