0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[occt.git] / src / TDataStd / TDataStd_ByteArray.hxx
1 // Created on: 2007-05-29
2 // Created by: Vlad Romashko
3 // Copyright (c) 2007-2014 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _TDataStd_ByteArray_HeaderFile
17 #define _TDataStd_ByteArray_HeaderFile
18
19 #include <Standard.hxx>
20 #include <Standard_Type.hxx>
21
22 #include <TColStd_HArray1OfByte.hxx>
23 #include <Standard_Boolean.hxx>
24 #include <TDF_Attribute.hxx>
25 #include <Standard_Integer.hxx>
26 #include <Standard_Byte.hxx>
27 #include <Standard_OStream.hxx>
28 #include <Standard_GUID.hxx>
29
30 class TDataStd_DeltaOnModificationOfByteArray;
31 class Standard_GUID;
32 class TDF_Label;
33 class TDF_Attribute;
34 class TDF_RelocationTable;
35 class TDF_DeltaOnModification;
36
37
38 class TDataStd_ByteArray;
39 DEFINE_STANDARD_HANDLE(TDataStd_ByteArray, TDF_Attribute)
40
41 //! An array of Byte (unsigned char) values.
42 class TDataStd_ByteArray : public TDF_Attribute
43 {
44   friend class TDataStd_DeltaOnModificationOfByteArray;
45   DEFINE_STANDARD_RTTIEXT(TDataStd_ByteArray, TDF_Attribute)
46 public:
47
48   
49   //! Static methods
50   //! ==============
51   //! Returns an ID for array.
52   Standard_EXPORT static const Standard_GUID& GetID();
53   
54   //! Finds or creates an attribute with the array on the specified label.
55   //! If <isDelta> == False, DefaultDeltaOnModification is used.
56   //! If <isDelta> == True, DeltaOnModification of the current attribute is used.
57   //! If attribute is already set, all input parameters are refused and the found
58   //! attribute is returned.
59   Standard_EXPORT static Handle(TDataStd_ByteArray) Set (const TDF_Label& label, const Standard_Integer lower, const Standard_Integer upper, const Standard_Boolean isDelta = Standard_False);
60   
61   //! Finds or creates an attribute with byte array and explicit user defined <guid> on the specified label.
62   Standard_EXPORT static Handle(TDataStd_ByteArray) Set (const TDF_Label& label, const Standard_GUID&   theGuid,
63                                                          const Standard_Integer lower, const Standard_Integer upper, 
64                                                          const Standard_Boolean isDelta = Standard_False);
65   
66   //! Initialize the inner array with bounds from <lower> to <upper>
67   Standard_EXPORT void Init (const Standard_Integer lower, const Standard_Integer upper);
68   
69   //! Sets the <Index>th element of the array to <Value>
70   //! OutOfRange exception is raised if <Index> doesn't respect Lower and Upper bounds of the internal  array.
71   Standard_EXPORT void SetValue (const Standard_Integer index, const Standard_Byte value);
72   
73   //! Sets the explicit GUID (user defined) for the attribute.
74   Standard_EXPORT void SetID( const Standard_GUID&  theGuid) Standard_OVERRIDE;
75
76   //! Sets default GUID for the attribute.
77   Standard_EXPORT void SetID() Standard_OVERRIDE;
78
79   //! Return the value of the <Index>th element of the array.
80   Standard_EXPORT Standard_Byte Value (const Standard_Integer Index) const;
81
82   Standard_Byte operator () (const Standard_Integer Index) const
83   {
84     return Value(Index);
85   }
86   
87   //! Returns the lower boundary of the array.
88   Standard_EXPORT Standard_Integer Lower() const;
89   
90   //! Returns the upper boundary of the array.
91   Standard_EXPORT Standard_Integer Upper() const;
92   
93   //! Returns the number of elements in the array.
94   Standard_EXPORT Standard_Integer Length() const;
95
96   const Handle(TColStd_HArray1OfByte)& InternalArray() const { return myValue; }
97
98   //! Sets the inner array <myValue>  of the attribute to
99   //! <newArray>. If value of <newArray> differs from <myValue>, Backup performed
100   //! and myValue refers to new instance of HArray1OfInteger that holds <newArray>
101   //! values.
102   //! If <isCheckItems> equal True each item of <newArray> will be checked with each
103   //! item of <myValue> for coincidence (to avoid backup).
104   Standard_EXPORT void ChangeArray (const Handle(TColStd_HArray1OfByte)& newArray, const Standard_Boolean isCheckItems = Standard_True);
105
106   Standard_Boolean GetDelta() const { return myIsDelta; }
107
108   //! for internal  use  only!
109   void SetDelta (const Standard_Boolean isDelta) { myIsDelta = isDelta; }
110
111   Standard_EXPORT TDataStd_ByteArray();
112   
113   Standard_EXPORT const Standard_GUID& ID() const Standard_OVERRIDE;
114   
115   Standard_EXPORT void Restore (const Handle(TDF_Attribute)& with) Standard_OVERRIDE;
116   
117   Standard_EXPORT Handle(TDF_Attribute) NewEmpty() const Standard_OVERRIDE;
118   
119   Standard_EXPORT void Paste (const Handle(TDF_Attribute)& into, const Handle(TDF_RelocationTable)& RT) const Standard_OVERRIDE;
120   
121   Standard_EXPORT virtual Standard_OStream& Dump (Standard_OStream& OS) const Standard_OVERRIDE;
122   
123   //! Makes a DeltaOnModification between <me> and
124   //! <anOldAttribute>.
125   Standard_EXPORT virtual Handle(TDF_DeltaOnModification) DeltaOnModification (const Handle(TDF_Attribute)& anOldAttribute) const Standard_OVERRIDE;
126   
127   //! Dumps the content of me into the stream
128   Standard_EXPORT virtual void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const Standard_OVERRIDE;
129
130 private:
131
132   void RemoveArray() { myValue.Nullify(); }
133   
134 private:
135
136   Handle(TColStd_HArray1OfByte) myValue;
137   Standard_Boolean myIsDelta;
138   Standard_GUID myID;
139
140 };
141
142 #endif // _TDataStd_ByteArray_HeaderFile