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

Modifiers.h

00001 /*
00002  * Modifiers.h -- class interface for lists of modifiers
00003  * Copyright (C) 2002  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: Modifiers.h,v 1.3 2003/04/13 05:25:51 elemings Exp $
00021  */
00022 
00023 #ifdef __cplusplus
00024 
00025 #  ifndef OGS_CORE_MODIFIERS_H
00026 #    define OGS_CORE_MODIFIERS_H
00027 
00028 #    include <cassert>
00029 #    include <list>
00030 
00031 #    include <ogs/Support.h>
00032 #    include <ogs/core/Modifier.h>
00033 #    include <ogs/core/Namespace.h>
00034 
00035 OGS_BEGIN_CORE_NAMESPACE
00036 
00048 class Modifiers: public std::list<Modifier*>,
00049                  public ogs::support::Object,
00050                  private ogs::support::Observer {
00051   public:
00052     class Event;
00053 
00054     Modifiers ();
00055 
00056     void addModifier (Modifier& modifier);
00057     void removeModifier (Modifier& modifier);
00058 
00059     Modifier::Value getValue () const;
00060 
00061   private:
00062     Modifier::Value _value;
00063 
00064     void handleEvent (ogs::support::Event& event);
00065 };
00066 
00070 inline
00071 Modifiers::Modifiers ():
00072   _value (0) {
00073   // empty constructor body
00074 }
00075 
00081 inline Modifier::Value
00082 Modifiers::getValue () const {
00083   return (this->_value);
00084 }
00085 
00094 class Modifiers::Event: public ogs::support::Event {
00095   public:
00097     enum Type {
00099       ADDED,
00101       REMOVED,
00103       CHANGED
00104     };
00105 
00106     Modifier::Value getPreviousValue () const;
00107     Type getType () const;
00108     Modifier& getModifier () const;
00109 
00110   protected:
00111     Event (Modifiers& modifiers, Type type, Modifier& modifier);
00112 
00113     friend void Modifiers::addModifier (Modifier& modifier);
00114     friend void Modifiers::removeModifier (Modifier& modifier);
00115     friend void Modifiers::handleEvent (ogs::support::Event& event);
00116 
00117   private:
00118     Modifier::Value _value;
00119     Type _type;
00120     Modifier* _modifier;
00121 };
00122 
00130 inline
00131 Modifiers::Event::Event            (Modifiers& modifiers,
00132                                     Type type,
00133                                     Modifier& modifier):
00134   ogs::support::Event (modifiers),
00135   _value (modifiers.getValue ()),
00136   _type (type),
00137   _modifier (&modifier) {
00138   // empty constructor body
00139 }
00140 
00146 inline Modifier::Value
00147 Modifiers::Event::getPreviousValue () const {
00148   return (this->_value);
00149 }
00150 
00157 inline Modifiers::Event::Type
00158 Modifiers::Event::getType () const {
00159   return (this->_type);
00160 }
00161 
00168 inline Modifier&
00169 Modifiers::Event::getModifier () const {
00170   assert (this->_modifier != NULL);
00171   return (*(this->_modifier));
00172 }
00173 
00174 OGS_END_CORE_NAMESPACE
00175 
00176 #  endif /* !defined OGS_CORE_MODIFIERS_H */
00177 
00178 #endif /* defined __cplusplus */
00179 

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