1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-06-13 04:37:05 +01:00

XMLReader implementation and a virtual Reader/Writer template framework.

Test_serialisation has an example of *code* *free* object serialisation
to both ostream and to XML using macro magic.

Implementing TextReader/TextWriter, YAML, JSON etc.. should be trivial
and we can use configure time options to select the default "Reader" typedef.

Present done with

"using XMLPolicy::Reader"

to pick up the default serialisation strategy.
This commit is contained in:
Peter Boyle
2015-08-20 16:21:26 +01:00
parent fdfe194c41
commit ab81a25073
10 changed files with 348 additions and 7 deletions

View File

@ -1,5 +1,5 @@
bin_PROGRAMS = Test_GaugeAction Test_cayley_cg Test_cayley_coarsen_support Test_cayley_even_odd Test_cayley_ldop_cr Test_cf_coarsen_support Test_cf_cr_unprec Test_cheby Test_contfrac_cg Test_contfrac_even_odd Test_contfrac_force Test_cshift Test_cshift_red_black Test_dwf_cg_prec Test_dwf_cg_schur Test_dwf_cg_unprec Test_dwf_cr_unprec Test_dwf_even_odd Test_dwf_force Test_dwf_fpgcr Test_dwf_hdcr Test_gamma Test_gparity Test_gpwilson_even_odd Test_hmc_EODWFRatio Test_hmc_EOWilsonFermionGauge Test_hmc_EOWilsonRatio Test_hmc_WilsonFermionGauge Test_hmc_WilsonGauge Test_hmc_WilsonRatio Test_lie_generators Test_main Test_multishift_sqrt Test_nersc_io Test_partfrac_force Test_quenched_update Test_remez Test_rhmc_EOWilson1p1 Test_rhmc_EOWilsonRatio Test_rhmc_Wilson1p1 Test_rhmc_WilsonRatio Test_rng Test_rng_fixed Test_simd Test_stencil Test_wilson_cg_prec Test_wilson_cg_schur Test_wilson_cg_unprec Test_wilson_cr_unprec Test_wilson_even_odd Test_wilson_force Test_wilson_force_phiMdagMphi Test_wilson_force_phiMphi
bin_PROGRAMS = Test_GaugeAction Test_cayley_cg Test_cayley_coarsen_support Test_cayley_even_odd Test_cayley_ldop_cr Test_cf_coarsen_support Test_cf_cr_unprec Test_cheby Test_contfrac_cg Test_contfrac_even_odd Test_contfrac_force Test_cshift Test_cshift_red_black Test_dwf_cg_prec Test_dwf_cg_schur Test_dwf_cg_unprec Test_dwf_cr_unprec Test_dwf_even_odd Test_dwf_force Test_dwf_fpgcr Test_dwf_hdcr Test_gamma Test_gparity Test_gpwilson_even_odd Test_hmc_EODWFRatio Test_hmc_EOWilsonFermionGauge Test_hmc_EOWilsonRatio Test_hmc_WilsonFermionGauge Test_hmc_WilsonGauge Test_hmc_WilsonRatio Test_lie_generators Test_main Test_multishift_sqrt Test_nersc_io Test_partfrac_force Test_quenched_update Test_remez Test_rhmc_EOWilson1p1 Test_rhmc_EOWilsonRatio Test_rhmc_Wilson1p1 Test_rhmc_WilsonRatio Test_rng Test_rng_fixed Test_serialisation Test_simd Test_stencil Test_wilson_cg_prec Test_wilson_cg_schur Test_wilson_cg_unprec Test_wilson_cr_unprec Test_wilson_even_odd Test_wilson_force Test_wilson_force_phiMdagMphi Test_wilson_force_phiMphi
Test_GaugeAction_SOURCES=Test_GaugeAction.cc
@ -174,6 +174,10 @@ Test_rng_fixed_SOURCES=Test_rng_fixed.cc
Test_rng_fixed_LDADD=-lGrid
Test_serialisation_SOURCES=Test_serialisation.cc
Test_serialisation_LDADD=-lGrid
Test_simd_SOURCES=Test_simd.cc
Test_simd_LDADD=-lGrid

View File

@ -0,0 +1,65 @@
#include <Grid.h>
using namespace Grid;
class myclass {
public:
GRID_DECL_CLASS_MEMBERS(myclass,
int, x,
double, y,
bool , b,
std::string, name,
std::vector<double>, array,
std::vector<std::vector<double> >, twodimarray,
);
myclass() : array(4,5.0), twodimarray(3,std::vector<double>(2,2.0)) {
x=1;
y=2;
b=false;
name="bother said pooh";
}
};
uint16_t i16 = 1;
uint16_t u16 = 2;
uint32_t i32 = 3;
uint32_t u32 = 4;
uint64_t i64 = 5;
uint64_t u64 = 6;
float f = M_PI;
double d = 2*M_PI;
bool b = false;
int main(int argc,char **argv)
{
{
Writer WR("bother.xml");
push(WR,"BasicTypes");
write(WR,"i16",i16);
write(WR,"u16",u16);
write(WR,"i32",i32);
write(WR,"i32",u32);
write(WR,"i64",i64);
write(WR,"i64",u64);
write(WR,"f",f);
write(WR,"d",d);
write(WR,"b",b);
pop(WR);
myclass obj;
write(WR,"obj",obj);
};
Reader RD("bother2.xml");
myclass copy;
read(RD,"obj",copy);
std::cout << "Loaded " << copy<<std::endl;
}