/usr/local/include/OpenEXR/ImfName.h
Line | Count | Source (jump to first uncovered line) |
1 | | // |
2 | | // SPDX-License-Identifier: BSD-3-Clause |
3 | | // Copyright (c) Contributors to the OpenEXR Project. |
4 | | // |
5 | | |
6 | | #ifndef INCLUDED_IMF_NAME_H |
7 | | #define INCLUDED_IMF_NAME_H |
8 | | |
9 | | //----------------------------------------------------------------------------- |
10 | | // |
11 | | // class ImfName -- a zero-terminated string |
12 | | // with a fixed, small maximum length |
13 | | // |
14 | | //----------------------------------------------------------------------------- |
15 | | |
16 | | #include "ImfExport.h" |
17 | | #include "ImfNamespace.h" |
18 | | |
19 | | #include <cstring> |
20 | | |
21 | | #if defined(_MSC_VER) |
22 | | # pragma warning(push, 0) |
23 | | # pragma warning(disable : 4996) |
24 | | #endif |
25 | | |
26 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER |
27 | | |
28 | | class IMF_EXPORT_TYPE Name |
29 | | { |
30 | | public: |
31 | | //------------- |
32 | | // Constructors |
33 | | //------------- |
34 | | |
35 | | Name (); |
36 | | Name (const char text[]); |
37 | | Name (const Name&) = default; |
38 | | Name (Name&&) = default; |
39 | | ~Name () = default; |
40 | | |
41 | | //-------------------- |
42 | | // Assignment operator |
43 | | //-------------------- |
44 | | |
45 | | Name& operator= (const Name&) = default; |
46 | | Name& operator= (Name&&) = default; |
47 | | Name& operator= (const char text[]); |
48 | | |
49 | | //--------------------- |
50 | | // Access to the string |
51 | | //--------------------- |
52 | | |
53 | 0 | inline const char* text () const { return _text; } |
54 | 14.4M | inline const char* operator* () const { return _text; } |
55 | | |
56 | | //--------------- |
57 | | // Maximum length |
58 | | //--------------- |
59 | | |
60 | | static const int SIZE = 256; |
61 | | static const int MAX_LENGTH = SIZE - 1; |
62 | | |
63 | | private: |
64 | | char _text[SIZE]; |
65 | | }; |
66 | | |
67 | | //----------------- |
68 | | // Inline functions |
69 | | //----------------- |
70 | | |
71 | | inline Name& |
72 | | Name::operator= (const char text[]) |
73 | 2.03M | { |
74 | 2.03M | strncpy (_text, text, MAX_LENGTH); |
75 | 2.03M | return *this; |
76 | 2.03M | } |
77 | | |
78 | | inline Name::Name () |
79 | | { |
80 | | _text[0] = 0; |
81 | | } |
82 | | |
83 | | inline Name::Name (const char text[]) |
84 | 2.03M | { |
85 | 2.03M | *this = text; |
86 | 2.03M | _text[MAX_LENGTH] = 0; |
87 | 2.03M | } |
88 | | |
89 | | inline bool |
90 | | operator== (const Name& x, const Name& y) |
91 | 0 | { |
92 | 0 | return strcmp (*x, *y) == 0; |
93 | 0 | } |
94 | | |
95 | | inline bool |
96 | | operator== (const Name& x, const char text[]) |
97 | 0 | { |
98 | 0 | return strcmp (*x, text) == 0; |
99 | 0 | } |
100 | | |
101 | | inline bool |
102 | | operator== (const char text[], const Name& y) |
103 | 0 | { |
104 | 0 | return strcmp (text, *y) == 0; |
105 | 0 | } |
106 | | |
107 | | inline bool |
108 | | operator!= (const Name& x, const Name& y) |
109 | 0 | { |
110 | 0 | return !(x == y); |
111 | 0 | } |
112 | | |
113 | | inline bool |
114 | | operator!= (const Name& x, const char text[]) |
115 | 0 | { |
116 | 0 | return !(x == text); |
117 | 0 | } |
118 | | |
119 | | inline bool |
120 | | operator!= (const char text[], const Name& y) |
121 | 0 | { |
122 | 0 | return !(text == y); |
123 | 0 | } |
124 | | |
125 | | inline bool |
126 | | operator< (const Name& x, const Name& y) |
127 | 7.15M | { |
128 | 7.15M | return strcmp (*x, *y) < 0; |
129 | 7.15M | } |
130 | | |
131 | | inline bool |
132 | | operator< (const Name& x, const char text[]) |
133 | 0 | { |
134 | 0 | return strcmp (*x, text) < 0; |
135 | 0 | } |
136 | | |
137 | | inline bool |
138 | | operator< (const char text[], const Name& y) |
139 | 0 | { |
140 | 0 | return strcmp (text, *y) < 0; |
141 | 0 | } |
142 | | |
143 | | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT |
144 | | |
145 | | #if defined(_MSC_VER) |
146 | | # pragma warning(pop) |
147 | | #endif |
148 | | |
149 | | #endif |