Skip to content

Commit fad9b66

Browse files
committed
Make nType and nVersion private and sometimes const
Make the various stream implementations' nType and nVersion private and const (except in CDataStream where we really need a setter).
1 parent c2c5d42 commit fad9b66

File tree

4 files changed

+20
-24
lines changed

4 files changed

+20
-24
lines changed

src/hash.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,9 @@ class CHashWriter
132132
private:
133133
CHash256 ctx;
134134

135+
const int nType;
136+
const int nVersion;
135137
public:
136-
int nType;
137-
int nVersion;
138138

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

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class CConnman
140140
void PushMessageWithVersionAndFlag(CNode* pnode, int nVersion, int flag, const std::string& sCommand, Args&&... args)
141141
{
142142
auto msg(BeginMessage(pnode, nVersion, flag, sCommand));
143-
::SerializeMany(msg, msg.nType, msg.nVersion, std::forward<Args>(args)...);
143+
::SerializeMany(msg, msg.GetType(), msg.GetVersion(), std::forward<Args>(args)...);
144144
EndMessage(msg);
145145
PushMessage(pnode, msg, sCommand);
146146
}

src/serialize.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,9 +937,9 @@ class CSizeComputer
937937
protected:
938938
size_t nSize;
939939

940+
const int nType;
941+
const int nVersion;
940942
public:
941-
int nType;
942-
int nVersion;
943943

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

src/streams.h

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ template<typename Stream>
2626
class OverrideStream
2727
{
2828
Stream* stream;
29-
public:
29+
3030
const int nType;
3131
const int nVersion;
3232

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

3536
template<typename T>
@@ -66,9 +67,10 @@ class CDataStream
6667
typedef CSerializeData vector_type;
6768
vector_type vch;
6869
unsigned int nReadPos;
69-
public:
70+
7071
int nType;
7172
int nVersion;
73+
public:
7274

7375
typedef vector_type::allocator_type allocator_type;
7476
typedef vector_type::size_type size_type;
@@ -251,9 +253,9 @@ class CDataStream
251253
int in_avail() { return size(); }
252254

253255
void SetType(int n) { nType = n; }
254-
int GetType() { return nType; }
256+
int GetType() const { return nType; }
255257
void SetVersion(int n) { nVersion = n; }
256-
int GetVersion() { return nVersion; }
258+
int GetVersion() const { return nVersion; }
257259

258260
void read(char* pch, size_t nSize)
259261
{
@@ -380,17 +382,15 @@ class CAutoFile
380382
CAutoFile(const CAutoFile&);
381383
CAutoFile& operator=(const CAutoFile&);
382384

383-
int nType;
384-
int nVersion;
385-
385+
const int nType;
386+
const int nVersion;
387+
386388
FILE* file;
387389

388390
public:
389-
CAutoFile(FILE* filenew, int nTypeIn, int nVersionIn)
391+
CAutoFile(FILE* filenew, int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn)
390392
{
391393
file = filenew;
392-
nType = nTypeIn;
393-
nVersion = nVersionIn;
394394
}
395395

396396
~CAutoFile()
@@ -425,10 +425,8 @@ class CAutoFile
425425
//
426426
// Stream subset
427427
//
428-
void SetType(int n) { nType = n; }
429-
int GetType() { return nType; }
430-
void SetVersion(int n) { nVersion = n; }
431-
int GetVersion() { return nVersion; }
428+
int GetType() const { return nType; }
429+
int GetVersion() const { return nVersion; }
432430

433431
void read(char* pch, size_t nSize)
434432
{
@@ -500,8 +498,8 @@ class CBufferedFile
500498
CBufferedFile(const CBufferedFile&);
501499
CBufferedFile& operator=(const CBufferedFile&);
502500

503-
int nType;
504-
int nVersion;
501+
const int nType;
502+
const int nVersion;
505503

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

532530
public:
533531
CBufferedFile(FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn) :
534-
nSrcPos(0), nReadPos(0), nReadLimit((uint64_t)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0)
532+
nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), nReadPos(0), nReadLimit((uint64_t)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0)
535533
{
536534
src = fileIn;
537-
nType = nTypeIn;
538-
nVersion = nVersionIn;
539535
}
540536

541537
~CBufferedFile()

0 commit comments

Comments
 (0)