21 static const char *next_object_id = NULL;
27 obstate *tmp =
new obstate(type, data);
29 obstate *&
p = rev->obstates[ob];
33 }
catch (std::bad_alloc
const &) {
63 if (!rev->is_transient)
68 rev->children[NULL].push_back(ob);
69 }
catch (std::bad_alloc
const &) {
73 rev->parent[ob] = NULL;
74 }
catch (std::bad_alloc
const &) {
75 rev->children[NULL].pop_back();
79 set_object_data(rev, ob, type, data);
80 }
catch (std::bad_alloc
const &) {
81 rev->parent.erase(rev->parent.find(ob));
82 rev->children[NULL].pop_back();
134 if (!rev->is_transient)
140 std::vector<xorn_object_t> >::const_iterator i
141 = rev->children.find(ob);
142 if (i != rev->children.end() && !i->second.empty())
146 std::map<xorn_object_t, xorn_object_t>::const_iterator i
147 = rev->parent.find(ob);
149 i != rev->parent.end() && i->second != NULL)
152 bool add = i == rev->parent.end();
155 rev->children[NULL].push_back(ob);
156 }
catch (std::bad_alloc
const &) {
160 rev->parent[ob] = NULL;
161 }
catch (std::bad_alloc
const &) {
162 rev->children[NULL].pop_back();
168 set_object_data(rev, ob, type, data);
169 }
catch (std::bad_alloc
const &) {
171 rev->parent.erase(rev->parent.find(ob));
172 rev->children[NULL].pop_back();
222 if (!rev->is_transient)
225 if (attach_to != NULL) {
236 std::vector<xorn_object_t> &old_children = rev->children[parent];
237 std::vector<xorn_object_t> &new_children = rev->children[attach_to];
239 std::vector<xorn_object_t>::iterator i = find(old_children.begin(),
240 old_children.end(), ob);
241 assert(i != old_children.end());
242 std::vector<xorn_object_t>::size_type pos = i - old_children.begin();
247 if (insert_before == NULL)
248 new_children.push_back(ob);
250 std::vector<xorn_object_t>::iterator j =
251 find(new_children.begin(),
252 new_children.end(), insert_before);
253 if (j == new_children.end())
255 if (&new_children == &old_children && j <= i)
257 new_children.insert(j, ob);
259 }
catch (std::bad_alloc
const &) {
263 old_children.erase(old_children.begin() + pos);
268 static void delete_object_but_leave_entry(
271 std::map<xorn_object_t, obstate *>::iterator i
272 = rev->obstates.find(ob);
273 i->second->dec_refcnt();
274 rev->obstates.erase(i);
276 rev->parent.erase(rev->parent.find(ob));
278 std::map<xorn_object_t, std::vector<xorn_object_t> >::iterator j
279 = rev->children.find(ob);
281 if (j == rev->children.end())
284 for (std::vector<xorn_object_t>::const_iterator k = j->second.begin();
285 k != j->second.end(); ++k)
286 delete_object_but_leave_entry(rev, *k);
288 rev->children.erase(j);
303 if (!rev->is_transient)
306 std::map<xorn_object_t, xorn_object_t>::const_iterator i
307 = rev->parent.find(ob);
308 if (i == rev->parent.end())
312 delete_object_but_leave_entry(rev, ob);
314 std::vector<xorn_object_t> &children = rev->children[parent];
315 children.erase(find(children.begin(), children.end(), ob));
330 if (!rev->is_transient)
333 for (std::set<xorn_object_t>::const_iterator i = sel->begin();
334 i != sel->end(); ++i)
341 std::vector<xorn_object_t> &copied)
344 dest->children[attach_to].push_back(dest_ob);
346 dest->parent[dest_ob] = attach_to;
347 }
catch (std::bad_alloc
const &) {
348 dest->children[attach_to].pop_back();
352 dest->obstates[dest_ob] = obstate;
353 obstate->inc_refcnt();
354 }
catch (std::bad_alloc
const &) {
355 dest->parent.erase(dest->parent.find(dest_ob));
356 dest->children[attach_to].pop_back();
360 copied.push_back(dest_ob);
361 }
catch (std::bad_alloc
const &) {
366 std::map<xorn_object_t, std::vector<xorn_object_t> >::const_iterator i
367 = src->children.find(src_ob);
369 if (i != src->children.end())
370 for (std::vector<xorn_object_t>::const_iterator j
371 = i->second.begin(); j != i->second.end(); ++j)
372 copy_object(dest, src, *j, src->obstates[*j],
395 if (!dest->is_transient)
398 std::map<xorn_object_t, obstate *>::const_iterator i
399 = src->obstates.find(ob);
401 if (i == src->obstates.end())
404 std::vector<xorn_object_t> copied;
407 return copy_object(dest, src, ob, i->second, NULL, copied);
408 }
catch (std::bad_alloc
const &) {
409 for (std::vector<xorn_object_t>::const_iterator i
410 = copied.begin(); i != copied.end(); ++i)
436 if (!dest->is_transient)
441 rsel =
new xorn_selection();
442 }
catch (std::bad_alloc
const &) {
446 std::map<xorn_object_t, obstate *>::const_iterator i
447 = src->obstates.begin();
448 std::set<xorn_object_t>::const_iterator j = sel->begin();
449 std::vector<xorn_object_t> copied;
451 while (i != src->obstates.end() && j != sel->end())
454 else if (i->first > *j)
459 dest, src, i->first, i->second, NULL, copied);
461 }
catch (std::bad_alloc
const &) {
462 for (std::vector<xorn_object_t>::const_iterator i
463 = copied.begin(); i != copied.end(); ++i)
xorn_selection_t xorn_copy_objects(xorn_revision_t dest, xorn_revision_t src, xorn_selection_t sel)
Copy some objects to a transient revision.
struct xorn_revision * xorn_revision_t
Opaque type representing the contents of a file.
bool xorn_object_exists_in_revision(xorn_revision_t rev, xorn_object_t ob)
Return whether an object exists in a revision.
xorn_obtype_t xorn_get_object_type(xorn_revision_t rev, xorn_object_t ob)
Get the type of an object in a given revision.
struct xorn_selection * xorn_selection_t
Opaque type representing the identity of a set of objects.
int xorn_set_object_data(xorn_revision_t rev, xorn_object_t ob, xorn_obtype_t type, void const *data)
Set an object in a transient revision to the given object type and data.
void xorn_delete_selected_objects(xorn_revision_t rev, xorn_selection_t sel)
Delete some objects from a transient revision.
int xorn_relocate_object(xorn_revision_t rev, xorn_object_t ob, xorn_object_t attach_to, xorn_object_t insert_before)
Change the location of an object in the object structure of a transient revision. ...
struct xorn_object * xorn_object_t
Opaque type representing the identity of an object.
xorn_obtype_t
Object types, each corresponding to a data structure.
xorn_object_t xorn_add_object(xorn_revision_t rev, xorn_obtype_t type, void const *data)
Add a new object to a transient revision.
void xorn_delete_object(xorn_revision_t rev, xorn_object_t ob)
Delete an object from a transient revision.
xorn_object_t xorn_copy_object(xorn_revision_t dest, xorn_revision_t src, xorn_object_t ob)
Copy an object to a transient revision.