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; } |
35 | |
36 | inline operator bool() const |
45d8465e |
37 | { return !myKeys.IsNull(); } |
38 | |
39 | const TCollection_ExtendedString& Key (Standard_Integer theIndex) const |
40 | { return myKeys->Array()->Value(theIndex)->ExtString()->String(); } |
ff205346 |
41 | |
45d8465e |
42 | ValueType Value (Standard_Integer theIndex) const |
43 | { return myValues ? myValues->Array()->Value(theIndex) : 0; } |
ff205346 |
44 | |
45 | private: |
45d8465e |
46 | Handle(StdLPersistent_HArray1::Persistent) myKeys; |
47 | Handle(HValuesArray) myValues; |
ff205346 |
48 | }; |
49 | |
50 | public: |
51 | //! Read persistent data from a file. |
52 | inline void Read (StdObjMgt_ReadData& theReadData) |
53 | { |
45d8465e |
54 | theReadData >> myDimensions; |
55 | myInts .Read (theReadData); |
56 | myReals .Read (theReadData); |
57 | myStrings .Read (theReadData); |
58 | myBytes .Read (theReadData); |
59 | myIntArrays .Read (theReadData); |
60 | myRealArrays.Read (theReadData); |
ff205346 |
61 | } |
62 | |
63 | //! Import transient attribuite from the persistent data. |
64 | void Import (const Handle(TDataStd_NamedData)& theAttribute) const; |
65 | |
66 | private: |
67 | inline Standard_Integer lower (Standard_Integer theIndex) const; |
68 | inline Standard_Integer upper (Standard_Integer theIndex) const; |
69 | |
70 | private: |
45d8465e |
71 | Handle(StdLPersistent_HArray2::Integer) myDimensions; |
72 | pMapData<StdLPersistent_HArray1::Integer> myInts; |
73 | pMapData<StdLPersistent_HArray1::Real> myReals; |
74 | pMapData<StdLPersistent_HArray1::Persistent> myStrings; |
75 | pMapData<StdLPersistent_HArray1::Byte> myBytes; |
76 | pMapData<StdLPersistent_HArray1::Persistent> myIntArrays; |
77 | pMapData<StdLPersistent_HArray1::Persistent> myRealArrays; |
ff205346 |
78 | }; |
79 | |
80 | #endif |