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

Commit47278eb

Browse files
Introduce 'Loaded' stamps
1 parente13d50f commit47278eb

File tree

5 files changed

+92
-0
lines changed

5 files changed

+92
-0
lines changed

‎Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ blob-stamper-clean:
4141
clean: blob-stamper-clean
4242
$(MAKE) -C blobstamper clean
4343
$(MAKE) -C t clean
44+
$(MAKE) -C examples clean
4445
$(MAKE) -C libtappp clean
4546
@echo Clean done!
4647

‎blobstamper/stamp.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,27 @@
2424

2525
#include"blob.h"
2626
#include"stamp.h"
27+
28+
29+
void
30+
StampBase::Load(Blob &blob)
31+
{
32+
33+
if (minSize() > blob.Size())
34+
{
35+
throwOutOfData();
36+
}
37+
38+
size_t res_size;
39+
if (isUnbounded())
40+
{
41+
res_size = blob.Size();
42+
}else
43+
{
44+
res_size =maxSize();
45+
if (res_size > blob.Size())
46+
res_size = blob.Size();
47+
}
48+
Blob *pb =newBlob(blob.ShiftBytes(res_size));
49+
bitten_blob = std::unique_ptr<Blob>(pb);
50+
}

‎blobstamper/stamp.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,21 @@
2222
#include<string>
2323
#include<list>
2424
#include<vector>
25+
#include<memory>
2526

2627
#include"helpers.h"
2728

2829

2930
classStampBase
3031
{
32+
protected:
33+
std::unique_ptr<Blob> bitten_blob;
3134
public:
3235
virtualintminSize() = 0;
3336
virtualintmaxSize() = 0;
3437

38+
voidLoad(Blob &blob);
39+
3540
boolisFixedSize() {returnminSize() ==maxSize();}
3641
boolisVariated() {return !isFixedSize() && !isUnbounded();}
3742
boolisUnbounded() {returnmaxSize() == -1;}
@@ -42,20 +47,23 @@ class StampBaseStr: public virtual StampBase
4247
{
4348
public:
4449
virtual std::stringExtractStr(Blob &blob) = 0;
50+
std::stringUnloadStr() {returnExtractStr(*bitten_blob);};
4551
};
4652

4753

4854
classStampBaseBin:publicvirtual StampBase
4955
{
5056
public:
5157
virtual std::vector<char>ExtractBin(Blob &blob) = 0;
58+
std::vector<char>UnloadBin() {returnExtractBin(*bitten_blob);};
5259
};
5360

5461

5562
template<classT>classStampBasePV:publicStampBaseBin
5663
{
5764
public:
5865
virtual sized_ptr<T>ExtractPValue(Blob &blob) = 0;/* Shoud be defined by derived classes*/
66+
sized_ptr<T>UnloadPValue() {returnExtractPValue(*bitten_blob);};
5967
virtual std::vector<char>ExtractBin(Blob &blob)override;
6068
};
6169

@@ -70,9 +78,12 @@ StampBasePV<T>::ExtractBin(Blob &blob)
7078
}
7179

7280
template<classT>classStampBaseV:publicStampBasePV<T>
81+
,publicvirtual StampBase//FIXME I do not understand why do we need it here, but wihtout it, it does not build
7382
{
7483
public:
7584
virtual TExtractValue(Blob &blob) = 0;/* Shoud be defined by derived classes*/
85+
TUnloadValue() {returnExtractValue(*bitten_blob);};
86+
7687
virtual std::vector<char>ExtractBin(Blob &blob)override;
7788
virtual sized_ptr<T>ExtractPValue(Blob &blob)override;
7889
};

‎examples/example01a.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
#include<string>
5+
#include<iostream>
6+
7+
#include<blobstamper/blobstamper.h>
8+
9+
intmain()
10+
{
11+
char data[] ="abcde";
12+
Blobblob(data,strlen(data));
13+
StampArithm<shortint> stamp;
14+
stamp.Load(blob);
15+
16+
std::string s = stamp.UnloadStr();
17+
18+
std::cout <<"Stamp minSize:" << stamp.minSize() <<"\n";
19+
std::cout <<"Stamp maxSize:" << stamp.maxSize() <<"\n";
20+
std::cout <<"Extracted value:" << s <<"\n";
21+
std::cout <<"Remaining blob:" << blob.asString() <<"\n";
22+
}

‎examples/example02a.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
#include<string>
5+
#include<iostream>
6+
7+
#include<blobstamper/blobstamper.h>
8+
9+
intmain()
10+
{
11+
char data[] ="abcdefjhi";
12+
Blobblob(data,strlen(data));
13+
StampArithm<shortint> stamp1;
14+
StampArithm<shortint> stamp2;
15+
StampArithm<shortint> stamp3;
16+
StampArithm<shortint> stamp4;
17+
18+
stamp1.Load(blob);
19+
stamp2.Load(blob);
20+
stamp3.Load(blob);
21+
stamp4.Load(blob);
22+
23+
std::string s = stamp1.UnloadStr();
24+
std::vector<char> vec= stamp2.UnloadBin();
25+
shortint i = stamp3.UnloadValue();
26+
27+
sized_ptr<shortint> spi = stamp4.UnloadPValue();
28+
shortint *pi = spi;
29+
30+
std::cout <<"String value: '" << s <<"'\n";
31+
std::cout <<"Bin value: '" << vec[0] <<"', '" << vec[1] <<"'\n";
32+
std::cout <<"Value:" << i <<"\n";
33+
std::cout <<"PValue:" << *pi <<"\n";
34+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp