Xorn
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
revision.cc
Go to the documentation of this file.
1 /* Copyright (C) 2013-2016 Roland Lutz
2 
3  This program is free software; you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation; either version 2 of the License, or
6  (at your option) any later version.
7 
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software Foundation,
15  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
16 
17 #include "internal.h"
18 
19 
20 xorn_revision::xorn_revision() : is_transient(true)
21 {
22 }
23 
24 xorn_revision::xorn_revision(xorn_revision_t rev)
25  : is_transient(true), obstates(rev->obstates),
26  children(rev->children), parent(rev->parent)
27 {
28  for (std::map<xorn_object_t, obstate *>::const_iterator i
29  = obstates.begin(); i != obstates.end(); ++i)
30  i->second->inc_refcnt();
31 }
32 
33 xorn_revision::~xorn_revision()
34 {
35  for (std::map<xorn_object_t, obstate *>::const_iterator i
36  = obstates.begin(); i != obstates.end(); ++i)
37  i->second->dec_refcnt();
38 }
39 
40 
57 {
58  try {
59  if (rev == NULL)
60  return new xorn_revision();
61  else
62  return new xorn_revision(rev);
63  } catch (std::bad_alloc const &) {
64  return NULL;
65  }
66 }
67 
77 {
78  return rev->is_transient;
79 }
80 
92 {
93  rev->is_transient = false;
94 }
95 
104 {
105  delete rev;
106 }
void xorn_free_revision(xorn_revision_t rev)
Free the memory associated with a revision.
Definition: revision.cc:103
struct xorn_revision * xorn_revision_t
Opaque type representing the contents of a file.
Definition: xornstorage.h:54
bool xorn_revision_is_transient(xorn_revision_t rev)
Return whether a revision can be changed.
Definition: revision.cc:76
xorn_revision_t xorn_new_revision(xorn_revision_t rev)
Create a new revision, either from scratch or by copying an existing one.
Definition: revision.cc:56
void xorn_finalize_revision(xorn_revision_t rev)
Prevent further changes to a revision.
Definition: revision.cc:91