CXXR (C++ R)
ListFrame.hpp
Go to the documentation of this file.
1 /*CXXR $Id: ListFrame.hpp 1389 2013-05-31 18:28:00Z 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  * Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
20  * Copyright (C) 1999-2006 The R Development Core Team.
21  *
22  * This program is free software; you can redistribute it and/or modify
23  * it under the terms of the GNU General Public License as published by
24  * the Free Software Foundation; either version 2.1 of the License, or
25  * (at your option) any later version.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  *
32  * You should have received a copy of the GNU General Public License
33  * along with this program; if not, a copy is available at
34  * http://www.r-project.org/Licenses/
35  */
36 
42 #ifndef LISTFRAME_HPP
43 #define LISTFRAME_HPP
44 
45 #include <list>
46 
47 #include "CXXR/Allocator.hpp"
48 #include "CXXR/Frame.hpp"
49 
50 namespace CXXR {
57  class ListFrame : public Frame {
58  private:
59  typedef
60  std::list<Binding, CXXR::Allocator<Binding> > List;
61  public:
62  // Virtual functions of Frame (qv):
63 #ifdef __GNUG__
64  __attribute__((hot,fastcall))
65 #endif
66  Binding* binding(const Symbol* symbol);
67 
68  const Binding* binding(const Symbol* symbol) const;
69  BindingRange bindingRange() const;
70  ListFrame* clone() const;
71  void lockBindings();
72  std::size_t size() const;
73  private:
74  friend class boost::serialization::access;
75 
76  List m_list;
77 
78  // Declared private to ensure that ListFrame objects are
79  // created only using 'new':
80  ~ListFrame() {}
81 
82  // Not (yet) implemented. Declared to prevent
83  // compiler-generated versions:
84  ListFrame& operator=(const ListFrame&);
85 
86  template<class Archive>
87  void load(Archive& ar, const unsigned int version)
88  {
89  ar >> BOOST_SERIALIZATION_BASE_OBJECT_NVP(Frame);
90  size_t numberOfBindings;
91  ar >> BOOST_SERIALIZATION_NVP(numberOfBindings);
92  for (size_t i = 0; i < numberOfBindings; ++i) {
93  GCStackRoot<Symbol> symbol;
94  GCNPTR_SERIALIZE(ar, symbol);
95  m_list.push_back(Binding());
96  Binding& binding = m_list.back();
97  binding.initialize(this, symbol);
98  statusChanged(symbol);
99  ar >> BOOST_SERIALIZATION_NVP(binding);
100  }
101  }
102 
103  template<class Archive>
104  void save(Archive& ar, const unsigned int version) const
105  {
106  ar << BOOST_SERIALIZATION_BASE_OBJECT_NVP(Frame);
107  size_t numberOfBindings = size();
108  ar << BOOST_SERIALIZATION_NVP(numberOfBindings);
109  for (List::const_iterator it = m_list.begin();
110  it != m_list.end(); ++it) {
111  const Binding& binding = *it;
112  const Symbol* symbol = binding.symbol();
113  GCNPTR_SERIALIZE(ar, symbol);
114  ar << BOOST_SERIALIZATION_NVP(binding);
115  }
116  }
117 
118  template<class Archive>
119  void serialize(Archive& ar, const unsigned int version) {
120  boost::serialization::split_member(ar, *this, version);
121  }
122 
123  // Virtual functions of Frame (qv):
124  void v_clear();
125  bool v_erase(const Symbol* symbol);
126  Binding* v_obtainBinding(const Symbol* symbol);
127  };
128 } // namespace CXXR
129 
130 BOOST_CLASS_EXPORT_KEY(CXXR::ListFrame)
131 
132 #endif // LISTFRAME_HPP