// PugArchive.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <vector>
#include <list>
#include <map>
#include <iobind/pair_policy.hpp>
#include "xml_bind.hpp"
int main(int argc, char* argv[])
{
using namespace pug;
using namespace iobind;
double d(1);
float f(2);
int i(3);
short s(4);
long l(5);
std::string str("escaped string: <>&\'\"");
LPCTSTR sz("static string");
std::vector<float> vf(5);
for (i=0;i<static_cast<int>(vf.size());++i)
vf[i]=i*1.1f;
std::list<std::string> ls;
for (i=0;i<3;++i)
ls.push_back( boost::io::str( boost::format("l_%1%") % i) );
std::map<size_t,std::string> mis;
for (i=0;i<3;++i)
mis[i]=boost::io::str( boost::format("m_%1%") % i);
xml_bind ar;
std::cerr<<"Testing xml_archive"<<std::endl;
ar.append_child_elem("test_append");
ar.into_elem();
// addind child elem and attribute
ar.append_child_elem("float", f);
ar.append_child_attribute("a_float",f);
ar.append_child_elem("double", d);
ar.append_child_attribute("a_double",d);
ar.append_child_elem("int", i);
ar.append_child_attribute("a_int",i);
ar.append_child_elem("long", l);
ar.append_child_attribute("a_long",l);
ar.append_child_elem("short", s);
ar.append_child_attribute("a_short",s);
ar.append_child_elem("static_string", sz);
ar.append_child_attribute("a_static_string",sz);
ar.append_child_elem("std::string", str);
ar.append_child_attribute("a_string",str);
ar.append_child_elem("base64", encode(str, to_base64_p) );
ar.append_child_elem("add_containers");
ar.into_elem();
ar.append_child_elem("vector", vf.begin(), vf.end());
ar.append_child_elem("list", ls.begin(), ls.end(),true);
ar.append_child_elem_p(
"map",
mis.begin(),
mis.end(),
sequence_to_string_p
.set_item_decorators("",",","")
<< pair_to_string_p
);
ar.out_of_elem();
ar.out_of_elem();
std::cerr<<ar<<std::endl;
// find child elem and attribute
ar.reset_child();
ar.into_elem();
f=0;
std::cerr<<"find - get for child named float."<<std::endl;
ar.find_get_child_data("float",f);
std::cerr<<"float: "<<f<<std::endl;
str.clear();
std::cerr<<"find - get for child named std::string"<<std::endl;
ar.find_get_child_data("std::string",str);
std::cerr<<"std::string: "<<str<<std::endl;
ar.find_get_child_data("base64",str);
std::cerr<<"base64: "<<encode(str, from_base64_p )<<std::endl;
ar.out_of_elem();
// loading from file.
ar.parse_file( "xml_file.xml");
ar.reset_cursors();
ar.into_elem();
std::cerr<<"Xml from file:\n"<<ar<<std::endl;
// traversing
/* do
{
std::cerr<<ar.get_child_elem().name()<<std::endl;
ar.next_child();
}
while (ar.next_elem());
*/
vf.clear();
ar.find_get_child_data_p(
"child2",
vf,
sequence_from_string_p
.set_item_decorators("",",","")
% vf
<< from_string<float>()
);
std::cerr<<"child2 data = "<<encode(vf.begin(), vf.end(), sequence_to_string_p)<<std::endl;
return 0;
}