Problem of scope with the replace in static data structure
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@main:right after the commit:_git " << p_h.value() <
Hi Rodrigo, First of all let me advice you to add the name of the library to the subject line of your post (in this case, [multi_index]) so that authors can more easily track messages of their particular interest. Rodrigo Dias Ferreira escribió:
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: [...] 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...
The code is too convoluted for me to detect anything suspicious: the fact that you check for the newly replaced element just before commitChanges returns and just after and have differing results cannot possibly be related to the fact that DynamicGraphs::_graphRep is static, so I'd look somewhere else. Suggestions: 1. Can you provide a narrowed down compilable program exhibiting the problem? 2. If the answer to 1 is no, can you post the debug console output of your program? 3. You're copying values of the type Graph. How's this type defined? Has it proper copy semantics? 4. What happens if you try the after-replace check inside Graph_h::commitChanges (that is, the section beginning with cout << "DEBUG@commitChanges:before replacing:_git Name: ") *twice* rather than just onec? Still got positive results for both checks? I'm sorry I can't be more helpful with the info you provide. Looking fwd to having your feedback. Joaquín M López Muñoz Telefónica, Investigación y Desarrollo
participants (2)
-
joaquin@tid.es
-
Rodrigo Dias Ferreira