CXXR (C++ R)
S3Launcher.hpp
1 /*CXXR $Id: S3Launcher.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 
39 #ifndef S3LAUNCHER_HPP
40 #define S3LAUNCHER_HPP 1
41 
42 #include "CXXR/GCNode.hpp"
43 
44 #include "CXXR/StringVector.h"
45 
46 namespace CXXR {
47  class Environment;
48  class Frame;
49  class FunctionBase;
50  class Symbol;
51 
58  class S3Launcher : public GCNode {
59  public:
74  void addMethodBindings(Frame* frame) const;
75 
81  const StringVector* classes() const
82  {
83  return m_classes;
84  }
85 
92  String* className() const
93  {
94  if (!usingClass())
95  return 0;
96  return (*m_classes)[m_index];
97  }
98 
139  static S3Launcher*
140  create(RObject* object, std::string generic, std::string group,
141  Environment* call_env, Environment* table_env,
142  bool allow_default);
143 
209  static std::pair<FunctionBase*, bool>
210  findMethod(const Symbol* symbol, Environment* call_env,
211  Environment* table_env);
212 
218  FunctionBase* function() const
219  {
220  return m_function;
221  }
222 
228  std::size_t locInClasses() const
229  {
230  return m_index;
231  }
232 
238  Symbol* symbol() const
239  {
240  return m_symbol;
241  }
242 
249  bool usingClass() const
250  {
251  return m_index < m_classes->size();
252  }
253 
254  // Virtual function of GCNode:
255  void visitReferents(const_visitor* v) const;
256  protected:
257  // Virtual function of GCNode:
258  void detachReferents();
259  private:
260  std::string m_generic;
261  std::string m_group;
262  GCEdge<Environment> m_call_env;
263  GCEdge<Environment> m_table_env;
264  GCEdge<StringVector> m_classes; // Pointer to a vector of
265  // class names, or a null pointer. If null, subsequent
266  // fields are not meaningful.
267  GCEdge<FunctionBase> m_function; // Pointer to the method found, or
268  // null if no method was found. If null, subsequent fields
269  // are not meaningful.
270  Symbol* m_symbol; // Pointer to the Symbol naming the method found.
271  std::size_t m_index; // Location within the classes vector to which
272  // 'function' corresponds, or one past the end if using a
273  // default method.
274  bool m_using_group; // True iff 'function' is a group method.
275 
276  S3Launcher(const std::string& generic, const std::string& group,
277  Environment* call_env, Environment* table_env)
278  : m_generic(generic), m_group(group), m_call_env(call_env),
279  m_table_env(table_env), m_using_group(false)
280  {}
281  };
282 }
283 
284 #endif // S3LAUNCHER_HPP