AaronCameron.net
I care not for your petty politics.
Not a Member? - Login or Create an Account
Sunday the 20th of May 2012 @ 04:13pm
Front Page Journal Projects Your Profile About
[]

LibN2L-4 Library Code Reference

Classes
Compounds
Files
Members
Method Index
Full Reference

cGuiACIf.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 Nova-2 Library (libN2L, or simply n2l) Game development C++ Library
00003 Copyright (C) 2003  Aaron Cameron
00004 
00005 This library is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU Lesser General Public
00007 License as published by the Free Software Foundation; either
00008 version 2.1 of the License, or (at your option) any later version.
00009 
00010 This library 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 GNU
00013 Lesser General Public License for more details.
00014 
00015 You should have received a copy of the GNU Lesser General Public
00016 License along with this library; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00018 
00019 A copy of the GNU Lesser General Public License has been provided with
00020 this library in the file 'COPYING'.
00021 
00022 Contact information for the author of this library has been provided
00023 with this library in the file 'AUTHOR'.
00024 ************************************************************************/
00025 #include "gui/cGuiACIf.h"
00026 
00027 #include "gui/cGuiSEFactory.h"
00028 
00029 /******************************************************************************/
00030 namespace n2l
00031 {
00032     /**************************************************************************/
00033     cGuiACIf::cGuiACIf()
00034     {
00035         init();
00036     }
00037 
00038     /**************************************************************************/
00039     cGuiACIf::cGuiACIf( const cDynVar &iDef )
00040     {
00041         init();
00042         load( iDef );
00043     }
00044 
00045     /**************************************************************************/
00046     cGuiACIf::~cGuiACIf()
00047     {
00048     }
00049 
00050     /**************************************************************************/
00051     void cGuiACIf::load( const cDynVar &iDef )
00052     {
00053         cGuiACInt::load( iDef );
00054 
00055         {
00056             const tString Op = strToLower(iDef["op"]);
00057             if (Op == "<") mOp = Op_LessThan;
00058             else if (Op == ">") mOp = Op_GreaterThan;
00059             else if (Op == "==") mOp = Op_Equals;
00060             else if (Op == "!=") mOp = Op_Not;
00061             else mOp = Op_Equals;
00062         }
00063 
00064         mKey = iDef.keyValueOr( "key", mKey );
00065         
00066         mValue = iDef.keyValueOr( "value", mValue );
00067 
00068         mAction = cGuiACFactory::current().load( iDef["action"] );
00069 
00070         if (iDef.keyExists("elseAction"))
00071             mElseAction = cGuiACFactory::current().load( iDef["elseAction"] );
00072     }
00073 
00074     /**************************************************************************/
00075     const tBool cGuiACIf::preserveAction() const
00076     {
00077         return mAction.isSet() || mElseAction.isSet();
00078     }
00079 
00080     /**************************************************************************/
00081     void cGuiACIf::execute( cGuiElement *const ioElement,
00082         const tGuiActionType iType, const cDynVar &iData )
00083     {
00084         tBool ok = true;
00085         switch (mOp) {
00086             case Op_Equals:
00087                 if (iData[mKey] != mValue) ok = false;
00088                 break;
00089 
00090             case Op_GreaterThan:
00091                 if (iData[mKey] <= mValue) ok = false;
00092                 break;
00093 
00094             case Op_LessThan:
00095                 if (iData[mKey] >= mValue) ok = false;
00096                 break;
00097 
00098             case Op_Not:
00099                 if (iData[mKey] == mValue) ok = false;
00100                 break;
00101 
00102             default:
00103                 throw cOutOfBoundsException( "cGuiACIf::execute", "" );
00104         }
00105 
00106         if (ok) {
00107             if (!mAction.isSet()) return;
00108             mAction->execute( ioElement, iType, iData );
00109             if (!mAction->preserveAction()) mAction = 0;
00110         } else {
00111             if (!mElseAction.isSet()) return;
00112             mElseAction->execute( ioElement, iType, iData );
00113             if (!mElseAction->preserveAction()) mElseAction = 0;
00114         }
00115     }
00116 
00117     /**************************************************************************/
00118     const cAutoPtr<cGuiACInt> cGuiACIf::clone() const
00119     {
00120         cAutoPtr<cGuiACIf> newElement( new cGuiACIf );
00121         cloneInto( newElement );
00122         return newElement;
00123     }
00124 
00125     /**************************************************************************/
00126     void cGuiACIf::cloneInto( const cAutoPtr<cGuiACIf> &ioElement ) const
00127     {
00128         cGuiACInt::cloneInto( ioElement );
00129         ioElement->mOp = mOp;
00130         ioElement->mKey = mKey;
00131         ioElement->mValue = mValue;
00132 
00133         if (mAction.isSet())
00134             ioElement->mAction = mAction->clone();
00135         else
00136             ioElement->mAction = 0;
00137 
00138         if (mElseAction.isSet())
00139             ioElement->mElseAction = mElseAction->clone();
00140         else
00141             ioElement->mElseAction = 0;
00142     }
00143 
00144     /**************************************************************************/
00145     void cGuiACIf::init()
00146     {
00147         mOp = Op_Equals;
00148         mKey = "";
00149         mValue = true;
00150         lockPreserveAction( true );
00151     }
00152 
00153 }
©2012 Aaron Cameron