Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:56

0001 //===-- Baton.h -------------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_UTILITY_BATON_H
0010 #define LLDB_UTILITY_BATON_H
0011 
0012 #include "lldb/lldb-enumerations.h"
0013 #include "lldb/lldb-public.h"
0014 
0015 #include "llvm/Support/raw_ostream.h"
0016 
0017 #include <memory>
0018 
0019 namespace lldb_private {
0020 class Stream;
0021 }
0022 
0023 namespace lldb_private {
0024 
0025 /// \class Baton Baton.h "lldb/Core/Baton.h"
0026 /// A class designed to wrap callback batons so they can cleanup
0027 ///        any acquired resources
0028 ///
0029 /// This class is designed to be used by any objects that have a callback
0030 /// function that takes a baton where the baton might need to
0031 /// free/delete/close itself.
0032 ///
0033 /// The default behavior is to not free anything. Subclasses can free any
0034 /// needed resources in their destructors.
0035 class Baton {
0036 public:
0037   Baton() = default;
0038   virtual ~Baton() = default;
0039 
0040   virtual void *data() = 0;
0041 
0042   virtual void GetDescription(llvm::raw_ostream &s,
0043                               lldb::DescriptionLevel level,
0044                               unsigned indentation) const = 0;
0045 };
0046 
0047 class UntypedBaton : public Baton {
0048 public:
0049   UntypedBaton(void *Data) : m_data(Data) {}
0050   ~UntypedBaton() override {
0051     // The default destructor for an untyped baton does NOT attempt to clean up
0052     // anything in m_data.
0053   }
0054 
0055   void *data() override { return m_data; }
0056   void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level,
0057                       unsigned indentation) const override;
0058 
0059   void *m_data; // Leave baton public for easy access
0060 };
0061 
0062 template <typename T> class TypedBaton : public Baton {
0063 public:
0064   explicit TypedBaton(std::unique_ptr<T> Item) : Item(std::move(Item)) {}
0065 
0066   T *getItem() { return Item.get(); }
0067   const T *getItem() const { return Item.get(); }
0068 
0069   void *data() override { return Item.get(); }
0070   void GetDescription(llvm::raw_ostream &s, lldb::DescriptionLevel level,
0071                       unsigned indentation) const override {}
0072 
0073 protected:
0074   std::unique_ptr<T> Item;
0075 };
0076 
0077 } // namespace lldb_private
0078 
0079 #endif // LLDB_UTILITY_BATON_H