Globals.cpp

Go to the documentation of this file.
00001 /************************************************************************
00002 * Verve                                                                 *
00003 * Copyright (C) 2004-2006                                               *
00004 * Tyler Streeter  tylerstreeter@gmail.com                               *
00005 * All rights reserved.                                                  *
00006 * Web: http://verve-agents.sourceforge.net                              *
00007 *                                                                       *
00008 * This library is free software; you can redistribute it and/or         *
00009 * modify it under the terms of EITHER:                                  *
00010 *   (1) The GNU Lesser General Public License as published by the Free  *
00011 *       Software Foundation; either version 2.1 of the License, or (at  *
00012 *       your option) any later version. The text of the GNU Lesser      *
00013 *       General Public License is included with this library in the     *
00014 *       file license-LGPL.txt.                                          *
00015 *   (2) The BSD-style license that is included with this library in     *
00016 *       the file license-BSD.txt.                                       *
00017 *                                                                       *
00018 * This library is distributed in the hope that it will be useful,       *
00019 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00020 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
00021 * license-LGPL.txt and license-BSD.txt for more details.                *
00022 ************************************************************************/
00023 
00024 #include "Globals.h"
00025 #include "external/tinyxml/tinyxml.h"
00026 
00027 namespace verve
00028 {
00029         namespace globals
00030         {
00031                 real VERVE_CALL getAttributeReal(const TiXmlNode* nodePtr, 
00032                         const std::string& name)
00033                 {
00034                         TiXmlElement* elementPtr = 
00035                                 const_cast<TiXmlNode*>(nodePtr)->ToElement();
00036                         double temp = 0;
00037 
00038                         if (NULL == elementPtr->Attribute(name.c_str(), &temp))
00039                         {
00040                                 VERVE_LOGGER("warning") << 
00041                                         "verve::globals::getAttributeReal: Element " 
00042                                         << nodePtr->Value() << " is missing attribute '" 
00043                                         << name << "'.  Parameter will be set to '0.0'." 
00044                                         << std::endl;
00045                                 return 0;
00046                         }
00047                         else
00048                         {
00049                                 return (real)temp;
00050                         }
00051                 }
00052 
00053                 int VERVE_CALL getAttributeInt(const TiXmlNode* nodePtr, 
00054                         const std::string& name)
00055                 {
00056                         TiXmlElement* elementPtr = 
00057                                 const_cast<TiXmlNode*>(nodePtr)->ToElement();
00058                         int temp = 0;
00059 
00060                         if (NULL == elementPtr->Attribute(name.c_str(), &temp))
00061                         {
00062                                 VERVE_LOGGER("warning") << 
00063                                         "verve::globals::getAttributeInt: Element " 
00064                                         << nodePtr->Value() << " is missing attribute '" 
00065                                         << name << "'.  Parameter will be set to '0'." 
00066                                         << std::endl;
00067                                 return 0;
00068                         }
00069                         else
00070                         {
00071                                 return temp;
00072                         }
00073                 }
00074 
00075                 bool VERVE_CALL getAttributeBool(const TiXmlNode* nodePtr, 
00076                         const std::string& name)
00077                 {
00078                         TiXmlElement* elementPtr = 
00079                                 const_cast<TiXmlNode*>(nodePtr)->ToElement();
00080                         const char* temp = elementPtr->Attribute(name.c_str());
00081 
00082                         if (NULL == temp)
00083                         {
00084                                 VERVE_LOGGER("warning") << 
00085                                         "verve::globals::getAttributeBool: Element " 
00086                                         << nodePtr->Value() << " is missing attribute '" 
00087                                         << name << "'.  Parameter will be set to 'false'." 
00088                                         << std::endl;
00089                                 return false;
00090                         }
00091                         else
00092                         {
00093                                 std::string value = temp;
00094                                 if ("true" == value || "1" == value)
00095                                 {
00096                                         return true;
00097                                 }
00098                                 else if ("false" == value || "0" == value)
00099                                 {
00100                                         return false;
00101                                 }
00102                                 else
00103                                 {
00104                                         VERVE_LOGGER("warning") << 
00105                                                 "verve::globals::getAttributeBool: Element " 
00106                                                 << nodePtr->Value() << " attribute '" << name 
00107                                                 << "' has an invalid value.  Possible " 
00108                                                 << "values are 'true', 'false', '1', and '0'.  "
00109                                                 << "Parameter will be set to 'false'." << std::endl;
00110                                         return false;
00111                                 }
00112                         }
00113                 }
00114 
00115                 std::string VERVE_CALL getAttributeString(const TiXmlNode* nodePtr, 
00116                         const std::string& name)
00117                 {
00118                         TiXmlElement* elementPtr = 
00119                                 const_cast<TiXmlNode*>(nodePtr)->ToElement();
00120                         const char* temp = elementPtr->Attribute(name.c_str());
00121 
00122                         if (NULL == temp)
00123                         {
00124                                 VERVE_LOGGER("warning") << 
00125                                         "verve::globals::getAttributeString: Element " 
00126                                         << nodePtr->Value() << " is missing attribute '" 
00127                                         << name << "'.  Parameter will be set to \"\"." 
00128                                         << std::endl;
00129                                 return "";
00130                         }
00131                         else
00132                         {
00133                                 return temp;
00134                         }
00135                 }
00136         }
00137 }

Generated on Tue Jan 24 21:46:37 2006 for Verve by  doxygen 1.4.6-NO