Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/dconfig/test_serialization.cxx

Go to the documentation of this file.
00001 // Filename: test_serialization.cxx
00002 // Created by:  cary (31Aug98)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include <serialization.h>
00020 #include <list>
00021 #include <vector>
00022 #include <algo.h>
00023 #include <string>
00024 
00025 typedef std::list<int> intlist;
00026 typedef std::vector<float> floatvec;
00027 
00028 intlist refints;
00029 floatvec reffloats;
00030 
00031 int ints[10] = { 3, 1, 4, 1, 5, 9, 2, 6, 5, 3 };
00032 float floats[10] = { 0.1, 1.2, 2.3, 3.4, 4.5, 5.6, 6.7, 7.8, 8.9, 9.0 };
00033 
00034 void TestToString()
00035 {
00036    std::string line;
00037    Serialize::Serializer<intlist> intser(refints);
00038    Serialize::Serializer<floatvec> floatser(reffloats);
00039 
00040    line = intser;
00041    cout << "Int list serialization: '" << line << "'" << endl;
00042    line = floatser;
00043    cout << "Float vector serialization: '" << line << "'" << endl;
00044 }
00045 
00046 void TestFromString()
00047 {
00048    std::string line;
00049    Serialize::Serializer<intlist> intser(refints);
00050    Serialize::Serializer<floatvec> floatser(reffloats);
00051 
00052    line = intser;
00053    Serialize::Deserializer<intlist> intdes1(line);
00054    cout << "Int list deserialization: ";
00055    intlist ides1 = intdes1;
00056    for (intlist::iterator i=ides1.begin(); i!=ides1.end(); ++i) {
00057       if (i != ides1.begin())
00058          cout << ", ";
00059       cout << (*i);
00060    }
00061    cout << endl;
00062    line = floatser;
00063    Serialize::Deserializer<floatvec> floatdes1(line);
00064    cout << "Float vector deserialization: ";
00065    floatvec fdes1 = floatdes1;
00066    for (floatvec::iterator j=fdes1.begin(); j!=fdes1.end(); ++j) {
00067       if (j != fdes1.begin())
00068          cout << ", ";
00069       cout << (*j);
00070    }
00071    cout << endl;
00072 }
00073 
00074 main()
00075 {
00076    // initialize the collections
00077    for (int i=0; i<10; ++i) {
00078       refints.push_back(ints[i]);
00079       reffloats.push_back(floats[i]);
00080    }
00081 
00082    // now run tests
00083    cout << "Serialization to string:" << endl;
00084    TestToString();
00085    cout << endl << "Deserialization from string:" << endl;
00086    TestFromString();
00087 }

Generated on Thu May 1 22:12:58 2003 for DTool by doxygen1.3