Skip to content

Commit

Permalink
Make nType and nVersion private and sometimes const
Browse files Browse the repository at this point in the history
Make the various stream implementations' nType and nVersion private
and const (except in CDataStream where we really need a setter).
  • Loading branch information
sipa committed Nov 7, 2016
1 parent c2c5d42 commit fad9b66
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ class CHashWriter
private:
CHash256 ctx;

const int nType;
const int nVersion;
public:
int nType;
int nVersion;

CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {}

Expand Down
2 changes: 1 addition & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class CConnman
void PushMessageWithVersionAndFlag(CNode* pnode, int nVersion, int flag, const std::string& sCommand, Args&&... args)
{
auto msg(BeginMessage(pnode, nVersion, flag, sCommand));
::SerializeMany(msg, msg.nType, msg.nVersion, std::forward<Args>(args)...);
::SerializeMany(msg, msg.GetType(), msg.GetVersion(), std::forward<Args>(args)...);
EndMessage(msg);
PushMessage(pnode, msg, sCommand);
}
Expand Down
4 changes: 2 additions & 2 deletions src/serialize.h
Original file line number Diff line number Diff line change
Expand Up @@ -937,9 +937,9 @@ class CSizeComputer
protected:
size_t nSize;

const int nType;
const int nVersion;
public:
int nType;
int nVersion;

CSizeComputer(int nTypeIn, int nVersionIn) : nSize(0), nType(nTypeIn), nVersion(nVersionIn) {}

Expand Down
34 changes: 15 additions & 19 deletions src/streams.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ template<typename Stream>
class OverrideStream
{
Stream* stream;
public:

const int nType;
const int nVersion;

public:
OverrideStream(Stream* stream_, int nType_, int nVersion_) : stream(stream_), nType(nType_), nVersion(nVersion_) {}

template<typename T>
Expand Down Expand Up @@ -66,9 +67,10 @@ class CDataStream
typedef CSerializeData vector_type;
vector_type vch;
unsigned int nReadPos;
public:

int nType;
int nVersion;
public:

typedef vector_type::allocator_type allocator_type;
typedef vector_type::size_type size_type;
Expand Down Expand Up @@ -251,9 +253,9 @@ class CDataStream
int in_avail() { return size(); }

void SetType(int n) { nType = n; }
int GetType() { return nType; }
int GetType() const { return nType; }
void SetVersion(int n) { nVersion = n; }
int GetVersion() { return nVersion; }
int GetVersion() const { return nVersion; }

void read(char* pch, size_t nSize)
{
Expand Down Expand Up @@ -380,17 +382,15 @@ class CAutoFile
CAutoFile(const CAutoFile&);
CAutoFile& operator=(const CAutoFile&);

int nType;
int nVersion;
const int nType;
const int nVersion;

FILE* file;

public:
CAutoFile(FILE* filenew, int nTypeIn, int nVersionIn)
CAutoFile(FILE* filenew, int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn)
{
file = filenew;
nType = nTypeIn;
nVersion = nVersionIn;
}

~CAutoFile()
Expand Down Expand Up @@ -425,10 +425,8 @@ class CAutoFile
//
// Stream subset
//
void SetType(int n) { nType = n; }
int GetType() { return nType; }
void SetVersion(int n) { nVersion = n; }
int GetVersion() { return nVersion; }
int GetType() const { return nType; }
int GetVersion() const { return nVersion; }

void read(char* pch, size_t nSize)
{
Expand Down Expand Up @@ -500,8 +498,8 @@ class CBufferedFile
CBufferedFile(const CBufferedFile&);
CBufferedFile& operator=(const CBufferedFile&);

int nType;
int nVersion;
const int nType;
const int nVersion;

FILE *src; // source file
uint64_t nSrcPos; // how many bytes have been read from source
Expand Down Expand Up @@ -531,11 +529,9 @@ class CBufferedFile

public:
CBufferedFile(FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn) :
nSrcPos(0), nReadPos(0), nReadLimit((uint64_t)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0)
nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), nReadPos(0), nReadLimit((uint64_t)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0)
{
src = fileIn;
nType = nTypeIn;
nVersion = nVersionIn;
}

~CBufferedFile()
Expand Down

0 comments on commit fad9b66

Please sign in to comment.