Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.9

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

XPathFunctionTable.hpp

Go to the documentation of this file.
00001 /*
00002  * Copyright 1999-2004 The Apache Software Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #if !defined(XPATHFUNCTIONTABLE_HEADER_GUARD_1357924680)
00017 #define XPATHFUNCTIONTABLE_HEADER_GUARD_1357924680
00018 
00019 
00020 
00021 // Base include file.  Must be first.
00022 #include <xalanc/XPath/XPathDefinitions.hpp>
00023 
00024 
00025 
00026 #include <algorithm>
00027 
00028 
00029 
00030 #include <xalanc/XalanDOM/XalanDOMString.hpp>
00031 
00032 
00033 
00034 #include <xalanc/Include/STLHelper.hpp>
00035 
00036 
00037 
00038 #include <xalanc/XPath/Function.hpp>
00039 #include <xalanc/XPath/XalanXPathException.hpp>
00040 
00041 
00042 
00043 XALAN_CPP_NAMESPACE_BEGIN
00044 
00045 
00046 
00050 class XALAN_XPATH_EXPORT XPathExceptionFunctionNotAvailable : public XalanXPathException
00051 {
00052 public:
00053 
00054     typedef Function::LocatorType   LocatorType;
00055 
00056     XPathExceptionFunctionNotAvailable(const XalanDOMString&    theFunctionNumber,
00057                                         XalanDOMString&         theResult);
00058 
00059     XPathExceptionFunctionNotAvailable(
00060         const XalanDOMString&   theFunctionNumber,
00061         const LocatorType&      theLocator,
00062         XalanDOMString&         theResult);
00063 
00064     ~XPathExceptionFunctionNotAvailable();
00065 };
00066 
00067 
00068 
00073 class XALAN_XPATH_EXPORT XPathExceptionFunctionNotSupported : public XalanXPathException
00074 {
00075 public:
00076 
00077     XPathExceptionFunctionNotSupported(const XalanDOMChar*  theFunctionName,
00078                                         XalanDOMString&     theResult);
00079 
00080     ~XPathExceptionFunctionNotSupported();
00081 };
00082 
00083 
00084 
00088 class XALAN_XPATH_EXPORT XPathFunctionTable
00089 {
00090 public:
00091 
00092     enum { InvalidFunctionNumberID = -1, TableSize = 36 };
00093 
00094     typedef size_t                      SizeType;
00095     typedef XalanDOMString::size_type   StringSizeType;
00096     typedef DeleteFunctor<Function>     DeleteFunctorType;
00097 
00103     XPathFunctionTable(bool     fCreateTable = true);
00104 
00105     ~XPathFunctionTable();
00106 
00107     void
00108     setMemoryManager(MemoryManagerType& theManager)
00109     {
00110         m_memoryManager = &theManager;
00111     }
00115     void
00116     CreateTable();
00117 
00121     void
00122     DestroyTable();
00123 
00130     const Function&
00131     operator[](const XalanDOMString&    theFunctionName) const
00132     {
00133         const int   theFunctionID =
00134             getFunctionIndex(theFunctionName);
00135 
00136         if (theFunctionID != InvalidFunctionNumberID)
00137         {
00138             return *m_functionTable[theFunctionID];
00139         }
00140         else
00141         {
00142             MemoryManagerType* theManager = const_cast<MemoryManagerType*>(m_memoryManager);
00143 
00144             XalanDOMString   theResult(*theManager);
00145 
00146             throw XPathExceptionFunctionNotAvailable(theFunctionName, theResult);
00147         }
00148     }
00149 
00156     const Function&
00157     operator[](int  theFunctionID) const
00158     {
00159         assert(theFunctionID >= 0 && theFunctionID < TableSize);
00160         assert(m_functionTable[theFunctionID] != 0);
00161 
00162         return *m_functionTable[theFunctionID];
00163     }
00164 
00171     const XalanDOMString&
00172     idToName(int    theFunctionID,
00173                 XalanDOMString& theResult) const
00174     {
00175 
00176         if (theFunctionID >= 0 && theFunctionID < TableSize)
00177         {
00178             theResult.assign(
00179                 s_functionNames[theFunctionID].m_name,
00180                 s_functionNames[theFunctionID].m_size);
00181         }
00182 
00183         return theResult;
00184     }
00185 
00192     int
00193     nameToID(const XalanDOMString&  theName) const
00194     {
00195         return getFunctionIndex(theName);
00196     }
00197 
00204     void
00205     InstallFunction(
00206             const XalanDOMString&   theFunctionName,
00207             const Function&         theFunction)
00208     {
00209         InstallFunction(theFunctionName.c_str(), theFunction);
00210     }
00211 
00218     bool
00219     UninstallFunction(const XalanDOMString&     theFunctionName)
00220     {
00221         return UninstallFunction(theFunctionName.c_str());
00222     }
00223 
00230     void
00231     InstallFunction(
00232             const XalanDOMChar*     theFunctionName,
00233             const Function&         theFunction);
00234 
00241     bool
00242     UninstallFunction(const XalanDOMChar*   theFunctionName);
00243 
00250     bool
00251     isInstalledFunction(const XalanDOMString&   theFunctionName) const
00252     {
00253         return getFunctionIndex(theFunctionName) != InvalidFunctionNumberID ? true : false;
00254     }
00255 
00256 #if defined(XALAN_NO_MEMBER_TEMPLATES)
00257 
00258     typedef XalanVector<XalanDOMString>         InstalledFunctionNameVectorType;
00259 
00265     void
00266     getInstalledFunctionNames(InstalledFunctionNameVectorType&  theVector) const
00267     {
00268         XalanDOMString  theString;
00269 
00270         for (int i = 0; i < TableSize; ++i)
00271         {
00272             if (m_functionTable[i] != 0)
00273             {
00274                 theString.assign(
00275                     s_functionNames[i].m_name,
00276                     s_functionNames[i].m_size);
00277 
00278                 theVector.push_back(theString);
00279             }
00280         }
00281     }
00282 #else
00283 
00289     template<class OutputIteratorType>
00290     void
00291     getInstalledFunctionNames(OutputIteratorType    theIterator) const
00292     {
00293         XalanDOMString  theString(XalanMemMgrs::getDefaultXercesMemMgr());
00294 
00295         for (int i = 0; i < TableSize; ++i)
00296         {
00297             if (m_functionTable[i] != 0)
00298             {
00299                 theString.assign(
00300                     s_functionNames[i].m_name,
00301                     s_functionNames[i].m_size);
00302 
00303                 *theIterator = theString;
00304 
00305                 ++theIterator;
00306             }
00307         }
00308     }
00309 #endif
00310 
00311     struct FunctionNameTableEntry
00312     {
00313         const XalanDOMChar*     m_name;
00314 
00315         StringSizeType          m_size;
00316     };
00317 
00318     // These are static strings for the functions supported.
00319     // Note that the XSLT functions are also here, since it's
00320     // just easier to do it this way.
00321 
00322     // The string "id"
00323     static const XalanDOMChar   s_id[];
00324 
00325     // The string "key"
00326     static const XalanDOMChar   s_key[];
00327 
00328     // The string "not"
00329     static const XalanDOMChar   s_not[];
00330 
00331     // The string "sum"
00332     static const XalanDOMChar   s_sum[];
00333 
00334     // The string "lang"
00335     static const XalanDOMChar   s_lang[];
00336 
00337     // The string "last"
00338     static const XalanDOMChar   s_last[];
00339 
00340     // The string "name"
00341     static const XalanDOMChar   s_name[];
00342 
00343     // The string "true"
00344     static const XalanDOMChar   s_true[];
00345 
00346     // The string "count"
00347     static const XalanDOMChar   s_count[];
00348 
00349     // The string "false"
00350     static const XalanDOMChar   s_false[];
00351 
00352     // The string "floor"
00353     static const XalanDOMChar   s_floor[];
00354 
00355     // The string "round"
00356     static const XalanDOMChar   s_round[];
00357 
00358     // The string "concat"
00359     static const XalanDOMChar   s_concat[];
00360 
00361     // The string "number"
00362     static const XalanDOMChar   s_number[];
00363 
00364     // The string "string"
00365     static const XalanDOMChar   s_string[];
00366 
00367     // The string "boolean"
00368     static const XalanDOMChar   s_boolean[];
00369 
00370     // The string "ceiling"
00371     static const XalanDOMChar   s_ceiling[];
00372 
00373     // The string "current"
00374     static const XalanDOMChar   s_current[];
00375 
00376     // The string "contains"
00377     static const XalanDOMChar   s_contains[];
00378 
00379     // The string "document"
00380     static const XalanDOMChar   s_document[];
00381 
00382     // The string "position"
00383     static const XalanDOMChar   s_position[];
00384 
00385     // The string "substring"
00386     static const XalanDOMChar   s_substring[];
00387 
00388     // The string "translate"
00389     static const XalanDOMChar   s_translate[];
00390 
00391     // The string "local-name"
00392     static const XalanDOMChar   s_localName[];
00393 
00394     // The string "generate-id"
00395     static const XalanDOMChar   s_generateId[];
00396 
00397     // The string "starts-with"
00398     static const XalanDOMChar   s_startsWith[];
00399 
00400     // The string "format-number"
00401     static const XalanDOMChar   s_formatNumber[];
00402 
00403     // The string "namespace-uri"
00404     static const XalanDOMChar   s_namespaceUri[];
00405 
00406     // The string "string-length"
00407     static const XalanDOMChar   s_stringLength[];
00408 
00409     // The string "normalize-space"
00410     static const XalanDOMChar   s_normalizeSpace[];
00411 
00412     // The string "substring-after"
00413     static const XalanDOMChar   s_substringAfter[];
00414 
00415     // The string "system-property"
00416     static const XalanDOMChar   s_systemProperty[];
00417 
00418     // The string "substring-before"
00419     static const XalanDOMChar   s_substringBefore[];
00420 
00421     // The string "element-available"
00422     static const XalanDOMChar   s_elementAvailable[];
00423 
00424     // The string "function-available"
00425     static const XalanDOMChar   s_functionAvailable[];
00426 
00427     // The string "unparsed-entity-uri"
00428     static const XalanDOMChar   s_unparsedEntityUri[];
00429 
00430     // A table of function names.
00431     static const FunctionNameTableEntry         s_functionNames[];
00432 
00433     // The size of the table.
00434     static const SizeType                       s_functionNamesSize;
00435 
00436 private:
00437 
00438     static int
00439     getFunctionIndex(const XalanDOMString&  theName)
00440     {
00441         return getFunctionIndex(
00442                 theName.c_str(),
00443                 theName.length());
00444     }
00445 
00446     static int
00447     getFunctionIndex(const XalanDOMChar*    theName)
00448     {
00449         return getFunctionIndex(
00450                 theName,
00451                 XalanDOMString::length(theName));
00452     }
00453 
00454     static int
00455     getFunctionIndex(
00456             const XalanDOMChar*     theName,
00457             StringSizeType          theNameLength);
00458 
00459     MemoryManagerType*          m_memoryManager;
00460 
00461     const Function*             m_functionTable[TableSize];
00462 
00463     const Function** const      m_functionTableEnd;
00464 
00465     // The last one in the table of function names.
00466     static const FunctionNameTableEntry* const  s_lastFunctionName;
00467 };
00468 
00469 
00470 
00471 XALAN_CPP_NAMESPACE_END
00472 
00473 
00474 
00475 #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++ XSLT Processor Version 1.9
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.