stdcpp/tsrc/Boost_test/graph/src/serialize.cpp
changeset 0 e4d67989cc36
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (C) 2006 Trustees of Indiana University
       
     2 //
       
     3 // Distributed under the Boost Software License, Version 1.0.
       
     4 // (See accompanying file LICENSE_1_0.txt or copy at
       
     5 // http://www.boost.org/LICENSE_1_0.txt)
       
     6 /*
       
     7  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
       
     8 */
       
     9 
       
    10 
       
    11 #include <boost/config.hpp>
       
    12 #include <iostream>
       
    13 #include <fstream>
       
    14 #include <string>
       
    15 #include <boost/tuple/tuple.hpp>
       
    16 #include <boost/graph/adjacency_list.hpp>
       
    17 #include <boost/graph/visitors.hpp>
       
    18 #include <boost/graph/breadth_first_search.hpp>
       
    19 #include <map>
       
    20 #include <boost/graph/adj_list_serialize.hpp>
       
    21 #include <boost/archive/xml_iarchive.hpp>
       
    22 #include <boost/archive/xml_oarchive.hpp>
       
    23 
       
    24 #ifdef __SYMBIAN32__
       
    25 #include "std_log_result.h"
       
    26 #define LOG_FILENAME_LINE __FILE__, __LINE__
       
    27 #endif
       
    28 struct vertex_properties {
       
    29   std::string name;
       
    30 
       
    31   template<class Archive>
       
    32   void serialize(Archive & ar, const unsigned int version) {
       
    33     ar & BOOST_SERIALIZATION_NVP(name);
       
    34   }  
       
    35 };
       
    36 
       
    37 struct edge_properties {
       
    38   std::string name;
       
    39 
       
    40   template<class Archive>
       
    41   void serialize(Archive & ar, const unsigned int version) {
       
    42     ar & BOOST_SERIALIZATION_NVP(name);
       
    43   }  
       
    44 };
       
    45 
       
    46 using namespace boost;
       
    47 
       
    48 typedef adjacency_list<vecS, vecS, undirectedS, 
       
    49                vertex_properties, edge_properties> Graph;
       
    50 
       
    51 typedef graph_traits<Graph>::vertex_descriptor vd_type;
       
    52 
       
    53 
       
    54 typedef adjacency_list<vecS, vecS, undirectedS, 
       
    55                vertex_properties> Graph_no_edge_property;
       
    56 
       
    57 int main()
       
    58 {
       
    59   {
       
    60     std::ofstream ofs("./kevin-bacon2.dat");
       
    61     archive::xml_oarchive oa(ofs);
       
    62     Graph g;
       
    63 		vertex_properties vp;
       
    64 		vp.name = "A";
       
    65 		vd_type A = add_vertex( vp, g );
       
    66 		vp.name = "B";
       
    67 		vd_type B = add_vertex( vp, g );
       
    68 
       
    69 		edge_properties ep;
       
    70 		ep.name = "a";
       
    71 		add_edge( A, B, ep, g);
       
    72 
       
    73     oa << BOOST_SERIALIZATION_NVP(g);
       
    74 
       
    75     Graph_no_edge_property g_n;
       
    76     oa << BOOST_SERIALIZATION_NVP(g_n);
       
    77   }
       
    78 
       
    79   {
       
    80     std::ifstream ifs("./kevin-bacon2.dat");
       
    81     archive::xml_iarchive ia(ifs);
       
    82     Graph g;
       
    83     ia >> BOOST_SERIALIZATION_NVP(g);
       
    84 
       
    85 		if  (!( g[*(vertices( g ).first)].name == "A" )) return -1;
       
    86 
       
    87     Graph_no_edge_property g_n;
       
    88     ia >> BOOST_SERIALIZATION_NVP(g_n);
       
    89   }
       
    90   
       
    91   #ifdef __SYMBIAN32__
       
    92   
       
    93   	std_log(LOG_FILENAME_LINE,"[End Test Case ]");
       
    94 
       
    95 	testResultXml("serialize");
       
    96 	close_log_file();
       
    97 #endif
       
    98   return 0;
       
    99 }