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_IntegerListDriver.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_Array1OfInteger.hxx> |
23 | #include <TColStd_ListIteratorOfListOfInteger.hxx> |
42cf5bc1 |
24 | #include <TDataStd_IntegerList.hxx> |
25 | #include <TDF_Attribute.hxx> |
7fd59977 |
26 | |
92efcf78 |
27 | IMPLEMENT_STANDARD_RTTIEXT(BinMDataStd_IntegerListDriver,BinMDF_ADriver) |
28 | |
7fd59977 |
29 | //======================================================================= |
30 | //function : BinMDataStd_IntegerListDriver |
31 | //purpose : Constructor |
32 | //======================================================================= |
83ae3591 |
33 | BinMDataStd_IntegerListDriver::BinMDataStd_IntegerListDriver(const Handle(Message_Messenger)& theMsgDriver) |
7fd59977 |
34 | : BinMDF_ADriver (theMsgDriver, STANDARD_TYPE(TDataStd_IntegerList)->Name()) |
35 | { |
36 | |
37 | } |
38 | |
39 | //======================================================================= |
40 | //function : NewEmpty |
41 | //purpose : |
42 | //======================================================================= |
43 | Handle(TDF_Attribute) BinMDataStd_IntegerListDriver::NewEmpty() const |
44 | { |
45 | return new TDataStd_IntegerList(); |
46 | } |
47 | |
48 | //======================================================================= |
49 | //function : Paste |
50 | //purpose : persistent -> transient (retrieve) |
51 | //======================================================================= |
52 | Standard_Boolean BinMDataStd_IntegerListDriver::Paste(const BinObjMgt_Persistent& theSource, |
5a1271c8 |
53 | const Handle(TDF_Attribute)& theTarget, |
b34d86cb |
54 | BinObjMgt_RRelocationTable& theRelocTable) const |
7fd59977 |
55 | { |
56 | Standard_Integer aIndex, aFirstInd, aLastInd; |
57 | if (! (theSource >> aFirstInd >> aLastInd)) |
58 | return Standard_False; |
d585e74e |
59 | const Handle(TDataStd_IntegerList) anAtt = Handle(TDataStd_IntegerList)::DownCast(theTarget); |
5a1271c8 |
60 | if(aLastInd > 0) { |
61 | const Standard_Integer aLength = aLastInd - aFirstInd + 1; |
62 | if (aLength > 0) { |
63 | TColStd_Array1OfInteger aTargetArray(aFirstInd, aLastInd); |
64 | theSource.GetIntArray (&aTargetArray(aFirstInd), aLength); |
65 | for (aIndex = aFirstInd; aIndex <= aLastInd; aIndex++) |
66 | anAtt->Append(aTargetArray.Value(aIndex)); |
67 | } |
7fd59977 |
68 | } |
5a1271c8 |
69 | |
b34d86cb |
70 | BinMDataStd::SetAttributeID(theSource, anAtt, theRelocTable.GetHeaderData()->StorageVersion().IntegerValue()); |
7fd59977 |
71 | return Standard_True; |
72 | } |
73 | |
74 | //======================================================================= |
75 | //function : Paste |
76 | //purpose : transient -> persistent (store) |
77 | //======================================================================= |
78 | void BinMDataStd_IntegerListDriver::Paste(const Handle(TDF_Attribute)& theSource, |
79 | BinObjMgt_Persistent& theTarget, |
80 | BinObjMgt_SRelocationTable& ) const |
81 | { |
d585e74e |
82 | const Handle(TDataStd_IntegerList) anAtt = Handle(TDataStd_IntegerList)::DownCast(theSource); |
83 | const Standard_Integer aFirstInd = (anAtt->Extent()> 0) ? 1 : 0; |
84 | const Standard_Integer aLastInd(anAtt->Extent()); |
7fd59977 |
85 | const Standard_Integer aLength = aLastInd - aFirstInd + 1; |
86 | if (aLength <= 0) |
87 | return; |
88 | theTarget << aFirstInd << aLastInd; |
d585e74e |
89 | if(aLastInd == 0) return; |
7fd59977 |
90 | TColStd_Array1OfInteger aSourceArray(aFirstInd, aLastInd); |
91 | if (aLastInd >= 1) |
92 | { |
93 | TColStd_ListIteratorOfListOfInteger itr(anAtt->List()); |
94 | for (Standard_Integer i = 1; itr.More(); itr.Next(), i++) |
95 | { |
96 | aSourceArray.SetValue(i, itr.Value()); |
97 | } |
98 | Standard_Integer *aPtr = (Standard_Integer *) &aSourceArray(aFirstInd); |
99 | theTarget.PutIntArray(aPtr, aLength); |
100 | } |
5a1271c8 |
101 | |
102 | // process user defined guid |
103 | if(anAtt->ID() != TDataStd_IntegerList::GetID()) |
104 | theTarget << anAtt->ID(); |
7fd59977 |
105 | } |