aboutsummaryrefslogtreecommitdiffhomepage
path: root/qbuffers.h
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2012-12-03 02:25:05 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2012-12-03 03:53:59 +0100
commit0c07fd231d6de047cc0037b0de37c691561e34fa (patch)
treef9f0a734b569030259d11188a74d32233b5cb9ec /qbuffers.h
parent1d44c8f0f75acb979a98d94e4dae6ff44d1accbf (diff)
organize buffer ring as a tail-q (double-linked list with tail pointer)
* new buffers are added at the list tail * when closing a buffer, the next one is selected or the previous one if it is the tail * the ring may be traversed in reverse order * undoing a buffer close (Ring::UndoTokenEdit) could be cleaned up to only use standard macros (is slightly less efficient though)
Diffstat (limited to 'qbuffers.h')
-rw-r--r--qbuffers.h32
1 files changed, 19 insertions, 13 deletions
diff --git a/qbuffers.h b/qbuffers.h
index 0fd588d..05ec388 100644
--- a/qbuffers.h
+++ b/qbuffers.h
@@ -263,17 +263,11 @@ class Buffer {
UndoTokenClose(Buffer *_buffer)
: UndoToken(), buffer(_buffer) {}
- void
- run(void)
- {
- buffer->close();
- /* NOTE: the buffer is NOT deleted on Token destruction */
- delete buffer;
- }
+ void run(void);
};
public:
- LIST_ENTRY(Buffer) buffers;
+ TAILQ_ENTRY(Buffer) buffers;
gchar *filename;
gint dot;
@@ -300,7 +294,14 @@ public:
inline Buffer *&
next(void)
{
- return LIST_NEXT(this, buffers);
+ return TAILQ_NEXT(this, buffers);
+ }
+ inline Buffer *&
+ prev(void)
+ {
+ TAILQ_HEAD(Head, Buffer);
+
+ return TAILQ_PREV(this, Head, buffers);
}
inline void
@@ -329,7 +330,6 @@ public:
bool load(const gchar *filename);
- void close(void);
inline void
undo_close(void)
{
@@ -376,21 +376,26 @@ extern class Ring {
}
};
- LIST_HEAD(Head, Buffer) head;
+ TAILQ_HEAD(Head, Buffer) head;
public:
Buffer *current;
Ring() : current(NULL)
{
- LIST_INIT(&head);
+ TAILQ_INIT(&head);
}
~Ring();
inline Buffer *
first(void)
{
- return LIST_FIRST(&head);
+ return TAILQ_FIRST(&head);
+ }
+ inline Buffer *
+ last(void)
+ {
+ return TAILQ_LAST(&head, Head);
}
Buffer *find(const gchar *filename);
@@ -411,6 +416,7 @@ public:
bool save(const gchar *filename);
+ void close(Buffer *buffer);
void close(void);
inline void
undo_close(void)