0024186: Eliminate remaining compiler warnings in MSVC++ 2010 64 bit with warning...
[occt.git] / src / XmlTObjDrivers / XmlTObjDrivers_IntSparseArrayDriver.cxx
CommitLineData
b311480e 1// Created on: 2007-03-30
2// Created by: Michael SAZONOV
3// Copyright (c) 2007-2012 OPEN CASCADE SAS
4//
5// The content of this file is subject to the Open CASCADE Technology Public
6// License Version 6.5 (the "License"). You may not use the content of this file
7// except in compliance with the License. Please obtain a copy of the License
8// at http://www.opencascade.org and read it completely before using this file.
9//
10// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
12//
13// The Original Code and all software distributed under the License is
14// distributed on an "AS IS" basis, without warranty of any kind, and the
15// Initial Developer hereby disclaims all such warranties, including without
16// limitation, any warranties of merchantability, fitness for a particular
17// purpose or non-infringement. Please see the License for the specific terms
18// and conditions governing the rights and limitations under the License.
19
7fd59977 20// The original implementation Copyright: (C) RINA S.p.A
21
22#include <XmlTObjDrivers_IntSparseArrayDriver.hxx>
23#include <CDM_MessageDriver.hxx>
24#include <TDF_Attribute.hxx>
25#include <XmlObjMgt_Persistent.hxx>
26#include <TObj_TIntSparseArray.hxx>
27#include <TObj_Assistant.hxx>
28#include <TCollection_AsciiString.hxx>
29#include <TDF_Tool.hxx>
30
31IMPLEMENT_STANDARD_HANDLE(XmlTObjDrivers_IntSparseArrayDriver,XmlMDF_ADriver)
32IMPLEMENT_STANDARD_RTTIEXT(XmlTObjDrivers_IntSparseArrayDriver,XmlMDF_ADriver)
33
34#define ITEM_ID "itemId_"
35#define ITEM_VALUE "itemValue_"
36
37//=======================================================================
38//function : XmlTObjDrivers_IntSparseArrayDriver
39//purpose : constructor
40//=======================================================================
41
42XmlTObjDrivers_IntSparseArrayDriver::XmlTObjDrivers_IntSparseArrayDriver
43 (const Handle(CDM_MessageDriver)& theMessageDriver)
44: XmlMDF_ADriver( theMessageDriver, NULL)
45{
46}
47
48//=======================================================================
49//function : NewEmpty
50//purpose : Creates a new attribute
51//=======================================================================
52
53Handle(TDF_Attribute) XmlTObjDrivers_IntSparseArrayDriver::NewEmpty() const
54{
55 return new TObj_TIntSparseArray;
56}
57
58//=======================================================================
59//function : Paste
60//purpose : Retrieve. Translate the contents of <theSource> and put it
61// into <theTarget>.
62//=======================================================================
63
64Standard_Boolean XmlTObjDrivers_IntSparseArrayDriver::Paste
65 (const XmlObjMgt_Persistent& theSource,
66 const Handle(TDF_Attribute)& theTarget,
67 XmlObjMgt_RRelocationTable&) const
68{
69 const XmlObjMgt_Element& anElement = theSource;
70 Handle(TObj_TIntSparseArray) aTarget =
71 Handle(TObj_TIntSparseArray)::DownCast(theTarget);
72
73 // get pairs (ID, value) while ID != 0
74 Standard_Integer i = 1;
75 TCollection_AsciiString anItemID;
76 TCollection_AsciiString anIdStr = TCollection_AsciiString( ITEM_ID ) +
77 TCollection_AsciiString( i );
78 anItemID = anElement.getAttribute( anIdStr.ToCString() );
79 while( anItemID.IsIntegerValue() && anItemID.IntegerValue() != 0 )
80 {
81 TCollection_AsciiString aStrIndex = TCollection_AsciiString( ITEM_VALUE ) +
82 TCollection_AsciiString( i );
83 TCollection_AsciiString anItemValue = anElement.getAttribute( aStrIndex.ToCString() );
84 if ( anItemValue.IsIntegerValue() )
85 {
86 // store the value in the target array
87 aTarget->SetDoBackup (Standard_False);
88 aTarget->SetValue (anItemID.IntegerValue(), anItemValue.IntegerValue());
89 aTarget->SetDoBackup (Standard_True);
90 }
91 i++;
92 }
93 return Standard_True;
94}
95
96//=======================================================================
97//function : Paste
98//purpose : Store. Translate the contents of <theSource> and put it
99// into <theTarget>
100//=======================================================================
101
102void XmlTObjDrivers_IntSparseArrayDriver::Paste
103 (const Handle(TDF_Attribute)& theSource,
104 XmlObjMgt_Persistent& theTarget,
105 XmlObjMgt_SRelocationTable&) const
106{
107 Handle(TObj_TIntSparseArray) aSource =
108 Handle(TObj_TIntSparseArray)::DownCast (theSource);
109
110 // put only non-null values as pairs (ID, value)
111 // terminate the list by ID=0
112 TObj_TIntSparseArray::Iterator anIt = aSource->GetIterator();
113 Standard_Integer i = 1;
114 for ( ; anIt.More() ; anIt.Next() )
115 {
116 Standard_Integer aValue = anIt.Value();
117 if (aValue == 0)
118 continue;
119 TCollection_AsciiString anIdStr = TCollection_AsciiString( ITEM_ID ) +
120 TCollection_AsciiString( i );
121 TCollection_AsciiString aStrIndex = TCollection_AsciiString( ITEM_VALUE ) +
122 TCollection_AsciiString( i );
7dc9e047 123 theTarget.Element().setAttribute( anIdStr.ToCString(), (Standard_Integer)anIt.Index() );
7fd59977 124 theTarget.Element().setAttribute( aStrIndex.ToCString(), anIt.Value() );
125 i++;
126 }
127 // write last item
128 TCollection_AsciiString anIdStr = TCollection_AsciiString( ITEM_ID ) +
129 TCollection_AsciiString( i );
130 TCollection_AsciiString aStrIndex = TCollection_AsciiString( ITEM_VALUE ) +
131 TCollection_AsciiString( i );
132 theTarget.Element().setAttribute( anIdStr.ToCString(), 0 );
133 theTarget.Element().setAttribute( aStrIndex.ToCString(), 0 );
134}