Archived
This forum has been archived. Please start a new discussion on GitHub.
what operations can I do with the type "dictionary"?
When I write the Ice code, I want to use the Ice::Context to transfer some simple information, in the example presented in the manual, I found this piece of code:
is there any document that can guide me to deal with this dictionary type, such as getting keys, size, access the key-value from beginning to end etc.
Thanks so much
Ice::Context::const_iterator i = c.ctx.find("write policy"); if (i != c.ctx.end() && i->second == "immediate") { // some operations here } ...but in my code, I tried to retrieve the keys the dictionary has, using the following code:
Ice::Context _ctx = c.ctx; // Ice::Current& c string key = _ctx.first; string val = _ctx.second;but the compiler told me that the Ice::Context has no members first and second, I searched the user manual, no detailed info about this, so this is my question:
is there any document that can guide me to deal with this dictionary type, such as getting keys, size, access the key-value from beginning to end etc.
Thanks so much
0
Comments
-
Hi,
You can use the Ice::Context just like you would use any Slice dictionary<string, string> (this is how Ice::Context is defined, see slice/Ice/Current.ice). In C++, the Slice dictionary<string, string> type is mapped to a std::map<std::string, std::string> so you can simply extract the map keys and values, using std::map iterators:for(Ice::Context::const_iterator p = c.ctx.begin(); p != c.ctx.end(); ++p) { string key = p->first; string value = p->second; ... }
Cheers,
Benoit.0 -
Thanks, Benoit
I think I got it.
So if I want to play with a common dictionary, such as dictionary<string, int>,
I can use std::map<string, int>::const_iterator to point to that new dictionary, and all the methods of the std::map can be applied to the dictionary elements, am I right?0 -
Yes, see the C++ client side mapping chapter in the Ice manual: 6.7.5 Mapping for Dictionaries.
Cheers,
Benoit.0