]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/STLUtils.h
Update tcsh to git revision 83c5be0 bringing in a number of bug fixes.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / STLUtils.h
1 //===-- STLUtils.h ----------------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef liblldb_STLUtils_h_
10 #define liblldb_STLUtils_h_
11
12 #include <string.h>
13
14 #include <map>
15 #include <ostream>
16 #include <vector>
17
18
19 // C string less than compare function object
20 struct CStringCompareFunctionObject {
21   bool operator()(const char *s1, const char *s2) const {
22     return strcmp(s1, s2) < 0;
23   }
24 };
25
26 // C string equality function object (binary predicate).
27 struct CStringEqualBinaryPredicate {
28   bool operator()(const char *s1, const char *s2) const {
29     return strcmp(s1, s2) == 0;
30   }
31 };
32
33 // Templated type for finding an entry in a std::map<F,S> whose value is equal
34 // to something
35 template <class F, class S> class ValueEquals {
36 public:
37   ValueEquals(const S &val) : second_value(val) {}
38
39   // Compare the second item
40   bool operator()(std::pair<const F, S> elem) {
41     return elem.second == second_value;
42   }
43
44 private:
45   S second_value;
46 };
47
48 template <class T>
49 inline void PrintAllCollectionElements(std::ostream &s, const T &coll,
50                                        const char *header_cstr = nullptr,
51                                        const char *separator_cstr = " ") {
52   typename T::const_iterator pos;
53
54   if (header_cstr)
55     s << header_cstr;
56   for (pos = coll.begin(); pos != coll.end(); ++pos) {
57     s << *pos << separator_cstr;
58   }
59   s << std::endl;
60 }
61
62 // The function object below can be used to delete a STL container that
63 // contains C++ object pointers.
64 //
65 // Usage: std::for_each(vector.begin(), vector.end(), for_each_delete());
66
67 struct for_each_cplusplus_delete {
68   template <typename T> void operator()(T *ptr) { delete ptr; }
69 };
70
71 typedef std::vector<std::string> STLStringArray;
72 typedef std::vector<const char *> CStringArray;
73
74 #endif // liblldb_STLUtils_h_