Boost logo

Boost Users :

Subject: [Boost-users] Problem of scope with the replace in static data structure
From: Rodrigo Dias Ferreira (rodrigodias_at_[hidden])
Date: 2009-02-10 04:51:01


Hi there,

I am having a problem with Boost.MultiIndex (I'm using Boost 1.37).

So the problem is the following:
I am using a static data structure, an index which I use as my graph repository:
/// Data member to represent the graph repository (using ordered_unique index)
        static graphIndex _graphRep;
which is from the type graphIndex:
///ordered_unique Index in the data structure graph_hm
typedef multi_index_container<
        graphMap,
        indexed_by<
                ordered_unique<
                        BOOST_MULTI_INDEX_MEMBER(graphMap,string,_name)
>
>
> graphIndex;

Here is the graphMap:
/// GraphMap: Data Structure for setting an index in the uniqueGraphName and retrieving handler Graph_h
struct graphMap {
        string _name;
        Graph _graph;

        /// Default Constructor
        graphMap(){}

        /// Constructor with parameters: initialize the name and graph
        graphMap(string uniqueGraphName, Graph graph) :
                _name(uniqueGraphName), _graph (graph) {}

        /// Constructor with parameters: initialize the name and graph
        graphMap(const graphMap &gm) : _name(gm._name), _graph (gm._graph) {}

};

For manipulating the graphs, I use a Graph_h (handler), which does a copy from the graph from this repository, does the changes in the local copy, and then the user has to call commitChanges(); to apply it in the repository (which I am using the replace function from the MultiIndex to commit it).

The problem it is that inside the commitChanges(); I can retrieve from the repository through the find function (from MultiIndex).

But when I the main program, it does not work (remark: I am trying right after calling the commitChanges();
It founds the graph, but it seems to be the old one, and I cannot retrieve the nodes...

Why is that happening?

Here it is a stretch of code from the main:
//Test of the commit
                                if (graph_h.commitChanges())
                                        cout << "Commit was successful!\n";
                                else
                                        cout << "Commit was unsuccessful!\n";
                                // Debug

                                //Graph_h graph_h;
                                //NodeIterator nodeIt;
                                //Node_h node_h;

                                graphIt it = DynamicGraphs::_graphRep.find("COI:0351-123-4555");
                                graph_h = Graph_h(it);
                                //propertystream_h propS;
                                propS = graph_h->lookupLocalProp("name");
                                p_h = propS.next();
                                cout << "DEBUG_at_main:right after the commit:_git " << p_h.value() <<endl;
                                nodeIt = graph_h->nodeIterator("Node:0351-123-4569");
                                        if (!nodeIt)
                                                cout << "Node version was not found!"<<endl;
                                        else //Works for both: one match and range lookup
                                                while (!nodeIt.end()){
                                                        node_h = nodeIt.next();
                                                        cout << "Found it: " << *node_h;
                                                }
                                //Debug

And here it is the code from inside the commit, which it works!!!

bool Graph_h::commitChanges(){

        bool success;
        propertystream_h ps_h = _localGraph.lookupLocalProp("name");
        //Exception handling in the case does not find the name property
        property_h p_h = ps_h.next();

        //TODO: Revise about the setting of the time in the graph... too stable
        _localGraph.resetTimeRange();

        // Debug
        cout << "DEBUG_at_commitChanges:before replacing:_git Name: " << p_h.value() <<endl;

        Graph_h graph_h;
        NodeIterator nodeIt;
        Node_h node_h;

        graphIt it = DynamicGraphs::_graphRep.find("COI:0351-123-4555");
        graph_h = Graph_h(it);
        nodeIt = graph_h->nodeIterator("Node:0351-123-4569");
                if (!nodeIt)
                        cout << "Node version was not found!"<<endl;
                else //Works for both: one match and range lookup
                        while (!nodeIt.end()){
                                node_h = nodeIt.next();
                                cout << "Found it: " << *node_h;
                        }
        //Debug

        success = DynamicGraphs::_graphRep.replace(_git, graphMap(p_h.value(),_localGraph));

        // Debug
        cout << "DEBUG_at_commitChanges:after replacing:_git Name: " << p_h.value() <<endl;

        it = DynamicGraphs::_graphRep.find("COI:0351-123-4555");
        graph_h = Graph_h(it);
        nodeIt = graph_h->nodeIterator("Node:0351-123-4569");
                if (!nodeIt)
                        cout << "Node version was not found!"<<endl;
                else //Works for both: one match and range lookup
                        while (!nodeIt.end()){
                                node_h = nodeIt.next();
                                cout << "Found it: " << *node_h;
                        }
        //Debug

        return success;

}

I hope someone can help me..

thanks in advance,

                               Rodrigo

-- 
*************************************************
Rodrigo Dias Ferreira
Master Student of Computational Engineering
Technische Universität Dresden - Germany
Mobile Phone:+49 171 3158797
E-mail: rodrigodias_at_[hidden]
*************************************************
Jetzt 1 Monat kostenlos! GMX FreeDSL - Telefonanschluss + DSL 
für nur 17,95 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net