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
PChildren(SequenceOfPersistent & theChildren) const45     virtual void PChildren (SequenceOfPersistent& theChildren) const
46     {
47       theChildren.Append(this->myPreviuos);
48       theChildren.Append(this->myNext);
49     }
50 
51     //! Returns persistent type name
PName() const52     virtual Standard_CString PName() const
53     {
54       Standard_NotImplemented::Raise("ShapePersistent_HSequence::node::PName - not implemented");
55       return "";
56     }
57 
Handle(node)58     const Handle(node)& Previuos() const  { return myPreviuos; }
Handle(node)59     const Handle(node)& Next()     const  { return myNext; }
Item() const60     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     //! Empty constructor.
instance()76     instance()
77     : mySize(0)
78     {
79     }
80 
81     //! Read persistent data from a file.
82     Standard_EXPORT virtual void Read (StdObjMgt_ReadData& theReadData);
83 
84     //! Write persistent data to a file.
85     Standard_EXPORT virtual void Write (StdObjMgt_WriteData& theWriteData) const;
86 
87     //! Gets persistent objects
PChildren(SequenceOfPersistent & theChildren) const88     virtual void PChildren(SequenceOfPersistent& theChildren) const
89     {
90       theChildren.Append(this->myFirst);
91       theChildren.Append(this->myLast);
92     }
93 
94     //! Returns persistent type name
PName() const95     virtual Standard_CString PName() const
96     {
97       Standard_NotImplemented::Raise("ShapePersistent_HSequence::instance::PName - not implemented");
98       return "";
99     }
100 
101     //! Import transient object from the persistent data.
102     Standard_EXPORT Handle(SequenceClass) Import() const;
103 
104   private:
105     Handle(Node)     myFirst;
106     Handle(Node)     myLast;
107     Standard_Integer mySize;
108   };
109 
110 public:
111   typedef instance<TColgp_HSequenceOfXYZ> XYZ;
112   typedef instance<TColgp_HSequenceOfPnt> Pnt;
113   typedef instance<TColgp_HSequenceOfDir> Dir;
114   typedef instance<TColgp_HSequenceOfVec> Vec;
115 };
116 
117 //=======================================================================
118 // XYZ
119 //=======================================================================
120 template<>
121 Standard_CString ShapePersistent_HSequence::instance<TColgp_HSequenceOfXYZ>
122   ::PName() const;
123 
124 template<>
125 Standard_CString ShapePersistent_HSequence::node<TColgp_HSequenceOfXYZ>
126   ::PName() const;
127 
128 //=======================================================================
129 // Pnt
130 //=======================================================================
131 template<>
132 Standard_CString ShapePersistent_HSequence::instance<TColgp_HSequenceOfPnt>
133   ::PName() const;
134 
135 template<>
136 Standard_CString ShapePersistent_HSequence::node<TColgp_HSequenceOfPnt>
137   ::PName() const;
138 
139 //=======================================================================
140 // Dir
141 //=======================================================================
142 template<>
143 Standard_CString ShapePersistent_HSequence::instance<TColgp_HSequenceOfDir>
144   ::PName() const;
145 
146 template<>
147 Standard_CString ShapePersistent_HSequence::node<TColgp_HSequenceOfDir>
148   ::PName() const;
149 
150 //=======================================================================
151 // Vec
152 //=======================================================================
153 template<>
154 Standard_CString ShapePersistent_HSequence::instance<TColgp_HSequenceOfVec>
155   ::PName() const;
156 
157 template<>
158 Standard_CString ShapePersistent_HSequence::node<TColgp_HSequenceOfVec>
159   ::PName() const;
160 
161 #endif
162