diff --git a/blobstamper/blob.cpp b/blobstamper/blob.cpp index 2efd6a0..1e9f9a0 100644 --- a/blobstamper/blob.cpp +++ b/blobstamper/blob.cpp @@ -46,7 +46,7 @@ Blob::Dump() hexdump(data + begin, length); } -Blob +std::shared_ptr Blob::ShiftBytes(size_t n) { if (this->Size() < n) @@ -54,10 +54,10 @@ Blob::ShiftBytes(size_t n) throw OutOfData(); } - Blob new_blob(this->data, size); + std::shared_ptr new_blob = std::make_shared(this->data, size); - new_blob.begin = begin; /* FIXME this should go private once */ - new_blob.end = begin + n - 1; + new_blob->begin = begin; /* FIXME this should go private once */ + new_blob->end = begin + n - 1; begin += n; diff --git a/blobstamper/blob.h b/blobstamper/blob.h index 988a991..6f6534f 100644 --- a/blobstamper/blob.h +++ b/blobstamper/blob.h @@ -22,6 +22,7 @@ #include #include #include +#include class StampBase; @@ -38,7 +39,7 @@ class Blob bool isEmpty (); size_t Size(); void Dump(); - Blob ShiftBytes(size_t n); + std::shared_ptr ShiftBytes(size_t n); std::vector ChopBlank(StampBase &stmp); void DataDup(char *& data_out, size_t& size_out); std::vector asVector(); diff --git a/blobstamper/blobstamper.h b/blobstamper/blobstamper.h index 74e8c07..67dc91b 100644 --- a/blobstamper/blobstamper.h +++ b/blobstamper/blobstamper.h @@ -24,4 +24,5 @@ #include "galley.h" #include "stamp_enumerator.h" #include "stamp_lottery.h" -#include "stamp_math_op.h" \ No newline at end of file +#include "stamp_math_op.h" +#include "stamp_text.h" diff --git a/blobstamper/galley.cpp b/blobstamper/galley.cpp index 97eb6f7..74c71df 100644 --- a/blobstamper/galley.cpp +++ b/blobstamper/galley.cpp @@ -49,9 +49,9 @@ GalleyVectorBase::minSize() std::vector -GalleyVectorStr::ExtractStrVector(Blob &blob) +GalleyVectorStr::ExtractStrVector(std::shared_ptr blob) { - std::vector blobs = extract_internal(blob); + std::vector> blobs = extract_internal(blob); std::vector res(blobs.size()); for(int i = 0; i> -GalleyVectorBin::ExtractBinVector(Blob &blob) +GalleyVectorBin::ExtractBinVector(std::shared_ptr blob) { - std::vector blobs = extract_internal(blob); + std::vector> blobs = extract_internal(blob); std::vector> res(blobs.size()); for(int i = 0; i -GalleyVectorBase::extract_internal(Blob &blob) +std::vector> +GalleyVectorBase::extract_internal(std::shared_ptr blob) { - if (blob.Size()Size() res; + std::vector> res; if (stamp.isFixedSize()) { int size = stamp.minSize(); - while (blob.Size() >= size) + while (blob->Size() >= size) { - Blob el = blob.ShiftBytes(size); + std::shared_ptr el = blob->ShiftBytes(size); res.push_back(el); } } @@ -112,7 +112,7 @@ GalleyVectorBase::extract_internal(Blob &blob) */ /* Getting count oracle and normalze it to fit available size */ - 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 + 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 ORACLE_STAMP stamp_oracle; ORACLE_TYPE count_oracle = stamp_oracle.ExtractValue(blob); @@ -139,7 +139,7 @@ GalleyVectorBase::extract_internal(Blob &blob) } /* Calculating available vairable size, that will be destributed between parts according to size oracles */ - int data_size = blob.Size(); + int data_size = blob->Size(); int fixed_data_size = stamp.minSize() * count_target; int var_data_size = data_size - fixed_data_size; @@ -151,7 +151,7 @@ GalleyVectorBase::extract_internal(Blob &blob) int el_size = el_size_f; remainder = el_size_f - el_size; - Blob blob2 = blob.ShiftBytes(el_size); + std::shared_ptr blob2 = blob->ShiftBytes(el_size); res.push_back(blob2); } } @@ -163,7 +163,7 @@ GalleyVectorBase::extract_internal(Blob &blob) ORACLE_STAMP stamp_oracle; while(1) { - if(stamp.minSize() + stamp_oracle.minSize() > blob.Size()) + if(stamp.minSize() + stamp_oracle.minSize() > blob->Size()) break; ORACLE_TYPE oracle = stamp_oracle.ExtractValue(blob); @@ -171,7 +171,7 @@ GalleyVectorBase::extract_internal(Blob &blob) int size = (double) oracle / ORACLE_MAX * (var_size + 1); /* +1 -- это грубая эмуляция округления вверх. oracle == ORACLE_MAX-1 == 65534 должен дать count_max*/ if (size > var_size) size = var_size; // In case we've hit oracle == ORACLE_MAX boundary size += fixed_size; - Blob blob2 = blob.ShiftBytes(size); + std::shared_ptr blob2 = blob->ShiftBytes(size); res.push_back(blob2); } } @@ -181,10 +181,10 @@ GalleyVectorBase::extract_internal(Blob &blob) /**********************************************/ -std::vector -GalleySetBase::extract_internal(Blob &blob) +std::vector> +GalleySetBase::extract_internal(std::shared_ptr blob) { - std::vector res; + std::vector> res; int fixed_total_size = 0; // Summ of sizes of fixed parts of all stamps int max_varited_total_size = 0; // Summ of sizes of variable parts of variated stamps ORACLE_STAMP oracle_stamp; @@ -225,12 +225,12 @@ GalleySetBase::extract_internal(Blob &blob) This is a variable that will set limits to gariated stamps greed (will be rediced later */ int varited_total_size_limit = max_varited_total_size; - if(fixed_total_size > blob.Size()) /* Not enought data case*/ + if(fixed_total_size > blob->Size()) /* Not enought data case*/ { throw OutOfData(); } - int avaliable_nonfixed_size = blob.Size() - fixed_total_size; /* The ammount of data available for non-fixed part of variated or unbounded stamps*/ + int avaliable_nonfixed_size = blob->Size() - fixed_total_size; /* The ammount of data available for non-fixed part of variated or unbounded stamps*/ if (varited_total_size_limit > avaliable_nonfixed_size) varited_total_size_limit = avaliable_nonfixed_size; /* Can't use more than we have */ @@ -341,19 +341,19 @@ GalleySetBase::extract_internal(Blob &blob) unbounded_remainder = len - el_size; el_size +=s.minSize(); } - Blob blob2 = blob.ShiftBytes(el_size); + std::shared_ptr blob2 = blob->ShiftBytes(el_size); res.push_back(blob2); } return res; } void -GalleySetBase::LoadAll(Blob &blob) +GalleySetBase::LoadAll(std::shared_ptr blob) { - std::vector blobs = extract_internal(blob); + std::vector> blobs = extract_internal(blob); for(int i=0; i blob = blobs[i]; StampBase & stamp = stamps[i]; stamp.Load(blob); } @@ -361,13 +361,13 @@ GalleySetBase::LoadAll(Blob &blob) std::vector -GalleySetStr::ExtractStrSet(Blob &blob) +GalleySetStr::ExtractStrSet(std::shared_ptr blob) { std::vector res; - std::vector blobs = extract_internal(blob); + std::vector> blobs = extract_internal(blob); for(int i=0; i blob = blobs[i]; StampBaseStr & stamp = s_stamps[i]; std::string str = stamp.ExtractStr(blob); res.push_back(str); @@ -376,13 +376,13 @@ GalleySetStr::ExtractStrSet(Blob &blob) } std::vector> -GalleySetBin::ExtractBinSet(Blob &blob) +GalleySetBin::ExtractBinSet(std::shared_ptr blob) { std::vector> res; - std::vector blobs = extract_internal(blob); + std::vector> blobs = extract_internal(blob); for(int i=0; i blob = blobs[i]; StampBaseBin & stamp = b_stamps[i]; std::vector v = stamp.ExtractBin(blob); res.push_back(v); diff --git a/blobstamper/galley.h b/blobstamper/galley.h index 67b6ab9..002ca72 100644 --- a/blobstamper/galley.h +++ b/blobstamper/galley.h @@ -46,7 +46,7 @@ class GalleyVectorBase : public GalleyBase StampBase &stamp; public: GalleyVectorBase(StampBase & stamp_arg) : stamp(stamp_arg) {}; - std::vector extract_internal(Blob &blob); + std::vector> extract_internal(std::shared_ptr blob); int minSize() override; int maxSize() override {return -1;}; /* Sereies always takes as much data as it can take */ }; @@ -56,7 +56,7 @@ class GalleyVectorStr: public GalleyVectorBase { public: GalleyVectorStr(StampBaseStr & stamp_arg): GalleyVectorBase(stamp_arg) {}; - std::vector ExtractStrVector(Blob &blob); + std::vector ExtractStrVector(std::shared_ptr blob); }; template class GalleyVectorStrStampBase: public GalleyVectorStr, public StampBaseStr @@ -74,7 +74,7 @@ class GalleyVectorBin: public GalleyVectorBase StampBaseBin & b_stamp; public: GalleyVectorBin(StampBaseBin & stamp_arg): GalleyVectorBase(stamp_arg), b_stamp(stamp_arg) {}; - std::vector> ExtractBinVector(Blob &blob); + std::vector> ExtractBinVector(std::shared_ptr blob); }; @@ -83,14 +83,14 @@ template class GalleyVectorV: public GalleyVectorBase StampBaseV& v_stamp; public: GalleyVectorV(StampBaseV & stamp_arg): GalleyVectorBase(stamp_arg), v_stamp(stamp_arg) {}; - std::vector ExtractValuesVector(Blob &blob); + std::vector ExtractValuesVector(std::shared_ptr blob); }; template std::vector -GalleyVectorV::ExtractValuesVector(Blob &blob) +GalleyVectorV::ExtractValuesVector(std::shared_ptr blob) { - std::vector blobs = extract_internal(blob); + std::vector> blobs = extract_internal(blob); std::vector res(blobs.size()); for(int i=0; i> stamps; public: GalleySetBase(std::vector> arg) : stamps(arg) {}; - std::vector extract_internal(Blob &blob); - void LoadAll(Blob &blob); + std::vector> extract_internal(std::shared_ptr blob); + void LoadAll(std::shared_ptr blob); int minSize() override; int maxSize() override; @@ -119,7 +119,7 @@ class GalleySetBin : public GalleySetBase std::vector> b_stamps; public: GalleySetBin(std::vector> arg) : GalleySetBase(cast_arg(arg)), b_stamps(arg) {}; - std::vector> ExtractBinSet(Blob &blob); + std::vector> ExtractBinSet(std::shared_ptr blob); std::vector> cast_arg(std::vector> in) { @@ -138,7 +138,7 @@ class GalleySetStr : public GalleySetBase std::vector> s_stamps; public: GalleySetStr(std::vector> arg) : GalleySetBase(cast_arg(arg)), s_stamps(arg) {}; - std::vector ExtractStrSet(Blob &blob); + std::vector ExtractStrSet(std::shared_ptr blob); std::vector> cast_arg(std::vector> in) { diff --git a/blobstamper/stamp.cpp b/blobstamper/stamp.cpp index 20d9cdc..33fb7a1 100644 --- a/blobstamper/stamp.cpp +++ b/blobstamper/stamp.cpp @@ -27,10 +27,10 @@ void -StampBase::Load(Blob &blob) +StampBase::Load(std::shared_ptr blob) { - if (minSize() > blob.Size()) + if (minSize() > blob->Size()) { throw OutOfData(); } @@ -38,13 +38,12 @@ StampBase::Load(Blob &blob) size_t res_size; if (isUnbounded()) { - res_size = blob.Size(); + res_size = blob->Size(); } else { res_size = maxSize(); - if (res_size > blob.Size()) - res_size = blob.Size(); + if (res_size > blob->Size()) + res_size = blob->Size(); } - Blob *pb = new Blob(blob.ShiftBytes(res_size)); - bitten_blob = std::unique_ptr(pb); + bitten_blob = blob->ShiftBytes(res_size); } diff --git a/blobstamper/stamp.h b/blobstamper/stamp.h index 1de717d..b2adeac 100644 --- a/blobstamper/stamp.h +++ b/blobstamper/stamp.h @@ -31,12 +31,12 @@ class StampBase { protected: - std::unique_ptr bitten_blob; + std::shared_ptr bitten_blob; public: virtual int minSize() = 0; virtual int maxSize() = 0; - void Load(Blob &blob); + void Load(std::shared_ptr blob); bool isFixedSize() {return minSize() == maxSize();} bool isVariated() {return ! isFixedSize() && ! isUnbounded();} @@ -47,30 +47,30 @@ class StampBase class StampBaseStr: public virtual StampBase { public: - virtual std::string ExtractStr(Blob &blob) = 0; - std::string UnloadStr() {return ExtractStr(*bitten_blob);}; + virtual std::string ExtractStr(std::shared_ptr blob) = 0; + std::string UnloadStr() {return ExtractStr(bitten_blob);}; }; class StampBaseBin: public virtual StampBase { public: - virtual std::vector ExtractBin(Blob &blob) = 0; - std::vector UnloadBin() {return ExtractBin(*bitten_blob);}; + virtual std::vector ExtractBin(std::shared_ptr blob) = 0; + std::vector UnloadBin() {return ExtractBin(bitten_blob);}; }; template class StampBasePV: public StampBaseBin { public: - virtual sized_ptr ExtractPValue(Blob &blob) = 0;/* Should be defined by derived classes*/ + virtual sized_ptr ExtractPValue(std::shared_ptr blob) = 0;/* Should be defined by derived classes*/ sized_ptr UnloadPValue() {return ExtractPValue(*bitten_blob);}; - virtual std::vector ExtractBin(Blob &blob) override; + virtual std::vector ExtractBin(std::shared_ptr blob) override; }; /* If we have pointer and size, we can represent it std::vector for free */ template std::vector -StampBasePV::ExtractBin(Blob &blob) +StampBasePV::ExtractBin(std::shared_ptr blob) { sized_ptr sp = this->ExtractPValue(blob); T* pval = sp; @@ -82,15 +82,15 @@ template class StampBaseV: public StampBasePV ,public virtual StampBase //FIXME I do not understand why do we need it here, but wihtout it, it does not build { public: - virtual T ExtractValue(Blob &blob) = 0;/* Should be defined by derived classes*/ + virtual T ExtractValue(std::shared_ptr blob) = 0;/* Should be defined by derived classes*/ T UnloadValue() {return ExtractValue(*bitten_blob);}; - virtual std::vector ExtractBin(Blob &blob) override; - virtual sized_ptr ExtractPValue(Blob &blob) override; + virtual std::vector ExtractBin(std::shared_ptr blob) override; + virtual sized_ptr ExtractPValue(std::shared_ptr blob) override; }; template sized_ptr -StampBaseV::ExtractPValue(Blob &blob) +StampBaseV::ExtractPValue(std::shared_ptr blob) { T* p = (T*) malloc(sizeof(T)); *p = ExtractValue(blob); @@ -100,7 +100,7 @@ StampBaseV::ExtractPValue(Blob &blob) /* If we have value, we can represent it as binary */ template std::vector -StampBaseV::ExtractBin(Blob &blob) +StampBaseV::ExtractBin(std::shared_ptr blob) { T value = this->ExtractValue(blob); std::vector v((char *) &value, (char *) &value + sizeof(T)); diff --git a/blobstamper/stamp_arithm.h b/blobstamper/stamp_arithm.h index 03049fb..3b03042 100644 --- a/blobstamper/stamp_arithm.h +++ b/blobstamper/stamp_arithm.h @@ -28,21 +28,21 @@ template class StampArithm: public StampBaseStr, public StampBaseV public: virtual int minSize() override {return sizeof(T);} virtual int maxSize() override {return sizeof(T);} - virtual std::string ExtractStr(Blob &blob) override; - virtual T ExtractValue(Blob &blob) override; + virtual std::string ExtractStr(std::shared_ptr blob) override; + virtual T ExtractValue(std::shared_ptr blob) override; }; template std::string -StampArithm::ExtractStr(Blob &blob) +StampArithm::ExtractStr(std::shared_ptr blob) { T value = this->ExtractValue(blob); return to_string_precise(value); } template T -StampArithm::ExtractValue(Blob &blob) +StampArithm::ExtractValue(std::shared_ptr blob) { - std::vector v = blob.ChopBlank(*this); /* Chop out blank of maxSize */ + std::vector v = blob->ChopBlank(*this); /* Chop out blank of maxSize */ T *pT = (T *) &v[0]; /* And interpret it as value of arithmetic type */ return *pT; } diff --git a/blobstamper/stamp_dict.cpp b/blobstamper/stamp_dict.cpp index fcec9e0..7a0be53 100644 --- a/blobstamper/stamp_dict.cpp +++ b/blobstamper/stamp_dict.cpp @@ -44,7 +44,7 @@ StampDict::ChooseStampSize(std::shared_ptr dict) } std::string -StampDict::ExtractStr(Blob &blob) +StampDict::ExtractStr(std::shared_ptr blob) { unsigned long long index_oracle; diff --git a/blobstamper/stamp_dict.h b/blobstamper/stamp_dict.h index f4b80d8..2971362 100644 --- a/blobstamper/stamp_dict.h +++ b/blobstamper/stamp_dict.h @@ -42,7 +42,7 @@ class StampDict: public StampBaseStr public: StampDict(std::shared_ptr dict_arg) : dict(dict_arg), stamp_size(ChooseStampSize(dict_arg)) {}; - std::string ExtractStr(Blob &blob) override; + std::string ExtractStr(std::shared_ptr blob) override; int minSize() override {return stamp_size;} int maxSize() override {return stamp_size;} }; diff --git a/blobstamper/stamp_enumerator.cpp b/blobstamper/stamp_enumerator.cpp index d6eaf46..9419dd1 100644 --- a/blobstamper/stamp_enumerator.cpp +++ b/blobstamper/stamp_enumerator.cpp @@ -24,7 +24,7 @@ -std::string StampStrEnumerator::ExtractStr(Blob &blob) +std::string StampStrEnumerator::ExtractStr(std::shared_ptr blob) { std::vector data = ExtractStrVector(blob); std::string res = ""; diff --git a/blobstamper/stamp_enumerator.h b/blobstamper/stamp_enumerator.h index 32f2204..5ab73f1 100644 --- a/blobstamper/stamp_enumerator.h +++ b/blobstamper/stamp_enumerator.h @@ -44,7 +44,7 @@ class StampStrEnumerator: public GalleyVectorStr, public StampBaseStr right_bracket(arg_r), GalleyVectorStr(arg_stamp) {}; - virtual std::string ExtractStr(Blob &blob) override; + virtual std::string ExtractStr(std::shared_ptr blob) override; }; diff --git a/blobstamper/stamp_lottery.h b/blobstamper/stamp_lottery.h index debcc3b..f315994 100644 --- a/blobstamper/stamp_lottery.h +++ b/blobstamper/stamp_lottery.h @@ -43,7 +43,7 @@ template class StampLottery: public StampT virtual bool soft_maxsize_filter(StampT &stamp, int data_size) {return true;}; /* Allow to skip stamps that would leave to much data unused. But not active here*/ - virtual std::string ExtractStr(Blob &blob) override; + virtual std::string ExtractStr(std::shared_ptr blob) override; void Append(StampT & stamp); }; @@ -137,7 +137,7 @@ StampLottery::maxSize() template std::string -StampLottery::ExtractStr(Blob &blob) +StampLottery::ExtractStr(std::shared_ptr blob) { unsigned long oracle; unsigned long oracle_max; @@ -180,9 +180,9 @@ StampLottery::ExtractStr(Blob &blob) std::ref_vector actual_stamps; for(StampT & stamp : stamps) { - if(blob.Size() < stamp.minSize()) // Skip all stamps that dose not fit + if(blob->Size() < stamp.minSize()) // Skip all stamps that dose not fit continue; - if (soft_maxsize_filter(stamp, blob.Size())) + if (soft_maxsize_filter(stamp, blob->Size())) actual_stamps.push_back(stamp); } if (actual_stamps.empty()) @@ -190,7 +190,7 @@ StampLottery::ExtractStr(Blob &blob) // Add just everything that fits for(StampT & stamp : stamps) { - if(blob.Size() < stamp.minSize()) // Skip all stamps that dose not fit + if(blob->Size() < stamp.minSize()) // Skip all stamps that dose not fit continue; actual_stamps.push_back(stamp); } diff --git a/blobstamper/stamp_math_op.cpp b/blobstamper/stamp_math_op.cpp index 04ea7df..de102ef 100644 --- a/blobstamper/stamp_math_op.cpp +++ b/blobstamper/stamp_math_op.cpp @@ -20,16 +20,16 @@ #include"stamp_math_op.h" std::string -StampMathUnaryOp::ExtractStr(Blob &blob) +StampMathUnaryOp::ExtractStr(std::shared_ptr blob) { return op_name + "(" + stamp.ExtractStr(blob) + ")"; } std::string -StampMathBinaryOp::ExtractStr(Blob &blob) +StampMathBinaryOp::ExtractStr(std::shared_ptr blob) { - std::vector blobs = extract_internal(blob); + std::vector> blobs = extract_internal(blob); return (std::string)"(" + stamp1.ExtractStr(blobs[0]) + " "+ op_name + " " + stamp2.ExtractStr(blobs[1]) + ")"; } diff --git a/blobstamper/stamp_math_op.h b/blobstamper/stamp_math_op.h index d8645d3..3b14ba8 100644 --- a/blobstamper/stamp_math_op.h +++ b/blobstamper/stamp_math_op.h @@ -30,7 +30,7 @@ class StampMathUnaryOp: public StampBaseStr std::string op_name; StampBaseStr &stamp; public: - virtual std::string ExtractStr(Blob &blob) override; + virtual std::string ExtractStr(std::shared_ptr blob) override; StampMathUnaryOp(std::string arg_op_name, StampBaseStr& arg_stamp) : op_name(arg_op_name), stamp(arg_stamp) {}; virtual int maxSize() override {return -1;}; virtual int minSize() override {return stamp.minSize();}; @@ -45,7 +45,7 @@ class StampMathBinaryOp: public StampBaseStr, public GalleySetBase StampBaseStr &stamp1; StampBaseStr &stamp2; public: - virtual std::string ExtractStr(Blob &blob) override; + virtual std::string ExtractStr(std::shared_ptr blob) override; StampMathBinaryOp(std::string arg_op_name, StampBaseStr& arg_stamp1, StampBaseStr& arg_stamp2) : GalleySetBase({arg_stamp1, arg_stamp2}), op_name(arg_op_name), diff --git a/blobstamper/stamp_text.cpp b/blobstamper/stamp_text.cpp index a7c1890..8ab2e3c 100644 --- a/blobstamper/stamp_text.cpp +++ b/blobstamper/stamp_text.cpp @@ -19,10 +19,10 @@ #include"stamp_text.h" std::string -StampTextPulp::ExtractStr(Blob &blob) +StampTextPulp::ExtractStr(std::shared_ptr blob) { - std::vector data = blob.ChopBlank(*this); + std::vector data = blob->ChopBlank(*this); std::vector::iterator the_iterator; @@ -37,7 +37,7 @@ StampTextPulp::ExtractStr(Blob &blob) return res; } -std::string StampTextPulpWords::ExtractStr(Blob &blob) +std::string StampTextPulpWords::ExtractStr(std::shared_ptr blob) { std::vector data = ExtractStrVector(blob); std::string res = ""; @@ -53,7 +53,7 @@ std::string StampTextPulpWords::ExtractStr(Blob &blob) return res; } -std::string StampTextDictWords::ExtractStr(Blob &blob) +std::string StampTextDictWords::ExtractStr(std::shared_ptr blob) { std::vector data = ExtractStrVector(blob); std::string res = ""; diff --git a/blobstamper/stamp_text.h b/blobstamper/stamp_text.h index 7651fb8..3b5c7fa 100644 --- a/blobstamper/stamp_text.h +++ b/blobstamper/stamp_text.h @@ -29,19 +29,19 @@ class StampTextPulp: public StampBaseStr public: virtual int minSize() override {return 1;} virtual int maxSize() override {return -1;} - std::string ExtractStr(Blob &blob) override; + std::string ExtractStr(std::shared_ptr blob) override; }; class StampTextPulpWords: public GalleyVectorStrStampBase { public: - virtual std::string ExtractStr(Blob &blob) override; + virtual std::string ExtractStr(std::shared_ptr blob) override; }; class StampTextDictWords: public GalleyVectorStrStampBase { public: - virtual std::string ExtractStr(Blob &blob) override; + virtual std::string ExtractStr(std::shared_ptr blob) override; }; #endif /* STAMP_TEXT_H */ diff --git a/t/001-blob-generic.cpp b/t/001-blob-generic.cpp index cf6365f..9d1a170 100644 --- a/t/001-blob-generic.cpp +++ b/t/001-blob-generic.cpp @@ -55,25 +55,25 @@ main() char expected1[]="456"; char expected2[]="123"; - Blob blob1(short_sample,strlen(short_sample)); - Blob blob2 = blob1.ShiftBytes(3); + std::shared_ptr blob1 = std::make_shared(short_sample,strlen(short_sample)); + std::shared_ptr blob2 = blob1->ShiftBytes(3); - blob1.DataDup(ptr,size); + blob1->DataDup(ptr,size); ok(size == strlen(expected1), "Blob shifted data size ok"); ok(! memcmp(expected1, ptr, size), "Blob shifted data ok"); free(ptr); - blob2.DataDup(ptr,size); + blob2->DataDup(ptr,size); ok(size == strlen(expected2), "Blob remained data size ok"); ok(! memcmp(expected2, ptr, size), "Blob remained data ok"); free(ptr); } { /* 7 */ /* Check that shifting too many bytes return empty result */ - Blob blob(my_data, strlen(my_data)); + std::shared_ptr blob = std::make_shared(my_data, strlen(my_data)); try { - Blob blob_res = blob.ShiftBytes(99999); + std::shared_ptr blob_res = blob->ShiftBytes(99999); ok(false, "Shift too many bytes"); } catch (OutOfData) diff --git a/t/100-stamp-base.cpp b/t/100-stamp-base.cpp index 85f5ff6..d908190 100644 --- a/t/100-stamp-base.cpp +++ b/t/100-stamp-base.cpp @@ -54,12 +54,12 @@ main() char expected2[] = "34567"; - Blob blob(short_sample, strlen(short_sample)); + std::shared_ptr blob = std::make_shared(short_sample, strlen(short_sample)); StampTwoChars stamp; std::string str = stamp.ExtractStr(blob); is(str, expected1, "ShiftSingleStampStr: shifts ok"); - blob.DataDup(ptr,size); + blob->DataDup(ptr,size); ok(size == strlen(expected2), "ShiftSingleStampStr: Remaining blob data size ok"); ok(! memcmp(expected2, ptr, size), "ShiftSingleStampStr: Remaining blob data ok"); free(ptr); @@ -69,7 +69,7 @@ main() { /* 4 */ char sample_two_bytes[]="12"; std::string expected1 = "12"; - Blob blob(sample_two_bytes, strlen(sample_two_bytes)); + std::shared_ptr blob = std::make_shared(sample_two_bytes, strlen(sample_two_bytes)); StampTwoChars stamp; std::string str = stamp.ExtractStr(blob); is(str, expected1, "ShiftSingleStampStr: shifts first two bytes ok"); @@ -78,7 +78,7 @@ main() { /* 5,6 */ char sample[]="1234567890"; - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampSeveralChars stamp; /* accepts from 2 to 8 bytes*/ /* If used alone, is shifts as much bytes as it can. When blob has a lot, it shifts maxSize bytes */ @@ -92,7 +92,7 @@ main() { /* 7,8 */ char sample[]="123456789"; - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampSeveralChars stamp; /* accepts from 2 to 8 bytes*/ /* If used alone, is shifts as much bytes as it can. When blob has a lot, it shifts maxSize bytes */ @@ -116,7 +116,7 @@ main() { /* 9 */ char sample[]="1"; - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampTwoChars stamp; try { std::string str = stamp.ExtractStr(blob); @@ -134,7 +134,7 @@ main() { /* 10 */ char sample[]="1"; - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampTwoCharsList stamp; try { std::string str = stamp.ExtractStr(blob); diff --git a/t/110-stamp-arithm.cpp b/t/110-stamp-arithm.cpp index c91b0cd..a6eaa0e 100644 --- a/t/110-stamp-arithm.cpp +++ b/t/110-stamp-arithm.cpp @@ -52,7 +52,7 @@ main() /* Check that Bin and Str Char stamps works well */ { /* 1..4 */ - Blob blob(sample_data_char, strlen(sample_data_char)); + std::shared_ptr blob = std::make_shared(sample_data_char, strlen(sample_data_char)); StampArithm stamp; std::vector v = stamp.ExtractBin(blob); @@ -74,7 +74,7 @@ main() /* Check that Bin and Srt Int16 stamps works well */ { /* 5..11 */ - Blob blob((char *)sample_data_int16, sample_data_int16_size); + std::shared_ptr blob = std::make_shared((char *)sample_data_int16, sample_data_int16_size); StampArithm stamp; std::vector v = stamp.ExtractBin(blob); short int * pi = (short int *) &v[0]; @@ -105,7 +105,7 @@ main() /* Check that Bin and Srt Int32 stamps works well */ { /* 12..18 */ - Blob blob((char *)sample_data_int32, sample_data_int32_size); + std::shared_ptr blob = std::make_shared((char *)sample_data_int32, sample_data_int32_size); StampArithm stamp; std::vector v = stamp.ExtractBin(blob); @@ -139,7 +139,7 @@ main() /* Check that Bin and Srt Int64 stamps works well */ { /* 19..25 */ - Blob blob((char *)sample_data_int64, sample_data_int64_size); + std::shared_ptr blob = std::make_shared((char *)sample_data_int64, sample_data_int64_size); StampArithm stamp; std::vector v = stamp.ExtractBin(blob); @@ -173,7 +173,7 @@ main() /* Test Double stamp */ { /* 26..29 */ - Blob blob((char *)sample_data_double, sample_data_double_size); + std::shared_ptr blob = std::make_shared((char *)sample_data_double, sample_data_double_size); StampArithm stamp; std::vector v = stamp.ExtractBin(blob); double *pd = (double *) &v[0]; diff --git a/t/120-stamp_dict.cpp b/t/120-stamp_dict.cpp index 670b64c..176d8df 100644 --- a/t/120-stamp_dict.cpp +++ b/t/120-stamp_dict.cpp @@ -50,7 +50,7 @@ main() { /* 1..4 */ auto dict = std::make_shared(); StampDict stamp(dict); - Blob blob((char *) sample, 4); + std::shared_ptr blob = std::make_shared((char *) sample, 4); std::string s; s = stamp.ExtractStr(blob); diff --git a/t/130-stamp_enumerator.cpp b/t/130-stamp_enumerator.cpp index dfe1fb7..8349365 100644 --- a/t/130-stamp_enumerator.cpp +++ b/t/130-stamp_enumerator.cpp @@ -37,7 +37,7 @@ main() { TEST_START(1); { /* 1..1 */ - Blob blob((char *) sample, sizeof(sample)); + std::shared_ptr blob = std::make_shared((char *) sample, sizeof(sample)); StampArithm base_stamp; StampStrEnumerator stamp(base_stamp, "; ", "<", ">"); diff --git a/t/140-stamp_lottery.cpp b/t/140-stamp_lottery.cpp index c264f80..d550ae5 100644 --- a/t/140-stamp_lottery.cpp +++ b/t/140-stamp_lottery.cpp @@ -41,7 +41,7 @@ main() /* Tests for common Stamp Lottery*/ { /* 1..5 */ - Blob blob((char *) sample, sizeof(sample)); + std::shared_ptr blob = std::make_shared((char *) sample, sizeof(sample)); StampArithm stamp_s; StampArithm stamp_c; StampArithm stamp_i; @@ -64,7 +64,7 @@ main() { /* 6 */ sample[0] = 255; /* Should choose last stamp*/ - Blob blob((char *) sample, sizeof(sample)); + std::shared_ptr blob = std::make_shared((char *) sample, sizeof(sample)); StampArithm stamp_s; StampArithm stamp_c; StampArithm stamp_i; @@ -77,7 +77,7 @@ main() { /* 7 */ sample[0] = 128; /* Should choose stamp in the middle */ - Blob blob((char *) sample, sizeof(sample)); + std::shared_ptr blob = std::make_shared((char *) sample, sizeof(sample)); StampArithm stamp_s; StampArithm stamp_c; StampArithm stamp_i; @@ -90,7 +90,7 @@ main() { /* 8 */ sample[0] = 1; /* Should choose first available stamp*/ - Blob blob((char *) sample, 2); /* Sic! */ + std::shared_ptr blob = std::make_shared((char *) sample, 2); /* Sic! */ StampArithm stamp_s; StampArithm stamp_c; StampArithm stamp_l; @@ -106,7 +106,7 @@ main() { /* 9 */ sample2[0] = 1; /* Should choose first available stamp*/ - Blob blob((char *) sample2, sizeof(sample2)); + std::shared_ptr blob = std::make_shared((char *) sample2, sizeof(sample2)); StampArithm stamp_s; StampArithm stamp_c; StampArithm stamp_l; @@ -119,7 +119,7 @@ main() { /* 10 */ sample2[0] = 255; /* Should choose last available stamp*/ - Blob blob((char *) sample2, sizeof(sample2) -1 ); /*One byte short for unsigned long*/ + std::shared_ptr blob = std::make_shared((char *) sample2, sizeof(sample2) -1 ); /*One byte short for unsigned long*/ StampArithm stamp_s; StampArithm stamp_c; StampArithm stamp_l; diff --git a/t/150-stamp_text.cpp b/t/150-stamp_text.cpp index 53cadc9..9bd2165 100644 --- a/t/150-stamp_text.cpp +++ b/t/150-stamp_text.cpp @@ -34,7 +34,7 @@ main() TEST_START(3); { /* 1..1 */ char data[] = "папа\0мама\0бабушка\0дедушка\0братик\0сестричка"; - Blob blob(data, (sizeof data)-1); + std::shared_ptr blob = std::make_shared(data, (sizeof data)-1); StampTextPulp stamp; std::string s = stamp.ExtractStr(blob); is(s, "папа мама бабушка дедушка братик сестричка", "StampTextSimple"); @@ -42,7 +42,7 @@ main() } { /* 2..2 */ char data[] = "dad\0mam\0granddad\0grandmam\0brother\0sister"; - Blob blob(data, (sizeof data)-1); + std::shared_ptr blob = std::make_shared(data, (sizeof data)-1); StampTextPulpWords stamp; std::string s = stamp.ExtractStr(blob); is(s, "d dad gra n dmam broth er siste", "GalleyTextSimple"); @@ -50,7 +50,7 @@ main() } { /* 3..3 */ char data[] = "abcdef" "abcdef" "ABCDEF" "012345"; - Blob blob(data, (sizeof data)-1); + std::shared_ptr blob = std::make_shared(data, (sizeof data)-1); StampTextDictWords stamp; std::string s = stamp.ExtractStr(blob); is(s, "gleam godfather graffiti greened grouping gunshots gleam godfather graffiti greened grouping gunshots dismally dissented divested doorstep dread drunks convertors corpulent counterparts cranking crippled crusades", "GalleyLCAlphaSmall"); diff --git a/t/300-galley.cpp b/t/300-galley.cpp index 8ab91a4..ecabb4d 100644 --- a/t/300-galley.cpp +++ b/t/300-galley.cpp @@ -46,7 +46,7 @@ main() StampTwoChars stamp; GalleyVectorStr galley(stamp); - Blob blob(short_sample, strlen(short_sample)); + std::shared_ptr blob = std::make_shared(short_sample, strlen(short_sample)); std::vector res = galley.ExtractStrVector(blob); is(res[0], expected1, "GalleyVector, fixed size string stamp: First element of shifted list is ok"); @@ -64,7 +64,7 @@ main() std::string expected3 = "(zA, B%, CD, EF, GH, IJ, KL)"; std::string expected4 = "(MN, OP, QR, ST, UV, WX, YZ)"; - Blob blob(longer_sample, strlen(longer_sample)); + std::shared_ptr blob= std::make_shared(longer_sample, strlen(longer_sample)); StampTwoCharsList stamp_charlist; GalleyVectorStr galley(stamp_charlist); @@ -86,7 +86,7 @@ main() StampArithm stamp; GalleyVectorBin galley(stamp); - Blob blob(short_sample, strlen(short_sample)); + std::shared_ptr blob = std::make_shared(short_sample, strlen(short_sample)); std::vector> res = galley.ExtractBinVector(blob); std::vector v; @@ -112,7 +112,7 @@ main() signed int sample[] = {1, -2, -30, 40, -55, 6}; StampArithm stamp; GalleyVectorV galley(stamp); - Blob blob((char*)sample, sizeof(sample)); + std::shared_ptr blob = std::make_shared((char*)sample, sizeof(sample)); std::vector res = galley.ExtractValuesVector(blob); ok(!memcmp((void*) &sample, (void *) &res[0], sizeof(sample)), "GalleyVectorV returns ok"); } @@ -129,7 +129,7 @@ main() std::string expected3 = "bcde"; std::string expected4 = "ghij"; - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampSeveralChars stamp; GalleyVectorStr galley(stamp); @@ -154,7 +154,7 @@ main() std::string expected2 = "23"; - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampTwoChars stamp; std::vector> stamps; @@ -173,7 +173,7 @@ main() is(res.size(), 2, "GalleySet, fixed size string stamps: The vector has only two elements "); - is(blob.Size(), strlen(sample) - res[0].length() - res[1].length(), "GalleySet: shifts no extra bytes for fixed stamps"); + is(blob->Size(), strlen(sample) - res[0].length() - res[1].length(), "GalleySet: shifts no extra bytes for fixed stamps"); is(galley.minSize(), stamp.minSize()*2, "GalleySet, fixed size string stamps: galley min size is ok"); is(galley.maxSize(), stamp.maxSize()*2, "GalleySet, fixed size string stamps: galley max size is ok"); @@ -187,7 +187,7 @@ main() std::string expected1 = "456"; std::string expected2 = "7*8"; - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampSeveralChars stamp; std::vector> stamps; @@ -207,7 +207,7 @@ main() is(res.size(), 2, "GalleySet, variated size string stamp: The vector has only two elements "); - is(blob.Size(), strlen(sample) - res[0].length() - res[1].length() - ORACLE_SIZE*2, "GalleySet: shifts one oracle for each variated stamps"); + is(blob->Size(), strlen(sample) - res[0].length() - res[1].length() - ORACLE_SIZE*2, "GalleySet: shifts one oracle for each variated stamps"); is(galley.minSize(), stamp.minSize()*2 + ORACLE_SIZE * 2, "GalleySet, variated size string stamps: galley min size is ok"); is(galley.maxSize(), stamp.maxSize()*2 + ORACLE_SIZE * 2, "GalleySet, variated size string stamps: galley max size is ok"); @@ -221,7 +221,7 @@ main() std::string expected1 = "(45, 67, *8, 9a, bc)"; std::string expected2 = "(de, &f, gh, ij, kl)"; - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampTwoCharsList stamp; std::vector> stamps; @@ -239,7 +239,7 @@ main() is(res.size(), 2, "GalleySet, unbounded size string stamp: The vector has only two elements "); - is(blob.Size(), 0 , "GalleySet: will use all data for unbounded stamp"); + is(blob->Size(), 0 , "GalleySet: will use all data for unbounded stamp"); is(galley.minSize(), stamp.minSize()*2 + ORACLE_SIZE * 2, "GalleySet, unbounded size string stamps: galley min size is ok"); is(galley.maxSize(), -1, "GalleySet, unbounded size string stamps: galley max size is ok"); @@ -258,7 +258,7 @@ main() std::string expected5 = "(CD, EF, GH, IJ, KL, MN, OP, QR, ST, UV, WX)"; //second u_stamp std::string expected6 = "Z!"; //second f_stamp - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampTwoChars f_stamp; @@ -298,7 +298,7 @@ main() is(res.size(), 6, "GalleySet, mixed type stamps: The vector has only six elements "); - is(blob.Size(), 0 , "GalleySet: will use all data if we have at least one unbounded stamp"); + is(blob->Size(), 0 , "GalleySet: will use all data if we have at least one unbounded stamp"); is(galley.minSize(), (f_stamp.minSize()+v_stamp.minSize()+u_stamp.minSize())*2 + ORACLE_SIZE * (2+2+1), "GalleySet, mixed types stamps: galley min size is ok"); is(galley.maxSize(), -1, "GalleySet, mixed types stamps: galley max size is ok"); @@ -313,7 +313,7 @@ main() std::string expected2 = "(23, 45, 67, *8, 9a, bc, de, &f, gh, ij, kl, mn, op, qr, st, uv, wx, yz, AB, %C, DE, FG, HI, JK, LM, NO, PQ, RS, TU, VW, XY)"; // u_stamp std::string expected3 = "Z!"; // second f_stamp - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampTwoChars f_stamp; @@ -340,7 +340,7 @@ main() is(res.size(), 3, "GalleySet, mixed type stamps 2: The vector has only three elements "); - is(blob.Size(), 0 , "GalleySet 2: will use all data if we have at least one unbounded stamp"); + is(blob->Size(), 0 , "GalleySet 2: will use all data if we have at least one unbounded stamp"); is(galley.minSize(), f_stamp.minSize()*2 + u_stamp.minSize() , "GalleySet 2, mixed types stamps: galley min size is ok"); is(galley.maxSize(), -1, "GalleySet, mixed types stamps 2: galley max size is ok"); @@ -358,7 +358,7 @@ main() std::string expected5 = "(89)"; //second u_stamp std::string expected6 = "ab"; //second f_stamp - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampTwoChars f_stamp; StampSeveralChars v_stamp; @@ -397,7 +397,7 @@ main() is(res.size(), 6, "GalleySet, mixed type stamps 3: The vector has only six elements "); - is(blob.Size(), 0 , "GalleySet 3: will use all data if we have at least one unbounded stamp"); + is(blob->Size(), 0 , "GalleySet 3: will use all data if we have at least one unbounded stamp"); is(galley.minSize(), (f_stamp.minSize()+v_stamp.minSize()+u_stamp.minSize())*2 + ORACLE_SIZE * (2+2+1), "GalleySet, mixed types stamps 3: galley min size is ok"); is(galley.maxSize(), -1, "GalleySet, mixed types stamps 3: galley max size is ok"); @@ -408,7 +408,7 @@ main() char sample[] = "oo" "oo" "oo" "oo" "oo" "z1" "23" "45" "67" "89" "a"; - Blob blob(sample, strlen(sample)); + std::shared_ptr blob = std::make_shared(sample, strlen(sample)); StampTwoChars f_stamp; StampSeveralChars v_stamp; @@ -436,7 +436,7 @@ main() ok(false, "GalleySet, not enough data"); } - is(blob.Size(), strlen(sample) , "GalleySet 4: will use keep all data when applying galley fails"); + is(blob->Size(), strlen(sample) , "GalleySet 4: will use keep all data when applying galley fails"); is(galley.minSize(), (f_stamp.minSize()+v_stamp.minSize()+u_stamp.minSize())*2 + ORACLE_SIZE * (2+2+1), "GalleySet, mixed types stamps 4: galley min size is ok"); is(galley.maxSize(), -1, "GalleySet, mixed types stamps 4: galley max size is ok"); diff --git a/t/320-galley-recursion-experiments.cpp b/t/320-galley-recursion-experiments.cpp index 502d5e9..1a1286c 100644 --- a/t/320-galley-recursion-experiments.cpp +++ b/t/320-galley-recursion-experiments.cpp @@ -198,7 +198,7 @@ class SimpeRecursionNode: public StampBase, public Variants public: GalleySimpleRecusion * recursor; - virtual std::string do_recursion(Blob &blob) = 0; + virtual std::string do_recursion(std::shared_ptr blob) = 0; virtual std::string tmpID() = 0; }; @@ -206,7 +206,7 @@ class TestRNode1: public SimpeRecursionNode { std::vector operations = {"+","-","*","/","^"} ; public: - virtual std::string do_recursion(Blob &blob) override; + virtual std::string do_recursion(std::shared_ptr blob) override; int minSize() override {return 1; }; // FIXME correct it int maxSize() override {return -1;}; /* Sereies always takes as much data as it can take */ @@ -218,7 +218,7 @@ class TestRNode1: public SimpeRecursionNode class TestRNode2: public SimpeRecursionNode { public: - virtual std::string do_recursion(Blob &blob) override; + virtual std::string do_recursion(std::shared_ptr blob) override; int minSize() override {return 1; }; // FIXME correct it int maxSize() override {return -1;}; /* Sereies always takes as much data as it can take */ @@ -227,7 +227,7 @@ class TestRNode2: public SimpeRecursionNode class TestRNode3: public SimpeRecursionNode { public: - virtual std::string do_recursion(Blob &blob) override; + virtual std::string do_recursion(std::shared_ptr blob) override; int minSize() override {return 1; }; // FIXME correct it int maxSize() override {return -1;}; /* Sereies always takes as much data as it can take */ @@ -247,7 +247,7 @@ class GalleySimpleRecusion : public GalleyBase int maxSize() override {return -1;}; /* Sereies always takes as much data as it can take */ - virtual std::string do_recursion(Blob &blob); + virtual std::string do_recursion(std::shared_ptr blob); }; @@ -255,7 +255,7 @@ class GalleySimpleRecusion : public GalleyBase std::string -TestRNode1::do_recursion(Blob &blob) +TestRNode1::do_recursion(std::shared_ptr blob) { int variant_n = GetVariantSelected(); /* Copy it as early as possible as it can be overwritten while recursion */ @@ -265,7 +265,7 @@ TestRNode1::do_recursion(Blob &blob) unsigned short int spl_val; - if (blob.Size() < (stamp_sint.minSize() + 4* stamp_char.minSize()) ) + if (blob->Size() < (stamp_sint.minSize() + 4* stamp_char.minSize()) ) { try{ std::string val = stamp_char.ExtractStr(blob); @@ -273,7 +273,7 @@ TestRNode1::do_recursion(Blob &blob) } catch (OutOfData) { -printf("___________________________ %i\n", blob.Size()); +printf("___________________________ %i\n", blob->Size()); return "Q"; } @@ -288,11 +288,11 @@ printf("___________________________ %i\n", blob.Size()); } std::vector split_data_in = {spl_val, (unsigned short int) std::numeric_limits::max() - spl_val }; - std::vector split_data = fit_sizes(split_data_in, blob.Size() - 4* stamp_char.minSize()); + std::vector split_data = fit_sizes(split_data_in, blob->Size() - 4* stamp_char.minSize()); printf("llll - %i %i \n", split_data[0], split_data[1]); - Blob blob_left = blob.ShiftBytes(split_data[0]+ 2*stamp_char.minSize() ); + std::shared_ptr blob_left = blob->ShiftBytes(split_data[0]+ 2*stamp_char.minSize() ); printf("~~~ %i\n",variant_n); @@ -300,10 +300,10 @@ printf("~~~ %i\n",variant_n); } std::string -TestRNode2::do_recursion(Blob &blob) +TestRNode2::do_recursion(std::shared_ptr blob) { try{ - Blob tmp = blob.ShiftBytes(1); + std::shared_ptr tmp = blob->ShiftBytes(1); } catch (OutOfData) { @@ -315,10 +315,10 @@ TestRNode2::do_recursion(Blob &blob) std::string -TestRNode3::do_recursion(Blob &blob) +TestRNode3::do_recursion(std::shared_ptr blob) { try{ - Blob tmp = blob.ShiftBytes(1); + std::shared_ptr tmp = blob->ShiftBytes(1); } catch (OutOfData) { @@ -329,7 +329,7 @@ TestRNode3::do_recursion(Blob &blob) } std::string -GalleySimpleRecusion::do_recursion(Blob& blob) +GalleySimpleRecusion::do_recursion(std::shared_ptr blob) { @@ -411,7 +411,7 @@ main() TEST_START(1); { // Blob blob(short_sample, strlen(short_sample)); - Blob blob((char *)bin_sample, strlen((char *)bin_sample)); + std::shared_ptr blob = std::make_shared((char *)bin_sample, strlen((char *)bin_sample)); GalleySimpleRecusion galley; fprintf(stderr,"--1\n"); diff --git a/t/test-chars-stamps.h b/t/test-chars-stamps.h index f8e7224..3e3ec5c 100644 --- a/t/test-chars-stamps.h +++ b/t/test-chars-stamps.h @@ -22,17 +22,17 @@ class StampTwoChars: public StampBaseStr { public: - std::string ExtractStr(Blob &blob) override; + std::string ExtractStr(std::shared_ptr blob) override; virtual int minSize() override {return 2;} /* This stamp shifts two characters only */ virtual int maxSize() override {return 2;} /* This stamp shifts two characters only */ }; std::string -StampTwoChars::ExtractStr(Blob &blob) +StampTwoChars::ExtractStr(std::shared_ptr blob) { /* Chopping suitable data chunk from blob */ - std::vector data = blob.ChopBlank(*this); + std::vector data = blob->ChopBlank(*this); size_t buf_size = data.size() + 1; char * buf = (char *) malloc(buf_size); @@ -53,14 +53,14 @@ class StampSeveralChars: public StampBaseStr public: virtual int minSize() override {return 2;} /* Minimal size of consumed data */ virtual int maxSize() override {return 8;} /* Maximal size of consumed data */ - std::string ExtractStr(Blob &blob) override; + std::string ExtractStr(std::shared_ptr blob) override; }; std::string -StampSeveralChars::ExtractStr(Blob &blob) +StampSeveralChars::ExtractStr(std::shared_ptr blob) { - std::vector data = blob.ChopBlank(*this); + std::vector data = blob->ChopBlank(*this); /* Save optained data as string */ /* NEVER do this in prod, as in real live blob is binary and may have 0 in the middle of it */ char * buf; @@ -81,7 +81,7 @@ class StampTwoCharsList: public StampBaseStr StampTwoChars el_stamp; GalleyVectorStr galley; public: - std::string ExtractStr(Blob &blob) override; + std::string ExtractStr(std::shared_ptr blob) override; StampTwoCharsList(): el_stamp {}, galley {el_stamp} {}; virtual int minSize() override {return el_stamp.minSize();}; @@ -89,7 +89,7 @@ class StampTwoCharsList: public StampBaseStr }; std::string -StampTwoCharsList::ExtractStr(Blob &blob) +StampTwoCharsList::ExtractStr(std::shared_ptr blob) { std::string res = ""; std::vector list = galley.ExtractStrVector(blob);