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

Commitcee0bc8

Browse files
Rest object references are moved to std::shared_ptr<>
1 parentbe561c5 commitcee0bc8

File tree

7 files changed

+45
-46
lines changed

7 files changed

+45
-46
lines changed

‎blobstamper/galley.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@
2929
int
3030
GalleyVectorBase::minSize()
3131
{
32-
if (stamp.isFixedSize())
32+
if (stamp->isFixedSize())
3333
{
34-
return stamp.minSize();// When size is fixed, series can have only one member with no extra data used
34+
return stamp->minSize();// When size is fixed, series can have only one member with no extra data used
3535
}
3636
else
3737
{
38-
if (stamp.isUnbounded())
38+
if (stamp->isUnbounded())
3939
{
40-
return stamp.minSize() + ORACLE_SIZE *2;// One -- count oracle, one -- size oracle
40+
return stamp->minSize() + ORACLE_SIZE *2;// One -- count oracle, one -- size oracle
4141
}
4242
else
4343
{
44-
return stamp.minSize() + ORACLE_SIZE;// At leas one element with an oracle
44+
return stamp->minSize() + ORACLE_SIZE;// At leas one element with an oracle
4545
}
4646
}
4747
}
@@ -56,7 +56,8 @@ GalleyVectorStr::ExtractStrVector(std::shared_ptr<Blob> blob)
5656

5757
for(int i =0; i<blobs.size(); i++)
5858
{
59-
res[i] = (dynamic_cast<StampBaseStr &>(stamp)).ExtractStr(blobs[i]);// We know for sure that stamp is StampBaseStr
59+
std::shared_ptr<StampBaseStr> s = std::dynamic_pointer_cast<StampBaseStr>(stamp);
60+
res[i] = s->ExtractStr(blobs[i]);// We know for sure that stamp is StampBaseStr
6061
}
6162
return res;
6263
}
@@ -69,22 +70,22 @@ GalleyVectorBin::ExtractBinVector(std::shared_ptr<Blob> blob)
6970

7071
for(int i =0; i<blobs.size(); i++)
7172
{
72-
res[i] = b_stamp.ExtractBin(blobs[i]);
73+
res[i] = b_stamp->ExtractBin(blobs[i]);
7374
}
7475
return res;
7576
}
7677

7778
std::vector<std::shared_ptr<Blob>>
7879
GalleyVectorBase::extract_internal(std::shared_ptr<Blob> blob)
7980
{
80-
if (blob->Size()<stamp.minSize())
81+
if (blob->Size()<stamp->minSize())
8182
{
8283
throwOutOfData();/* FIXME: May be later add option that allows empty lists if needed*/
8384
}
8485
std::vector<std::shared_ptr<Blob>> res;
85-
if (stamp.isFixedSize())
86+
if (stamp->isFixedSize())
8687
{
87-
int size = stamp.minSize();
88+
int size = stamp->minSize();
8889
while (blob->Size() >= size)
8990
{
9091
std::shared_ptr<Blob> el = blob->Chop(size);
@@ -93,7 +94,7 @@ GalleyVectorBase::extract_internal(std::shared_ptr<Blob> blob)
9394
}
9495
else
9596
{
96-
if (stamp.isUnbounded())
97+
if (stamp->isUnbounded())
9798
{
9899
/*
99100
The idea of this part is following:
@@ -112,7 +113,7 @@ GalleyVectorBase::extract_internal(std::shared_ptr<Blob> blob)
112113
*/
113114

114115
/* Getting count oracle and normalze it to fit available size*/
115-
size_t count_max = (blob->Size() - ORACLE_SIZE) / (stamp.minSize() + ORACLE_SIZE);//First oracle - for number of items, and second one is oracle for each item size
116+
size_t count_max = (blob->Size() - ORACLE_SIZE) / (stamp->minSize() + ORACLE_SIZE);//First oracle - for number of items, and second one is oracle for each item size
116117

117118
ORACLE_STAMP stamp_oracle;
118119
ORACLE_TYPE count_oracle = stamp_oracle.ExtractValue(blob);
@@ -140,14 +141,14 @@ GalleyVectorBase::extract_internal(std::shared_ptr<Blob> blob)
140141

141142
/* Calculating available vairable size, that will be destributed between parts according to size oracles*/
142143
int data_size = blob->Size();
143-
int fixed_data_size = stamp.minSize() * count_target;
144+
int fixed_data_size = stamp->minSize() * count_target;
144145
int var_data_size = data_size - fixed_data_size;
145146

146147
/* normalizing oracles so they fit total variable size, chop to parts and stamp parts*/
147148
floatremainder =0;/* we do not want waste bytes because of rounding, so we keep the remainder, and reuse it. Thus we will use all bytes (alomost, may loose last one due to remainder=0.99999)*/
148149
for(ORACLE_TYPE o : size_oracles)
149150
{
150-
float el_size_f = stamp.minSize() + (float) o / size_oracle_total * var_data_size +remainder;
151+
float el_size_f = stamp->minSize() + (float) o / size_oracle_total * var_data_size +remainder;
151152
int el_size = el_size_f;
152153
remainder = el_size_f - el_size;
153154

@@ -158,12 +159,12 @@ GalleyVectorBase::extract_internal(std::shared_ptr<Blob> blob)
158159
else
159160
{
160161
/* Stamp is variated size*/
161-
int fixed_size = stamp.minSize();
162-
int var_size = stamp.maxSize() - fixed_size;
162+
int fixed_size = stamp->minSize();
163+
int var_size = stamp->maxSize() - fixed_size;
163164
ORACLE_STAMP stamp_oracle;
164165
while(1)
165166
{
166-
if(stamp.minSize() + stamp_oracle.minSize() > blob->Size())
167+
if(stamp->minSize() + stamp_oracle.minSize() > blob->Size())
167168
break;
168169

169170
ORACLE_TYPE oracle = stamp_oracle.ExtractValue(blob);

‎blobstamper/galley.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ class GalleyBase: public virtual StampBase
4343
classGalleyVectorBase :publicGalleyBase
4444
{
4545
protected:
46-
StampBase &stamp;
46+
std::shared_ptr<StampBase>stamp;
4747
public:
48-
GalleyVectorBase(StampBase & stamp_arg) : stamp(stamp_arg) {};
48+
GalleyVectorBase(std::shared_ptr<StampBase> stamp_arg) : stamp(stamp_arg) {};
4949
std::vector<std::shared_ptr<Blob>>extract_internal(std::shared_ptr<Blob> blob);
5050
intminSize()override;
5151
intmaxSize()override {return -1;};/* Sereies always takes as much data as it can take*/
@@ -55,34 +55,32 @@ class GalleyVectorBase : public GalleyBase
5555
classGalleyVectorStr:publicGalleyVectorBase
5656
{
5757
public:
58-
GalleyVectorStr(StampBaseStr & stamp_arg): GalleyVectorBase(stamp_arg) {};
58+
GalleyVectorStr(std::shared_ptr<StampBaseStr> stamp_arg): GalleyVectorBase(stamp_arg) {};
5959
std::vector<std::string>ExtractStrVector(std::shared_ptr<Blob> blob);
6060
};
6161

6262
template<classT>classGalleyVectorStrStampBase:publicGalleyVectorStr,publicStampBaseStr
6363
{
64-
protected:
65-
T * item_stamp_p;
6664
public:
67-
GalleyVectorStrStampBase(): GalleyVectorStr(*(item_stamp_p =new T())) {};
68-
~GalleyVectorStrStampBase() {delete item_stamp_p;};
65+
GalleyVectorStrStampBase(): GalleyVectorStr(std::make_shared<T>()) {};
66+
6967
};
7068

7169

7270
classGalleyVectorBin:publicGalleyVectorBase
7371
{
74-
StampBaseBin & b_stamp;
72+
std::shared_ptr<StampBaseBin> b_stamp;
7573
public:
76-
GalleyVectorBin(StampBaseBin & stamp_arg): GalleyVectorBase(stamp_arg), b_stamp(stamp_arg) {};
74+
GalleyVectorBin(std::shared_ptr<StampBaseBin> stamp_arg): GalleyVectorBase(stamp_arg), b_stamp(stamp_arg) {};
7775
std::vector<std::vector<char>>ExtractBinVector(std::shared_ptr<Blob> blob);
7876
};
7977

8078

8179
template<classT>classGalleyVectorV:publicGalleyVectorBase
8280
{
83-
StampBaseV<T>& v_stamp;
81+
std::shared_ptr<StampBaseV<T>> v_stamp;
8482
public:
85-
GalleyVectorV(StampBaseV<T> & stamp_arg): GalleyVectorBase(stamp_arg), v_stamp(stamp_arg) {};
83+
GalleyVectorV(std::shared_ptr<StampBaseV<T>> stamp_arg): GalleyVectorBase(stamp_arg), v_stamp(stamp_arg) {};
8684
std::vector<T>ExtractValuesVector(std::shared_ptr<Blob> blob);
8785
};
8886

@@ -95,7 +93,7 @@ GalleyVectorV<T>::ExtractValuesVector(std::shared_ptr<Blob> blob)
9593

9694
for(int i=0; i<blobs.size(); i++)
9795
{
98-
res[i] = v_stamp.ExtractValue(blobs[i]);
96+
res[i] = v_stamp->ExtractValue(blobs[i]);
9997
}
10098
return res;
10199
}

‎blobstamper/stamp_enumerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
classStampStrEnumerator:publicGalleyVectorStr,publicStampBaseStr
2929
{
3030
protected:
31-
StampBaseStr & stamp_str;
31+
std::shared_ptr<StampBaseStr> stamp_str;
3232
const std::string separator;
3333
const std::string left_bracket;
3434
const std::string right_bracket;
3535
public:
36-
StampStrEnumerator(StampBaseStr &arg_stamp,
36+
StampStrEnumerator(std::shared_ptr<StampBaseStr>arg_stamp,
3737
const std::string arg_sep,
3838
const std::string arg_l,
3939
const std::string arg_r

‎t/130-stamp_enumerator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ main()
3737
{
3838
TEST_START(1);
3939
{/* 1..1*/
40-
std::shared_ptr<Blob> blob = std::make_shared<Blob>((char *) sample,sizeof(sample));
41-
StampArithm<unsignedchar> base_stamp;
40+
std::shared_ptr<Blob> blob = std::make_shared<Blob>((char *) sample,sizeof(sample));
41+
std::shared_ptr<StampArithm<unsignedchar>> base_stamp = std::make_shared<StampArithm<unsignedchar>>();
4242
StampStrEnumeratorstamp(base_stamp,";","<",">");
4343

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

‎t/300-galley.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ main()
4444
std::string expected2 ="34";
4545
std::string expected3 ="56";
4646

47-
StampTwoChars stamp;
47+
std::shared_ptr<StampTwoChars> stamp = std::make_shared<StampTwoChars>();
4848
GalleyVectorStrgalley(stamp);
49-
std::shared_ptr<Blob> blob = std::make_shared<Blob>(short_sample,strlen(short_sample));
49+
std::shared_ptr<Blob> blob = std::make_shared<Blob>(short_sample,strlen(short_sample));
5050
std::vector<std::string> res = galley.ExtractStrVector(blob);
5151

5252
is(res[0], expected1,"GalleyVector, fixed size string stamp: First element of shifted list is ok");
@@ -64,8 +64,8 @@ main()
6464
std::string expected3 ="(zA, B%, CD, EF, GH, IJ, KL)";
6565
std::string expected4 ="(MN, OP, QR, ST, UV, WX, YZ)";
6666

67-
std::shared_ptr<Blob> blob= std::make_shared<Blob>(longer_sample,strlen(longer_sample));
68-
StampTwoCharsList stamp_charlist;
67+
std::shared_ptr<Blob> blob= std::make_shared<Blob>(longer_sample,strlen(longer_sample));
68+
std::shared_ptr<StampTwoCharsList> stamp_charlist = std::make_shared<StampTwoCharsList>();
6969
GalleyVectorStrgalley(stamp_charlist);
7070

7171
std::vector<std::string> res = galley.ExtractStrVector(blob);
@@ -84,9 +84,9 @@ main()
8484
unsignedshortint expected2 = (unsignedchar)'4' *256 +(unsignedchar)'3';
8585
unsignedshortint expected3 = (unsignedchar)'6' *256 +(unsignedchar)'5';
8686

87-
StampArithm<unsignedshortint> stamp;
87+
std::shared_ptr<StampArithm<unsignedshortint>> stamp = std::make_shared<StampArithm<unsignedshortint>>();
8888
GalleyVectorBingalley(stamp);
89-
std::shared_ptr<Blob> blob = std::make_shared<Blob>(short_sample,strlen(short_sample));
89+
std::shared_ptr<Blob> blob = std::make_shared<Blob>(short_sample,strlen(short_sample));
9090
std::vector<std::vector<char>> res = galley.ExtractBinVector(blob);
9191

9292
std::vector<char> v;
@@ -110,7 +110,7 @@ main()
110110
{/* 14*/
111111

112112
signedint sample[] = {1, -2, -30,40, -55,6};
113-
StampArithm<signedint> stamp;
113+
std::shared_ptr<StampArithm<signedint>> stamp = std::make_shared<StampArithm<signedint>>();
114114
GalleyVectorV<signedint>galley(stamp);
115115
std::shared_ptr<Blob> blob = std::make_shared<Blob>((char*)sample,sizeof(sample));
116116
std::vector<signedint> res = galley.ExtractValuesVector(blob);
@@ -129,8 +129,8 @@ main()
129129
std::string expected3 ="bcde";
130130
std::string expected4 ="ghij";
131131

132-
std::shared_ptr<Blob> blob = std::make_shared<Blob>(sample,strlen(sample));
133-
StampSeveralChars stamp;
132+
std::shared_ptr<Blob> blob = std::make_shared<Blob>(sample,strlen(sample));
133+
std::shared_ptr<StampSeveralChars> stamp = std::make_shared<StampSeveralChars>();
134134
GalleyVectorStrgalley(stamp);
135135

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

‎t/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ build-libtappp:
2121
$(MAKE) -C ../libtappp
2222

2323
%.t:%.cpp$(BLOBSTAMPER_OBJ)
24-
$(CXX)$(CXXFLAGS) -I../libtappp/include -I.. -o$@$<$(BLOBSTAMPER_OBJ) -L../libtappp -ltap++
24+
$(CXX)$(CXXFLAGS) -I../libtappp/include -g -I.. -o$@$<$(BLOBSTAMPER_OBJ) -L../libtappp -ltap++
2525

2626
test: all
2727
@echo run_tests.pl$(TEST_BIN)

‎t/test-chars-stamps.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ StampSeveralChars::ExtractStr(std::shared_ptr<Blob> blob)
7777
classStampTwoCharsList:publicStampBaseStr
7878
{
7979
protected:
80-
StampTwoChars el_stamp;
80+
std::shared_ptr<StampTwoChars> el_stamp;
8181
GalleyVectorStr galley;
8282
public:
8383
std::stringExtractStr(std::shared_ptr<Blob> blob)override;
84-
StampTwoCharsList(): el_stamp {}, galley {el_stamp} {};
84+
StampTwoCharsList(): el_stamp {std::make_shared<StampTwoChars>()}, galley {el_stamp} {};
8585

86-
virtualintminSize()override {return el_stamp.minSize();};
86+
virtualintminSize()override {return el_stamp->minSize();};
8787
virtualintmaxSize()override {return -1;};
8888
};
8989

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp