CXXR (C++ R)
Evaluator_Context.hpp
Go to the documentation of this file.
1 /*CXXR $Id: Evaluator_Context.hpp 1348 2013-02-25 17:49:03Z arr $
2  *CXXR
3  *CXXR This file is part of CXXR, a project to refactor the R interpreter
4  *CXXR into C++. It may consist in whole or in part of program code and
5  *CXXR documentation taken from the R project itself, incorporated into
6  *CXXR CXXR (and possibly MODIFIED) under the terms of the GNU General Public
7  *CXXR Licence.
8  *CXXR
9  *CXXR CXXR is Copyright (C) 2008-13 Andrew R. Runnalls, subject to such other
10  *CXXR copyrights and copyright restrictions as may be stated below.
11  *CXXR
12  *CXXR CXXR is not part of the R project, and bugs and other issues should
13  *CXXR not be reported via r-bugs or other R project channels; instead refer
14  *CXXR to the CXXR website.
15  *CXXR */
16 
17 /*
18  * R : A Computer Language for Statistical Data Analysis
19  *
20  * This program is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation; either version 2.1 of the License, or
23  * (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  * GNU Lesser General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program; if not, a copy is available at
32  * http://www.r-project.org/Licenses/
33  */
34 
45 #ifndef CONTEXT_HPP
46 #define CONTEXT_HPP 1
47 
48 #include "CXXR/Evaluator.h"
49 
50 namespace CXXR {
90  public:
98  enum Type {
99  BAILOUT = 0,
103  };
104 
105  ~Context()
106  {
107  Evaluator::setDepth(m_eval_depth);
108  Evaluator::current()->m_innermost_context = m_next_out;
109  }
110 
116  static Context* innermost()
117  {
119  }
120 
127  Context* nextOut() const
128  {
129  return m_next_out;
130  }
131 
136  Type type() const
137  {
138  return m_type;
139  }
140  protected:
141  Context()
142  : m_next_out(innermost()), m_eval_depth(Evaluator::depth())
143  {
144  Evaluator::current()->m_innermost_context = this;
145  }
146 
151  void setType(Type the_type)
152  {
153  m_type = the_type;
154  }
155  private:
156  Context *m_next_out;
157  unsigned int m_eval_depth;
158  Type m_type;
159  };
160 } // namespace CXXR
161 
162 extern "C" {
163  void Rf_jump_to_toplevel(void);
164 }
165 
166 #endif // CONTEXT_HPP