property map: does a given key exist?

In nutshell: how can I check whether a property map has some given
key?
The exact problem is as follows. I have graph edges with the property
"lambdas" of positive integers, but its the exact meaning is not
important here. With the read_graphviz function I am loading graph
files which look like this:
graph {
a;
b;
c;
c -- a [distance="100"];
a -- b [lambdas="8"];
}
After I load the file I want to examine which edges have the "lambdas"
property, but I don't know how to do this. If I request the property
value with the "get" function, I get some random value. My program is
at the bottom of this email.
The program prints the edge and the value of the "lambdas" property.
I get this:
(2,0): 33489268
(0,1): 8
The first line is bad: the edge (2,0), i.e. c -- a in my graphviz
file, has the reported value of 33489268. The second line is OK.
Thanks for reading.
Best,
Irek
*********************************************************************
#include

On Saturday 15 April 2006 15:25, Irek Szczesniak wrote:
In nutshell: how can I check whether a property map has some given key?
Some property maps may provide bounds checking, but the property map concept doesn't require it, so in general you can't.
graph { a; b; c; c -- a [distance="100"]; a -- b [lambdas="8"]; }
I think you'll need to give every edge a lambda number, but you might reserve a special value to indicate that the lambda property isn't applicable to that edge. Daniel

Hi Daniel, Thank you for your email.
In nutshell: how can I check whether a property map has some given key?
Some property maps may provide bounds checking, but the property map concept doesn't require it, so in general you can't.
Good to know. I didn't find this in the property map documentation.
I think you'll need to give every edge a lambda number, but you might reserve a special value to indicate that the lambda property isn't applicable to that edge.
I had the class def_int as the type of the lambda property: struct def_int { int value; def_int() : value(-1) {} def_int & operator = (int a) { value = a; } bool operator < (const def_int &a) { return value < a.value; } }; In this way if a link doesn't have this property, then the property map has -1 for that edge. The problem is that I needed to define operators =, <, <<, >> to make it work. Then I wanted to use some other stuff and got cryptic error messages at compilation. Finally I dropped the def_int class in favor of the int type, and now I make sure that every link in the .dot file has a lambdas property. Best, Irek

Irek Szczesniak wrote:
In nutshell: how can I check whether a property map has some given key?
One way which may work for you is to use optional<value> as the actual value_type of the map. That way, your map can just return an absent optional if there is no value associated with a key. http://www.boost.org/libs/optional/doc/optional.html -- Fernando Cacciola SciSoft http://fcacciola.50webs.com/
participants (3)
-
Daniel Mitchell
-
Fernando Cacciola
-
Irek Szczesniak