CXXR (C++ R)
CommandChronicle.hpp
Go to the documentation of this file.
1 /*CXXR $Id: CommandChronicle.hpp 1353 2013-03-18 16:59:38Z 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 /* This file incorporates material Copyright (C) Chris A. Silles 2009-12.
18  */
19 
20 /*
21  * This program is free software; you can redistribute it and/or modify
22  * it under the terms of the GNU General Public License as published by
23  * the Free Software Foundation; either version 2.1 of the License, or
24  * (at your option) any later version.
25  *
26  * This program is distributed in the hope that it will be useful,
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29  * GNU Lesser General Public License for more details.
30  *
31  * You should have received a copy of the GNU General Public License
32  * along with this program; if not, a copy is available at
33  * http://www.r-project.org/Licenses/
34  */
35 
41 #ifndef COMMANDCHRONICLE_HPP
42 #define COMMANDCHRONICLE_HPP 1
43 
44 #include <set>
45 #include <vector>
46 #include <boost/serialization/access.hpp>
47 #include <boost/serialization/nvp.hpp>
48 
49 #include "CXXR/GCEdge.hpp"
50 #include "CXXR/RObject.h"
51 
52 namespace CXXR {
53  class Provenance;
54 
69  class CommandChronicle : public GCNode {
70  public:
77  typedef std::vector<GCEdge<const Provenance> > ParentVector;
78 
85  CommandChronicle(const RObject* command_arg)
86  : m_command(command_arg)
87  {}
88 
95  const ParentVector& bindingsRead() const
96  {
97  return m_reads;
98  }
99 
112  void close()
113  {
114  m_seen.clear();
115  }
116 
122  const RObject* command() const
123  {
124  return m_command;
125  }
126 
135  void readBinding(const Provenance* bdgprov);
136 
147  void writeBinding(const Provenance* bdgprov);
148 
149  // Virtual functions of GCNode:
150  void detachReferents();
151  void visitReferents(const_visitor* v) const;
152  private:
153  friend class boost::serialization::access;
154  friend class Provenance;
155 
156  ParentVector m_reads;
157 
158  std::set<unsigned int> m_seen; // Set of serial numbers of
159  // all Provenance objects associated with bindings so far
160  // read or written during the evaluation of the top-level
161  // command.
162 
163  GCEdge<const RObject> m_command;
164 
165  // Although it is possible that a CommandChronicle object may
166  // not have been closed by the time it is serialised, it is
167  // assumed that it *will* have been closed before any
168  // subsequent deserialisation of it takes place. Consequently
169  // the m_seen set is not itself serialised.
170  template<class Archive>
171  void serialize(Archive & ar, const unsigned int version) {
172  using namespace boost::serialization;
173  ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(GCNode);
174  size_t sz = m_reads.size();
175  ar & boost::serialization::make_nvp("size", sz);
176  m_reads.resize(sz);
177  for (size_t i = 0; i < sz; ++i) {
178  GCEdge<const Provenance>& parent = m_reads[i];
179  GCNPTR_SERIALIZE(ar, parent);
180  }
181  }
182  };
183 } // namespace CXXR
184 
185 BOOST_CLASS_EXPORT_KEY(CXXR::CommandChronicle)
186 
187 namespace boost {
188  namespace serialization {
207  template<class Archive>
208  void load_construct_data(Archive& ar, CXXR::CommandChronicle* chron,
209  const unsigned int version)
210  {
211  using namespace CXXR;
212  GCStackRoot<> command;
213  GCNPTR_SERIALIZE(ar, command);
214  new (chron) CommandChronicle(command);
215  }
216 
236  template<class Archive>
237  void save_construct_data(Archive& ar,
238  const CXXR::CommandChronicle* chron,
239  const unsigned int version)
240  {
241  using namespace CXXR;
242  const RObject* command = chron->command();
243  GCNPTR_SERIALIZE(ar, command);
244  }
245  } // namespace serialization
246 } // namespace boost
247 
248 #endif // COMMANDCHRONICLE_HPP