UCStack.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003-2004 The Pentagram team
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017 */
00018 
00019 #include "pent_include.h"
00020 
00021 #include "UCStack.h"
00022 #include "IDataSource.h"
00023 #include "ODataSource.h"
00024 
00025 void UCStack::save(ODataSource* ods)
00026 {
00027         ods->write4(size);
00028         ods->write4(getSP());
00029 
00030         ods->write(buf_ptr, stacksize());
00031 }
00032 
00033 bool UCStack::load(IDataSource* ids, uint32 version)
00034 {
00035         size = ids->read4();
00036 #ifdef USE_DYNAMIC_UCSTACK
00037         if (buf) delete[] buf;
00038         buf = new uint8[size];
00039 #else
00040         if (size > sizeof(buf_array)) 
00041         {
00042                 perr << "Error: UCStack size mismatch (buf_array too small)" << std::endl;
00043                 return false;
00044         }
00045         buf = buf_array;
00046 #endif
00047         uint32 sp = ids->read4();
00048         buf_ptr = buf + sp;
00049 
00050         ids->read(buf_ptr, size - sp);
00051 
00052         return true;
00053 }

Generated on Fri Jul 27 22:27:50 2007 for pentagram by  doxygen 1.4.7