⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 objectstack.cpp

📁 "More for C++" is a class library that provides some features that are usually common for object ori
💻 CPP
字号:
////  This file is part of the "More for C++" library////  Copyright (c) 1999-2003 by Thorsten Goertz (thorsten@morefor.org)////  The "More for C++" library is free software; you can redistribute it and/or//  modify it under the terms of the license that comes with this package.////  Read "license.txt" for more details.////  THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED//  WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES//  OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.////////////////////////////////////////////////////////////////////////////////#include <cstddef>#include "objectstack.hpp"using namespace more::core;////////////////////////////////////////////////////////////////////////////////const size_t SIZE_OF_STACKED_OBJECTS = 1000;////////////////////////////////////////////////////////////////////////////////struct ObjectStack::StackedObjects{  StackedObjects*   m_pPrevObjects;  size_t            m_nNoOfObjects;  void*             m_pObjects[SIZE_OF_STACKED_OBJECTS];};////////////////////////////////////////////////////////////////////////////////ObjectStack::ObjectStack( ): m_pStackedObjects( 0 ){}////////////////////////////////////////////////////////////////////////////////ObjectStack::~ObjectStack( ){  while( m_pStackedObjects != 0 )  {    StackedObjects* pObjects = m_pStackedObjects;    m_pStackedObjects = pObjects -> m_pPrevObjects;    delete pObjects;  }}////////////////////////////////////////////////////////////////////////////////bool ObjectStack::isEmpty( ) const{  return m_pStackedObjects == 0;}////////////////////////////////////////////////////////////////////////////////void ObjectStack::pushObject(  void* pObject){  if( m_pStackedObjects == 0 || m_pStackedObjects -> m_nNoOfObjects == SIZE_OF_STACKED_OBJECTS )  {    StackedObjects* pObjects;    pObjects = new StackedObjects;    pObjects -> m_pPrevObjects = m_pStackedObjects;    pObjects -> m_nNoOfObjects = 0;    m_pStackedObjects = pObjects;  }  size_t& rnNoOfObjects = m_pStackedObjects -> m_nNoOfObjects;  m_pStackedObjects -> m_pObjects[rnNoOfObjects++] = pObject;}////////////////////////////////////////////////////////////////////////////////void* ObjectStack::popObject( ){  void* pResult = 0;  if( m_pStackedObjects != 0 )  {    size_t& rnNoOfObjects = m_pStackedObjects -> m_nNoOfObjects;    pResult = m_pStackedObjects -> m_pObjects[--rnNoOfObjects];    if( rnNoOfObjects == 0 )    {      StackedObjects* pObjects = m_pStackedObjects;      m_pStackedObjects = pObjects -> m_pPrevObjects;      delete pObjects;    }  }  return pResult;}////////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -