0029220: Application Framework - replace CDM_MessageDriver interface by Message_Messe...
[occt.git] / src / BinMDataStd / BinMDataStd_ExtStringListDriver.cxx
CommitLineData
b311480e 1// Created on: 2007-05-29
2// Created by: Vlad Romashko
973c2be1 3// Copyright (c) 2007-2014 OPEN CASCADE SAS
b311480e 4//
973c2be1 5// This file is part of Open CASCADE Technology software library.
b311480e 6//
d5f74e42 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
973c2be1 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.
b311480e 12//
973c2be1 13// Alternatively, this file may be used under the terms of Open CASCADE
14// commercial license or contractual agreement.
7fd59977 15
42cf5bc1 16
17#include <BinMDataStd_ExtStringListDriver.hxx>
5a1271c8 18#include <BinMDataStd.hxx>
42cf5bc1 19#include <BinObjMgt_Persistent.hxx>
83ae3591 20#include <Message_Messenger.hxx>
42cf5bc1 21#include <Standard_Type.hxx>
7fd59977 22#include <TColStd_Array1OfExtendedString.hxx>
42cf5bc1 23#include <TDataStd_ExtStringList.hxx>
7fd59977 24#include <TDataStd_ListIteratorOfListOfExtendedString.hxx>
42cf5bc1 25#include <TDF_Attribute.hxx>
7fd59977 26
92efcf78 27IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_ExtStringListDriver,BinMDF_ADriver)
28
7fd59977 29//=======================================================================
30//function : BinMDataStd_ExtStringListDriver
31//purpose : Constructor
32//=======================================================================
83ae3591 33BinMDataStd_ExtStringListDriver::BinMDataStd_ExtStringListDriver(const Handle(Message_Messenger)& theMsgDriver)
7fd59977 34 : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_ExtStringList)->Name())
35{
36
37}
38
39//=======================================================================
40//function : NewEmpty
41//purpose :
42//=======================================================================
43Handle(TDF_Attribute) BinMDataStd_ExtStringListDriver::NewEmpty() const
44{
45 return new TDataStd_ExtStringList();
46}
47
48//=======================================================================
49//function : Paste
50//purpose : persistent -> transient (retrieve)
51//=======================================================================
d585e74e 52Standard_Boolean BinMDataStd_ExtStringListDriver::Paste
53 (const BinObjMgt_Persistent& theSource,
54 const Handle(TDF_Attribute)& theTarget,
55 BinObjMgt_RRelocationTable& ) const
7fd59977 56{
57 Standard_Integer aFirstInd, aLastInd;
58 if (! (theSource >> aFirstInd >> aLastInd))
59 return Standard_False;
5a1271c8 60
61 const Handle(TDataStd_ExtStringList) anAtt = Handle(TDataStd_ExtStringList)::DownCast(theTarget);
62 if(aLastInd > 0) {
63 const Standard_Integer aLength = aLastInd - aFirstInd + 1;
64 if (aLength <= 0)
7fd59977 65 return Standard_False;
5a1271c8 66 for (Standard_Integer i = aFirstInd; i <= aLastInd; i ++)
67 {
68 TCollection_ExtendedString aStr;
69 if ( !(theSource >> aStr) )
70 {
71 return Standard_False;
72 }
73 anAtt->Append(aStr);
7fd59977 74 }
7fd59977 75 }
76
5a1271c8 77 BinMDataStd::SetAttributeID(theSource, anAtt);
7fd59977 78 return Standard_True;
79}
80
81//=======================================================================
82//function : Paste
83//purpose : transient -> persistent (store)
84//=======================================================================
d585e74e 85void BinMDataStd_ExtStringListDriver::Paste
86 (const Handle(TDF_Attribute)& theSource,
87 BinObjMgt_Persistent& theTarget,
88 BinObjMgt_SRelocationTable& ) const
7fd59977 89{
d585e74e 90 const Handle(TDataStd_ExtStringList) anAtt =
91 Handle(TDataStd_ExtStringList)::DownCast(theSource);
92 const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0;
93 const Standard_Integer aLastInd(anAtt->Extent());
7fd59977 94 theTarget << aFirstInd << aLastInd;
95 TDataStd_ListIteratorOfListOfExtendedString itr(anAtt->List());
96 for (; itr.More(); itr.Next())
97 {
98 theTarget << itr.Value();
99 }
5a1271c8 100
101 // process user defined guid
102 if(anAtt->ID() != TDataStd_ExtStringList::GetID())
103 theTarget << anAtt->ID();
7fd59977 104}