ff205346 |
1 | // Copyright (c) 2015 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | |
15 | #ifndef _StdLPersistent_NamedData_HeaderFile |
16 | #define _StdLPersistent_NamedData_HeaderFile |
17 | |
18 | #include <StdObjMgt_Attribute.hxx> |
19 | #include <StdLPersistent_HArray1.hxx> |
20 | #include <StdLPersistent_HArray2.hxx> |
21 | |
22 | #include <TDataStd_NamedData.hxx> |
23 | #include <TCollection_HExtendedString.hxx> |
24 | |
25 | class StdLPersistent_NamedData : public StdObjMgt_Attribute<TDataStd_NamedData> |
26 | { |
27 | template <class HValuesArray> |
45d8465e |
28 | class pMapData |
ff205346 |
29 | { |
30 | public: |
45d8465e |
31 | typedef typename HValuesArray::ValueType ValueType; |
32 | |
ff205346 |
33 | inline void Read (StdObjMgt_ReadData& theReadData) |
34 | { theReadData >> myKeys >> myValues; } |
ec964372 |
35 | inline void Write (StdObjMgt_WriteData& theWriteData) const |
36 | { theWriteData << myKeys << myValues; } |
ff205346 |
37 | |
38 | inline operator bool() const |
45d8465e |
39 | { return !myKeys.IsNull(); } |
40 | |
41 | const TCollection_ExtendedString& Key (Standard_Integer theIndex) const |
42 | { return myKeys->Array()->Value(theIndex)->ExtString()->String(); } |
ff205346 |
43 | |
45d8465e |
44 | ValueType Value (Standard_Integer theIndex) const |
45 | { return myValues ? myValues->Array()->Value(theIndex) : 0; } |
ff205346 |
46 | |
47 | private: |
45d8465e |
48 | Handle(StdLPersistent_HArray1::Persistent) myKeys; |
49 | Handle(HValuesArray) myValues; |
ff205346 |
50 | }; |
51 | |
52 | public: |
53 | //! Read persistent data from a file. |
54 | inline void Read (StdObjMgt_ReadData& theReadData) |
55 | { |
45d8465e |
56 | theReadData >> myDimensions; |
57 | myInts .Read (theReadData); |
58 | myReals .Read (theReadData); |
59 | myStrings .Read (theReadData); |
60 | myBytes .Read (theReadData); |
61 | myIntArrays .Read (theReadData); |
62 | myRealArrays.Read (theReadData); |
ff205346 |
63 | } |
64 | |
ec964372 |
65 | //! Write persistent data to a file. |
66 | inline void Write (StdObjMgt_WriteData& theWriteData) const |
67 | { |
68 | theWriteData << myDimensions; |
69 | myInts.Write(theWriteData); |
70 | myReals.Write(theWriteData); |
71 | myStrings.Write(theWriteData); |
72 | myBytes.Write(theWriteData); |
73 | myIntArrays.Write(theWriteData); |
74 | myRealArrays.Write(theWriteData); |
75 | } |
76 | |
77 | //! Gets persistent child objects |
78 | void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const {} |
79 | |
80 | //! Returns persistent type name |
81 | Standard_CString PName() const { return "PDataStd_NamedData"; } |
82 | |
316ea293 |
83 | //! Import transient attribute from the persistent data. |
ff205346 |
84 | void Import (const Handle(TDataStd_NamedData)& theAttribute) const; |
85 | |
86 | private: |
87 | inline Standard_Integer lower (Standard_Integer theIndex) const; |
88 | inline Standard_Integer upper (Standard_Integer theIndex) const; |
89 | |
90 | private: |
45d8465e |
91 | Handle(StdLPersistent_HArray2::Integer) myDimensions; |
92 | pMapData<StdLPersistent_HArray1::Integer> myInts; |
93 | pMapData<StdLPersistent_HArray1::Real> myReals; |
94 | pMapData<StdLPersistent_HArray1::Persistent> myStrings; |
95 | pMapData<StdLPersistent_HArray1::Byte> myBytes; |
96 | pMapData<StdLPersistent_HArray1::Persistent> myIntArrays; |
97 | pMapData<StdLPersistent_HArray1::Persistent> myRealArrays; |
ff205346 |
98 | }; |
99 | |
100 | #endif |