Xalan-C++ API Documentation

The Xalan C++ XSL Transformer Version 1.1

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

XPathFunctionTable.hpp

Go to the documentation of this file.
00001 /*
00002  * The Apache Software License, Version 1.1
00003  *
00004  *
00005  * Copyright (c) 1999 The Apache Software Foundation.  All rights 
00006  * reserved.
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions
00010  * are met:
00011  *
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer. 
00014  *
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in
00017  *    the documentation and/or other materials provided with the
00018  *    distribution.
00019  *
00020  * 3. The end-user documentation included with the redistribution,
00021  *    if any, must include the following acknowledgment:  
00022  *       "This product includes software developed by the
00023  *        Apache Software Foundation (http://www.apache.org/)."
00024  *    Alternately, this acknowledgment may appear in the software itself,
00025  *    if and wherever such third-party acknowledgments normally appear.
00026  *
00027  * 4. The names "Xalan" and "Apache Software Foundation" must
00028  *    not be used to endorse or promote products derived from this
00029  *    software without prior written permission. For written 
00030  *    permission, please contact apache@apache.org.
00031  *
00032  * 5. Products derived from this software may not be called "Apache",
00033  *    nor may "Apache" appear in their name, without prior written
00034  *    permission of the Apache Software Foundation.
00035  *
00036  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00037  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00038  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00039  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00040  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00041  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00042  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00043  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00044  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00045  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00046  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00047  * SUCH DAMAGE.
00048  * ====================================================================
00049  *
00050  * This software consists of voluntary contributions made by many
00051  * individuals on behalf of the Apache Software Foundation and was
00052  * originally based on software copyright (c) 1999, International
00053  * Business Machines, Inc., http://www.ibm.com.  For more
00054  * information on the Apache Software Foundation, please see
00055  * <http://www.apache.org/>.
00056  */
00057 #if !defined(XPATHFUNCTIONTABLE_HEADER_GUARD_1357924680)
00058 #define XPATHFUNCTIONTABLE_HEADER_GUARD_1357924680
00059 
00060 
00061 
00062 // Base include file.  Must be first.
00063 #include <XPath/XPathDefinitions.hpp>
00064 
00065 
00066 
00067 #include <algorithm>
00068 #include <map>
00069 
00070 
00071 
00072 #include <XalanDOM/XalanDOMString.hpp>
00073 
00074 
00075 
00076 #include <Include/STLHelper.hpp>
00077 
00078 
00079 
00080 #include <XPath/Function.hpp>
00081 #include <XPath/XPathException.hpp>
00082 
00083 
00084 
00088 class XALAN_XPATH_EXPORT XPathExceptionFunctionNotAvailable : public XPathException
00089 {
00090 public:
00091 
00092     XPathExceptionFunctionNotAvailable(
00093         int                 theFunctionName,
00094         const XalanNode*    styleNode = 0);
00095 
00096     XPathExceptionFunctionNotAvailable(
00097         const XalanDOMString&   theFunctionName,
00098         const XalanNode*        styleNode = 0);
00099 
00100     ~XPathExceptionFunctionNotAvailable();
00101 };
00102 
00103 
00104 
00108 class XALAN_XPATH_EXPORT XPathFunctionTable
00109 {
00110 public:
00111 
00112 #if defined(XALAN_NO_NAMESPACES)
00113     typedef vector<Function*>               CollectionType;
00114     typedef map<XalanDOMString,
00115                 int,
00116                 less<XalanDOMString> >      FunctionNameIndexMapType;
00117 #else
00118     typedef std::vector<Function*>          CollectionType;
00119     typedef std::map<XalanDOMString, int>   FunctionNameIndexMapType;
00120 #endif
00121 
00122     typedef DeleteFunctor<Function>     DeleteFunctorType;
00123 
00129     XPathFunctionTable(bool     fCreateTable = true);
00130 
00131     ~XPathFunctionTable();
00132 
00136     void
00137     CreateTable();
00138 
00142     void
00143     DestroyTable();
00144 
00151     Function&
00152     operator[](const XalanDOMString&    theFunctionName) const
00153     {
00154         FunctionNameIndexMapType::const_iterator    i =
00155             m_FunctionNameIndex.find(theFunctionName);
00156 
00157         if (i != m_FunctionNameIndex.end())
00158         {
00159             return *m_FunctionCollection[(*i).second];
00160         }
00161         else
00162         {
00163             throw XPathExceptionFunctionNotAvailable(theFunctionName);
00164         }
00165     }
00166 
00173     Function&
00174     operator[](int  theFunctionID) const
00175     {
00176         if (theFunctionID >= 0 &&
00177             CollectionType::size_type(theFunctionID) < m_FunctionCollection.size())
00178         {
00179             return *m_FunctionCollection[theFunctionID];
00180         }
00181         else
00182         {
00183             throw XPathExceptionFunctionNotAvailable(theFunctionID);
00184         }
00185     }
00186 
00187     enum { InvalidFunctionNumberID = -1 };
00188 
00195     const XalanDOMString
00196     idToName(int    theFunctionID) const
00197     {
00198         XalanDOMString  theName;
00199 
00200         if (theFunctionID >= 0 &&
00201             CollectionType::size_type(theFunctionID) < m_FunctionCollection.size())
00202         {
00203             FunctionNameIndexMapType::const_iterator    i =
00204                 m_FunctionNameIndex.begin();
00205 
00206             while (i != m_FunctionNameIndex.end())
00207             {
00208                 if ((*i).second == theFunctionID)
00209                 {
00210                     theName = (*i).first;
00211 
00212                     break;
00213                 }
00214             }
00215         }
00216 
00217         return theName;
00218     }
00219 
00226     int
00227     nameToID(const XalanDOMString&  theName) const
00228     {
00229         const FunctionNameIndexMapType::const_iterator  i =
00230             m_FunctionNameIndex.find(theName);
00231 
00232         if (i != m_FunctionNameIndex.end())
00233         {
00234             return (*i).second;
00235         }
00236         else
00237         {
00238             return InvalidFunctionNumberID;
00239         }
00240     }
00241 
00248     void
00249     InstallFunction(
00250             const XalanDOMString&   theFunctionName,
00251             const Function&         theFunction);
00252 
00259     bool
00260     UninstallFunction(const XalanDOMString&     theFunctionName);
00261 
00268     bool
00269     isInstalledFunction(const XalanDOMString&   theFunctionName) const
00270     {
00271         if (m_FunctionNameIndex.find(theFunctionName) != m_FunctionNameIndex.end())
00272         {
00273             return true;
00274         }
00275         else
00276         {
00277             return false;
00278         }
00279     }
00280 
00281 #if defined(XALAN_NO_MEMBER_TEMPLATES)
00282 
00283 #if defined(XALAN_NO_NAMESPACES)
00284     typedef vector<XalanDOMString>          InstalledFunctionNameVectorType;
00285 #else
00286     typedef std::vector<XalanDOMString>     InstalledFunctionNameVectorType;
00287 #endif
00288 
00294     void
00295     getInstalledFunctionNames(InstalledFunctionNameVectorType&  theVector) const
00296     {
00297         FunctionNameIndexMapType::const_iterator    i =
00298             m_FunctionNameIndex.begin();
00299 
00300         while(i != m_FunctionNameIndex.end())
00301         {
00302             theVector.push_back((*i).first);
00303 
00304             ++i;
00305         }
00306     }
00307 #else
00308 
00313     template<class OutputIteratorType>
00314     void
00315     getInstalledFunctionNames(OutputIteratorType    theIterator) const
00316     {
00317         FunctionNameIndexMapType::const_iterator    i =
00318             m_FunctionNameIndex.begin();
00319 
00320         while(i != m_FunctionNameIndex.end())
00321         {
00322             *theIterator = (*i).first;
00323 
00324             ++i;
00325             ++theIterator;
00326         }
00327     }
00328 #endif
00329 
00330 private:
00331 
00332     CollectionType              m_FunctionCollection;
00333 
00334     FunctionNameIndexMapType    m_FunctionNameIndex;
00335 };
00336 
00337 
00338 
00339 #endif  // XPATHFUNCTIONTABLE_HEADER_GUARD_1357924680

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

Xalan-C++ XSL Transformer Version 1.1
Copyright © 2000, 2001 The Apache Software Foundation. All Rights Reserved.