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

source code of include/OpenEXR/ImfName.h