0031687: Draw Harness, ViewerTest - extend command vrenderparams with option updating...
[occt.git] / src / StdObjMgt / StdObjMgt_Attribute.hxx
CommitLineData
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#ifndef _StdObjMgt_Attribute_HeaderFile
15#define _StdObjMgt_Attribute_HeaderFile
16
17#include <StdObjMgt_Persistent.hxx>
18#include <StdObjMgt_ReadData.hxx>
ec964372 19#include <StdObjMgt_WriteData.hxx>
ff205346 20
21
22//! Root class for a temporary persistent object corresponding to an attribute.
23template <class Transient>
45d8465e 24class StdObjMgt_Attribute : public Standard_Transient
ff205346 25{
26 class base : public StdObjMgt_Persistent
27 {
28 public:
29 //! Create an empty transient attribuite
0f57ab75 30 virtual Handle(TDF_Attribute) CreateAttribute()
ff205346 31 { return myTransient = new Transient; }
32
33 //! Get transient attribuite for the persistent data
0f57ab75 34 virtual Handle(TDF_Attribute) GetAttribute() const
ec964372 35 { return Handle(TDF_Attribute)(myTransient); }
ff205346 36
37 protected:
38 Handle(Transient) myTransient;
39 };
40
41public:
42 class Static : public base {};
43
44 template <class DataType>
45 class Simple : public Static
46 {
47 public:
48 //! Read persistent data from a file.
0f57ab75 49 virtual void Read (StdObjMgt_ReadData& theReadData)
ff205346 50 { theReadData >> myData; }
ec964372 51 //! Write persistent data to a file.
0f57ab75 52 virtual void Write (StdObjMgt_WriteData& theWriteData) const
ec964372 53 { theWriteData << myData; }
0f57ab75 54 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const { }
55 virtual Standard_CString PName() const { return "StdObjMgt_Attribute::undefined"; }
ff205346 56
57 protected:
58 DataType myData;
59 };
60
45d8465e 61 struct SingleInt : Simple<Standard_Integer> {};
62 struct SingleRef : Simple<Handle(StdObjMgt_Persistent)> {};
ff205346 63
64private:
65 template <class Persistent>
66 class container : public base
67 {
68 public:
69 //! Read persistent data from a file.
0f57ab75 70 virtual void Read (StdObjMgt_ReadData& theReadData)
ff205346 71 {
72 myPersistent = new Persistent;
73 myPersistent->Read (theReadData);
74 }
ec964372 75 //! Write persistent data to a file.
0f57ab75 76 virtual void Write(StdObjMgt_WriteData& theWriteData) const
ec964372 77 { myPersistent->Write(theWriteData); }
0f57ab75 78 virtual void PChildren(StdObjMgt_Persistent::SequenceOfPersistent&) const { }
79 virtual Standard_CString PName() const
ec964372 80 { return myPersistent->PName(); }
ff205346 81
82 //! Import transient attribuite from the persistent data
0f57ab75 83 virtual void ImportAttribute()
ff205346 84 {
85 if (myPersistent && this->myTransient)
86 {
87 myPersistent->Import (this->myTransient);
88 myPersistent.Nullify();
89 }
90 }
91
92 private:
93 Handle(Persistent) myPersistent;
94 };
95
96public:
97 template <class Persistent>
98 static Handle(StdObjMgt_Persistent) Instantiate()
99 { return new container<Persistent>; }
100};
101
102#endif // _StdObjMgt_Attribute_HeaderFile