Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb68fd74

Browse files
Split one Stamp Base class into three subclasses: fixed, variable and unbounded. variable size stamps is not implemented yet, the rest are implemented
1 parent71c7f51 commitb68fd74

File tree

11 files changed

+62
-66
lines changed

11 files changed

+62
-66
lines changed

‎blobstamper/blob.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ Blob::Size()
5454
}
5555

5656
void *
57-
Blob::ShiftSingleStampBin(StampGeneric& stmp)
57+
Blob::ShiftSingleStampBin(StampBase& stmp)
5858
{
5959
return stmp.Extract(*this);
6060
}
6161

6262
std::string
63-
Blob::ShiftSingleStampStr(StampGeneric& stmp)
63+
Blob::ShiftSingleStampStr(StampBase& stmp)
6464
{
6565
return stmp.ExtractStr(*this);
6666
}

‎blobstamper/blob.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include<string>
66
#include<list>
77

8-
classStampGeneric;
8+
classStampBase;
99

1010
classBlob
1111
{
@@ -22,8 +22,8 @@ class Blob
2222
BlobShiftBytes(size_t n);
2323
voidDataDup(char *& data_out,size_t& size_out);
2424

25-
void *ShiftSingleStampBin(StampGeneric &stmp);
26-
std::stringShiftSingleStampStr(StampGeneric &stmp);
25+
void *ShiftSingleStampBin(StampBase &stmp);
26+
std::stringShiftSingleStampStr(StampBase &stmp);
2727
};
2828

2929

‎blobstamper/galley.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ class GalleyBase
2222
classGalleySeries :publicGalleyBase
2323
{
2424
protected:
25-
StampGeneric &stamp;
25+
StampBase &stamp;
2626
public:
27-
GalleySeries(StampGeneric & stamp_arg) : stamp(stamp_arg) {};
27+
GalleySeries(StampBase & stamp_arg) : stamp(stamp_arg) {};
2828
std::list<Blob>extract_internal(Blob &blob);
2929
std::list<std::string>Extract(Blob &blob);
3030
std::list<void *>ExtractBin(Blob &blob);

‎blobstamper/stamp.cpp‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@
1010

1111
/*************************************************************************************/
1212

13+
/* Generic Exrtact Bin function for fixed size stamp. In some cases we need just a chunk of raw blob data.*/
14+
/* Use this method in such a case*/
1315
void *
14-
StampGeneric::Extract(Blob &blob)
16+
StampFixed::Extract(Blob &blob)
1517
{
16-
if (!is_fixed_size)
17-
{
18-
fprintf(stderr,"Something is really wrong. Default extract method does not support dynamic stamp size\n");
19-
returnNULL;
20-
}
21-
Blob blob2 = blob.ShiftBytes(min_size);
18+
Blob blob2 = blob.ShiftBytes(size);
2219

2320
if (blob2.isEmpty())/* original blob does not have enought data*/
2421
returnNULL;

‎blobstamper/stamp.h‎

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,41 @@
55
#include<string>
66
#include<list>
77

8-
classStampGeneric
8+
classStampBase
99
{
10-
protected:
11-
bool is_fixed_size;
12-
int min_size;
13-
int max_size;
1410
public:
15-
virtualboolisFixedSize() {return is_fixed_size;}
16-
virtualintminSize() {return min_size;}
17-
virtualintmaxSize() {return max_size;}
11+
virtualintminSize() = 0;
12+
virtualintmaxSize() = 0;
1813

19-
virtualvoid *Extract(Blob &blob);
20-
virtual std::stringExtractStr(Blob &blob) {printf ("22222\n");return"";}
14+
boolisFixedSize() {returnminSize()==maxSize();}
15+
boolisUnbounded() {returnmaxSize() == -1;}
2116

17+
virtualvoid *Extract(Blob &blob) {printf ("Not implemented");exit(1);}
18+
virtual std::stringExtractStr(Blob &blob) {printf ("Not implemented");exit(1);}
2219
};
2320

24-
classStampList:publicStampGeneric
21+
22+
classStampFixed :publicStampBase
2523
{
2624
protected:
27-
StampGeneric& target_stamp;
25+
int size;
2826
public:
29-
StampList(StampGeneric &stamp) : target_stamp(stamp) {};
27+
virtualintminSize() {return size;}
28+
virtualintmaxSize() {return size;}
29+
30+
void *Extract(Blob &blob)override;
3031
};
3132

33+
classStampUnbounded :publicStampBase
34+
{
35+
protected:
36+
int min_size;
37+
public:
38+
virtualintminSize() {return min_size;}
39+
virtualintmaxSize() {return -1;}
40+
};
41+
42+
43+
44+
3245
#endif/* STAMP_H*/

‎blobstamper/stamp_atomic.cpp‎

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,9 @@
33
#include"stamp_atomic.h"
44

55

6-
StampBinChar::StampBinChar() :StampGeneric()
6+
StampBinChar::StampBinChar() :StampFixed()
77
{
8-
min_size =sizeof(char);
9-
max_size =sizeof(char);
10-
is_fixed_size =true;
8+
size =sizeof(char);
119
}
1210

1311

@@ -24,11 +22,9 @@ StampStrUInt8::ExtractStr(Blob &blob)
2422
}
2523
/* ----*/
2624

27-
StampBinInt16::StampBinInt16() :StampGeneric()
25+
StampBinInt16::StampBinInt16() :StampFixed()
2826
{
29-
min_size =sizeof(shortint);
30-
max_size =sizeof(shortint);
31-
is_fixed_size =true;
27+
size =sizeof(shortint);
3228
}
3329

3430
std::string
@@ -57,11 +53,9 @@ StampStrSInt16::ExtractStr(Blob &blob)
5753

5854
/* ----*/
5955

60-
StampBinInt32::StampBinInt32() :StampGeneric()
56+
StampBinInt32::StampBinInt32() :StampFixed()
6157
{
62-
min_size =sizeof(int);
63-
max_size =sizeof(int);
64-
is_fixed_size =true;
58+
size =sizeof(int);
6559
}
6660

6761
std::string
@@ -90,11 +84,9 @@ StampStrSInt32::ExtractStr(Blob &blob)
9084

9185
/* ----*/
9286

93-
StampBinInt64::StampBinInt64() :StampGeneric()
87+
StampBinInt64::StampBinInt64() :StampFixed()
9488
{
95-
min_size =sizeof(longlong);
96-
max_size =sizeof(longlong);
97-
is_fixed_size =true;
89+
size =sizeof(longlong);
9890
}
9991

10092
std::string
@@ -123,11 +115,9 @@ StampStrSInt64::ExtractStr(Blob &blob)
123115

124116
/* ----*/
125117

126-
StampBinDouble::StampBinDouble() :StampGeneric()
118+
StampBinDouble::StampBinDouble() :StampFixed()
127119
{
128-
min_size =sizeof(double);
129-
max_size =sizeof(double);
130-
is_fixed_size =true;
120+
size =sizeof(double);
131121
}
132122

133123
std::string

‎blobstamper/stamp_atomic.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include<string>
55

66

7-
classStampBinChar:publicStampGeneric
7+
classStampBinChar:publicStampFixed
88
{
99
public:
1010
StampBinChar();
@@ -18,7 +18,7 @@ class StampStrUInt8: public StampBinChar
1818

1919
/* ---*/
2020

21-
classStampBinInt16:publicStampGeneric
21+
classStampBinInt16:publicStampFixed
2222
{
2323
public:
2424
StampBinInt16();
@@ -39,7 +39,7 @@ class StampStrSInt16: public StampBinInt16
3939

4040
/* ---*/
4141

42-
classStampBinInt32:publicStampGeneric
42+
classStampBinInt32:publicStampFixed
4343
{
4444
public:
4545
StampBinInt32();
@@ -59,7 +59,7 @@ class StampStrSInt32: public StampBinInt32
5959

6060
/* ---*/
6161

62-
classStampBinInt64:publicStampGeneric
62+
classStampBinInt64:publicStampFixed
6363
{
6464
public:
6565
StampBinInt64();
@@ -80,7 +80,7 @@ class StampStrSInt64: public StampBinInt64
8080
/* ---*/
8181

8282

83-
classStampBinDouble:publicStampGeneric
83+
classStampBinDouble:publicStampFixed
8484
{
8585
public:
8686
StampBinDouble();

‎blobstamper/stamp_dict.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include"stamp_atomic.h"
55
#include"stamp_dict.h"
66

7-
StampGeneric&
7+
StampFixed&
88
StampDict::GuessStamp(DictBase & dict)
99
{
1010
if (dict.size()<= UCHAR_MAX+1)

‎blobstamper/stamp_dict.h‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,22 @@
99
#include"stamp_atomic.h"
1010
#include"dict.h"
1111

12-
classStampDict:publicStampGeneric
12+
classStampDict:publicStampFixed
1313
{
1414
protected:
1515
StampBinChar stamp8;
1616
StampBinInt16 stamp16;
1717
StampBinInt32 stamp32;
1818
StampBinInt64 stamp64;
19-
StampGeneric& stamp;
19+
StampFixed& stamp;
2020
DictBase& dict;
2121
unsignedlonglong stamp_max_value;
2222

23-
StampGeneric&GuessStamp(DictBase & dict);
23+
StampFixed&GuessStamp(DictBase & dict);
2424

2525
public:
2626
StampDict(DictBase & dict_arg) : dict{dict_arg}, stamp{GuessStamp(dict_arg)} {};
2727
std::stringExtractStr(Blob &blob)override;
28-
boolisFixedSize()override {returntrue;}
2928
intminSize()override {return stamp.minSize();}
3029
intmaxSize()override {return stamp.maxSize();}
3130
};

‎t/300-galley.cpp‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212

1313
usingnamespaceTAP;
1414

15-
classStampTwoCharsList:publicStampGeneric
15+
classStampTwoCharsList:publicStampUnbounded
1616
{
1717
protected:
1818
StampTwoChars el_stamp;
1919
GalleySeries galley;
2020
public:
2121
std::stringExtractStr(Blob &blob)override;
2222
StampTwoCharsList(): el_stamp {}, galley {el_stamp} {};
23-
virtualboolisFixedSize()override {returnfalse;};
24-
virtualintmaxSize()override {return -1;};
23+
2524
virtualintminSize()override {return el_stamp.minSize();};
2625
};
2726

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp