Commit 3d98ef99 authored by Romain Bertozzi's avatar Romain Bertozzi Committed by Silbino Gonçalves Matado

utils: add utility method for vectors and arrays

This patch adds a new utility method to convert C++ data containers to
Objective-C ones.
Here, std::vector of std::map containers are translated to NSArray of
NSDictionary.

Issue: #1391
Change-Id: I61f7a57d2801949eac5685ffb0d734f26eeab87c
Reviewed-by: default avatarSilbino Gonçalves Matado <silbino.gmatado@savoirfairelinux.com>
parent 1caaa4be
......@@ -31,5 +31,6 @@
+ (NSMutableDictionary*)mapToDictionnary:
(const std::map<std::string, std::string>&)map;
+ (std::map<std::string, std::string>)dictionnaryToMap:(NSDictionary*)dict;
+ (NSArray*)vectorOfMapsToArray:(const std::vector<std::map<std::string, std::string>>&)vectorOfMaps;
@end
......@@ -56,4 +56,17 @@
return resMap;
}
+ (NSArray*)vectorOfMapsToArray:
(const std::vector<std::map<std::string, std::string>>&)vectorOfMaps {
NSMutableArray* array = [[NSMutableArray alloc] initWithCapacity:vectorOfMaps.size()];
std::for_each(
vectorOfMaps.begin(), vectorOfMaps.end(), ^(std::map<std::string, std::string> map) {
NSDictionary *dictionary = [Utils mapToDictionnary:map];
[array addObject:dictionary];
});
return [NSArray arrayWithArray:array];
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment