dbertoni    2003/06/05 16:11:21

  Modified:    c/src/XalanEXSLT XalanEXSLTMath.cpp XalanEXSLTMathImpl.hpp
  Log:
  Implementation of random() function from [EMAIL PROTECTED]
  
  Revision  Changes    Path
  1.6       +60 -3     xml-xalan/c/src/XalanEXSLT/XalanEXSLTMath.cpp
  
  Index: XalanEXSLTMath.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanEXSLT/XalanEXSLTMath.cpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XalanEXSLTMath.cpp        3 Feb 2003 22:13:07 -0000       1.5
  +++ XalanEXSLTMath.cpp        5 Jun 2003 23:11:20 -0000       1.6
  @@ -60,7 +60,7 @@
   
   
   #include <cmath>
  -
  +#include <ctime>
   
   
   #include <PlatformSupport/DoubleSupport.hpp>
  @@ -339,6 +339,45 @@
   
   
   XObjectPtr
  +XalanEXSLTFunctionRandom::execute(
  +                     XPathExecutionContext&                  
executionContext,
  +                     XalanNode*                                              
context,
  +                     const XObjectArgVectorType&             args,
  +                     const LocatorType*                              
locator) const
  +{
  +     if (args.size() != 0)
  +     {
  +             executionContext.error(getError(), context, locator);
  +     }
  +
  +#if defined(XALAN_STRICT_ANSI_HEADERS)
  +     using std::rand;
  +#endif
  +
  +     const int       value = rand();
  +
  +     double          result = 0.0;
  +
  +     if (value != 0)
  +     {
  +             result = double(value) / RAND_MAX;
  +     }
  +     assert(result >= 0.0L && result <= 1.0L);
  +
  +     return executionContext.getXObjectFactory().createNumber(result);
  +}
  +
  +
  +
  +const XalanDOMString
  +XalanEXSLTFunctionRandom::getError() const
  +{
  +     return StaticStringToDOMString(XALAN_STATIC_UCODE_STRING("The EXSLT 
function random() accepts no arguments"));
  +}
  +
  +
  +
  +XObjectPtr
   XalanEXSLTFunctionAcos::execute(
                        XPathExecutionContext&                  
executionContext,
                        XalanNode*                                              
context,
  @@ -1353,7 +1392,16 @@
        0
   };
   
  -
  +static const XalanDOMChar    s_randomFunctionName[] =
  +{
  +     XalanUnicode::charLetter_r,
  +     XalanUnicode::charLetter_a,
  +     XalanUnicode::charLetter_n,
  +     XalanUnicode::charLetter_d,
  +     XalanUnicode::charLetter_o,
  +     XalanUnicode::charLetter_m,
  +     0
  +};
   
   static const XalanEXSLTFunctionAbs                   s_absFunction;
   static const XalanEXSLTFunctionAcos                  s_acosFunction;
  @@ -1372,7 +1420,7 @@
   static const XalanEXSLTFunctionSin                   s_sinFunction;
   static const XalanEXSLTFunctionSqrt                  s_sqrtFunction;
   static const XalanEXSLTFunctionTan                   s_tanFunction;
  -
  +static const XalanEXSLTFunctionRandom                s_randomFunction;
   
   
   static const XalanEXSLTMathFunctionsInstaller::FunctionTableEntry    
theFunctionTable[] =
  @@ -1394,6 +1442,7 @@
        { s_sinFunctionName, &s_sinFunction },
        { s_sqrtFunctionName, &s_sqrtFunction },
        { s_tanFunctionName, &s_tanFunction },
  +     { s_randomFunctionName, &s_randomFunction },
        { 0, 0 }
   };
   
  @@ -1411,6 +1460,14 @@
   XalanEXSLTMathFunctionsInstaller::installGlobal()
   {
        doInstallGlobal(s_mathNamespace, theFunctionTable);
  +
  +     // Sets the starting point for generating a series of pseudorandom 
integers,
  +     // we need it for random() EXSLT function
  +#if defined(XALAN_STRICT_ANSI_HEADERS)
  +     using std::srand;
  +     using std::time;
  +#endif
  +     srand( (unsigned)time( NULL ) );
   }
   
   
  
  
  
  1.6       +55 -0     xml-xalan/c/src/XalanEXSLT/XalanEXSLTMathImpl.hpp
  
  Index: XalanEXSLTMathImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XalanEXSLT/XalanEXSLTMathImpl.hpp,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- XalanEXSLTMathImpl.hpp    13 Feb 2003 02:47:24 -0000      1.5
  +++ XalanEXSLTMathImpl.hpp    5 Jun 2003 23:11:21 -0000       1.6
  @@ -126,6 +126,61 @@
   
   
   
  +class XALAN_EXSLT_EXPORT XalanEXSLTFunctionRandom : public Function
  +{
  +public:
  +
  +     typedef Function        ParentType;
  +
  +     XalanEXSLTFunctionRandom()
  +     {
  +     }
  +
  +     virtual
  +     ~XalanEXSLTFunctionRandom()
  +     {
  +     }
  +
  +     // These methods are inherited from Function ...
  +
  +     virtual XObjectPtr
  +     execute(
  +                     XPathExecutionContext&                  
executionContext,
  +                     XalanNode*                                              
context,
  +                     const XObjectArgVectorType&             args,
  +                     const LocatorType*                              
locator) const;
  +
  +#if !defined(XALAN_NO_USING_DECLARATION)
  +     using ParentType::execute;
  +#endif
  +
  +#if defined(XALAN_NO_COVARIANT_RETURN_TYPE)
  +     virtual Function*
  +#else
  +     virtual XalanEXSLTFunctionRandom*
  +#endif
  +     clone() const
  +     {
  +             return new XalanEXSLTFunctionRandom(*this);
  +     }
  +
  +protected:
  +
  +     const XalanDOMString
  +     getError() const;
  +
  +private:
  +
  +     // Not implemented...
  +     XalanEXSLTFunctionRandom&
  +     operator=(const XalanEXSLTFunctionRandom&);
  +
  +     bool
  +     operator==(const XalanEXSLTFunctionRandom&) const;
  +};
  +
  +
  +
   class XALAN_EXSLT_EXPORT XalanEXSLTFunctionAcos : public Function
   {
   public:
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to