Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Codechange: Remove using namespace std; #41

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions src/ExpandingArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@
#else
#include<vector>
#endif
using namespace std;

template<typename _Ty>class ExpandingArray:public vector<_Ty>{
template<typename _Ty>class ExpandingArray:public std::vector<_Ty>{
typedef ExpandingArray<_Ty> _MyT;
typedef vector<_Ty> _Mybase;
typedef std::vector<_Ty> _Mybase;
public:
ExpandingArray(){}
ExpandingArray(const _Ty&_fill):m_fill(_fill){}
const _Ty&operator[](unsigned int x)const{
if(x>=_MyT::size())return m_fill;
return vector<_Ty>::operator[](x);
return std::vector<_Ty>::operator[](x);
}
_Ty&operator[](unsigned int x){
if(x>=_MyT::size())_MyT::resize(x+1);
Expand All @@ -52,27 +51,27 @@ template<typename _Ty>class ExpandingArray:public vector<_Ty>{
_Ty m_fill;
};

template<typename _Ty>class Expanding0Array:public vector<_Ty>{
template<typename _Ty>class Expanding0Array:public std::vector<_Ty>{
typedef Expanding0Array<_Ty> _MyT;
public:
_Ty operator[](unsigned int x)const{
if(x>=_MyT::size())return 0;
return vector<_Ty>::operator[](x);
return std::vector<_Ty>::operator[](x);
}
_Ty&operator[](unsigned int x){
if(x>=_MyT::size())_MyT::resize(x+1,0);
return vector<_Ty>::operator[](x);
return std::vector<_Ty>::operator[](x);
}
};
template<>class Expanding0Array<bool>:public vector<bool>{
template<>class Expanding0Array<bool>:public std::vector<bool>{
public:
bool operator[](unsigned int x)const{
if(x>=size())return false;
return vector<bool>::operator[](x);
return std::vector<bool>::operator[](x);
}
reference operator[](unsigned int x){
if(x>=size())resize(x+1,false);
return vector<bool>::operator[](x);
return std::vector<bool>::operator[](x);
}
};

Expand Down
1 change: 0 additions & 1 deletion src/IDs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include<errno.h>
#include<cstdlib>

using namespace std;

#include"nforenum.h"
#include"inlines.h"
Expand Down
11 changes: 5 additions & 6 deletions src/act0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include<errno.h>
#include<cstdlib>

using namespace std;

#include"nforenum.h"
#include"inlines.h"
Expand Down Expand Up @@ -92,12 +91,12 @@ char FD takes the same type of parameter as r, but adds that value to the
char FE as above
char C0 means to insert a linebreak (as if encountering C1..C4) but without
reading any bytes
A backslash is used to escape nulls that are not end-of-string characters
A backslash is used to escape nulls that are not end-of-std::string characters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
A backslash is used to escape nulls that are not end-of-std::string characters
A backslash is used to escape nulls that are not end-of-string characters

char FF is undef
*/

typedef basic_string<uchar> ustring;
typedef vector<int> int_str;
typedef std::basic_string<uchar> ustring;
typedef std::vector<int> int_str;

class PropData:public auto_array<PropData>{
public:
Expand All @@ -111,7 +110,7 @@ class PropData:public auto_array<PropData>{
uint maxlast(int prop){return (idRange[prop]>>8)&0xFF;}
private:
ustring length;
vector<uint> idRange;
std::vector<uint> idRange;
void readString(FILE*,bool);
int CountFE();
void operator=(const PropData&);
Expand Down Expand Up @@ -259,7 +258,7 @@ void Init0(){

bool IsTextDefined(uint);

static vector<uint> lengthlist;
static std::vector<uint> lengthlist;

static void FormatSprite(PseudoSprite&str, uint&ofs, const uint format, const uint IDs = 1) {
uint feature = str.ExtractByte(1);
Expand Down
2 changes: 1 addition & 1 deletion src/act0.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
#ifndef _RENUM_PROPERTIES_H_INCLUDED_
#define _RENUM_PROPERTIES_H_INCLUDED_

void Check0(const string&);
void Check0(const std::string&);

#endif
1 change: 0 additions & 1 deletion src/act123.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include<errno.h>
#include<cstdlib>

using namespace std;

#include"inlines.h"
#include"ExpandingArray.h"
Expand Down
2 changes: 1 addition & 1 deletion src/act123.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class varRange{
private:
int num;
uint width;
vector<range>ranges;
std::vector<range>ranges;
void AddRangeInternal(uint min,uint max,RenumMessageId unreachable);
};

Expand Down
15 changes: 7 additions & 8 deletions src/act123_classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include<cstdlib>
#include<algorithm>

using namespace std;

#include"inlines.h"
#include"ExpandingArray.h"
Expand Down Expand Up @@ -54,10 +53,10 @@ void act123::init(){
}

uint act123::MaxFoundFeat()const{
const vector<IDarray::info>&m=defined2IDs._m;
const std::vector<IDarray::info>&m=defined2IDs._m;
short ret=0;
for(uint i=0;i<(uint)m.size();i++)
ret=max<short>(ret,m[i].feature);
ret=std::max<short>(ret,m[i].feature);
return ret;
}

Expand Down Expand Up @@ -243,7 +242,7 @@ void varRange::UpdateRange(uint Var,uint op,uint shift,const PseudoSprite&data,u
}
if(shift&0x80){// %
var.min=0;
var.max=min<uint>(var.max,divmod-1);
var.max=std::min<uint>(var.max,divmod-1);
add%=divmod;
}else{// /
var.min/=divmod;
Expand Down Expand Up @@ -288,12 +287,12 @@ void varRange::UpdateRange(uint Var,uint op,uint shift,const PseudoSprite&data,u
break;
case 4:// min
case 0xB:// &
dflt.min=min(dflt.min,var.min);
dflt.max=min(dflt.max,var.max);
dflt.min=std::min(dflt.min,var.min);
dflt.max=std::min(dflt.max,var.max);
break;
case 5:// max
dflt.min=max(dflt.min,var.min);
dflt.max=max(dflt.max,var.max);
dflt.min=std::max(dflt.min,var.min);
dflt.max=std::max(dflt.max,var.max);
/* FALLTHROUGH */
case 8:// /
if(var.min==0){
Expand Down
9 changes: 4 additions & 5 deletions src/act14.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,20 @@
#include<cassert>
#include<sstream>

using namespace std;

#include"nforenum.h"
#include"pseudo.h"
#include"messages.h"
#include"strings.h"
#include"command.h"

static bool Check14(PseudoSprite&data, uint&offset, vector<uint>&idstack)
static bool Check14(PseudoSprite&data, uint&offset, std::vector<uint>&idstack)
{
/* NFORenum reads the NFO, which is a text file. As per definition the
* NFO is LE ordered. If characters are interpreted as bytes they will
* therefore be read in LE order. ExtractDword does interpret the
* characters as bytes and construct a host endian ordered integer.
* Consequently, there is no need to swap endian for the read data; it
* characters as bytes and construct a host endian ordered integer.
* Consequently, there is no need to std::swap endian for the read data; it
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Consequently, there is no need to std::swap endian for the read data; it
* Consequently, there is no need to swap endian for the read data; it

* will always be in the host order, or the constant below as long as
* they have the expected integer value, thus reverse due to LE. */
static const uint ID_INFO = 0x4F464E49; // INFO in reverse order (LE)
Expand Down Expand Up @@ -94,7 +93,7 @@ static bool Check14(PseudoSprite&data, uint&offset, vector<uint>&idstack)

void Check14(PseudoSprite&data)
{
vector<uint>idstack;
std::vector<uint>idstack;
uint offset = 1;
Check14(data, offset, idstack);
}
15 changes: 7 additions & 8 deletions src/act5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include<cassert>
#include<errno.h>

using namespace std;

#include"nforenum.h"
#include"sanity.h"
Expand All @@ -41,15 +40,15 @@ extern bool _base_grf;
class c5{
public:
int maxFeature(){return (int)sizes.size()+3;}
const vector<int>&operator[](int x)const {return sizes[x-4];}
const std::vector<int>&operator[](int x)const {return sizes[x-4];}
SINGLETON(c5)
private:
vector<vector<int> >sizes;
std::vector<std::vector<int> >sizes;
};

c5::c5(){
FILE*pFile=myfopen(5);
vector<int> temp;
std::vector<int> temp;
int ch, count, opts, flags;
while((ch=GetCheckByte(5))!=0){
flags = 0;
Expand All @@ -72,9 +71,9 @@ c5::c5(){
}

// I finally want to do runtime-generated varargs calls.
// But I can't, so I have to manually generate the string instead.
void Act5CountWarn(const vector<int>&sizes){
string str = mysprintf("%S",ACT5_SIZE, sizes[1], sizes[1]);
// But I can't, so I have to manually generate the std::string instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// But I can't, so I have to manually generate the std::string instead.
// But I can't, so I have to manually generate the string instead.

void Act5CountWarn(const std::vector<int>&sizes){
std::string str = mysprintf("%S",ACT5_SIZE, sizes[1], sizes[1]);
int count=(int)sizes.size()-1;
switch(count){
case 1:
Expand All @@ -101,7 +100,7 @@ int Check5(PseudoSprite&data,sanstate&state){
IssueMessage(FATAL,INVALID_FEATURE);
return sprites;
}
const vector<int>&expSprites=c5::Instance()[feature];
const std::vector<int>&expSprites=c5::Instance()[feature];
if(!hasoffset){
for(int i=(int)expSprites.size();--i;){ // Test [1] ... [.size()-1]
if(expSprites[i] == 0)goto countok;
Expand Down
1 change: 0 additions & 1 deletion src/act6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include<cassert>
#include<algorithm>

using namespace std;

#include"nforenum.h"
#include"inlines.h"
Expand Down
3 changes: 1 addition & 2 deletions src/act79D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include<fstream>
#include<errno.h>

using namespace std;

#include"nforenum.h"
#include"inlines.h"
Expand Down Expand Up @@ -87,7 +86,7 @@ struct act7{
uint act,spriteno,skips;
};

static vector<act7>jumps;
static std::vector<act7>jumps;

int Check7(PseudoSprite&data){
uint desiredSize=data.Length()-5;
Expand Down
1 change: 0 additions & 1 deletion src/actB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include<fstream>
#include<string>

using namespace std;

#include"nforenum.h"
#include"inlines.h"
Expand Down
5 changes: 2 additions & 3 deletions src/actF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include<cassert>
#include<sstream>

using namespace std;

#include"nforenum.h"
#include"inlines.h"
Expand Down Expand Up @@ -111,7 +110,7 @@ void CheckF(PseudoSprite&data){
uint total_prob=0,firstbit=data.ExtractByte(++offset),fb_offs=offset,numbits=data.ExtractByte(++offset);
if(textcount>1){
if(bitsused&BITS(firstbit,numbits)){
ostringstream s;
std::ostringstream s;
int first=-1,bits=bitsused&BITS(firstbit,numbits);
for(int j=0;j<32;j++){
if(bits&(1<<j)){
Expand All @@ -124,7 +123,7 @@ void CheckF(PseudoSprite&data){
else s<<first<<".."<<j-1<<", ";
first=-1;
}
string str=s.str();
std::string str=s.str();
str[str.length()-2]='\0';
IssueMessage(WARNING1,BITS_OVERLAP,fb_offs,i,str.c_str());
}
Expand Down
Loading