Skip to content

Commit 37132ff

Browse files
Fix examples to work with shared_ptr instead of references
1 parent 3520bb3 commit 37132ff

12 files changed

+60
-67
lines changed

blobstamper/stamp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ template<class T> class StampBasePV: public StampBaseBin
6464
{
6565
public:
6666
virtual sized_ptr<T> ExtractPValue(std::shared_ptr<Blob> blob) = 0;/* Should be defined by derived classes*/
67-
sized_ptr<T> UnloadPValue() {return ExtractPValue(*bitten_blob);};
67+
sized_ptr<T> UnloadPValue() {return ExtractPValue(bitten_blob);};
6868
virtual std::vector<char> ExtractBin(std::shared_ptr<Blob> blob) override;
6969
};
7070

@@ -83,7 +83,7 @@ template<class T> class StampBaseV: public StampBasePV<T>
8383
{
8484
public:
8585
virtual T ExtractValue(std::shared_ptr<Blob> blob) = 0;/* Should be defined by derived classes*/
86-
T UnloadValue() {return ExtractValue(*bitten_blob);};
86+
T UnloadValue() {return ExtractValue(bitten_blob);};
8787

8888
virtual std::vector<char> ExtractBin(std::shared_ptr<Blob> blob) override;
8989
virtual sized_ptr<T> ExtractPValue(std::shared_ptr<Blob> blob) override;

examples/example01.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
int main()
1010
{
1111
char data[] = "abcde";
12-
Blob blob(data, strlen(data));
12+
auto blob = std::make_shared<Blob>(data, strlen(data));
1313
StampArithm<short int> stamp;
1414
std::string s = stamp.ExtractStr(blob);
1515

1616
std::cout << "Stamp minSize: " << stamp.minSize() << "\n";
1717
std::cout << "Stamp maxSize: " << stamp.maxSize() << "\n";
1818
std::cout << "Extracted value: " << s <<"\n";
19-
std::cout << "Remaining blob: " << blob.asString() << "\n";
20-
}
19+
std::cout << "Remaining blob: " << blob->asString() << "\n";
20+
}

examples/example01a.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
int main()
1010
{
1111
char data[] = "abcde";
12-
Blob blob(data, strlen(data));
12+
auto blob = std::make_shared<Blob>(data, strlen(data));
1313
StampArithm<short int> stamp;
1414
stamp.Load(blob);
1515

@@ -18,5 +18,5 @@ int main()
1818
std::cout << "Stamp minSize: " << stamp.minSize() << "\n";
1919
std::cout << "Stamp maxSize: " << stamp.maxSize() << "\n";
2020
std::cout << "Extracted value: " << s <<"\n";
21-
std::cout << "Remaining blob: " << blob.asString() << "\n";
22-
}
21+
std::cout << "Remaining blob: " << blob->asString() << "\n";
22+
}

examples/example02.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
int main()
1010
{
1111
char data[] = "abcdefjhi";
12-
Blob blob(data, strlen(data));
12+
auto blob = std::make_shared<Blob>(data, strlen(data));
1313
StampArithm<short int> stamp;
1414

1515
std::string s = stamp.ExtractStr(blob);
@@ -23,4 +23,4 @@ int main()
2323
std::cout << "Bin value: '" << vec[0] <<"', '" << vec[1] <<"'\n";
2424
std::cout << "Value: " << i <<"\n";
2525
std::cout << "PValue: " << *pi <<"\n";
26-
}
26+
}

examples/example02a.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
int main()
1010
{
1111
char data[] = "abcdefjhi";
12-
Blob blob(data, strlen(data));
12+
auto blob = std::make_shared<Blob>(data, strlen(data));
1313
StampArithm<short int> stamp1;
1414
StampArithm<short int> stamp2;
1515
StampArithm<short int> stamp3;
@@ -31,4 +31,4 @@ int main()
3131
std::cout << "Bin value: '" << vec[0] <<"', '" << vec[1] <<"'\n";
3232
std::cout << "Value: " << i <<"\n";
3333
std::cout << "PValue: " << *pi <<"\n";
34-
}
34+
}

examples/example03.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class StampPoint3D: public StampBaseStr
1313
public:
1414
virtual int minSize() override;
1515
virtual int maxSize() override;
16-
virtual std::string ExtractStr(Blob &blob) override;
16+
virtual std::string ExtractStr(std::shared_ptr<Blob> blob) override;
1717
};
1818

1919
int StampPoint3D::minSize()
@@ -23,10 +23,10 @@ int StampPoint3D::minSize()
2323

2424
int StampPoint3D::maxSize()
2525
{
26-
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
26+
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
2727
}
2828

29-
std::string StampPoint3D::ExtractStr(Blob &blob)
29+
std::string StampPoint3D::ExtractStr(std::shared_ptr<Blob> blob)
3030
{
3131
std::string X,Y,Z;
3232
X = stampX.ExtractStr(blob);
@@ -39,10 +39,10 @@ std::string StampPoint3D::ExtractStr(Blob &blob)
3939
int main()
4040
{
4141
char data[] = "abcdef";
42-
Blob blob(data, strlen(data));
42+
auto blob = std::make_shared<Blob>(data, strlen(data));
4343
StampPoint3D stamp;
4444

4545
std::string s = stamp.ExtractStr(blob);
4646

4747
std::cout << "String value: '" << s <<"'\n";
48-
}
48+
}

examples/example04.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class StampPoint3D: public StampBaseStr, public StampBaseV<Point3D>
2020
public:
2121
virtual int minSize() override;
2222
virtual int maxSize() override;
23-
virtual std::string ExtractStr(Blob &blob) override;
24-
virtual Point3D ExtractValue(Blob &blob) override;
23+
virtual std::string ExtractStr(std::shared_ptr<Blob> blob) override;
24+
virtual Point3D ExtractValue(std::shared_ptr<Blob> blob) override;
2525
};
2626

2727
int StampPoint3D::minSize()
@@ -31,10 +31,10 @@ int StampPoint3D::minSize()
3131

3232
int StampPoint3D::maxSize()
3333
{
34-
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
34+
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
3535
}
3636

37-
std::string StampPoint3D::ExtractStr(Blob &blob)
37+
std::string StampPoint3D::ExtractStr(std::shared_ptr<Blob> blob)
3838
{
3939
std::string X,Y,Z;
4040
X = stampX.ExtractStr(blob);
@@ -43,7 +43,7 @@ std::string StampPoint3D::ExtractStr(Blob &blob)
4343
return "(" + X + ", " + Y + ", " + Z + ")";
4444
}
4545

46-
Point3D StampPoint3D::ExtractValue(Blob &blob)
46+
Point3D StampPoint3D::ExtractValue(std::shared_ptr<Blob> blob)
4747
{
4848
Point3D res;
4949
res.X = stampX.ExtractValue(blob);
@@ -55,12 +55,12 @@ Point3D StampPoint3D::ExtractValue(Blob &blob)
5555
int main()
5656
{
5757
char data[] = "abcdef" "abcdef";
58-
Blob blob(data, strlen(data));
58+
auto blob = std::make_shared<Blob>(data, strlen(data));
5959
StampPoint3D stamp;
6060

6161
std::string s = stamp.ExtractStr(blob);
6262
Point3D p = stamp.ExtractValue(blob);
6363

6464
std::cout << "String value: '" << s <<"'\n";
6565
std::cout << "Point3D value: (" << p.X << ", " << p.Y << ", " << p.Z << ")\n";
66-
}
66+
}

examples/example05.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class StampPoint3D: public StampBaseStr, public StampBaseV<Point3D>
2020
public:
2121
virtual int minSize() override;
2222
virtual int maxSize() override;
23-
virtual std::string ExtractStr(Blob &blob) override;
24-
virtual Point3D ExtractValue(Blob &blob) override;
23+
virtual std::string ExtractStr(std::shared_ptr<Blob> blob) override;
24+
virtual Point3D ExtractValue(std::shared_ptr<Blob> blob) override;
2525
};
2626

2727
int StampPoint3D::minSize()
@@ -31,10 +31,10 @@ int StampPoint3D::minSize()
3131

3232
int StampPoint3D::maxSize()
3333
{
34-
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
34+
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
3535
}
3636

37-
std::string StampPoint3D::ExtractStr(Blob &blob)
37+
std::string StampPoint3D::ExtractStr(std::shared_ptr<Blob> blob)
3838
{
3939
std::string X,Y,Z;
4040
X = stampX.ExtractStr(blob);
@@ -43,7 +43,7 @@ std::string StampPoint3D::ExtractStr(Blob &blob)
4343
return "(" + X + ", " + Y + ", " + Z + ")";
4444
}
4545

46-
Point3D StampPoint3D::ExtractValue(Blob &blob)
46+
Point3D StampPoint3D::ExtractValue(std::shared_ptr<Blob> blob)
4747
{
4848
Point3D res;
4949
res.X = stampX.ExtractValue(blob);
@@ -55,13 +55,13 @@ Point3D StampPoint3D::ExtractValue(Blob &blob)
5555
int main()
5656
{
5757
char data[] = "abcdef" "abcdef" "ABCDEF" "012345";
58-
Blob blob(data, strlen(data));
59-
StampPoint3D stamp;
58+
auto blob = std::make_shared<Blob>(data, strlen(data));
59+
auto stamp = std::make_shared<StampPoint3D>();
6060

6161
GalleyVectorStr galley(stamp);
6262

6363
std::vector<std::string> res = galley.ExtractStrVector(blob);
6464

6565
for(std::string s : res)
6666
std::cout << "'" << s <<"'\n";
67-
}
67+
}

examples/example06.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class StampPoint3D: public StampBaseStr, public StampBaseV<Point3D>
2020
public:
2121
virtual int minSize() override;
2222
virtual int maxSize() override;
23-
virtual std::string ExtractStr(Blob &blob) override;
24-
virtual Point3D ExtractValue(Blob &blob) override;
23+
virtual std::string ExtractStr(std::shared_ptr<Blob> blob) override;
24+
virtual Point3D ExtractValue(std::shared_ptr<Blob> blob) override;
2525
};
2626

2727
int StampPoint3D::minSize()
@@ -31,10 +31,10 @@ int StampPoint3D::minSize()
3131

3232
int StampPoint3D::maxSize()
3333
{
34-
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
34+
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
3535
}
3636

37-
std::string StampPoint3D::ExtractStr(Blob &blob)
37+
std::string StampPoint3D::ExtractStr(std::shared_ptr<Blob> blob)
3838
{
3939
std::string X,Y,Z;
4040
X = stampX.ExtractStr(blob);
@@ -43,7 +43,7 @@ std::string StampPoint3D::ExtractStr(Blob &blob)
4343
return "(" + X + ", " + Y + ", " + Z + ")";
4444
}
4545

46-
Point3D StampPoint3D::ExtractValue(Blob &blob)
46+
Point3D StampPoint3D::ExtractValue(std::shared_ptr<Blob> blob)
4747
{
4848
Point3D res;
4949
res.X = stampX.ExtractValue(blob);
@@ -55,8 +55,8 @@ Point3D StampPoint3D::ExtractValue(Blob &blob)
5555
int main()
5656
{
5757
char data[] = "abcdef" "abcdef" "ABCDEF" "012345";
58-
Blob blob(data, strlen(data));
59-
StampPoint3D stamp;
58+
auto blob = std::make_shared<Blob>(data, strlen(data));
59+
auto stamp = std::make_shared<StampPoint3D>();
6060

6161
GalleyVectorV<Point3D> galley(stamp);
6262
std::vector<Point3D> res = galley.ExtractValuesVector(blob);
@@ -68,4 +68,4 @@ int main()
6868
{
6969
std::cout << "(" << p[i].X << ", " << p[i].Y << ", " << p[i].Z << ")\n";
7070
}
71-
}
71+
}

examples/example07.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class StampPoint3D: public StampBaseStr, public StampBaseV<Point3D>
2020
public:
2121
virtual int minSize() override;
2222
virtual int maxSize() override;
23-
virtual std::string ExtractStr(Blob &blob) override;
24-
virtual Point3D ExtractValue(Blob &blob) override;
23+
virtual std::string ExtractStr(std::shared_ptr<Blob> blob) override;
24+
virtual Point3D ExtractValue(std::shared_ptr<Blob> blob) override;
2525
};
2626

2727
int StampPoint3D::minSize()
@@ -31,10 +31,10 @@ int StampPoint3D::minSize()
3131

3232
int StampPoint3D::maxSize()
3333
{
34-
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
34+
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
3535
}
3636

37-
std::string StampPoint3D::ExtractStr(Blob &blob)
37+
std::string StampPoint3D::ExtractStr(std::shared_ptr<Blob> blob)
3838
{
3939
std::string X,Y,Z;
4040
X = stampX.ExtractStr(blob);
@@ -43,7 +43,7 @@ std::string StampPoint3D::ExtractStr(Blob &blob)
4343
return "(" + X + ", " + Y + ", " + Z + ")";
4444
}
4545

46-
Point3D StampPoint3D::ExtractValue(Blob &blob)
46+
Point3D StampPoint3D::ExtractValue(std::shared_ptr<Blob> blob)
4747
{
4848
Point3D res;
4949
res.X = stampX.ExtractValue(blob);
@@ -55,17 +55,13 @@ Point3D StampPoint3D::ExtractValue(Blob &blob)
5555

5656
class StampPolyLine3D: public GalleyVectorStr, public StampBaseStr
5757
{
58-
protected:
59-
StampPoint3D * item_stamp_p;
6058
public:
61-
StampPolyLine3D(): GalleyVectorStr(*(item_stamp_p = new StampPoint3D())) {};
62-
~StampPolyLine3D() {delete item_stamp_p;};
63-
64-
virtual std::string ExtractStr(Blob &blob) override;
59+
StampPolyLine3D(): GalleyVectorStr(std::make_shared<StampPoint3D>()) {};
60+
virtual std::string ExtractStr(std::shared_ptr<Blob> blob) override;
6561
};
6662

6763

68-
std::string StampPolyLine3D::ExtractStr(Blob &blob)
64+
std::string StampPolyLine3D::ExtractStr(std::shared_ptr<Blob> blob)
6965
{
7066
std::vector<std::string> data = ExtractStrVector(blob);
7167
std::string res = "";
@@ -85,7 +81,7 @@ std::string StampPolyLine3D::ExtractStr(Blob &blob)
8581
int main()
8682
{
8783
char data[] = "abcdef" "abcdef" "ABCDEF" "012345";
88-
Blob blob(data, strlen(data));
84+
auto blob = std::make_shared<Blob>(data, strlen(data));
8985
StampPolyLine3D stamp;
9086

9187
std::string s = stamp.ExtractStr(blob);

examples/example08.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class StampPoint3D: public StampBaseStr, public StampBaseV<Point3D>
2020
public:
2121
virtual int minSize() override;
2222
virtual int maxSize() override;
23-
virtual std::string ExtractStr(Blob &blob) override;
24-
virtual Point3D ExtractValue(Blob &blob) override;
23+
virtual std::string ExtractStr(std::shared_ptr<Blob> blob) override;
24+
virtual Point3D ExtractValue(std::shared_ptr<Blob> blob) override;
2525
};
2626

2727
int StampPoint3D::minSize()
@@ -34,7 +34,7 @@ int StampPoint3D::maxSize()
3434
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
3535
}
3636

37-
std::string StampPoint3D::ExtractStr(Blob &blob)
37+
std::string StampPoint3D::ExtractStr(std::shared_ptr<Blob> blob)
3838
{
3939
std::string X,Y,Z;
4040
X = stampX.ExtractStr(blob);
@@ -43,7 +43,7 @@ std::string StampPoint3D::ExtractStr(Blob &blob)
4343
return "(" + X + ", " + Y + ", " + Z + ")";
4444
}
4545

46-
Point3D StampPoint3D::ExtractValue(Blob &blob)
46+
Point3D StampPoint3D::ExtractValue(std::shared_ptr<Blob> blob)
4747
{
4848
Point3D res;
4949
res.X = stampX.ExtractValue(blob);
@@ -55,19 +55,16 @@ Point3D StampPoint3D::ExtractValue(Blob &blob)
5555

5656
class StampPolyLine3D: public StampStrEnumerator
5757
{
58-
protected:
59-
StampPoint3D * item_stamp_p;
6058
public:
61-
StampPolyLine3D(): StampStrEnumerator(*(item_stamp_p = new StampPoint3D()), ",", "(",")") {};
62-
~StampPolyLine3D() {delete item_stamp_p;};
59+
StampPolyLine3D(): StampStrEnumerator(std::make_shared<StampPoint3D>(), ",", "(",")") {};
6360
};
6461

6562

6663

6764
int main()
6865
{
6966
char data[] = "abcdef" "abcdef" "ABCDEF" "012345";
70-
Blob blob(data, strlen(data));
67+
auto blob = std::make_shared<Blob>(data, strlen(data));
7168

7269
StampPolyLine3D stamp;
7370

0 commit comments

Comments
 (0)