ConsoleRuleFnIAdapter.cpp

Go to the documentation of this file.
00001 ////////////////////////////////////////////////////////////////////////////////
00002 //    Scorched3D (c) 2000-2009
00003 //
00004 //    This file is part of Scorched3D.
00005 //
00006 //    Scorched3D is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    Scorched3D is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with Scorched3D; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 ////////////////////////////////////////////////////////////////////////////////
00020 
00021 #include <common/Defines.h>
00022 #include <console/Console.h>
00023 #include <console/ConsoleRuleFnIAdapter.h>
00024 
00025 ConsoleRuleFnIBooleanAdapter::ConsoleRuleFnIBooleanAdapter(const char *name, bool &param) : 
00026         name_(name), param_(param),
00027         readRule_(0), writeRule_(0)
00028 {
00029         readRule_ = new ConsoleRuleFn(name, this, ConsoleRuleTypeBoolean, false);
00030         writeRule_ = new ConsoleRuleFn(name, this, ConsoleRuleTypeBoolean, true);
00031         Console::instance()->addRule(readRule_);
00032         Console::instance()->addRule(writeRule_);
00033 }
00034 
00035 ConsoleRuleFnIBooleanAdapter::~ConsoleRuleFnIBooleanAdapter()
00036 {
00037         Console::instance()->removeRule(readRule_);
00038         Console::instance()->removeRule(writeRule_);
00039         delete readRule_;
00040         delete writeRule_;
00041 }
00042 
00043 bool ConsoleRuleFnIBooleanAdapter::getBoolParam(const char *name)
00044 {
00045         DIALOG_ASSERT(name_ == name);
00046         return param_;
00047 }
00048 
00049 void ConsoleRuleFnIBooleanAdapter::setBoolParam(const char *name, bool value)
00050 {
00051         DIALOG_ASSERT(name_ == name);
00052         param_ = value;
00053 }
00054 
00055 ConsoleRuleFnINumberAdapter::ConsoleRuleFnINumberAdapter(const char *name, float &param) : 
00056         name_(name), param_(param),
00057         readRule_(0), writeRule_(0)
00058 {
00059         readRule_ = new ConsoleRuleFn(name, this, ConsoleRuleTypeNumber, false);
00060         writeRule_ = new ConsoleRuleFn(name, this, ConsoleRuleTypeNumber, true);
00061         Console::instance()->addRule(readRule_);
00062         Console::instance()->addRule(writeRule_);
00063 }
00064 
00065 ConsoleRuleFnINumberAdapter::~ConsoleRuleFnINumberAdapter()
00066 {
00067         Console::instance()->removeRule(readRule_);
00068         Console::instance()->removeRule(writeRule_);
00069         delete readRule_;
00070         delete writeRule_;
00071 }
00072 
00073 float ConsoleRuleFnINumberAdapter::getNumberParam(const char *name)
00074 {
00075         DIALOG_ASSERT(name_ == name);
00076         return param_;
00077 }
00078 
00079 void ConsoleRuleFnINumberAdapter::setNumberParam(const char *name, float value)
00080 {
00081         DIALOG_ASSERT(name_ == name);
00082         param_ = value;
00083 }
00084 
00085 ConsoleRuleFnIOptionsAdapter::ConsoleRuleFnIOptionsAdapter(OptionEntry &entry, bool write) :
00086         entry_(entry),
00087         readRule_(0), writeRule_(0)
00088 {
00089         ConsoleRuleType type = ConsoleRuleTypeNone;
00090         switch (entry.getEntryType())
00091         {
00092                 case OptionEntry::OptionEntryEnumType:
00093                 case OptionEntry::OptionEntryIntType:
00094                 case OptionEntry::OptionEntryBoundedIntType:
00095                 case OptionEntry::OptionEntryFloatType:
00096                 case OptionEntry::OptionEntryFixedType:
00097                         type = ConsoleRuleTypeNumber;
00098                 break;
00099                 case OptionEntry::OptionEntryVectorType:
00100                 case OptionEntry::OptionEntryStringEnumType:
00101                 case OptionEntry::OptionEntryStringType:
00102                 case OptionEntry::OptionEntryTextType:
00103                         type = ConsoleRuleTypeString;
00104                 break;
00105                 case OptionEntry::OptionEntryBoolType:
00106                         type = ConsoleRuleTypeBoolean;
00107                 break;
00108                 default:
00109                         DIALOG_ASSERT(0);
00110                 break;
00111         }
00112 
00113         readRule_ = new ConsoleRuleFn(entry.getName(), this, type, false);
00114         Console::instance()->addRule(readRule_);
00115         if (write) 
00116         {
00117                 writeRule_ = new ConsoleRuleFn(entry.getName(), this, type, true);
00118                 Console::instance()->addRule(writeRule_);
00119         }
00120 }
00121 
00122 ConsoleRuleFnIOptionsAdapter::~ConsoleRuleFnIOptionsAdapter()
00123 {
00124         if (readRule_)
00125         {
00126                 Console::instance()->removeRule(readRule_);
00127                 delete readRule_;
00128         }
00129         if (writeRule_)
00130         {
00131                 Console::instance()->removeRule(writeRule_);
00132                 delete writeRule_;
00133         }
00134 }
00135 
00136 bool ConsoleRuleFnIOptionsAdapter::getBoolParam(const char *name)
00137 {
00138         return ((OptionEntryBool &) entry_).getValue();
00139 }
00140 
00141 void ConsoleRuleFnIOptionsAdapter::setBoolParam(const char *name, bool value)
00142 {
00143         ((OptionEntryBool &) entry_).setValue(value);
00144 }
00145 
00146 float ConsoleRuleFnIOptionsAdapter::getNumberParam(const char *name)
00147 {
00148         if (entry_.getEntryType() == OptionEntry::OptionEntryIntType)
00149         {
00150                 return (float) (((OptionEntryInt &) entry_).getValue());
00151         }
00152         else if (entry_.getEntryType() == OptionEntry::OptionEntryFloatType)
00153         {
00154                 return ((OptionEntryFloat &) entry_).getValue();
00155         }
00156         else if (entry_.getEntryType() == OptionEntry::OptionEntryFixedType)
00157         {
00158                 return ((OptionEntryFixed&) entry_).getValue().asFloat();
00159         }
00160         return -99.99f;
00161 }
00162 
00163 void  ConsoleRuleFnIOptionsAdapter::setNumberParam(const char *name, float value)
00164 {
00165         if (entry_.getEntryType() == OptionEntry::OptionEntryIntType)
00166         {
00167                 ((OptionEntryInt &) entry_).setValue(int(value));
00168         }
00169         else if (entry_.getEntryType() == OptionEntry::OptionEntryFloatType)
00170         {
00171                 ((OptionEntryFloat &) entry_).setValue(value);
00172         }
00173         else if (entry_.getEntryType() == OptionEntry::OptionEntryFixedType)
00174         {
00175                 ((OptionEntryFixed &) entry_).setValue(fixed(int(value)));
00176         }
00177 }
00178 
00179 const char *ConsoleRuleFnIOptionsAdapter::getStringParam(const char *name)
00180 {
00181         return ((OptionEntryString &) entry_).getValue();
00182 }
00183 
00184 void ConsoleRuleFnIOptionsAdapter::setStringParam(const char *name, const char *value)
00185 {
00186         ((OptionEntryString &) entry_).setValue(value);
00187 }

Generated on Mon Feb 16 15:14:37 2009 for Scorched3D by  doxygen 1.5.3