vfs: check userland buffers before reading them.
[haiku.git] / src / apps / haikudepot / edits_generic / CompoundEdit.cpp
blob7c2c405c4b8523befc0894505c9c4915059a761e
1 /*
2 * Copyright 2006-2112, Stephan Aßmus <superstippi@gmx.de>
3 * Distributed under the terms of the MIT License.
4 */
6 #include "CompoundEdit.h"
8 #include <stdio.h>
11 CompoundEdit::CompoundEdit(const char* name)
12 : UndoableEdit()
13 , fEdits()
14 , fName(name)
19 CompoundEdit::~CompoundEdit()
24 status_t
25 CompoundEdit::InitCheck()
27 return B_OK;
31 status_t
32 CompoundEdit::Perform(EditContext& context)
34 status_t status = B_OK;
36 int32 count = fEdits.CountItems();
37 int32 i = 0;
38 for (; i < count; i++) {
39 status = fEdits.ItemAtFast(i)->Perform(context);
40 if (status != B_OK)
41 break;
44 if (status != B_OK) {
45 // roll back
46 i--;
47 for (; i >= 0; i--) {
48 fEdits.ItemAtFast(i)->Undo(context);
52 return status;
56 status_t
57 CompoundEdit::Undo(EditContext& context)
59 status_t status = B_OK;
61 int32 count = fEdits.CountItems();
62 int32 i = count - 1;
63 for (; i >= 0; i--) {
64 status = fEdits.ItemAtFast(i)->Undo(context);
65 if (status != B_OK)
66 break;
69 if (status != B_OK) {
70 // roll back
71 i++;
72 for (; i < count; i++) {
73 fEdits.ItemAtFast(i)->Redo(context);
77 return status;
81 status_t
82 CompoundEdit::Redo(EditContext& context)
84 status_t status = B_OK;
86 int32 count = fEdits.CountItems();
87 int32 i = 0;
88 for (; i < count; i++) {
89 status = fEdits.ItemAtFast(i)->Redo(context);
90 if (status != B_OK)
91 break;
94 if (status != B_OK) {
95 // roll back
96 i--;
97 for (; i >= 0; i--) {
98 fEdits.ItemAtFast(i)->Undo(context);
102 return status;
106 void
107 CompoundEdit::GetName(BString& name)
109 name << fName;
113 bool
114 CompoundEdit::AppendEdit(const UndoableEditRef& edit)
116 return fEdits.Add(edit);