Design: data sharing and presentation

There is some old code that I would like to reorganize.

There is some data obtained by reading some registers. This data is presented in csv and xml files.

The current path is dirty. There is no separation between data and presentation (XML, CSV). Thus, for each format, data is collected each time.

To give you an image, it looks like this:

A::Timestamp()
{
  //does some data collection and dumps to csv file
  //the header for this csv file is built in PreTimeStamp function.
  //depending on some command line options certain cols are added.
  filehndle << data1 << ","<<data2<<"," << data3;

  if( cmd_line_opt1 )
  {
    filehndle << "," << statdata1 <<","<<statdata2;
  }
} 

A::PreTimeStamp()
{
  //header for csv file
  filehndle << "start, end, delta";
  if( cmd_line_opt1 )
  {
     filehndle << "," << "statdata1 , statdata2";
  }

}

Another class B :: Profile (), which collects data in the same way as A :: Timestamp, but data is dumped as XML.

I would like to reorganize it to collect data in a common place. And use some adapters for csv and xml to take data and dump it in this format.

, . , struct . , csv, .

, say, xmlWriter CsvWriter?

+5
6

. TimeStamp PreTimeStamp (.. Virtual void Timestamp() = 0) "Dumper", Dumper_A Dumper_B . , , .

+1

? , .

, , xml csv, .

0

, - , , XML , . , , ( , , YAML), . , , YAML JSON, -, .

0

XML (1 ) XSL transforms, . CSV.

0

, MVC .

(), (, cmd). , - . , , XML CSV (, ),

0

You need a structure that includes all the possible data collected for a particular iteration and an adapter class that maps text fields (desired property labels in the output file) to member pointers in this structure (possibly functions for parsing or generating the desired type from text input or conclusion). If it is impossible or desirable to have a structure with all possible data collected, you can simply use the map as a prototyped object.

0
source

All Articles