Skip to content

Commit

Permalink
test serialization with default val
Browse files Browse the repository at this point in the history
# Conflicts:
#	MMVII/src/CodedTarget/cGenerateEncoding.cpp
  • Loading branch information
jmmuller committed Sep 2, 2024
1 parent f891610 commit 7ca6983
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
40 changes: 40 additions & 0 deletions MMVII/include/MMVII_2Include_Serial_Tpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,46 @@ template <class Type> void OnePtrAddData(const cAuxAr2007 & anAux,Type * & aL)
AddData(anAux,*aL);
}

// general AddData where a default value is given if value not found at reading
template <class Type> void AddData(const cAuxAr2007 & anAux,const std::string & aTag0,Type & aL, const Type & aDefValIfAbsentAtRead)
{
const std::string * anAdrTag = & aTag0;

// In input mode, we must decide if the value is present
if (anAux.Input())
{
// The archive knows if the object is present
if (anAux.NbNextOptionnal(*anAdrTag))
{
// If yes read it and initialize optional value
Type aV;
AddData(cAuxAr2007(*anAdrTag,anAux),aV);
aL = aV;
}
else
aL = aDefValIfAbsentAtRead;
return;
}

// Now in writing mode
int aNb = 1; // value always present for output
// Tagged format (xml) is a special case
if (anAux.Tagged())
{
// always write value in writing mode
AddData(cAuxAr2007(*anAdrTag,anAux),aL);
}
else
{
// Indicate that the value is present and put it
AddData(anAux,aNb);
anAux.Ar().Separator();
AddData(anAux,aL);
anAux.Ar().Separator();
}
}


// need general inteface for things like std::vector<Type *>
template <class Type> void AddData(const cAuxAr2007 & anAux,Type * & aL)
{
Expand Down
5 changes: 5 additions & 0 deletions MMVII/include/MMVII_Class4Bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class cTestSerial1 : public cMemCheck
std::vector<double> mVD;
std::optional<cPt2dr> mO1;
std::optional<cPt2dr> mO2;
std::optional<std::string> mO3;
std::string mD1; // with default val
double mD2;


};
void AddData(const cAuxAr2007 & anAux, cTestSerial1 & aTS1) ;

Expand Down
1 change: 1 addition & 0 deletions MMVII/src/CodedTarget/cGenerateEncoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ void cSpecBitEncoding::AddData(const cAuxAr2007 & anAux)
{
MMVII::AddData(cAuxAr2007("Prefix",anAux),mPrefix);
MMVII::AddData(cAuxAr2007("NbDigit",anAux),mNbDigit);
MMVII::AddData(anAux,"TargetNamePrefix",mTargetNamePrefix, std::string());
MMVII::AddData(cAuxAr2007("MaxNum",anAux),mMaxNum);
MMVII::AddData(cAuxAr2007("MaxLowCode",anAux),mMaxLowCode);
MMVII::AddData(cAuxAr2007("MaxCodeEqui",anAux),mMaxCodeEqui);
Expand Down
13 changes: 11 additions & 2 deletions MMVII/src/Serial/BenchSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ cTestSerial1::cTestSerial1() :
mLI{1,22,333},
mVD {314,27,14},
mO1 (cPt2dr(99,999)),
mO2 (cPt2dr(100,1000))
mO2 (cPt2dr(100,1000)),
mO3 ("HelloO"),
mD1("HelloD"),
mD2(1.0)
{
}

Expand All @@ -86,7 +89,10 @@ bool cTestSerial1::operator == (const cTestSerial1 & aT1) const
&& (mP3==aT1.mP3)
&& (mO1==aT1.mO1)
&& (mO2==aT1.mO2)
&& EqualCont(mLI,aT1.mLI)
&& (mO3==aT1.mO3)
&& (mD1==aT1.mD1)
&& (mD2==aT1.mD2)
&& EqualCont(mLI,aT1.mLI)
;
}

Expand All @@ -104,6 +110,9 @@ void AddData(const cAuxAr2007 & anAux0, cTestSerial1 & aTS1)
AddData(cAuxAr2007("VD",anAux),aTS1.mVD);
AddOptData(anAux,"O1",aTS1.mO1);
AddOptData(anAux,"O2",aTS1.mO2);
AddOptData(anAux,"O3",aTS1.mO3);
AddData(anAux,"D1",aTS1.mD1, std::string("toto"));
AddData(anAux,"D2",aTS1.mD2, 3.14);
}


Expand Down

0 comments on commit 7ca6983

Please sign in to comment.