HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_StringSet.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_StringSet.h
7  *
8  * COMMENTS: No UT_API here because there's no lib implementation!
9  */
10 
11 #pragma once
12 
13 #ifndef __UT_StringSet_h__
14 #define __UT_StringSet_h__
15 
16 #include "UT_ArrayStringSet.h" // This is only included to avoid sweeping for it right now.
17 #include "UT_Set.h"
18 #include "UT_StringHolder.h"
19 
20 /// We want methods like find() to take a const UT_StringRef& instead of a
21 /// const UT_StringHolder& for the following reasons:
22 /// - This allows a const char* to be passed in without forcing a copy of the string.
23 /// - A UT_StringRef can be used without converting it to a UT_StringHolder
24 /// (which hardens the string if necessary).
25 /// - A UT_StringHolder can still be directly passed in.
26 #define UT_STRINGREF_WRAPPER(return_type, name, qualifier) \
27  inline return_type name(const UT_StringRef &key) qualifier \
28  { \
29  return Parent::name(UTmakeUnsafeRef(key)); \
30  }
31 /// Specialization of the above macro for methods that return an iterator
32 /// range, since something like std::pair<iterator, iterator> is interpreted as
33 /// two arguments when being passed to a macro (due to the comma).
34 #define UT_STRINGREF_WRAPPER_RANGE(iterator_type, name, qualifier) \
35  inline std::pair<iterator_type, iterator_type> \
36  name(const UT_StringRef &key) qualifier \
37  { \
38  return Parent::name(UTmakeUnsafeRef(key)); \
39  }
40 
41 /// UT_StringSet is a simple specialization of a UT_Set that has
42 /// UT_StringHolder as its key type which allows C strings to be used.
43 /// If you know that a string will not be destroyed during the set's
44 /// lifetime, UTmakeUnsafeRef can be used to insert a shallow reference.
45 class UT_StringSet : public UT_Set<UT_StringHolder>
46 {
48 
49 public:
52  typedef Parent::size_type size_type;
53 
55  { return Parent::erase(pos); }
57  { return Parent::erase(first, last); }
58 
60  UT_STRINGREF_WRAPPER_RANGE(iterator, equal_range, )
63  UT_STRINGREF_WRAPPER(iterator, find, )
64  UT_STRINGREF_WRAPPER(const_iterator, find, const)
65 
67  { return count(ref) > 0; }
68 
69  bool contains(const UT_StringSet &src) const
70  { for (const_iterator it = src.begin(); it != src.end(); ++it)
71  if (!contains(*it))
72  return false;
73  return true; }
74 
75  /// Set-wise boolean operations.
77  { for (const_iterator it = src.begin(); it != src.end(); ++it)
78  insert(*it);
79  return *this; }
82  for (const_iterator it = src.begin(); it != src.end(); ++it)
83  if (contains(*it))
84  result.insert(*it);
85  *this = std::move(result);
86  return *this; }
88  { for (const_iterator it = src.begin(); it != src.end(); ++it)
89  erase(*it);
90  return *this; }
91 };
92 
93 class UT_SortedStringSet : public UT_SortedSet<UT_StringHolder>
94 {
96 
97 public:
100  typedef Parent::size_type size_type;
101 
103  { return Parent::erase(pos); }
105  { return Parent::erase(first, last); }
106 
108  UT_STRINGREF_WRAPPER_RANGE(iterator, equal_range, )
111  UT_STRINGREF_WRAPPER(iterator, find, )
112  UT_STRINGREF_WRAPPER(const_iterator, find, const)
113  UT_STRINGREF_WRAPPER(iterator, lower_bound, )
114  UT_STRINGREF_WRAPPER(const_iterator, lower_bound, const)
115  UT_STRINGREF_WRAPPER(iterator, upper_bound, )
116  UT_STRINGREF_WRAPPER(const_iterator, upper_bound, const)
117 
119  { return count(ref) > 0; }
120 
121  bool contains(const UT_SortedStringSet &src) const
122  { for (const_iterator it = src.begin(); it != src.end(); ++it)
123  if (!contains(*it))
124  return false;
125  return true; }
126 
127  /// Set-wise boolean operations.
129  { for (const_iterator it = src.begin(); it != src.end(); ++it)
130  insert(*it);
131  return *this; }
134  for (const_iterator it = src.begin(); it != src.end(); ++it)
135  if (contains(*it))
136  result.insert(*it);
137  *this = std::move(result);
138  return *this; }
140  { for (const_iterator it = src.begin(); it != src.end(); ++it)
141  erase(*it);
142  return *this; }
143 };
144 
145 #undef UT_STRINGREF_WRAPPER
146 #undef UT_STRINGREF_WRAPPER_RANGE
147 
148 #endif
bool contains(const UT_StringSet &src) const
Definition: UT_StringSet.h:69
vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
Definition: simd.h:3340
Definition: UT_Set.h:58
bool contains(const UT_SortedStringSet &src) const
Definition: UT_StringSet.h:121
GLenum src
Definition: glew.h:2410
GLenum GLint ref
Definition: glew.h:1845
Parent::size_type size_type
Definition: UT_StringSet.h:52
Parent::size_type size_type
Definition: UT_StringSet.h:100
UT_StringSet & operator-=(const UT_StringSet &src)
Definition: UT_StringSet.h:87
Base::const_iterator const_iterator
Definition: UT_Set.h:144
const GLint * first
Definition: glew.h:1528
bool contains(const UT_StringRef &ref) const
Definition: UT_StringSet.h:66
iterator erase(const_iterator first, const_iterator last)
Definition: UT_StringSet.h:104
UT_StringSet & operator|=(const UT_StringSet &src)
Set-wise boolean operations.
Definition: UT_StringSet.h:76
UT_SortedStringSet & operator&=(const UT_SortedStringSet &src)
Definition: UT_StringSet.h:132
Base::const_iterator const_iterator
Definition: UT_Set.h:215
Parent::const_iterator const_iterator
Definition: UT_StringSet.h:50
#define UT_STRINGREF_WRAPPER(return_type, name, qualifier)
Definition: UT_StringSet.h:26
Parent::const_iterator const_iterator
Definition: UT_StringSet.h:98
iterator erase(const_iterator pos)
Definition: UT_StringSet.h:102
UT_StringSet & operator&=(const UT_StringSet &src)
Definition: UT_StringSet.h:80
iterator erase(const_iterator first, const_iterator last)
Definition: UT_StringSet.h:56
UT_SortedStringSet & operator-=(const UT_SortedStringSet &src)
Definition: UT_StringSet.h:139
iterator erase(const_iterator pos)
Definition: UT_StringSet.h:54
#define UT_STRINGREF_WRAPPER_RANGE(iterator_type, name, qualifier)
Definition: UT_StringSet.h:34
FMT_CONSTEXPR bool find(Ptr first, Ptr last, T value, Ptr &out)
Definition: format.h:2104
GLuint GLuint GLsizei count
Definition: glew.h:1253
bool contains(const UT_StringRef &ref) const
Definition: UT_StringSet.h:118
GLuint64EXT * result
Definition: glew.h:14007
#define const
Definition: zconf.h:214
UT_SortedStringSet & operator|=(const UT_SortedStringSet &src)
Set-wise boolean operations.
Definition: UT_StringSet.h:128
Parent::iterator iterator
Definition: UT_StringSet.h:51
Base::iterator iterator
Definition: UT_Set.h:143
Parent::iterator iterator
Definition: UT_StringSet.h:99