CXXR (C++ R)
Browser.hpp
Go to the documentation of this file.
1 /*CXXR $Id: Browser.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 
40 #ifndef BROWSER_HPP
41 #define BROWSER_HPP 1
42 
44 #include "CXXR/GCStackRoot.hpp"
45 #include "CXXR/RObject.h"
46 
47 namespace CXXR {
55  class Browser {
56  public:
65  Browser(RObject* the_text, RObject* the_condition)
66  : m_text(the_text), m_condition(the_condition),
67  m_context(Evaluator::Context::innermost())
68  {
69  s_browsers.push_back(this);
70  }
71 
72  ~Browser()
73  {
74  s_browsers.pop_back();
75  }
76 
81  static unsigned int numberActive()
82  {
83  return s_browsers.size();
84  }
85 
90  RObject* condition() const
91  {
92  return m_condition;
93  }
94 
104  {
105  return m_context;
106  }
107 
116  static Browser* fromOutermost(unsigned int i)
117  {
118  return s_browsers.at(i);
119  }
120 
125  RObject* text() const
126  {
127  return m_text;
128  }
129  private:
130  static std::vector<Browser*> s_browsers;
131  GCStackRoot<> m_text;
132  GCStackRoot<> m_condition;
133  Evaluator::Context* m_context;
134  };
135 }
136 
137 #endif // BROWSER_HPP