1
#pragma once
2

            
3
#include <cstdint>
4
#include <functional>
5
#include <memory>
6

            
7
#include "source/common/common/assert.h"
8

            
9
namespace Envoy {
10
namespace ThreadLocal {
11

            
12
/**
13
 * All objects that are stored via the ThreadLocal interface must derive from this type.
14
 */
15
class ThreadLocalObject {
16
public:
17
978137
  virtual ~ThreadLocalObject() = default;
18

            
19
  /**
20
   * Return the object casted to a concrete type. See getTyped() below for comments on the casts.
21
   */
22
113332
  template <class T> T& asType() {
23
113332
    ASSERT(dynamic_cast<T*>(this) != nullptr);
24
113332
    return *static_cast<T*>(this);
25
113332
  }
26
};
27

            
28
using ThreadLocalObjectSharedPtr = std::shared_ptr<ThreadLocalObject>;
29

            
30
template <class T = ThreadLocalObject> class TypedSlot;
31

            
32
} // namespace ThreadLocal
33
} // namespace Envoy