]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/include/lldb/Core/STLUtils.h
Merge ^/head r311812 through r311939.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / include / lldb / Core / STLUtils.h
1 //===-- STLUtils.h ----------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef liblldb_STLUtils_h_
11 #define liblldb_STLUtils_h_
12
13 // C Includes
14 #include <string.h>
15
16 // C++ Includes
17 #include <map>
18 #include <ostream>
19 #include <vector>
20
21 // Other libraries and framework includes
22 // Project includes
23
24 //----------------------------------------------------------------------
25 // C string less than compare function object
26 //----------------------------------------------------------------------
27 struct CStringCompareFunctionObject {
28   bool operator()(const char *s1, const char *s2) const {
29     return strcmp(s1, s2) < 0;
30   }
31 };
32
33 //----------------------------------------------------------------------
34 // C string equality function object (binary predicate).
35 //----------------------------------------------------------------------
36 struct CStringEqualBinaryPredicate {
37   bool operator()(const char *s1, const char *s2) const {
38     return strcmp(s1, s2) == 0;
39   }
40 };
41
42 //----------------------------------------------------------------------
43 // Templated type for finding an entry in a std::map<F,S> whose value
44 // is equal to something
45 //----------------------------------------------------------------------
46 template <class F, class S> class ValueEquals {
47 public:
48   ValueEquals(const S &val) : second_value(val) {}
49
50   // Compare the second item
51   bool operator()(std::pair<const F, S> elem) {
52     return elem.second == second_value;
53   }
54
55 private:
56   S second_value;
57 };
58
59 template <class T>
60 inline void PrintAllCollectionElements(std::ostream &s, const T &coll,
61                                        const char *header_cstr = nullptr,
62                                        const char *separator_cstr = " ") {
63   typename T::const_iterator pos;
64
65   if (header_cstr)
66     s << header_cstr;
67   for (pos = coll.begin(); pos != coll.end(); ++pos) {
68     s << *pos << separator_cstr;
69   }
70   s << std::endl;
71 }
72
73 // The function object below can be used to delete a STL container that
74 // contains C++ object pointers.
75 //
76 // Usage: std::for_each(vector.begin(), vector.end(), for_each_delete());
77
78 struct for_each_cplusplus_delete {
79   template <typename T> void operator()(T *ptr) { delete ptr; }
80 };
81
82 typedef std::vector<std::string> STLStringArray;
83 typedef std::vector<const char *> CStringArray;
84
85 #endif // liblldb_STLUtils_h_