1 // Created on: 2007-03-30
2 // Created by: Michael SAZONOV
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // The original implementation Copyright: (C) RINA S.p.A
18 #include <XmlTObjDrivers_IntSparseArrayDriver.hxx>
19 #include <Message_Messenger.hxx>
20 #include <TDF_Attribute.hxx>
21 #include <XmlObjMgt_Persistent.hxx>
22 #include <TObj_TIntSparseArray.hxx>
23 #include <TObj_Assistant.hxx>
24 #include <TCollection_AsciiString.hxx>
25 #include <TDF_Tool.hxx>
28 IMPLEMENT_STANDARD_RTTIEXT(XmlTObjDrivers_IntSparseArrayDriver,XmlMDF_ADriver)
30 #define ITEM_ID "itemId_"
31 #define ITEM_VALUE "itemValue_"
33 //=======================================================================
34 //function : XmlTObjDrivers_IntSparseArrayDriver
35 //purpose : constructor
36 //=======================================================================
38 XmlTObjDrivers_IntSparseArrayDriver::XmlTObjDrivers_IntSparseArrayDriver
39 (const Handle(Message_Messenger)& theMessageDriver)
40 : XmlMDF_ADriver( theMessageDriver, NULL)
44 //=======================================================================
46 //purpose : Creates a new attribute
47 //=======================================================================
49 Handle(TDF_Attribute) XmlTObjDrivers_IntSparseArrayDriver::NewEmpty() const
51 return new TObj_TIntSparseArray;
54 //=======================================================================
56 //purpose : Retrieve. Translate the contents of <theSource> and put it
58 //=======================================================================
60 Standard_Boolean XmlTObjDrivers_IntSparseArrayDriver::Paste
61 (const XmlObjMgt_Persistent& theSource,
62 const Handle(TDF_Attribute)& theTarget,
63 XmlObjMgt_RRelocationTable&) const
65 const XmlObjMgt_Element& anElement = theSource;
66 Handle(TObj_TIntSparseArray) aTarget =
67 Handle(TObj_TIntSparseArray)::DownCast(theTarget);
69 // get pairs (ID, value) while ID != 0
70 Standard_Integer i = 1;
71 TCollection_AsciiString anItemID;
72 TCollection_AsciiString anIdStr = TCollection_AsciiString( ITEM_ID ) +
73 TCollection_AsciiString( i );
74 anItemID = anElement.getAttribute( anIdStr.ToCString() );
75 while( anItemID.IsIntegerValue() && anItemID.IntegerValue() != 0 )
77 TCollection_AsciiString aStrIndex = TCollection_AsciiString( ITEM_VALUE ) +
78 TCollection_AsciiString( i );
79 TCollection_AsciiString anItemValue = anElement.getAttribute( aStrIndex.ToCString() );
80 if ( anItemValue.IsIntegerValue() )
82 // store the value in the target array
83 aTarget->SetDoBackup (Standard_False);
84 aTarget->SetValue (anItemID.IntegerValue(), anItemValue.IntegerValue());
85 aTarget->SetDoBackup (Standard_True);
92 //=======================================================================
94 //purpose : Store. Translate the contents of <theSource> and put it
96 //=======================================================================
98 void XmlTObjDrivers_IntSparseArrayDriver::Paste
99 (const Handle(TDF_Attribute)& theSource,
100 XmlObjMgt_Persistent& theTarget,
101 XmlObjMgt_SRelocationTable&) const
103 Handle(TObj_TIntSparseArray) aSource =
104 Handle(TObj_TIntSparseArray)::DownCast (theSource);
106 // put only non-null values as pairs (ID, value)
107 // terminate the list by ID=0
108 TObj_TIntSparseArray::Iterator anIt = aSource->GetIterator();
109 Standard_Integer i = 1;
110 for ( ; anIt.More() ; anIt.Next() )
112 Standard_Integer aValue = anIt.Value();
115 TCollection_AsciiString anIdStr = TCollection_AsciiString( ITEM_ID ) +
116 TCollection_AsciiString( i );
117 TCollection_AsciiString aStrIndex = TCollection_AsciiString( ITEM_VALUE ) +
118 TCollection_AsciiString( i );
119 theTarget.Element().setAttribute( anIdStr.ToCString(), (Standard_Integer)anIt.Index() );
120 theTarget.Element().setAttribute( aStrIndex.ToCString(), anIt.Value() );
124 TCollection_AsciiString anIdStr = TCollection_AsciiString( ITEM_ID ) +
125 TCollection_AsciiString( i );
126 TCollection_AsciiString aStrIndex = TCollection_AsciiString( ITEM_VALUE ) +
127 TCollection_AsciiString( i );
128 theTarget.Element().setAttribute( anIdStr.ToCString(), 0 );
129 theTarget.Element().setAttribute( aStrIndex.ToCString(), 0 );