Boost: Serilization help

I am using code::blocks to make my program. When running I get the windows 7 box saying program has stopped running.

the line in question is ia >> aMap;
1
2
3
4
5
6
7
8
9
  

levelMap* aMap= new levelMap();

    std::ifstream ifs("filename.map");
    boost::archive::text_iarchive ia(ifs);


   ia >> aMap;


It is saved later by

1
2
3
    std::ofstream ofs("filename.map");
    boost::archive::text_oarchive oa(ofs);
    oa<<aMap;


Levelmap serialize is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
private:

    friend class boost::serialization::access;
    std::vector<std::vector<std::vector<tile > > > mapArray;

    template<class Archive>


    void serialize(Archive & ar, const unsigned int version)
    {
        ar & mapArray;
    }



};



The Tile class is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class tile
{
public:
    int TileNum;
    bool Passable;
    bool Illusion;
    bool DrawAbove;
    unsigned int HideOnCondition;
    bool CastShadow;
    bool ShowShadow;

    tile()
    {

        TileNum=998;
        Passable=false;
        Illusion=false;
        DrawAbove=false;
        HideOnCondition=0;
        CastShadow=true;
        ShowShadow=true;
    }

    friend class boost::serialization::access;
    // When the class Archive corresponds to an output archive, the
    // & operator is defined similar to <<.  Likewise, when the class Archive
    // is a type of input archive the & operator is defined similar to >>.
    template<class Archive>

    void save(Archive & ar, const unsigned int version) const
    {
        ar & TileNum;
        ar & HideOnCondition;

        unsigned int bitTotal = 0;

        if (Passable) bitTotal +=1 ;
        if (Illusion) bitTotal +=2;
        if (DrawAbove) bitTotal +=4 ;
        if (CastShadow) bitTotal +=8 ;
        if (ShowShadow) bitTotal +=16 ;

        ar & bitTotal;

    }

    template<class Archive>
    void load(Archive & ar, const unsigned int version)
    {

        unsigned int bitTotal;

        ar & TileNum;
        ar & HideOnCondition;
        ar & bitTotal;

        Passable=false;
        if((bitTotal & 1) == 1)Passable=true;


        Illusion=false;
        if((bitTotal & 2) == 2)Illusion=true;


        DrawAbove=false;
        if((bitTotal & 4) == 4)DrawAbove=true;

        CastShadow=false;
        if((bitTotal & 8) == 8)CastShadow=true;

        ShowShadow=false;
        if((bitTotal & 16) == 16)ShowShadow=true;



    }
    BOOST_SERIALIZATION_SPLIT_MEMBER()
};



the output looks correct (if I comment out the loading line so, it runs to the saving line)

first few bits of the output are

1
2
22 serialization::archive 9 0 1 0
0 0 0 31 0 0 0 25 0 0 0 3 0 0 0 1 0 24 1 0 24 2 0 24 3 0 1 0 24 1 0 24 2 0 24 3 0 1 0 24 1 0 24 2 0 24 3 0 1 0 24 1 0 24 2 0 24 3 0 1 0 24 1 0 24 2 0 24 3 0 1 0 24 1 0 24 2 0 24 3 0 1 0 24
Last edited on
Topic archived. No new replies allowed.