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

xmlvaluable.cpp

Go to the documentation of this file.
00001 //============================================================================= 
00002 //
00003 // XDFLengine library
00004 //
00005 //-----------------------------------------------------------------------------
00006 //  XMLVALUABLE.CPP
00007 //-----------------------------------------------------------------------------
00013 //_____________________________________________________________________________
00014 //
00015 //  Copyright (C) 2003 Guillaume Baurand. All Rights Reserved.
00016 //
00017 //  This file is part of the XDFLengine project.
00018 //
00019 //  The XDFLengine is free software; you can redistribute it and/or modify
00020 //  it under the terms of the GNU General Public License as published by
00021 //  the Free Software Foundation; either version 2 of the License, or
00022 //  (at your option) any later version.
00023 //
00024 //  This program is distributed in the hope that it will be useful,
00025 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00026 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00027 //  GNU General Public License for more details.
00028 //
00029 //  You should have received a copy of the GNU General Public License
00030 //  along with this program; if not, write to the Free Software
00031 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
00032 //  USA.
00033 //
00034 //  For more information, 
00035 //      contact  : guillaume@baurand.net 
00036 //      or visit : http://xdflengine.sourceforge.net
00037 //
00038 //============================================================================= 
00039 
00040 #   include "xmlvaluable.hpp"
00041 #   include "valuers/xmlvaluer.hpp"
00042 
00043 BEGIN_XDFLENGINE_NS
00044 
00045 //=============================================================================
00046 //  CLASS XMLVALUABLE
00047 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00048 
00049     //_________________________________________________________________________
00050     //  XMLVALUABLE
00051     //-------------------------------------------------------------------------
00052     XMLValuable::XMLValuable()
00053     {
00054         DEBUG_CREATE(XMLValuable)
00055     }
00056 
00057     //_________________________________________________________________________
00058     //  ~XMLVALUABLE
00059     //-------------------------------------------------------------------------
00060     XMLValuable::~XMLValuable()
00061     {
00062         DEBUG_DEL(XMLValuable)
00063 
00064         // Empty valuers map;
00065         while( !m_vaValuers.empty() )(delete m_vaValuers.pop());
00066 
00067     }
00068 
00069     //_________________________________________________________________________
00070     //  CALCULATEVALUE
00071     //-------------------------------------------------------------------------
00072     char* XMLValuable::calculateValue( const char* p_pszValue)
00073     {
00074         char*       l_pszBefore = 0;
00075         char*       l_pszPrefix = 0;
00076         char*       l_pszExpr = 0;
00077         char*       l_pszAfter = 0;
00078         char*       l_pszValue = 0;
00079         char*       l_pszRet = 0;
00080         char*       l_pszTmp = 0;
00081         XMLValuer*  l_pXMLValuer;
00082 
00083         
00084         DEBUG_FUNC(XMLValuable::calculateValue)
00085 
00086         l_pszTmp = copyCharBuffer( p_pszValue);
00087         l_pszBefore = l_pszTmp;
00088         l_pszAfter = l_pszTmp;
00089         l_pszRet=copyCharBuffer("");
00090 
00091         while(true)
00092         {
00093             // separate parts of the expression
00094             
00095             // find a prefix
00096             l_pszPrefix = strstr(l_pszBefore, XMLVALUER_DELIM);
00097             if( ! l_pszPrefix) break;
00098             l_pszPrefix[0]='\0';
00099             l_pszPrefix+= strlen( XMLVALUER_DELIM); 
00100             
00101             // find expression
00102             l_pszExpr = strstr(l_pszPrefix, XMLVALUER_SEP);
00103             if( ! l_pszExpr) break;
00104             l_pszExpr[0]='\0';
00105             l_pszExpr+= strlen( XMLVALUER_SEP);
00106 
00107             // find end 
00108             l_pszAfter = strstr(l_pszExpr, XMLVALUER_DELIM);
00109             if( ! l_pszAfter) break;
00110             l_pszAfter[0]='\0';
00111             l_pszAfter+= strlen( XMLVALUER_DELIM);  
00112             
00113 
00114             l_pXMLValuer = getValuer( l_pszPrefix);
00115             
00116             l_pszValue = 0;
00117             if( l_pXMLValuer)
00118             {   
00119                 l_pszValue = l_pXMLValuer->calculateExpression( l_pszExpr);             
00120             }
00121 
00122             if( !l_pszValue)
00123             {
00124                 l_pszValue = copyCharBuffer("");
00125                 l_pszValue = concatCharBuffer( l_pszValue,XMLVALUER_DELIM);
00126                 l_pszValue = concatCharBuffer( l_pszValue,l_pszPrefix);
00127                 l_pszValue = concatCharBuffer( l_pszValue,XMLVALUER_SEP);
00128                 l_pszValue = concatCharBuffer( l_pszValue,l_pszExpr);
00129                 l_pszValue = concatCharBuffer( l_pszValue,XMLVALUER_DELIM);
00130             }
00131 
00132             l_pszRet = concatCharBuffer(l_pszRet, l_pszBefore);             
00133             l_pszRet = concatCharBuffer(l_pszRet, l_pszValue);
00134             l_pszValue = releaseCharBuffer( l_pszValue);
00135             l_pszBefore = l_pszAfter;
00136 
00137         }
00138 
00139         l_pszRet = concatCharBuffer(l_pszRet, l_pszAfter);
00140         //logout << "\n[[" << l_pszRet << "]]";
00141 
00142         l_pszTmp = releaseCharBuffer( l_pszTmp);
00143         
00144         return l_pszRet;
00145     }
00146 
00147     //_________________________________________________________________________
00148     //  ADDVALUER
00149     //-------------------------------------------------------------------------
00150     void XMLValuable::addValuer ( XMLValuer* p_pXV_valuer, const char* p_pszName)
00151     {
00152         DEBUG_FUNC(XMLValuable::addValuer)
00153         m_vaValuers.add( p_pXV_valuer, p_pszName);
00154     }
00155 
00156     //_________________________________________________________________________
00157     //  GETVALUER
00158     //-------------------------------------------------------------------------
00159     XMLValuer* XMLValuable::getValuer(const char* p_pszName) const
00160     {
00161         DEBUG_FUNC(XMLValuable::getValuer)
00162         return m_vaValuers.get( p_pszName);
00163     }
00164 
00165 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00166 //=============================================================================
00167 
00168 END_XDFLENGINE_NS

Generated on Sat Oct 4 13:20:04 2003 for XDFLengine by doxygen1.3-rc2