1 | /////////////////////////////////////////////////////////////////////////// |
2 | // |
3 | // Copyright (c) 2002, Industrial Light & Magic, a division of Lucas |
4 | // Digital Ltd. LLC |
5 | // |
6 | // All rights reserved. |
7 | // |
8 | // Redistribution and use in source and binary forms, with or without |
9 | // modification, are permitted provided that the following conditions are |
10 | // met: |
11 | // * Redistributions of source code must retain the above copyright |
12 | // notice, this list of conditions and the following disclaimer. |
13 | // * Redistributions in binary form must reproduce the above |
14 | // copyright notice, this list of conditions and the following disclaimer |
15 | // in the documentation and/or other materials provided with the |
16 | // distribution. |
17 | // * Neither the name of Industrial Light & Magic nor the names of |
18 | // its contributors may be used to endorse or promote products derived |
19 | // from this software without specific prior written permission. |
20 | // |
21 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
22 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
23 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
24 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
25 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
26 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
27 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
28 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
29 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
30 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
31 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
32 | // |
33 | /////////////////////////////////////////////////////////////////////////// |
34 | |
35 | |
36 | |
37 | #ifndef INCLUDED_IMF_NAME_H |
38 | #define INCLUDED_IMF_NAME_H |
39 | |
40 | //----------------------------------------------------------------------------- |
41 | // |
42 | // class ImfName -- a zero-terminated string |
43 | // with a fixed, small maximum length |
44 | // |
45 | //----------------------------------------------------------------------------- |
46 | |
47 | #include <string.h> |
48 | #include "ImfNamespace.h" |
49 | #include "ImfExport.h" |
50 | |
51 | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER |
52 | |
53 | |
54 | class Name |
55 | { |
56 | public: |
57 | |
58 | //------------- |
59 | // Constructors |
60 | //------------- |
61 | |
62 | IMF_EXPORT |
63 | Name (); |
64 | IMF_EXPORT |
65 | Name (const char text[]); |
66 | |
67 | |
68 | //-------------------- |
69 | // Assignment operator |
70 | //-------------------- |
71 | |
72 | IMF_EXPORT |
73 | Name & operator = (const char text[]); |
74 | |
75 | |
76 | //--------------------- |
77 | // Access to the string |
78 | //--------------------- |
79 | |
80 | inline |
81 | const char * text () const {return _text;} |
82 | inline |
83 | const char * operator * () const {return _text;} |
84 | |
85 | //--------------- |
86 | // Maximum length |
87 | //--------------- |
88 | |
89 | static const int SIZE = 256; |
90 | static const int MAX_LENGTH = SIZE - 1; |
91 | |
92 | private: |
93 | |
94 | char _text[SIZE]; |
95 | }; |
96 | |
97 | |
98 | IMF_EXPORT |
99 | bool operator == (const Name &x, const Name &y); |
100 | IMF_EXPORT |
101 | bool operator != (const Name &x, const Name &y); |
102 | IMF_EXPORT |
103 | bool operator < (const Name &x, const Name &y); |
104 | |
105 | |
106 | //----------------- |
107 | // Inline functions |
108 | //----------------- |
109 | |
110 | inline Name & |
111 | Name::operator = (const char text[]) |
112 | { |
113 | strncpy (dest: _text, src: text, n: MAX_LENGTH); |
114 | return *this; |
115 | } |
116 | |
117 | |
118 | inline |
119 | Name::Name () |
120 | { |
121 | _text[0] = 0; |
122 | } |
123 | |
124 | |
125 | inline |
126 | Name::Name (const char text[]) |
127 | { |
128 | *this = text; |
129 | _text [MAX_LENGTH] = 0; |
130 | } |
131 | |
132 | |
133 | inline bool |
134 | operator == (const Name &x, const Name &y) |
135 | { |
136 | return strcmp (s1: *x, s2: *y) == 0; |
137 | } |
138 | |
139 | |
140 | inline bool |
141 | operator != (const Name &x, const Name &y) |
142 | { |
143 | return !(x == y); |
144 | } |
145 | |
146 | |
147 | inline bool |
148 | operator < (const Name &x, const Name &y) |
149 | { |
150 | return strcmp (s1: *x, s2: *y) < 0; |
151 | } |
152 | |
153 | |
154 | OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT |
155 | |
156 | |
157 | |
158 | |
159 | #endif |
160 | |