Re: [Boost-users] [multi_index] Problem of scope with the replace in static data structure
Hi Joaquim,
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.
Thanks for the advice. :)
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?
I think that will be a little hard to do, let's first try these steps below first, maybe you can figure out what it is, because I'm not understanding what could be, since it seems to work inside the function and outside doesn't, and as it is a static data member...
2. If the answer to 1 is no, can you post the debug console output of your program? The output of this part of the code (I will mark the part inside the function commitChanges();: ///////////begin commitChanges();///////////////////////////// DEBUG@commitChanges:before replacing:_git Name: COI:0351-123-4555 Node version was not found! DEBUG@commitChanges:after replacing:_git Name: COI:0351-123-4555 Found it: Name: Node:0351-123-4569 Timestamp: 1234340512 Found it: Name: Node:0351-123-4569 Timestamp: 1234340521 ///////////end commitChanges();///////////////////////////// Commit was successful! Retrieving the graph with commit: Node version was not found!
3. You're copying values of the type Graph. How's this type defined? Has it proper copy semantics? Yes, I think so: class Graph { ...
- As you can see, inside before replacing, it did not find the nodes inserted, as expected. - Then after replacing it found the nodes inserted (as expected). - But then after goes out of the function, as you can see, no nodes was found it... they shouldn't be there? I mean because the repository is static, I think it should be no reason for the nodes be there inside the function, and outside no... public: // TODO: Really constructors /// Default Constructor Graph() { _rangeBegin = 0; _rangeEnd = 0; } /// Copy constructors Graph(const Graph &g) : _rangeBegin(g._rangeBegin), _rangeEnd(g._rangeEnd), _nodeRep(g._nodeRep), _nodeNameRep(g._nodeNameRep), _nodeTimeStampView(g._nodeTimeStampView), _localPropRep(g._localPropRep), _globalPropRep(g._globalPropRep){} ... }
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? Yes. I've added twice before the replace and after, the result is the same (as expected) and still I don't understand why does not work outside... DEBUG@commitChanges:before replacing:_git Name: COI:0351-123-4555 Node version was not found! DEBUG@commitChanges:before replacing:_git Name: COI:0351-123-4555 Node version was not found! DEBUG@commitChanges:after replacing:_git Name: COI:0351-123-4555 Found it: Name: Node:0351-123-4569 Timestamp: 1234341125 Found it: Name: Node:0351-123-4569 Timestamp: 1234341134 DEBUG@commitChanges:after replacing:_git Name: COI:0351-123-4555 Found it: Name: Node:0351-123-4569 Timestamp: 1234341125 Found it: Name: Node:0351-123-4569 Timestamp: 1234341134 Commit was successful! Retrieving the graph with commit: Node version was not found!
thanks a lot for the help, I hope you can figure it out what it is happen... best regards Rodrigo
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
-- ************************************************* Rodrigo Dias Ferreira Master Student of Computational Engineering Technische Universität Dresden - Germany Mobile Phone:+49 171 3158797 E-mail: rodrigodias@gmx.de ************************************************* Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01
Rodrigo Dias Ferreira escribió:
2. If the answer to 1 is no, can you post the debug console output of your program?
The output of this part of the code (I will mark the part inside the function commitChanges();: ///////////begin commitChanges();///////////////////////////// DEBUG@commitChanges:before replacing:_git Name: COI:0351-123-4555 Node version was not found! DEBUG@commitChanges:after replacing:_git Name: COI:0351-123-4555 Found it: Name: Node:0351-123-4569 Timestamp: 1234340512 Found it: Name: Node:0351-123-4569 Timestamp: 1234340521 ///////////end commitChanges();///////////////////////////// Commit was successful! Retrieving the graph with commit: Node version was not found!
[...] Nothing illuminating here... BTW, the code you ran to produce this output cannot be the same you posted before, as the traces are incompatible --the sentence "Retrieving the graph with commit:" appears nowhere in the code.
3. You're copying values of the type Graph. How's this type defined? Has it proper copy semantics?
Yes, I think so: class Graph { ... public:
// TODO: Really constructors /// Default Constructor Graph() { _rangeBegin = 0; _rangeEnd = 0; } /// Copy constructors Graph(const Graph &g) : _rangeBegin(g._rangeBegin), _rangeEnd(g._rangeEnd), _nodeRep(g._nodeRep), _nodeNameRep(g._nodeNameRep), _nodeTimeStampView(g._nodeTimeStampView), _localPropRep(g._localPropRep), _globalPropRep(g._globalPropRep){} ... }
It's hard to know whether you got copy semantics right without knowing
the types
of _rangeBegin, _rangeEnd and the rest of Graph data members, but this
has prompted
me to suspect that maybe there's something wrong with the handler type
Graph_h (which
I assume is some sort of ref-counted reference to Graph, right?). Can
you please
test the following? In your //Test of the commit section, rather than
reuse graph_h please
use a different variable to do the after-commitChanges check:
//Test of the commit
if (graph_h.commitChanges())
cout << "Commit was successful!\n";
else
cout << "Commitretr 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_h2 = Graph_h(it); // WE DON'T REUSE graph_h
//propertystream_h propS;
propS = graph_h2->lookupLocalProp("name");
p_h = propS.next();
cout << "DEBUG@main:right after the commit:_git " << p_h.value() <
participants (2)
-
joaquin@tid.es
-
Rodrigo Dias Ferreira