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

Commit2faa3fa

Browse files
Update examples from README.md to conform current implementation
1 parente5c7019 commit2faa3fa

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

‎README.md

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,9 @@ You can use stamp on a Blob as many times as you like until you are out of Blob
3333
Stamp is a C++ object that "bites" chunk of binary data from Blob and converts it
3434
into certain structured representation (text string with syntax that is provided
3535
by stamp or C-structure)
36-
3736
```
3837
char data[] ="abcdefghijk";
39-
Blob blob(data, strlen(data)); // Blob with "random" data
38+
auto blob = std::make_shared<Blob>(data, strlen(data)); // Blob with "random" data
4039
4140
StampArithm<short int> stamp; // Stamp for getting short integer (both string and value representations)
4241
@@ -110,10 +109,10 @@ Example:
110109

111110
```
112111
char data[] ="abcdefghijk";
113-
Blob blob1(data, strlen(data)); // Blob with "random" data
114-
Blob blob2(data, strlen(data)); // Another Blob with same data
112+
auto blob1 = std::make_shared<Blob>(data, strlen(data)); // Blob with "random" data
113+
auto blob2 = std::make_shared<Blob>(data, strlen(data)); // Another Blob with same data
115114
116-
StampArithm<short int> stamp; // Stamp for short integer data (both string and value)
115+
auto stamp = std::make_shared<StampArithm<short int>>(); // Stamp for short integer data (both string and value)
117116
118117
GalleyVectorStr galley_s(stamp);
119118
GalleyVectorV<short int> galley_v(stamp);
@@ -134,10 +133,10 @@ Example:
134133

135134
```
136135
char data[] ="abcdefghijk";
137-
Blob blob(data, strlen(data)); // Blob with "random" data
136+
auto blob = std::make_shared<Blob>(data, strlen(data)); // Blob with "random" data
138137
139-
StampArithm<short int> stamp_i; // Stamp for short integer data (both string and value)
140-
StampArithm<float> stamp_f; // Stamp for float numeric data (both string and value)
138+
auto stamp_i = std::make_shared<StampArithm<short int>>(); // Stamp for short integer data (both string and value)
139+
auto stamp_f = std::make_shared<StampArithm<float>>(); // Stamp for float numeric data (both string and value)
141140
142141
GalleySetStr galley({stamp_i, stamp_f});
143142
@@ -180,7 +179,7 @@ class ComplexIntStamp: public StampBaseStr
180179
public:
181180
virtual int minSize() override;
182181
virtual int maxSize() override;
183-
virtual std::string ExtractStr(Blob &blob) override;
182+
virtual std::string ExtractStr(std::shared_ptr<Blob>blob) override;
184183
};
185184
```
186185
Actually here we can have one`StampArithm<short int>` stamp, and apply it two times.
@@ -205,7 +204,7 @@ Now we will implement Extract Method.
205204
We just extract two values with`stampA` and`stampB` and combine them into string we want.
206205

207206
```
208-
std::string ComplexIntStamp::ExtractStr(Blob &blob)
207+
std::string ComplexIntStamp::ExtractStr(std::shared_ptr<Blob>blob)
209208
{
210209
std::string A, B;
211210
A = stampA.ExtractStr(blob);
@@ -220,7 +219,7 @@ Now you can use your stamp the way any stamp is used:
220219
int main()
221220
{
222221
char data[] = "abcdef";
223-
Blob blob(data, strlen(data));
222+
auto blob = std::make_shared<Blob>(data, strlen(data));
224223
ComplexIntStamp stamp;
225224
226225
std::string s = stamp.ExtractStr(blob);
@@ -254,7 +253,7 @@ class ComplexIntStamp: public StampBaseV<complex_short>
254253
public:
255254
virtual int minSize() override;
256255
virtual int maxSize() override;
257-
virtual complex_short ExtractValue(Blob &blob) override;
256+
virtual complex_short ExtractValue(std::shared_ptr<Blob>blob) override;
258257
};
259258
```
260259

@@ -277,7 +276,7 @@ In `ExtractValue` method we locally create desired structure, fill it with
277276
values fetched from the Blob, and return the structure by value.
278277

279278
```
280-
complex_short ComplexIntStamp::ExtractValue(Blob &blob)
279+
complex_short ComplexIntStamp::ExtractValue(std::shared_ptr<Blob>blob)
281280
{
282281
complex_short res;
283282
res.re = stampA.ExtractValue(blob);
@@ -292,7 +291,7 @@ Then we can use stamp for extracting `complex_short` directly from the Blob:
292291
int main()
293292
{
294293
char data[] = "abcdef";
295-
Blob blob(data, strlen(data));
294+
auto blob = std::make_shared<Blob>(data, strlen(data));
296295
ComplexIntStamp stamp;
297296
298297
complex_short cs = stamp.ExtractValue(blob);
@@ -310,14 +309,13 @@ To add extract method to Galley you should use multiple inheritance.
310309
```
311310
class ArrayOfComplexIntStamp: public GalleyVectorStr, public StampBaseStr
312311
{
313-
protected:
314-
ComplexIntStamp * item_stamp_p;
315312
public:
316-
ComplexIntArrayStamp(): GalleyVectorStr(*(item_stamp_p = new ComplexIntStamp())) {};
317-
~ComplexIntArrayStamp() {delete item_stamp_p;};
313+
ArrayOfComplexIntStamp(): GalleyVectorStr(std::dynamic_pointer_cast<StampBaseStr>(std::make_shared<ComplexIntStamp>())) {};
318314
319-
virtual std::string ExtractStr(Blob &blob) override;
315+
virtual std::string ExtractStr(std::shared_ptr<Blob>blob) override;
320316
};
317+
318+
321319
```
322320
Because of initialization order issue, we have to initialize the stamp inside the call of parent class constructor via`new` method, and then destroy in in the destructor.
323321

@@ -326,7 +324,7 @@ We implement only the Extract method we need.
326324

327325

328326
```
329-
std::stringComplexIntArrayStamp::ExtractStr(Blob &blob)
327+
std::stringArrayOfComplexIntStamp::ExtractStr(std::shared_ptr<Blob>blob)
330328
{
331329
std::vector<std::string> data = ExtractStrVector(blob);
332330
std::string res = "";
@@ -403,15 +401,14 @@ If you have Stamp with Value Extract Method, and you are going to use `GalleyVec
403401
It would be something like that:
404402

405403
```
406-
ComplexIntStamp stamp;
404+
auto stamp = std::make_shared<ComplexIntStamp>();
407405
GalleyVectorV<complex_short> galley(stamp);
408406
complex_short *result;
409-
int result_size;
410407
std::vector<complex_short> vec = galley.ExtractValuesVector(blob);
411-
result_len = vec.size();
408+
int result_size = vec.size();
412409
413-
result = (complex_short *) malloc(sizeof(complex_short) *result_len));
414-
memcpy((void*) result, (void*) &vec[0], sizeof(complex_short) *result_len);
410+
result = (complex_short *) malloc(sizeof(complex_short) *result_size);
411+
memcpy((void*) result, (void*) &vec[0], sizeof(complex_short) *result_size);
415412
```
416413

417414
##Further reading

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp