diff --git a/src/allocarray.h b/src/allocarray.h deleted file mode 100644 index 8dc51db..0000000 --- a/src/allocarray.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * AllocArray.h - * Defines a class for storing a collection of objects all derived from - * the same base class - * - * Copyright 2006 by Dale McCoy. - * dalestan@gmail.com - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, Inc. - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef _ALLOC_ARRAY_H -#define _ALLOC_ARRAY_H - -#ifdef _MSC_VER -#pragma warning(disable:4702)//Unreachable code -//Yes. I have a C++ library in which contains unreachable code. -#include -#pragma warning(default:4702) -#else -#include -#endif - -templateclass AllocArray:private std::vector<_Ty*>{ - typedef AllocArray<_Ty> _Myt; - typedef std::vector<_Ty*> _Mybase; - typedef typename _Mybase::size_type size_type; - typedef typename _Mybase::iterator iterator; - typedef typename _Mybase::reference reference; - typedef typename _Mybase::const_reference const_reference; -public: - AllocArray(){} - ~AllocArray(){ - for(size_type i=_Mybase::size();i;) - delete operator[](--i); - } - templatevoid push_back(const _Cty&val){ - _Mybase::push_back(new _Cty(val)); - } - templatevoid push_back(const _Cty*val){ - _Mybase::push_back(new _Cty(*val)); - } - size_type size()const{ - return _Mybase::size(); - } - reference last(){ - return operator[](size()-1); - } - reference operator[](size_type x){ - return _Mybase::operator [](x); - } - const_reference operator[](size_type x)const{ - return _Mybase::operator [](x); - } - void clear(){ - for(size_type i=_Mybase::size();i;) - delete operator[](--i); - _Mybase::clear(); - } -private: - AllocArray(const _Myt&right); - void operator=(const _Myt&right); -}; - -#endif /* _ALLOC_ARRAY_H */ diff --git a/src/info.cpp b/src/info.cpp index 166c4d4..a4c3deb 100644 --- a/src/info.cpp +++ b/src/info.cpp @@ -24,7 +24,7 @@ int makeint(U8 low, S8 high) return combined; } -void read_file(std::istream&in,int infover,int grfcontversion,AllocArray&sprites); +void read_file(std::istream&in,int infover,int grfcontversion,std::vector>&sprites); nfe_map nfo_escapes; diff --git a/src/info.h b/src/info.h index bf9cd4d..be424ad 100644 --- a/src/info.h +++ b/src/info.h @@ -4,12 +4,12 @@ #include #include +#include #include "pcxsprit.h" #include "pngsprit.h" #include "sprites.h" #include "nfosprite.h" -#include "allocarray.h" class inforeader { public: @@ -32,7 +32,7 @@ class inforeader { std::string imgname; int *colourmap; - AllocArray nfofile; + std::vector> nfofile; private: pcxread* MakeReader()const; }; diff --git a/src/readinfo.cpp b/src/readinfo.cpp index 63ee8fd..8f3d526 100644 --- a/src/readinfo.cpp +++ b/src/readinfo.cpp @@ -40,6 +40,7 @@ Version 7: Add backslash escapes #include #include #include +#include // grfcodec requires boost::date_time for its processing of the \wYMD and @@ -48,7 +49,6 @@ Version 7: Add backslash escapes using namespace boost::gregorian; #include"nfosprite.h" -#include"allocarray.h" #include"inlines.h" extern int _quiet; @@ -65,14 +65,14 @@ const char *depths[DEPTHS] = { "8bpp", "32bpp", "mask" }; if(true){\ if(buffer!=""){\ checkspriteno();\ - sprites.push_back(Pseudo(sprites.size(),infover,grfcontversion,buffer,claimed_size));\ + sprites.push_back(std::make_unique(sprites.size(),infover,grfcontversion,buffer,claimed_size));\ buffer="";\ }\ spriteno=temp;\ }else\ (void(0)) -void read_file(std::istream&in,int infover,int grfcontversion,AllocArray&sprites){ +void read_file(std::istream&in,int infover,int grfcontversion,std::vector>&sprites){ std::string sprite,datapart,buffer; int temp=-1,spriteno=-1,claimed_size=1; @@ -95,7 +95,7 @@ void read_file(std::istream&in,int infover,int grfcontversion,AllocArray getline(eat_white(spritestream.ignore()),datapart); strip_trailing_white(datapart); checkspriteno(); - sprites.push_back(Include(datapart)); + sprites.push_back(std::make_unique(datapart)); }else{ flush_buffer(); eat_white(spritestream>>claimed_size); @@ -115,13 +115,15 @@ void read_file(std::istream&in,int infover,int grfcontversion,AllocArray flush_buffer(); checkspriteno(); if (peeked!='|') { - sprites.push_back(Real()); + sprites.push_back(std::make_unique()); } else { do { datapart.erase(0, 1); } while (isspace(datapart[0])); } - ((Real*)sprites.last())->AddSprite(sprites.size()-1,infover,datapart); + Real *r = dynamic_cast(sprites.back().get()); + if (r == nullptr) throw Sprite::unparseable("internal error, expected Real sprite", sprites.size() - 1); + r->AddSprite(sprites.size()-1,infover,datapart); } } }