/src/openexr/src/lib/OpenEXR/ImfStringVectorAttribute.cpp
Line | Count | Source |
1 | | // |
2 | | // SPDX-License-Identifier: BSD-3-Clause |
3 | | // Copyright (c) Weta Digital, Ltd and Contributors to the OpenEXR Project. |
4 | | // |
5 | | |
6 | | //----------------------------------------------------------------------------- |
7 | | // |
8 | | // class StringVectorAttribute |
9 | | // |
10 | | //----------------------------------------------------------------------------- |
11 | | |
12 | | #define COMPILING_IMF_STRING_VECTOR_ATTRIBUTE |
13 | | |
14 | | #include "ImfStringVectorAttribute.h" |
15 | | |
16 | | #if defined(_MSC_VER) |
17 | | // suppress warning about non-exported base classes |
18 | | # pragma warning(disable : 4251) |
19 | | # pragma warning(disable : 4275) |
20 | | #endif |
21 | | |
22 | | OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER |
23 | | |
24 | | using namespace OPENEXR_IMF_INTERNAL_NAMESPACE; |
25 | | |
26 | | template <> |
27 | | IMF_EXPORT const char* |
28 | | StringVectorAttribute::staticTypeName () |
29 | 257 | { |
30 | 257 | return "stringvector"; |
31 | 257 | } |
32 | | |
33 | | template <> |
34 | | IMF_EXPORT void |
35 | | StringVectorAttribute::writeValueTo ( |
36 | | OPENEXR_IMF_INTERNAL_NAMESPACE::OStream& os, int version) const |
37 | 0 | { |
38 | 0 | int size = _value.size (); |
39 | |
|
40 | 0 | for (int i = 0; i < size; i++) |
41 | 0 | { |
42 | 0 | int strSize = _value[i].size (); |
43 | 0 | Xdr::write<StreamIO> (os, strSize); |
44 | 0 | Xdr::write<StreamIO> (os, &_value[i][0], strSize); |
45 | 0 | } |
46 | 0 | } |
47 | | |
48 | | template <> |
49 | | IMF_EXPORT void |
50 | | StringVectorAttribute::readValueFrom ( |
51 | | OPENEXR_IMF_INTERNAL_NAMESPACE::IStream& is, int size, int version) |
52 | 0 | { |
53 | 0 | int read = 0; |
54 | |
|
55 | 0 | while (read < size) |
56 | 0 | { |
57 | 0 | int strSize; |
58 | 0 | Xdr::read<StreamIO> (is, strSize); |
59 | 0 | read += Xdr::size<int> (); |
60 | | |
61 | | // check there is enough space remaining in attribute to |
62 | | // contain claimed string length |
63 | 0 | if (strSize < 0 || strSize > size - read) |
64 | 0 | { |
65 | 0 | throw IEX_NAMESPACE::InputExc ( |
66 | 0 | "Invalid size field reading stringvector attribute"); |
67 | 0 | } |
68 | | |
69 | 0 | std::string str; |
70 | 0 | str.resize (strSize); |
71 | |
|
72 | 0 | if (strSize > 0) { Xdr::read<StreamIO> (is, &str[0], strSize); } |
73 | |
|
74 | 0 | read += strSize; |
75 | |
|
76 | 0 | _value.push_back (str); |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | | template class IMF_EXPORT_TEMPLATE_INSTANCE |
81 | | TypedAttribute<OPENEXR_IMF_INTERNAL_NAMESPACE::StringVector>; |
82 | | |
83 | | OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT |