]> git.lyx.org Git - lyx.git/blob - src/BackStack.h
5ca40451a3cb009f7bcaa6a8091ccb85a648d6ac
[lyx.git] / src / BackStack.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *       
7  *          Copyright (C) 1997-1999 The LyX Team.
8  *
9  * ======================================================*/
10
11 #ifndef BACK_STACK_H
12 #define BACK_STACK_H
13
14 #include "LString.h"
15
16 // Created by Alejandro Aguilar Sierra, 970806
17
18 /**  Utility to get back from a reference or from a child document.
19  */
20 class BackStack {
21 public:
22         ///
23         struct BackStackItem {
24                 ///
25                 void set(string f, int xx, int yy) {
26                         fname = f;  x = xx;  y = yy;
27                 }
28                 /// Filename
29                 string fname;
30                 /// Cursor x-position
31                 int x;
32                 /// Cursor y-position
33                 int y;
34         };
35         ///
36         BackStack(int n) : item(new BackStackItem[n]) , i(0), imax(n) {}
37         ///
38         ~BackStack() {
39                 delete[] item;
40         }
41         ///
42         void push(string f, int x, int y) {
43                 if (i < imax) 
44                         item[i++].set(f, x, y);
45         }
46         ///
47         string & pop(int *x, int *y) {
48                 if (i > 0) i--;
49                 *x = item[i].x;
50                 *y = item[i].y;
51                 return item[i].fname;
52         }
53         ///
54         bool empty() const {
55                 return i == 0;
56         }
57 private:
58         ///
59         BackStackItem *item;
60         ///
61         int i;
62         ///
63         int imax;
64 };
65
66 #endif