Coverage Report

Created: 2025-10-10 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openexr/src/lib/OpenEXR/ImfBytesAttribute.h
Line
Count
Source
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
29
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
30
31
class IMF_EXPORT_TYPE BytesAttribute : public Attribute
32
{
33
public:
34
    //----------------------------
35
    // Constructors and destructor
36
    //----------------------------
37
38
    IMF_EXPORT BytesAttribute ();
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
69
    IMF_EXPORT void writeValueTo (
70
        OPENEXR_IMF_INTERNAL_NAMESPACE::OStream& os, int version) const override;
71
72
    IMF_EXPORT void readValueFrom (
73
        OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is, int size, int version) override;
74
75
    IMF_EXPORT void copyValueFrom (const Attribute& other) override;
76
77
0
    size_t size () const { return _data.size (); }
78
0
    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
122
OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
123
124
#endif