-// File: XmlMDataStd_RealArrayDriver.cxx
-// Created: Fri Aug 24 20:46:58 2001
-// Author: Alexnder GRIGORIEV
-// Copyright: Open Cascade 2001-2002
-// History: AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
-
-#define OCC6010 // vro 01.06.2004
+// Created on: 2001-08-24
+// Created by: Alexnder GRIGORIEV
+// Copyright (c) 2001-2014 OPEN CASCADE SAS
+//
+// This file is part of Open CASCADE Technology software library.
+//
+// This library is free software; you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License version 2.1 as published
+// by the Free Software Foundation, with special exception defined in the file
+// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
+// distribution for complete text of the license and disclaimer of any warranty.
+//
+// Alternatively, this file may be used under the terms of Open CASCADE
+// commercial license or contractual agreement.
+
+//AGV 150202: Changed prototype XmlObjMgt::SetStringValue()
# include <stdio.h>
#include <XmlMDataStd_RealArrayDriver.ixx>
#include <TDataStd_RealArray.hxx>
#include <XmlObjMgt.hxx>
#include <XmlMDataStd.hxx>
+#include <TColStd_HArray1OfReal.hxx>
+#include <NCollection_LocalArray.hxx>
+#include <Standard_ErrorHandler.hxx>
+#include <Standard_OutOfMemory.hxx>
IMPLEMENT_DOMSTRING (FirstIndexString, "first")
IMPLEMENT_DOMSTRING (LastIndexString, "last")
{
Handle(TDataStd_RealArray) aRealArray =
Handle(TDataStd_RealArray)::DownCast(theSource);
-
- Standard_Integer aL = aRealArray->Lower(), anU = aRealArray->Upper();
- TCollection_AsciiString aValueStr;
+ const Handle(TColStd_HArray1OfReal)& hRealArray = aRealArray->Array();
+ const TColStd_Array1OfReal& realArray = hRealArray->Array1();
+ Standard_Integer aL = realArray.Lower(), anU = realArray.Upper();
if (aL != 1) theTarget.Element().setAttribute(::FirstIndexString(), aL);
theTarget.Element().setAttribute(::LastIndexString(), anU);
theTarget.Element().setAttribute(::IsDeltaOn(), aRealArray->GetDelta());
+ // Allocation of 25 chars for each double value including the space:
+ // An example: -3.1512678732195273e+020
+ Standard_Integer iChar = 0;
+ NCollection_LocalArray<Standard_Character> str;
+ if (realArray.Length())
+ {
+ try
+ {
+ OCC_CATCH_SIGNALS
+ str.Allocate(25 * realArray.Length() + 1);
+ }
+ catch (Standard_OutOfMemory)
+ {
+ // If allocation of big space for the string of double array values failed,
+ // try to calculate the necessary space more accurate and allocate it.
+ // It may take some time... therefore it was not done initially and
+ // an attempt to use a simple 25 chars for a double value was used.
+ Standard_Character buf[25];
+ Standard_Integer i(aL), nbChars(0);
+ while (i <= anU)
+ {
+ nbChars += Sprintf(buf, "%.17g ", realArray.Value(i++)) + 1/*a space*/;
+ }
+ if (nbChars)
+ str.Allocate(nbChars);
+ }
+ }
+
Standard_Integer i = aL;
- while (1) {
-#ifndef OCC6010
- aValueStr += TCollection_AsciiString(aRealArray->Value(i));
-#else
- char aValueChar[32];
- sprintf(aValueChar, "%.15g", aRealArray->Value(i));
- aValueStr += aValueChar;
-#endif
- if (i >= anU) break;
- aValueStr += ' ';
+ for (;;)
+ {
+ iChar += Sprintf(&(str[iChar]), "%.17g ", realArray.Value(i));
+ if (i >= anU)
+ break;
++i;
}
+
// No occurrence of '&', '<' and other irregular XML characters
- XmlObjMgt::SetStringValue (theTarget, aValueStr.ToCString(), Standard_True);
+ if (realArray.Length())
+ {
+ str[iChar - 1] = '\0';
+ XmlObjMgt::SetStringValue (theTarget, (Standard_Character*)str, Standard_True);
+ }
}