1 //===-- STLUtils.h ----------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef liblldb_STLUtils_h_
11 #define liblldb_STLUtils_h_
12 #if defined(__cplusplus)
20 //----------------------------------------------------------------------
21 // C string less than compare function object
22 //----------------------------------------------------------------------
23 struct CStringCompareFunctionObject
25 bool operator() (const char* s1, const char* s2) const
27 return strcmp(s1, s2) < 0;
32 //----------------------------------------------------------------------
33 // C string equality function object (binary predicate).
34 //----------------------------------------------------------------------
35 struct CStringEqualBinaryPredicate
37 bool operator()(const char* s1, const char* s2) const
39 return strcmp(s1, s2) == 0;
44 //----------------------------------------------------------------------
45 // Templated type for finding an entry in a std::map<F,S> whose value
46 // is equal to something
47 //----------------------------------------------------------------------
48 template <class F, class S>
55 ValueEquals (const S& val) : second_value(val)
57 // Compare the second item
58 bool operator() (std::pair<const F, S> elem)
60 return elem.second == second_value;
65 inline void PrintAllCollectionElements (std::ostream &s, const T& coll, const char* header_cstr=NULL, const char* separator_cstr=" ")
67 typename T::const_iterator pos;
71 for (pos=coll.begin(); pos!=coll.end(); ++pos) {
72 s << *pos << separator_cstr;
77 // The function object below can be used to delete a STL container that
78 // contains C++ object pointers.
80 // Usage: std::for_each(vector.begin(), vector.end(), for_each_delete());
82 struct for_each_cplusplus_delete
85 void operator()(T *ptr){ delete ptr;}
88 typedef std::vector<std::string> STLStringArray;
89 typedef std::vector<const char *> CStringArray;
93 #endif // #if defined(__cplusplus)
94 #endif // liblldb_STLUtils_h_