HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfBytesAttribute.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5 
6 #ifndef INCLUDED_IMF_BYTES_ATTRIBUTE_H
7 #define INCLUDED_IMF_BYTES_ATTRIBUTE_H
8 
9 //-----------------------------------------------------------------------------
10 //
11 // class BytesAttribute
12 //
13 // BytesAttribute allows arbitrary binary data to be stored as an attribute.
14 // It holds a sequence of bytes, with the length specified by the `size` arg.
15 //
16 // Unlike OpaqueAttribute, which also stores raw bytes, BytesAttribute is
17 // explicitly intended for use when the data is known to be a byte sequence.
18 // OpaqueAttribute should remain semantically uninterpreted, whereas
19 // BytesAttribute conveys an explicit intent to store binary data.
20 //
21 //-----------------------------------------------------------------------------
22 
23 #include "ImfExport.h"
24 #include "ImfNamespace.h"
25 
26 #include "ImfArray.h"
27 #include "ImfAttribute.h"
28 
30 
32 {
33 public:
34  //----------------------------
35  // Constructors and destructor
36  //----------------------------
37 
39  IMF_EXPORT BytesAttribute (
40  size_t size,
41  const void* data,
42  const std::string& typeHint = "");
43 
44  IMF_EXPORT BytesAttribute (const BytesAttribute& other);
45  IMF_EXPORT virtual ~BytesAttribute ();
46 
47  //----------
48  // Operators
49  //----------
50 
51  IMF_EXPORT bool operator==(const BytesAttribute& other) const;
52 
53  //-------------------------------
54  // Get this attribute's type name
55  //-------------------------------
56 
57  IMF_EXPORT const char* typeName () const override;
58 
59  //------------------------------
60  // Make a copy of this attribute
61  //------------------------------
62 
63  IMF_EXPORT Attribute* copy () const override;
64 
65  //----------------
66  // I/O and copying
67  //----------------
68 
70  OPENEXR_IMF_INTERNAL_NAMESPACE::OStream& os, int version) const override;
71 
73  OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is, int size, int version) override;
74 
75  IMF_EXPORT void copyValueFrom (const Attribute& other) override;
76 
77  size_t size () const { return _data.size (); }
78  const Array<unsigned char>& data () const { return _data; }
79  IMF_EXPORT void setData(const unsigned char* data, size_t size);
80  std::string typeHint;
81 
82  //--------------------------------
83  // Methods to support registration
84  //--------------------------------
85 
86  //---------------------------------------------------------
87  // Static version of typeName()
88  //---------------------------------------------------------
89 
90  static const char* staticTypeName ();
91 
92  //---------------------
93  // Make a new attribute
94  //---------------------
95 
96  static Attribute* makeNewAttribute ();
97 
98  //---------------------------------------------------------------
99  // Register this attribute type so that Attribute::newAttribute()
100  // knows how to make objects of this type.
101  //
102  // Note that this function is not thread-safe because it modifies
103  // a global variable in the IlmIlm library. A thread in a multi-
104  // threaded program may call registerAttributeType() only when no
105  // other thread is accessing any functions or classes in the
106  // OpenEXR library.
107  //
108  //---------------------------------------------------------------
109 
110  static void registerAttributeType ();
111 
112  //-----------------------------------------------------
113  // Un-register this attribute type (for debugging only)
114  //-----------------------------------------------------
115 
116  static void unRegisterAttributeType ();
117 
118 private:
119  Array<unsigned char> _data;
120 };
121 
123 
124 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:83
virtual Attribute * copy() const =0
const Array< unsigned char > & data() const
virtual void writeValueTo(OPENEXR_IMF_INTERNAL_NAMESPACE::OStream &os, int version) const =0
static IMF_EXPORT void unRegisterAttributeType(const char typeName[])
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
Definition: Dimensions.h:137
#define IMF_EXPORT
Definition: ImfExport.h:54
class IMF_EXPORT_TYPE OStream
Definition: ImfForward.h:86
static IMF_EXPORT void registerAttributeType(const char typeName[], Attribute *(*newAttribute)())
GT_API const UT_StringHolder version
GLsizeiptr size
Definition: glcorearb.h:664
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:80
std::string typeHint
virtual const char * typeName() const =0
virtual void readValueFrom(OPENEXR_IMF_INTERNAL_NAMESPACE::IStream &is, int size, int version)=0
size_t size() const
#define IMF_EXPORT_TYPE
Definition: ImfExport.h:57
Definition: format.h:1821
virtual void copyValueFrom(const Attribute &other)=0
class IMF_EXPORT_TYPE IStream
Definition: ImfForward.h:87