Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

stack.cpp

Go to the documentation of this file.
00001 
00005 /*
00006     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00007     Copyright (C) 1994-2005  Martin Bickel  and  Marc Schellenberger
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU General Public License for more details.
00018 
00019     You should have received a copy of the GNU General Public License
00020     along with this program; see the file COPYING. If not, write to the 
00021     Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00022     Boston, MA  02111-1307  USA
00023 */
00024 
00025 #include <cstring>
00026 
00027 #include "global.h"
00028 #include "stack.h"
00029 
00030 
00031 #define stacksize 10000  
00032 
00033 char*        stackpointer = NULL;
00034 int          stackofs = 0;
00035 
00036 const int magic = 0x12345678;
00037 
00038 void         push_data(char *       daten,
00039                       int          size)
00040 { 
00041   memcpy(stackpointer+stackofs, daten, size);
00042   stackofs+=size;
00043 } 
00044 
00045 
00046 
00047 void         pop_data(char *       daten,
00048                      int          size)
00049 { 
00050   if (stackofs < size) 
00051       throw fatalstackerror();
00052   
00053   stackofs-=size;
00054   memcpy(daten, stackpointer + stackofs, size);
00055 } 
00056 
00057 
00058 void         pushdata(char *       daten,
00059                       int          size)
00060 { 
00061    if ( !stackpointer ) {
00062       stackpointer = new char [ stacksize ];
00063       stackofs = 0;
00064    }
00065    push_data ( daten, size );
00066    push_data ( (char*) &magic, sizeof ( magic ));
00067 } 
00068 
00069 
00070 void         popdata(char *       daten,
00071                      int          size)
00072 { 
00073    int m;
00074    pop_data ( (char*) &m, sizeof ( m ));
00075    if ( m != magic )
00076       throw fatalstackerror();
00077    pop_data ( daten, size );
00078 } 
00079 
00080 
00081 int          stackfree(void)
00082 { 
00083   return ( stacksize - stackofs);
00084 } 
00085 

Generated on Tue Jun 24 01:27:52 2008 for Advanced Strategic Command by  doxygen 1.4.2