// Copyright (c) 1994 Darren Vengroff // // File: ami_stack.h // Author: Darren Vengroff // Created: 12/15/94 // // $Id: ami_stack.h,v 1.9 2005/01/21 16:52:39 tavi Exp $ // #ifndef _AMI_STACK_H #define _AMI_STACK_H // Get definitions for working with Unix and Windows #include "u/nvasil/tpie/portability.h" // Get the AMI_STREAM definition. #include "u/nvasil/tpie/ami_stream.h" template class AMI_stack : public AMI_STREAM { public: using AMI_STREAM::seek; using AMI_STREAM::truncate; using AMI_STREAM::stream_len; AMI_stack(); AMI_stack(const char* path, AMI_stream_type type = AMI_READ_WRITE_STREAM); ~AMI_stack(void); AMI_err push(const T &t); AMI_err pop(T **t); }; template AMI_stack::AMI_stack() : AMI_STREAM() { } template AMI_stack::AMI_stack(const char* path, AMI_stream_type type): AMI_STREAM(path, type) { } template AMI_stack::~AMI_stack(void) { } template AMI_err AMI_stack::push(const T &t) { AMI_err ae; TPIE_OS_OFFSET slen; ae = truncate((slen = stream_len())+1); if (ae != AMI_ERROR_NO_ERROR) { return ae; } ae = seek(slen); if (ae != AMI_ERROR_NO_ERROR) { return ae; } return write_item(t); } template AMI_err AMI_stack::pop(T **t) { AMI_err ae; TPIE_OS_OFFSET slen; slen = stream_len(); ae = seek(slen-1); if (ae != AMI_ERROR_NO_ERROR) { return ae; } ae = read_item(t); if (ae != AMI_ERROR_NO_ERROR) { return ae; } return truncate(slen-1); } #endif // _AMI_STACK_H