0028564: Support of applications using old persistence (ShapeSchema)
[occt.git] / src / ShapePersistent / ShapePersistent_HSequence.hxx
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 _ShapePersistent_HSequence_HeaderFile
16 #define _ShapePersistent_HSequence_HeaderFile
17
18 #include <Standard_NotImplemented.hxx>
19
20 #include <StdObjMgt_Persistent.hxx>
21 #include <StdObject_gp_Vectors.hxx>
22
23 #include <TColgp_HSequenceOfXYZ.hxx>
24 #include <TColgp_HSequenceOfPnt.hxx>
25 #include <TColgp_HSequenceOfDir.hxx>
26 #include <TColgp_HSequenceOfVec.hxx>
27
28
29 class ShapePersistent_HSequence
30 {
31   template <class SequenceClass>
32   class node : public StdObjMgt_Persistent
33   {
34   public:
35     typedef typename SequenceClass::value_type ItemType;
36
37   public:
38     //! Read persistent data from a file.
39     Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
40
41     //! Write persistent data to a file.
42     Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
43
44     //! Gets persistent objects
45     Standard_EXPORT virtual void PChildren (SequenceOfPersistent& theChildren) const
46     {
47       theChildren.Append(this->myPreviuos);
48       theChildren.Append(this->myNext);
49     }
50
51     //! Returns persistent type name
52     Standard_EXPORT virtual Standard_CString PName() const
53     {
54       Standard_NotImplemented::Raise("ShapePersistent_HSequence::node::PName - not implemented");
55       return "";
56     }
57
58     const Handle(node)& Previuos() const  { return myPreviuos; } 
59     const Handle(node)& Next()     const  { return myNext; } 
60     const ItemType&     Item()     const  { return myItem; }
61
62   private:
63     Handle(node) myPreviuos;
64     Handle(node) myNext;
65     ItemType     myItem;
66   };
67
68   template <class SequenceClass>
69   class instance : public StdObjMgt_Persistent
70   {
71   public:
72     typedef node<SequenceClass> Node;
73
74   public:
75     //! Read persistent data from a file.
76     Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
77
78     //! Write persistent data to a file.
79     Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
80
81     //! Gets persistent objects
82     Standard_EXPORT virtual void PChildren(SequenceOfPersistent& theChildren) const
83     {
84       theChildren.Append(this->myFirst);
85       theChildren.Append(this->myLast);
86     }
87
88     //! Returns persistent type name
89     Standard_EXPORT virtual Standard_CString PName() const
90     {
91       Standard_NotImplemented::Raise("ShapePersistent_HSequence::instance::PName - not implemented");
92       return "";
93     }
94
95     //! Import transient object from the persistent data.
96     Standard_EXPORT Handle(SequenceClass) Import() const;
97
98   private:
99     Handle(Node)     myFirst;
100     Handle(Node)     myLast;
101     Standard_Integer mySize;
102   };
103
104 public:
105   typedef instance<TColgp_HSequenceOfXYZ> XYZ;
106   typedef instance<TColgp_HSequenceOfPnt> Pnt;
107   typedef instance<TColgp_HSequenceOfDir> Dir;
108   typedef instance<TColgp_HSequenceOfVec> Vec;
109 };
110
111 //=======================================================================
112 // XYZ 
113 //=======================================================================
114 template<>
115 Standard_CString ShapePersistent_HSequence::instance<TColgp_HSequenceOfXYZ>
116   ::PName() const;
117
118 template<>
119 Standard_CString ShapePersistent_HSequence::node<TColgp_HSequenceOfXYZ>
120   ::PName() const;
121
122 //=======================================================================
123 // Pnt 
124 //=======================================================================
125 template<>
126 Standard_CString ShapePersistent_HSequence::instance<TColgp_HSequenceOfPnt>
127   ::PName() const;
128
129 template<>
130 Standard_CString ShapePersistent_HSequence::node<TColgp_HSequenceOfPnt>
131   ::PName() const;
132
133 //=======================================================================
134 // Dir 
135 //=======================================================================
136 template<>
137 Standard_CString ShapePersistent_HSequence::instance<TColgp_HSequenceOfDir>
138   ::PName() const;
139
140 template<>
141 Standard_CString ShapePersistent_HSequence::node<TColgp_HSequenceOfDir>
142   ::PName() const;
143
144 //=======================================================================
145 // Vec 
146 //=======================================================================
147 template<>
148 Standard_CString ShapePersistent_HSequence::instance<TColgp_HSequenceOfVec>
149   ::PName() const;
150
151 template<>
152 Standard_CString ShapePersistent_HSequence::node<TColgp_HSequenceOfVec>
153   ::PName() const;
154
155 #endif