1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-04 13:13:25 +03:00
Files
occt/src/XmlMDataStd/XmlMDataStd_IntegerListDriver.cxx
abv d5f74e42d6 0024624: Lost word in license statement in source files
License statement text corrected; compiler warnings caused by Bison 2.41 disabled for MSVC; a few other compiler warnings on 54-bit Windows eliminated by appropriate type cast
Wrong license statements corrected in several files.
Copyright and license statements added in XSD and GLSL files.
Copyright year updated in some files.
Obsolete documentation files removed from DrawResources.
2014-02-20 16:15:17 +04:00

144 lines
5.3 KiB
C++

// Created on: 2007-05-29
// Created by: Vlad Romashko
// Copyright (c) 2007-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.
#include <XmlMDataStd_IntegerListDriver.ixx>
#include <TDataStd_IntegerList.hxx>
#include <TColStd_ListIteratorOfListOfInteger.hxx>
#include <NCollection_LocalArray.hxx>
#include <XmlObjMgt.hxx>
IMPLEMENT_DOMSTRING (FirstIndexString, "first")
IMPLEMENT_DOMSTRING (LastIndexString, "last")
//=======================================================================
//function : XmlMDataStd_IntegerListDriver
//purpose : Constructor
//=======================================================================
XmlMDataStd_IntegerListDriver::XmlMDataStd_IntegerListDriver(const Handle(CDM_MessageDriver)& theMsgDriver)
: XmlMDF_ADriver (theMsgDriver, NULL)
{
}
//=======================================================================
//function : NewEmpty
//purpose :
//=======================================================================
Handle(TDF_Attribute) XmlMDataStd_IntegerListDriver::NewEmpty() const
{
return new TDataStd_IntegerList();
}
//=======================================================================
//function : Paste
//purpose : persistent -> transient (retrieve)
//=======================================================================
Standard_Boolean XmlMDataStd_IntegerListDriver::Paste(const XmlObjMgt_Persistent& theSource,
const Handle(TDF_Attribute)& theTarget,
XmlObjMgt_RRelocationTable& ) const
{
Standard_Integer aFirstInd, aLastInd, aValue, ind;
const XmlObjMgt_Element& anElement = theSource;
// Read the FirstIndex; if the attribute is absent initialize to 1
XmlObjMgt_DOMString aFirstIndex= anElement.getAttribute(::FirstIndexString());
if (aFirstIndex == NULL)
aFirstInd = 1;
else if (!aFirstIndex.GetInteger(aFirstInd))
{
TCollection_ExtendedString aMessageString =
TCollection_ExtendedString("Cannot retrieve the first index"
" for IntegerList attribute as \"")
+ aFirstIndex + "\"";
WriteMessage (aMessageString);
return Standard_False;
}
// Read the LastIndex; the attribute should be present
if (!anElement.getAttribute(::LastIndexString()).GetInteger(aLastInd))
{
TCollection_ExtendedString aMessageString =
TCollection_ExtendedString("Cannot retrieve the last index"
" for IntegerList attribute as \"")
+ aFirstIndex + "\"";
WriteMessage (aMessageString);
return Standard_False;
}
Handle(TDataStd_IntegerList) anIntList = Handle(TDataStd_IntegerList)::DownCast(theTarget);
if (aFirstInd == aLastInd)
{
Standard_Integer anInteger;
if (!XmlObjMgt::GetStringValue(anElement).GetInteger(anInteger))
{
TCollection_ExtendedString aMessageString =
TCollection_ExtendedString("Cannot retrieve integer member"
" for IntegerList attribute as \"");
WriteMessage (aMessageString);
return Standard_False;
}
anIntList->Append(anInteger);
}
else
{
Standard_CString aValueStr = Standard_CString(XmlObjMgt::GetStringValue(anElement).GetString());
for (ind = aFirstInd; ind <= aLastInd; ind++)
{
if (!XmlObjMgt::GetInteger(aValueStr, aValue))
{
TCollection_ExtendedString aMessageString =
TCollection_ExtendedString("Cannot retrieve integer member"
" for IntegerList attribute as \"")
+ aValueStr + "\"";
WriteMessage (aMessageString);
return Standard_False;
}
anIntList->Append(aValue);
}
}
return Standard_True;
}
//=======================================================================
//function : Paste
//purpose : transient -> persistent (store)
//=======================================================================
void XmlMDataStd_IntegerListDriver::Paste(const Handle(TDF_Attribute)& theSource,
XmlObjMgt_Persistent& theTarget,
XmlObjMgt_SRelocationTable& ) const
{
Handle(TDataStd_IntegerList) anIntList = Handle(TDataStd_IntegerList)::DownCast(theSource);
Standard_Integer anU = anIntList->Extent();
theTarget.Element().setAttribute(::LastIndexString(), anU);
if (anU >= 1)
{
// Allocation of 12 chars for each integer including the space.
// An example: -2 147 483 648
Standard_Integer iChar = 0;
NCollection_LocalArray<Standard_Character> str(12 * anU + 1);
TColStd_ListIteratorOfListOfInteger itr(anIntList->List());
for (; itr.More(); itr.Next())
{
const Standard_Integer& intValue = itr.Value();
iChar += Sprintf(&(str[iChar]), "%d ", intValue);
}
// No occurrence of '&', '<' and other irregular XML characters
XmlObjMgt::SetStringValue (theTarget, (Standard_Character*)str, Standard_True);
}
}