Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit e13d50f

Browse files
Some more examples. And now you can inherit galley asif it is a stamp. And make a stamp out of it
1 parent c52e036 commit e13d50f

File tree

5 files changed

+236
-10
lines changed

5 files changed

+236
-10
lines changed

blobstamper/galley.h

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,10 @@
2929
#define ORACLE_SIZE sizeof(ORACLE_TYPE)
3030
#define ORACLE_MAX std::numeric_limits<ORACLE_TYPE>::max()
3131

32-
class GalleyBase
32+
class GalleyBase: public virtual StampBase
33+
/* Galley is a kind of stamp, somwhere deep inside. */
34+
/* You can inherit it, and make a stamp out of it*/
3335
{
34-
public:
35-
virtual int minSize() = 0;
36-
virtual int maxSize() = 0;
37-
bool isFixedSize() {return minSize() == maxSize();}
38-
bool isUnbounded() {return maxSize() == -1;}
39-
4036
};
4137

4238
class GalleyVectorBase : public GalleyBase

examples/example06.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,4 @@ int main()
6868
{
6969
std::cout << "(" << p[i].X << ", " << p[i].Y << ", " << p[i].Z << ")\n";
7070
}
71-
72-
7371
}

examples/example07.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
#include<string>
5+
#include<iostream>
6+
7+
#include<blobstamper/blobstamper.h>
8+
9+
typedef struct Point3D
10+
{
11+
short int X;
12+
short int Y;
13+
short int Z;
14+
} Point3D;
15+
16+
class StampPoint3D: public StampBaseStr, public StampBaseV<Point3D>
17+
{
18+
protected:
19+
StampArithm<short int> stampX, stampY, stampZ;
20+
public:
21+
virtual int minSize() override;
22+
virtual int maxSize() override;
23+
virtual std::string ExtractStr(Blob &blob) override;
24+
virtual Point3D ExtractValue(Blob &blob) override;
25+
};
26+
27+
int StampPoint3D::minSize()
28+
{
29+
return stampX.minSize() + stampY.minSize() + stampZ.minSize();
30+
}
31+
32+
int StampPoint3D::maxSize()
33+
{
34+
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
35+
}
36+
37+
std::string StampPoint3D::ExtractStr(Blob &blob)
38+
{
39+
std::string X,Y,Z;
40+
X = stampX.ExtractStr(blob);
41+
Y = stampY.ExtractStr(blob);
42+
Z = stampZ.ExtractStr(blob);
43+
return "(" + X + ", " + Y + ", " + Z + ")";
44+
}
45+
46+
Point3D StampPoint3D::ExtractValue(Blob &blob)
47+
{
48+
Point3D res;
49+
res.X = stampX.ExtractValue(blob);
50+
res.Y = stampY.ExtractValue(blob);
51+
res.Z = stampZ.ExtractValue(blob);
52+
return res;
53+
}
54+
55+
56+
class StampPolyLine3D: public GalleyVectorStr, public StampBaseStr
57+
{
58+
protected:
59+
StampPoint3D * item_stamp_p;
60+
public:
61+
StampPolyLine3D(): GalleyVectorStr(*(item_stamp_p = new StampPoint3D())) {};
62+
~StampPolyLine3D() {delete item_stamp_p;};
63+
64+
virtual std::string ExtractStr(Blob &blob) override;
65+
};
66+
67+
68+
std::string StampPolyLine3D::ExtractStr(Blob &blob)
69+
{
70+
std::vector<std::string> data = ExtractStrVector(blob);
71+
std::string res = "";
72+
73+
for(std::string s : data)
74+
{
75+
if (!res.empty())
76+
{
77+
res+=", ";
78+
}
79+
res+= s;
80+
}
81+
res = "(" + res + ")";
82+
return res;
83+
}
84+
85+
int main()
86+
{
87+
char data[] = "abcdef" "abcdef" "ABCDEF" "012345";
88+
Blob blob(data, strlen(data));
89+
StampPolyLine3D stamp;
90+
91+
std::string s = stamp.ExtractStr(blob);
92+
std::cout << s <<"\n";
93+
}

examples/example08.cpp

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
4+
#include<string>
5+
#include<iostream>
6+
7+
#include<blobstamper/blobstamper.h>
8+
9+
typedef struct Point3D
10+
{
11+
short int X;
12+
short int Y;
13+
short int Z;
14+
} Point3D;
15+
16+
class StampPoint3D: public StampBaseStr, public StampBaseV<Point3D>
17+
{
18+
protected:
19+
StampArithm<short int> stampX, stampY, stampZ;
20+
public:
21+
virtual int minSize() override;
22+
virtual int maxSize() override;
23+
virtual std::string ExtractStr(Blob &blob) override;
24+
virtual Point3D ExtractValue(Blob &blob) override;
25+
};
26+
27+
int StampPoint3D::minSize()
28+
{
29+
return stampX.minSize() + stampY.minSize() + stampZ.minSize();
30+
}
31+
32+
int StampPoint3D::maxSize()
33+
{
34+
return stampX.maxSize() + stampY.maxSize() + stampZ.maxSize();
35+
}
36+
37+
std::string StampPoint3D::ExtractStr(Blob &blob)
38+
{
39+
std::string X,Y,Z;
40+
X = stampX.ExtractStr(blob);
41+
Y = stampY.ExtractStr(blob);
42+
Z = stampZ.ExtractStr(blob);
43+
return "(" + X + ", " + Y + ", " + Z + ")";
44+
}
45+
46+
Point3D StampPoint3D::ExtractValue(Blob &blob)
47+
{
48+
Point3D res;
49+
res.X = stampX.ExtractValue(blob);
50+
res.Y = stampY.ExtractValue(blob);
51+
res.Z = stampZ.ExtractValue(blob);
52+
return res;
53+
}
54+
55+
56+
class StampPolyLine3D: public GalleyVectorStr, public StampBaseStr
57+
{
58+
protected:
59+
StampPoint3D * item_stamp_p;
60+
public:
61+
StampPolyLine3D(): GalleyVectorStr(*(item_stamp_p = new StampPoint3D())) {};
62+
~StampPolyLine3D() {delete item_stamp_p;};
63+
64+
virtual std::string ExtractStr(Blob &blob) override;
65+
};
66+
67+
class StampStrEnumerator: public GalleyVectorStr, public StampBaseStr
68+
{
69+
protected:
70+
StampBaseStr & stamp_str;
71+
const std::string separator;
72+
const std::string left_bracket;
73+
const std::string right_bracket;
74+
public:
75+
StampStrEnumerator(StampBaseStr &arg_stamp,
76+
const std::string arg_sep,
77+
const std::string arg_l,
78+
const std::string arg_r
79+
):
80+
stamp_str(arg_stamp),
81+
separator(arg_sep),
82+
left_bracket(arg_l),
83+
right_bracket(arg_r),
84+
GalleyVectorStr(arg_stamp) {};
85+
86+
virtual std::string ExtractStr(Blob &blob) override;
87+
88+
};
89+
90+
91+
std::string StampStrEnumerator::ExtractStr(Blob &blob)
92+
{
93+
std::vector<std::string> data = ExtractStrVector(blob);
94+
std::string res = "";
95+
96+
for(std::string s : data)
97+
{
98+
if (!res.empty())
99+
{
100+
res+= separator;
101+
}
102+
res+= s;
103+
}
104+
res = left_bracket + res + right_bracket;
105+
return res;
106+
}
107+
108+
109+
110+
std::string StampPolyLine3D::ExtractStr(Blob &blob)
111+
{
112+
std::vector<std::string> data = ExtractStrVector(blob);
113+
std::string res = "";
114+
115+
for(std::string s : data)
116+
{
117+
if (!res.empty())
118+
{
119+
res+=", ";
120+
}
121+
res+= s;
122+
}
123+
res = "(" + res + ")";
124+
return res;
125+
}
126+
127+
int main()
128+
{
129+
char data[] = "abcdef" "abcdef" "ABCDEF" "012345";
130+
Blob blob(data, strlen(data));
131+
StampPoint3D stamp;
132+
133+
StampStrEnumerator stamp_e(stamp, " - ", "[", "]");
134+
135+
136+
std::string s = stamp_e.ExtractStr(blob);
137+
std::cout << s <<"\n";
138+
}

test_with_sanitizers.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export LDFLAGS="-fsanitize=address -fsanitize=undefined -fno-sanitize-recover=u
88

99
make clean
1010
make
11-
make test
11+
make test
12+
make examples

0 commit comments

Comments
 (0)