Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.8

Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | 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(int  theFunctionNumber);
00057 
00058     XPathExceptionFunctionNotAvailable(const XalanDOMString&    theFunctionName);
00059 
00060     XPathExceptionFunctionNotAvailable(
00061         int                 theFunctionNumber,
00062         const LocatorType&  theLocator);
00063 
00064     XPathExceptionFunctionNotAvailable(
00065         const XalanDOMString&   theFunctionName,
00066         const LocatorType&      theLocator);
00067 
00068     ~XPathExceptionFunctionNotAvailable();
00069 };
00070 
00071 
00072 
00077 class XALAN_XPATH_EXPORT XPathExceptionFunctionNotSupported : public XalanXPathException
00078 {
00079 public:
00080 
00081     XPathExceptionFunctionNotSupported(const XalanDOMChar*  theFunctionName);
00082 
00083     ~XPathExceptionFunctionNotSupported();
00084 };
00085 
00086 
00087 
00091 class XALAN_XPATH_EXPORT XPathFunctionTable
00092 {
00093 public:
00094 
00095     enum { InvalidFunctionNumberID = -1, TableSize = 36 };
00096 
00097     typedef size_t                      SizeType;
00098     typedef XalanDOMString::size_type   StringSizeType;
00099     typedef DeleteFunctor<Function>     DeleteFunctorType;
00100 
00106     XPathFunctionTable(bool     fCreateTable = true);
00107 
00108     ~XPathFunctionTable();
00109 
00113     void
00114     CreateTable();
00115 
00119     void
00120     DestroyTable();
00121 
00128     const Function&
00129     operator[](const XalanDOMString&    theFunctionName) const
00130     {
00131         const int   theFunctionID =
00132             getFunctionIndex(theFunctionName);
00133 
00134         if (theFunctionID != InvalidFunctionNumberID)
00135         {
00136             return *m_functionTable[theFunctionID];
00137         }
00138         else
00139         {
00140             throw XPathExceptionFunctionNotAvailable(theFunctionName);
00141         }
00142     }
00143 
00150     const Function&
00151     operator[](int  theFunctionID) const
00152     {
00153         assert(theFunctionID >= 0 && theFunctionID < TableSize);
00154         assert(m_functionTable[theFunctionID] != 0);
00155 
00156         return *m_functionTable[theFunctionID];
00157     }
00158 
00165     const XalanDOMString
00166     idToName(int    theFunctionID) const
00167     {
00168         XalanDOMString  theName;
00169 
00170         if (theFunctionID >= 0 && theFunctionID < TableSize)
00171         {
00172             theName.assign(
00173                 s_functionNames[theFunctionID].m_name,
00174                 s_functionNames[theFunctionID].m_size);
00175         }
00176 
00177         return theName;
00178     }
00179 
00186     int
00187     nameToID(const XalanDOMString&  theName) const
00188     {
00189         return getFunctionIndex(theName);
00190     }
00191 
00198     void
00199     InstallFunction(
00200             const XalanDOMString&   theFunctionName,
00201             const Function&         theFunction)
00202     {
00203         InstallFunction(theFunctionName.c_str(), theFunction);
00204     }
00205 
00212     bool
00213     UninstallFunction(const XalanDOMString&     theFunctionName)
00214     {
00215         return UninstallFunction(theFunctionName.c_str());
00216     }
00217 
00224     void
00225     InstallFunction(
00226             const XalanDOMChar*     theFunctionName,
00227             const Function&         theFunction);
00228 
00235     bool
00236     UninstallFunction(const XalanDOMChar*   theFunctionName);
00237 
00244     bool
00245     isInstalledFunction(const XalanDOMString&   theFunctionName) const
00246     {
00247         return getFunctionIndex(theFunctionName) != InvalidFunctionNumberID ? true : false;
00248     }
00249 
00250 #if defined(XALAN_NO_MEMBER_TEMPLATES)
00251 
00252 #if defined(XALAN_NO_STD_NAMESPACE)
00253     typedef vector<XalanDOMString>          InstalledFunctionNameVectorType;
00254 #else
00255     typedef std::vector<XalanDOMString>     InstalledFunctionNameVectorType;
00256 #endif
00257 
00263     void
00264     getInstalledFunctionNames(InstalledFunctionNameVectorType&  theVector) const
00265     {
00266         XalanDOMString  theString;
00267 
00268         for (int i = 0; i < TableSize; ++i)
00269         {
00270             if (m_functionTable[i] != 0)
00271             {
00272                 theString.assign(
00273                     s_functionNames[i].m_name,
00274                     s_functionNames[i].m_size);
00275 
00276                 theVector.push_back(theString);
00277             }
00278         }
00279     }
00280 #else
00281 
00287     template<class OutputIteratorType>
00288     void
00289     getInstalledFunctionNames(OutputIteratorType    theIterator) const
00290     {
00291         XalanDOMString  theString;
00292 
00293         for (int i = 0; i < TableSize; ++i)
00294         {
00295             if (m_functionTable[i] != 0)
00296             {
00297                 theString.assign(
00298                     s_functionNames[i].m_name,
00299                     s_functionNames[i].m_size);
00300 
00301                 *theIterator = theString;
00302 
00303                 ++theIterator;
00304             }
00305         }
00306     }
00307 #endif
00308 
00309     struct FunctionNameTableEntry
00310     {
00311         const XalanDOMChar*     m_name;
00312 
00313         StringSizeType          m_size;
00314     };
00315 
00316     // These are static strings for the functions supported.
00317     // Note that the XSLT functions are also here, since it's
00318     // just easier to do it this way.
00319 
00320     // The string "id"
00321     static const XalanDOMChar   s_id[];
00322 
00323     // The string "key"
00324     static const XalanDOMChar   s_key[];
00325 
00326     // The string "not"
00327     static const XalanDOMChar   s_not[];
00328 
00329     // The string "sum"
00330     static const XalanDOMChar   s_sum[];
00331 
00332     // The string "lang"
00333     static const XalanDOMChar   s_lang[];
00334 
00335     // The string "last"
00336     static const XalanDOMChar   s_last[];
00337 
00338     // The string "name"
00339     static const XalanDOMChar   s_name[];
00340 
00341     // The string "true"
00342     static const XalanDOMChar   s_true[];
00343 
00344     // The string "count"
00345     static const XalanDOMChar   s_count[];
00346 
00347     // The string "false"
00348     static const XalanDOMChar   s_false[];
00349 
00350     // The string "floor"
00351     static const XalanDOMChar   s_floor[];
00352 
00353     // The string "round"
00354     static const XalanDOMChar   s_round[];
00355 
00356     // The string "concat"
00357     static const XalanDOMChar   s_concat[];
00358 
00359     // The string "number"
00360     static const XalanDOMChar   s_number[];
00361 
00362     // The string "string"
00363     static const XalanDOMChar   s_string[];
00364 
00365     // The string "boolean"
00366     static const XalanDOMChar   s_boolean[];
00367 
00368     // The string "ceiling"
00369     static const XalanDOMChar   s_ceiling[];
00370 
00371     // The string "current"
00372     static const XalanDOMChar   s_current[];
00373 
00374     // The string "contains"
00375     static const XalanDOMChar   s_contains[];
00376 
00377     // The string "document"
00378     static const XalanDOMChar   s_document[];
00379 
00380     // The string "position"
00381     static const XalanDOMChar   s_position[];
00382 
00383     // The string "substring"
00384     static const XalanDOMChar   s_substring[];
00385 
00386     // The string "translate"
00387     static const XalanDOMChar   s_translate[];
00388 
00389     // The string "local-name"
00390     static const XalanDOMChar   s_localName[];
00391 
00392     // The string "generate-id"
00393     static const XalanDOMChar   s_generateId[];
00394 
00395     // The string "starts-with"
00396     static const XalanDOMChar   s_startsWith[];
00397 
00398     // The string "format-number"
00399     static const XalanDOMChar   s_formatNumber[];
00400 
00401     // The string "namespace-uri"
00402     static const XalanDOMChar   s_namespaceUri[];
00403 
00404     // The string "string-length"
00405     static const XalanDOMChar   s_stringLength[];
00406 
00407     // The string "normalize-space"
00408     static const XalanDOMChar   s_normalizeSpace[];
00409 
00410     // The string "substring-after"
00411     static const XalanDOMChar   s_substringAfter[];
00412 
00413     // The string "system-property"
00414     static const XalanDOMChar   s_systemProperty[];
00415 
00416     // The string "substring-before"
00417     static const XalanDOMChar   s_substringBefore[];
00418 
00419     // The string "element-available"
00420     static const XalanDOMChar   s_elementAvailable[];
00421 
00422     // The string "function-available"
00423     static const XalanDOMChar   s_functionAvailable[];
00424 
00425     // The string "unparsed-entity-uri"
00426     static const XalanDOMChar   s_unparsedEntityUri[];
00427 
00428     // A table of function names.
00429     static const FunctionNameTableEntry         s_functionNames[];
00430 
00431     // The size of the table.
00432     static const SizeType                       s_functionNamesSize;
00433 
00434 private:
00435 
00436     static int
00437     getFunctionIndex(const XalanDOMString&  theName)
00438     {
00439         return getFunctionIndex(
00440                 theName.c_str(),
00441                 theName.length());
00442     }
00443 
00444     static int
00445     getFunctionIndex(const XalanDOMChar*    theName)
00446     {
00447         return getFunctionIndex(
00448                 theName,
00449                 XalanDOMString::length(theName));
00450     }
00451 
00452     static int
00453     getFunctionIndex(
00454             const XalanDOMChar*     theName,
00455             StringSizeType          theNameLength);
00456 
00457 
00458     const Function*             m_functionTable[TableSize];
00459 
00460     const Function** const      m_functionTableEnd;
00461 
00462     // The last one in the table of function names.
00463     static const FunctionNameTableEntry* const  s_lastFunctionName;
00464 };
00465 
00466 
00467 
00468 XALAN_CPP_NAMESPACE_END
00469 
00470 
00471 
00472 #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.8
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.