Realistic 3D camera system
3D camera system components
call_stack.hpp
Go to the documentation of this file.
1 //
2 // detail/call_stack.hpp
3 // ~~~~~~~~~~~~~~~~~~~~~
4 //
5 // Copyright (c) 2003-2015 Christopher M. Kohlhoff (chris at kohlhoff dot com)
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See accompanying
8 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 //
10 
11 #ifndef ASIO_DETAIL_CALL_STACK_HPP
12 #define ASIO_DETAIL_CALL_STACK_HPP
13 
14 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
15 # pragma once
16 #endif // defined(_MSC_VER) && (_MSC_VER >= 1200)
17 
18 #include "asio/detail/config.hpp"
20 #include "asio/detail/tss_ptr.hpp"
21 
23 
24 namespace asio {
25 namespace detail {
26 
27 // Helper class to determine whether or not the current thread is inside an
28 // invocation of io_service::run() for a specified io_service object.
29 template <typename Key, typename Value = unsigned char>
31 {
32 public:
33  // Context class automatically pushes the key/value pair on to the stack.
34  class context
35  : private noncopyable
36  {
37  public:
38  // Push the key on to the stack.
39  explicit context(Key* k)
40  : key_(k),
41  next_(call_stack<Key, Value>::top_)
42  {
43  value_ = reinterpret_cast<unsigned char*>(this);
45  }
46 
47  // Push the key/value pair on to the stack.
48  context(Key* k, Value& v)
49  : key_(k),
50  value_(&v),
51  next_(call_stack<Key, Value>::top_)
52  {
54  }
55 
56  // Pop the key/value pair from the stack.
58  {
60  }
61 
62  // Find the next context with the same key.
63  Value* next_by_key() const
64  {
65  context* elem = next_;
66  while (elem)
67  {
68  if (elem->key_ == key_)
69  return elem->value_;
70  elem = elem->next_;
71  }
72  return 0;
73  }
74 
75  private:
76  friend class call_stack<Key, Value>;
77 
78  // The key associated with the context.
79  Key* key_;
80 
81  // The value associated with the context.
82  Value* value_;
83 
84  // The next element in the stack.
85  context* next_;
86  };
87 
88  friend class context;
89 
90  // Determine whether the specified owner is on the stack. Returns address of
91  // key if present, 0 otherwise.
92  static Value* contains(Key* k)
93  {
94  context* elem = top_;
95  while (elem)
96  {
97  if (elem->key_ == k)
98  return elem->value_;
99  elem = elem->next_;
100  }
101  return 0;
102  }
103 
104  // Obtain the value at the top of the stack.
105  static Value* top()
106  {
107  context* elem = top_;
108  return elem ? elem->value_ : 0;
109  }
110 
111 private:
112  // The top of the stack of calls for the current thread.
113  static tss_ptr<context> top_;
114 };
115 
116 template <typename Key, typename Value>
119 
120 } // namespace detail
121 } // namespace asio
122 
124 
125 #endif // ASIO_DETAIL_CALL_STACK_HPP
static Value * contains(Key *k)
Definition: call_stack.hpp:92
static Value * top()
Definition: call_stack.hpp:105