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

Commitbf2a3e7

Browse files
Now if you inherit you class from StampBaseV<> and define ExtractValue method, you will get ExtractBin of this value for free
1 parent5323b4e commitbf2a3e7

File tree

4 files changed

+12
-21
lines changed

4 files changed

+12
-21
lines changed

‎blobstamper/stamp.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,3 @@
66

77
#include"blob.h"
88
#include"stamp.h"
9-
10-
11-
/*************************************************************************************/
12-
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 those cases*/
15-
std::vector<char>
16-
StampFixed::ExtractBin(Blob &blob)
17-
{
18-
std::vector<char> res = blob.ChopBlank(*this);
19-
return res;
20-
}
21-

‎blobstamper/stamp.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ template<class T> class StampBaseV: public StampBasePV<T>
3535
{
3636
public:
3737
virtual TExtractValue(Blob &blob) = 0;/* Shoud be defined by derived classes*/
38+
virtual std::vector<char>ExtractBin(Blob &blob)override;
3839
virtual sized_ptr<T>ExtractPValue(Blob &blob)override;
3940
};
4041

@@ -47,10 +48,14 @@ StampBaseV<T>::ExtractPValue(Blob &blob)
4748
return res;
4849
}
4950

50-
51-
52-
53-
51+
/* If we have value, we can represent it as binary*/
52+
template<classT> std::vector<char>
53+
StampBaseV<T>::ExtractBin(Blob &blob)
54+
{
55+
T value =this->ExtractValue(blob);
56+
std::vector<char>v((char *) &value, (char *) &value +sizeof(T));
57+
return v;
58+
}
5459

5560
classStampFixed :publicvirtual StampBase
5661
{
@@ -59,8 +64,6 @@ class StampFixed : public virtual StampBase
5964
public:
6065
virtualintminSize()override {return size;}
6166
virtualintmaxSize()override {return size;}
62-
63-
std::vector<char>ExtractBin(Blob &blob)override;
6467
};
6568

6669
classStampVariated :publicvirtual StampBase

‎blobstamper/stamp_arithm.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ StampArithm<T>::ExtractStr(Blob &blob)
3030
template<classT> T
3131
StampArithm<T>::ExtractValue(Blob &blob)
3232
{
33-
std::vector<char> v =ExtractBin(blob);
34-
T *pT = (T *) &v[0];
33+
std::vector<char> v = blob.ChopBlank(*this);/* Chop out blank of maxSize*/
34+
T *pT = (T *) &v[0];/* And interpret it as value of arithmetic type*/
3535
return *pT;
3636
}
3737

‎t/110-stamp-arithm.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ main()
3636
{/* 1..4*/
3737
Blobblob(sample_data_char,strlen(sample_data_char));
3838
StampArithm<char> stamp;
39+
3940
std::vector<char> v = blob.ShiftSingleStampBin(stamp);
4041
char * pc = (char *) &v[0];
4142
is(*pc,'S' ,"Bin Char stamp works well");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp