@@ -40,6 +40,7 @@ Version 7: Add backslash escapes
4040#include < sstream>
4141#include < iomanip>
4242#include < cstdio>
43+ #include < memory>
4344
4445
4546// grfcodec requires boost::date_time for its processing of the \wYMD and
@@ -48,7 +49,6 @@ Version 7: Add backslash escapes
4849using namespace boost ::gregorian;
4950
5051#include " nfosprite.h"
51- #include " allocarray.h"
5252#include " inlines.h"
5353
5454extern int _quiet;
@@ -65,14 +65,14 @@ const char *depths[DEPTHS] = { "8bpp", "32bpp", "mask" };
6565 if (true ){\
6666 if (buffer!=" " ){\
6767 checkspriteno ();\
68- sprites.push_back (Pseudo (sprites.size (),infover,grfcontversion,buffer,claimed_size));\
68+ sprites.push_back (std::make_unique< Pseudo> (sprites.size (),infover,grfcontversion,buffer,claimed_size));\
6969 buffer=" " ;\
7070 }\
7171 spriteno=temp;\
7272 }else \
7373 (void (0 ))
7474
75- void read_file (std::istream&in,int infover,int grfcontversion,AllocArray< Sprite>&sprites){
75+ void read_file (std::istream&in,int infover,int grfcontversion,std::vector<std::unique_ptr< Sprite> >&sprites){
7676 std::string sprite,datapart,buffer;
7777
7878 int temp=-1 ,spriteno=-1 ,claimed_size=1 ;
@@ -95,7 +95,7 @@ void read_file(std::istream&in,int infover,int grfcontversion,AllocArray<Sprite>
9595 getline (eat_white (spritestream.ignore ()),datapart);
9696 strip_trailing_white (datapart);
9797 checkspriteno ();
98- sprites.push_back (Include (datapart));
98+ sprites.push_back (std::make_unique< Include> (datapart));
9999 }else {
100100 flush_buffer ();
101101 eat_white (spritestream>>claimed_size);
@@ -115,13 +115,15 @@ void read_file(std::istream&in,int infover,int grfcontversion,AllocArray<Sprite>
115115 flush_buffer ();
116116 checkspriteno ();
117117 if (peeked!=' |' ) {
118- sprites.push_back (Real ());
118+ sprites.push_back (std::make_unique< Real> ());
119119 } else {
120120 do {
121121 datapart.erase (0 , 1 );
122122 } while (isspace (datapart[0 ]));
123123 }
124- ((Real*)sprites.last ())->AddSprite (sprites.size ()-1 ,infover,datapart);
124+ Real *r = dynamic_cast <Real *>(sprites.back ().get ());
125+ if (r == nullptr ) throw Sprite::unparseable (" internal error, expected Real sprite" , sprites.size () - 1 );
126+ r->AddSprite (sprites.size ()-1 ,infover,datapart);
125127 }
126128 }
127129 }
0 commit comments