libpniio
Modules | Data Structures
Formatters: converting data to strings
Collaboration diagram for Formatters: converting data to strings:

Modules

 Internal classes used by the formatters
 

Data Structures

class  pni::io::formatter< T >
 scalar formatter More...
 

Detailed Description

The basic facility to convert data to a string is the formatter<T> template. It can be accessed by including formatter.hpp in the source code. Its usage is fairly simple, for a scalar type use

#include <iostream>
#include <pni/core/types.hpp>
#include <pni/io/formatter.hpp>
using namespace pni::core;
using namespace pni::io;
typedef pni::io::formatter<float64> float_fmt_type;
int main(int argc,char **argv)
{
float_fmt_type float_formatter;
float64 data=4.3902e+2;
std::cout<<float_formatter(data)<<std::endl;
return 0;
}

Also container types can be handled by using the container_io_config type. To convert the data stored in a std::vector to a string use something like this

#include <iostream>
#include <vector>
#include <pni/core/types.hpp>
#include <pni/io/formatter.hpp>
using namespace pni::core;
using namespace pni::io;
typedef std::vector<uint32> mca_type;
typedef formatter<mca_type> mca_fmt_type;
int main(int,char **)
{
mca_fmt_type mca_fmt(container_io_config('[',']',';'));
mca_type mca{1,20,84,11};
std::cout<<mca_fmt(mca)<<std::endl;
// // will output
// // [1;20;84;11]
return 0;
}