1 //===-- Baton.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 //===----------------------------------------------------------------------===//
13 #include "lldb/lldb-enumerations.h"
14 #include "lldb/lldb-public.h"
18 namespace lldb_private {
22 namespace lldb_private {
24 //----------------------------------------------------------------------
25 /// @class Baton Baton.h "lldb/Core/Baton.h"
26 /// A class designed to wrap callback batons so they can cleanup
27 /// any acquired resources
29 /// This class is designed to be used by any objects that have a callback
30 /// function that takes a baton where the baton might need to
31 /// free/delete/close itself.
33 /// The default behavior is to not free anything. Subclasses can free any
34 /// needed resources in their destructors.
35 //----------------------------------------------------------------------
41 virtual void *data() = 0;
43 virtual void GetDescription(Stream *s,
44 lldb::DescriptionLevel level) const = 0;
47 class UntypedBaton : public Baton {
49 UntypedBaton(void *Data) : m_data(Data) {}
50 virtual ~UntypedBaton() {
51 // The default destructor for an untyped baton does NOT attempt to clean up
52 // anything in m_data.
55 void *data() override { return m_data; }
56 void GetDescription(Stream *s, lldb::DescriptionLevel level) const override;
58 void *m_data; // Leave baton public for easy access
61 template <typename T> class TypedBaton : public Baton {
63 explicit TypedBaton(std::unique_ptr<T> Item) : Item(std::move(Item)) {}
65 T *getItem() { return Item.get(); }
66 const T *getItem() const { return Item.get(); }
68 void *data() override { return Item.get(); }
69 virtual void GetDescription(Stream *s,
70 lldb::DescriptionLevel level) const override {}
73 std::unique_ptr<T> Item;
76 } // namespace lldb_private
78 #endif // lldb_Baton_h_