]> git.lyx.org Git - lyx.git/blobdiff - src/BackStack.h
More fixes to insettabular/text (and some missing features added).
[lyx.git] / src / BackStack.h
index f9cea923cd6d5c6d8d447695b5cfd9adffdc8ebb..4974ce22d5aa60c968822663fad58a668d7e0221 100644 (file)
@@ -1,65 +1,64 @@
 // -*- C++ -*-
 /* This file is part of
-* ======================================================
-* 
-*           LyX, The Document Processor
-*       
-*          Copyright (C) 1997-1998 The LyX Team.
-*
-*======================================================*/
+ * ====================================================== 
+ 
+ *           LyX, The Document Processor
+ *      
+ *         Copyright 1997-2000 The LyX Team.
+ *
+ * ====================================================== */
 
-#ifndef _BACK_STACK_H
-#define _BACK_STACK_H
+#ifndef BACK_STACK_H
+#define BACK_STACK_H
 
-#include "LString.h"
+#include <stack>
 
-// Created by Alejandro Aguilar Sierra, 970806
+#include "LString.h"
 
 /**  Utility to get back from a reference or from a child document.
+     @author Alejandro Aguilar Sierra
+     @version 970806
  */
 class BackStack {
-public:
+private:
        ///
        struct BackStackItem {
                ///
-               void set(string f, int xx, int yy) {
-                       fname = f;  x = xx;  y = yy;
-               }
+               BackStackItem() 
+                       : x(0), y(0) {}
+               ///
+               BackStackItem(string const & f, int xx, int yy)
+                       : fname(f), x(xx), y(yy) {}
                /// Filename
                string fname;
                /// Cursor x-position
                int x;
                /// Cursor y-position
-               int y;   
+               int y;
        };
-       ///
-       BackStack(int n) : imax(n) {
-               item = new BackStackItem[imax];
-               i = 0;
-       }
-       ///
-       ~BackStack() {
-               delete[] item;
-       }
+public:
        ///
        void push(string f, int x, int y) {
-               if (i<imax) 
-                       item[i++].set(f, x, y);
+               BackStackItem bit(f, x, y);
+               stakk.push(bit);
        }
        ///
-       string &pop(int *x, int *y) {
-               if (i>0) i--;
-               *x = item[i].x;
-               *y = item[i].y;
-               return item[i].fname;
+       string const pop(int * x, int * y) {
+               BackStackItem bit = stakk.top();
+               *x = bit.x;
+               *y = bit.y;
+               stakk.pop();
+               return bit.fname;
+       }
+       /**
+          @return returns #true# if the stack is empty, #false# otherwise.
+        */
+       bool empty() const {
+               return stakk.empty();
        }
 private:
        ///
-       BackStackItem *item;
-       ///
-       int i;
-       ///
-       int imax;
+       std::stack<BackStackItem> stakk;
 };
 
 #endif