diff --git a/Ring/Ring/Account.swift b/Ring/Ring/Account.swift index 9c0c8f70a51d2d40f36c56b72390f8c0cdd262af..873939e1f5d9812d510e6a9e40beb18b91d877eb 100644 --- a/Ring/Ring/Account.swift +++ b/Ring/Ring/Account.swift @@ -26,13 +26,13 @@ enum AccountType: String { } struct Account { - - //MARK: - Properties + + // MARK: - Properties let id: String - - //FIXME: This should be private + + // FIXME: This should be private var details: Dictionary<String, String> - + var alias: String? { get { return details["Account.alias"] @@ -41,7 +41,7 @@ struct Account { details["Account.alias"] = newValue } } - + var videoEnabled: Bool { get { return (details["Account.videoEnabled"]?.toBool())! @@ -110,7 +110,7 @@ struct Account { } set { details["Account.enable"] = newValue.toString() - ConfigurationManagerAdaptator.sharedManager().setAccountActive(self.id, newValue) + ConfigurationManagerAdaptator.sharedManager().setAccountActive(self.id, active: newValue) } } @@ -149,14 +149,14 @@ struct Account { details["Account.displayName"] = newValue } } - - //MARK: - Init + + // MARK: - Init init(accID: String) { id = accID details = ConfigurationManagerAdaptator.sharedManager().getAccountDetails(id) as! Dictionary<String, String> } - + func save() { - ConfigurationManagerAdaptator.sharedManager().setAccountDetails(id, details) + ConfigurationManagerAdaptator.sharedManager().setAccountDetails(id, details: details) } } \ No newline at end of file diff --git a/Ring/Ring/AccountDetailsViewController.swift b/Ring/Ring/AccountDetailsViewController.swift index ed4055153cc4f1ecd4c7cee76fc0358d3a55a2f1..59f8a03a3488ccada965e83a3724329aebfa624b 100644 --- a/Ring/Ring/AccountDetailsViewController.swift +++ b/Ring/Ring/AccountDetailsViewController.swift @@ -22,17 +22,16 @@ import UIKit class AccountDetailsViewController: UIViewController { - //MARK: - Properties + // MARK: - Properties var account: Account! - + @IBOutlet weak var detailsLabel: UILabel! - - - //MARK: - UIViewController + + // MARK: - UIViewController override func viewDidLoad() { super.viewDidLoad() - - //FIXME: This is just a placeholder + + // FIXME: This is just a placeholder detailsLabel.text = account.details.description } diff --git a/Ring/Ring/AccountModel.swift b/Ring/Ring/AccountModel.swift index 58ee4166b74de051d6803e54fa60e52646aba5a2..6a6c76a1b7fffc056ec16545527c383e5275302b 100644 --- a/Ring/Ring/AccountModel.swift +++ b/Ring/Ring/AccountModel.swift @@ -22,20 +22,20 @@ import Foundation class AccountModel { - //MARK: - Properties + // MARK: - Properties let confAdapt = ConfigurationManagerAdaptator.sharedManager() var accountList: Array<Account> = [] - - //MARK: - Singleton + + // MARK: - Singleton static let sharedInstance = AccountModel() - + private init() { - NSNotificationCenter.defaultCenter().addObserverForName("AccountsChanged", object: nil, queue: nil, usingBlock: {_ in + NSNotificationCenter.defaultCenter().addObserverForName("AccountsChanged", object: nil, queue: nil, usingBlock: { _ in self.reload() }) } - //MARK: - Methods + // MARK: - Methods func reload() { accountList.removeAll() for acc in confAdapt.getAccountList() { @@ -43,20 +43,20 @@ class AccountModel { accountList.append(Account(accID: accID)) } } - + func addAccount() { - - //TODO: This need work for all account type + + // TODO: This need work for all account type let details = confAdapt.getAccountTemplate("RING") details.setValue("iOS", forKey: "Account.alias") details.setValue("iOS", forKey: "Account.displayName") - confAdapt.addAccount(details! as [NSObject : AnyObject]) + confAdapt.addAccount(details! as [NSObject: AnyObject]) } - + func removeAccount(row: Int) { if row < accountList.count { confAdapt.removeAccount(accountList[row].id) } } - + } \ No newline at end of file diff --git a/Ring/Ring/AccountTableViewCell.swift b/Ring/Ring/AccountTableViewCell.swift index 5f212259b55e94def60f6b251e3ddaaaf206cdcf..953463cd5b4b28d77c0b920fc1675388feaeaf53 100644 --- a/Ring/Ring/AccountTableViewCell.swift +++ b/Ring/Ring/AccountTableViewCell.swift @@ -22,14 +22,14 @@ import UIKit class AccountTableViewCell: UITableViewCell { - //MARK: - Properties + // MARK: - Properties @IBOutlet weak var activeSwitch: UISwitch! @IBOutlet weak var accountNameLabel: UILabel! @IBOutlet weak var accountTypeLabel: UILabel! - + var account: Account! - - //MARK: - UITableViewCell + + // MARK: - UITableViewCell override func awakeFromNib() { super.awakeFromNib() } @@ -37,8 +37,8 @@ class AccountTableViewCell: UITableViewCell { override func setSelected(selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) } - - //MARK: - Actions + + // MARK: - Actions @IBAction func switchAccountState(sender: UISwitch) { account.isEnabled = sender.on } diff --git a/Ring/Ring/AppDelegate.swift b/Ring/Ring/AppDelegate.swift index 6c92d420ca6fdf10987b9d324dde952873cabb73..cdd1cde20580c6ad2b7ab1bca2358f5f96ba2b26 100644 --- a/Ring/Ring/AppDelegate.swift +++ b/Ring/Ring/AppDelegate.swift @@ -36,7 +36,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { } return true } - + func pollFunction() { self.dRingAdapt.pollEvents() } @@ -69,7 +69,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { lazy var applicationDocumentsDirectory: NSURL = { // The directory the application uses to store the Core Data store file. This code uses a directory named "cx.ring.Ring" in the application's documents Application Support directory. let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask) - return urls[urls.count-1] + return urls[urls.count - 1] }() lazy var managedObjectModel: NSManagedObjectModel = { @@ -99,7 +99,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { NSLog("Unresolved error \(wrappedError), \(wrappedError.userInfo)") abort() } - + return coordinator }() diff --git a/Ring/Ring/ConfigurationManagerAdaptator.h b/Ring/Ring/ConfigurationManagerAdaptator.h index ee4809b1bef627f12620eb0eba574e64feaa33c8..c81dd85cb9ae1c51e97bf7bd7142a954ca02e771 100644 --- a/Ring/Ring/ConfigurationManagerAdaptator.h +++ b/Ring/Ring/ConfigurationManagerAdaptator.h @@ -15,7 +15,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA. */ #import <Foundation/Foundation.h> @@ -24,16 +25,18 @@ + (id)sharedManager; -- (void) registerConfigurationHandler; +- (void)registerConfigurationHandler; -- (NSArray*) getAccountList; -- (NSMutableDictionary*) getAccountTemplate: (NSString*) accountType; -- (NSString*) addAccount: (NSDictionary*) details; -- (void) removeAccount: (NSString*) accountID; -- (void) setAccountActive: (NSString*) accountID : (bool) active; -- (uint64_t) sendAccountTextMessage: (NSString*) accountID : (NSString*) to : (NSDictionary*) payloads; -- (NSDictionary*) getAccountDetails: (NSString*) accountID; -- (NSDictionary*) getVolatileAccountDetails: (NSString*) accountID; -- (void) setAccountDetails: (NSString*) accountID : (NSDictionary*) details; -- (int) getMessageStatus: (uint64_t) msgID; +- (NSArray*)getAccountList; +- (NSMutableDictionary*)getAccountTemplate:(NSString*)accountType; +- (NSString*)addAccount:(NSDictionary*)details; +- (void)removeAccount:(NSString*)accountID; +- (void)setAccountActive:(NSString*)accountID active:(bool)active; +- (uint64_t)sendAccountTextMessage:(NSString*)accountID + to:(NSString*)to + payloads:(NSDictionary*)payloads; +- (NSDictionary*)getAccountDetails:(NSString*)accountID; +- (NSDictionary*)getVolatileAccountDetails:(NSString*)accountID; +- (void)setAccountDetails:(NSString*)accountID details:(NSDictionary*)details; +- (int)getMessageStatus:(uint64_t)msgID; @end diff --git a/Ring/Ring/ConfigurationManagerAdaptator.mm b/Ring/Ring/ConfigurationManagerAdaptator.mm index 39362431c5ec34ae47fe882265a0d677798aefc6..58e2f4432b7a73842fba6f2e19b7cffc9b30c9e7 100644 --- a/Ring/Ring/ConfigurationManagerAdaptator.mm +++ b/Ring/Ring/ConfigurationManagerAdaptator.mm @@ -15,7 +15,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA. */ #import "ConfigurationManagerAdaptator.h" @@ -30,103 +31,104 @@ using namespace DRing; #pragma mark Singleton Methods + (id)sharedManager { - static ConfigurationManagerAdaptator *sharedMyManager = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - sharedMyManager = [[self alloc] init]; - }); - return sharedMyManager; + static ConfigurationManagerAdaptator* sharedMyManager = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + sharedMyManager = [[self alloc] init]; + }); + return sharedMyManager; } - (id)init { - if (self = [super init]) { - [self registerConfigurationHandler]; - } - return self; + if (self = [super init]) { + [self registerConfigurationHandler]; + } + return self; } -- (NSArray*) getAccountList -{ - auto accountVector = getAccountList(); +- (NSArray*)getAccountList { + auto accountVector = getAccountList(); - return [Utils vectorToArray:accountVector]; + return [Utils vectorToArray:accountVector]; } -- (NSMutableDictionary*) getAccountTemplate: (NSString*) accountType -{ - auto accountTemplate = getAccountTemplate(std::string([accountType UTF8String])); +- (NSMutableDictionary*)getAccountTemplate:(NSString*)accountType { + auto accountTemplate = + getAccountTemplate(std::string([accountType UTF8String])); - return [Utils mapToDictionnary:accountTemplate]; + return [Utils mapToDictionnary:accountTemplate]; } -- (NSString*) addAccount: (NSDictionary*) details -{ - auto accountID = addAccount([Utils dictionnaryToMap:details]); +- (NSString*)addAccount:(NSDictionary*)details { + auto accountID = addAccount([Utils dictionnaryToMap:details]); - return [NSString stringWithUTF8String:accountID.c_str()]; + return [NSString stringWithUTF8String:accountID.c_str()]; } -- (void) removeAccount: (NSString*) accountID -{ - removeAccount(std::string([accountID UTF8String])); +- (void)removeAccount:(NSString*)accountID { + removeAccount(std::string([accountID UTF8String])); } -- (void) setAccountActive: (NSString*) accountID : (bool) active -{ - setAccountActive(std::string([accountID UTF8String]), active); +- (void)setAccountActive:(NSString*)accountID active:(bool)active { + setAccountActive(std::string([accountID UTF8String]), active); } -- (uint64_t) sendAccountTextMessage: (NSString*) accountID : (NSString*) to : (NSDictionary*) payloads -{ - return sendAccountTextMessage(std::string([accountID UTF8String]), std::string([to UTF8String]), - [Utils dictionnaryToMap:payloads]); +- (uint64_t)sendAccountTextMessage:(NSString*)accountID + to:(NSString*)to + payloads:(NSDictionary*)payloads { + return sendAccountTextMessage(std::string([accountID UTF8String]), + std::string([to UTF8String]), + [Utils dictionnaryToMap:payloads]); } -- (NSDictionary*) getAccountDetails: (NSString*) accountID -{ - auto accDetails = getAccountDetails(std::string([accountID UTF8String])); - return [Utils mapToDictionnary:accDetails]; +- (NSDictionary*)getAccountDetails:(NSString*)accountID { + auto accDetails = getAccountDetails(std::string([accountID UTF8String])); + return [Utils mapToDictionnary:accDetails]; } -- (NSDictionary*) getVolatileAccountDetails: (NSString*) accountID -{ - auto volatileDetails = getVolatileAccountDetails(std::string([accountID UTF8String])); - return [Utils mapToDictionnary:volatileDetails]; +- (NSDictionary*)getVolatileAccountDetails:(NSString*)accountID { + auto volatileDetails = + getVolatileAccountDetails(std::string([accountID UTF8String])); + return [Utils mapToDictionnary:volatileDetails]; } -- (void) setAccountDetails: (NSString*) accountID : (NSDictionary*) details -{ - setAccountDetails(std::string([accountID UTF8String]), [Utils dictionnaryToMap:details]); +- (void)setAccountDetails:(NSString*)accountID details:(NSDictionary*)details { + setAccountDetails(std::string([accountID UTF8String]), + [Utils dictionnaryToMap:details]); } -- (int) getMessageStatus:(uint64_t) msgID -{ - return getMessageStatus(msgID); +- (int)getMessageStatus:(uint64_t)msgID { + return getMessageStatus(msgID); } -- (void) registerConfigurationHandler -{ - std::map<std::string, std::shared_ptr<CallbackWrapperBase>> confHandlers; - - confHandlers.insert(exportable_callback<ConfigurationSignal::IncomingAccountMessage>( - [&](const std::string& account_id, - const std::string& from, - const std::map<std::string, std::string>& payloads) { - - NSDictionary* userInfo = @{@"accountID": [NSString stringWithUTF8String:account_id.c_str()], - @"from": [NSString stringWithUTF8String:from.c_str()], - @"payloads": [Utils mapToDictionnary:payloads]}; - - NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; - [nc postNotificationName:@"IncomingAccountMessage" object:self userInfo:userInfo]; - })); - - confHandlers.insert(exportable_callback<ConfigurationSignal::AccountsChanged>([&](){ +- (void)registerConfigurationHandler { + std::map<std::string, std::shared_ptr<CallbackWrapperBase>> confHandlers; + + confHandlers.insert( + exportable_callback<ConfigurationSignal::IncomingAccountMessage>( + [&](const std::string& account_id, const std::string& from, + const std::map<std::string, std::string>& payloads) { + + NSDictionary* userInfo = @{ + @"accountID" : [NSString stringWithUTF8String:account_id.c_str()], + @"from" : [NSString stringWithUTF8String:from.c_str()], + @"payloads" : [Utils mapToDictionnary:payloads] + }; + + NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; + [nc postNotificationName:@"IncomingAccountMessage" + object:self + userInfo:userInfo]; + })); + + confHandlers.insert( + exportable_callback<ConfigurationSignal::AccountsChanged>([&]() { NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; - [nc postNotificationName:@"AccountsChanged" object:[ConfigurationManagerAdaptator sharedManager]]; - })); - - registerConfHandlers(confHandlers); + [nc postNotificationName:@"AccountsChanged" + object:[ConfigurationManagerAdaptator sharedManager]]; + })); + + registerConfHandlers(confHandlers); } @end diff --git a/Ring/Ring/DRingAdaptator.h b/Ring/Ring/DRingAdaptator.h index db9d9a747518c071a2a5251e42f58fecafa3012c..312432dc2fc59a07ffa2b2b0f7d507c4390fd02e 100644 --- a/Ring/Ring/DRingAdaptator.h +++ b/Ring/Ring/DRingAdaptator.h @@ -15,16 +15,16 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA. */ #import <Foundation/Foundation.h> @interface DRingAdaptator : NSObject -- (BOOL) initDaemon; -- (BOOL) startDaemon; -- (void) fini; -- (void) pollEvents; -- (nonnull NSString*) getVersion; +- (BOOL)initDaemon; +- (BOOL)startDaemon; +- (void)fini; +- (void)pollEvents; +- (nonnull NSString*)getVersion; @end - diff --git a/Ring/Ring/DRingAdaptator.mm b/Ring/Ring/DRingAdaptator.mm index bd44462ee5983c616601e78afc678136bbc35c4b..1152dbffa4a2a9ce603c7126f8c00e59daa861a3 100644 --- a/Ring/Ring/DRingAdaptator.mm +++ b/Ring/Ring/DRingAdaptator.mm @@ -15,7 +15,8 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA. */ #import "DRingAdaptator.h" @@ -24,30 +25,25 @@ @implementation DRingAdaptator -- (BOOL) initDaemon -{ - int flag = DRing::DRING_FLAG_CONSOLE_LOG | DRing::DRING_FLAG_DEBUG; - return DRing::init(static_cast<DRing::InitFlag>(flag)); +- (BOOL)initDaemon { + int flag = DRing::DRING_FLAG_CONSOLE_LOG | DRing::DRING_FLAG_DEBUG; + return DRing::init(static_cast<DRing::InitFlag>(flag)); } -- (BOOL) startDaemon -{ - return DRing::start(); +- (BOOL)startDaemon { + return DRing::start(); } -- (void) fini -{ - DRing::fini(); +- (void)fini { + DRing::fini(); } -- (void) pollEvents -{ - DRing::pollEvents(); +- (void)pollEvents { + DRing::pollEvents(); } -- (NSString*)getVersion -{ - return [NSString stringWithUTF8String:DRing::version()]; +- (NSString*)getVersion { + return [NSString stringWithUTF8String:DRing::version()]; } @end diff --git a/Ring/Ring/MeViewController.swift b/Ring/Ring/MeViewController.swift index 3d8c22889068b3cd7f8fc5bb91d4339058e3404b..7d9a6fbf2ed19ffa1461372f9228580e3f643c1e 100644 --- a/Ring/Ring/MeViewController.swift +++ b/Ring/Ring/MeViewController.swift @@ -21,14 +21,14 @@ import UIKit class MeViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { - + // MARK: - Properties let accountModel = AccountModel.sharedInstance @IBOutlet weak var accountTableView: UITableView! @IBOutlet weak var nameLabel: UILabel! @IBOutlet weak var qrImageView: UIImageView! - - //MARK: - UIViewController + + // MARK: - UIViewController override func viewDidLoad() { super.viewDidLoad() @@ -44,74 +44,74 @@ class MeViewController: UIViewController, UITableViewDelegate, UITableViewDataSo override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() } - - //MARK: - QRCode + + // MARK: - QRCode func createQRFromString(str: String) { - + let data = str.dataUsingEncoding(NSISOLatin1StringEncoding, allowLossyConversion: false) - + let filter = CIFilter(name: "CIQRCodeGenerator") filter!.setValue(data, forKey: "inputMessage") - - let qrImage:CIImage = filter!.outputImage! + + let qrImage: CIImage = filter!.outputImage! let scaleX = qrImageView.frame.size.width / qrImage.extent.size.width let scaleY = qrImageView.frame.size.height / qrImage.extent.size.height - + let resultQrImage = qrImage.imageByApplyingTransform(CGAffineTransformMakeScale(scaleX, scaleY)) qrImageView.image = UIImage(CIImage: resultQrImage) } - + // MARK: - TableView func numberOfSectionsInTableView(tableView: UITableView) -> Int { return 1; } - + func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return accountModel.accountList.count + 1 } - + func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - + if indexPath.row < accountModel.accountList.count { let cell = tableView.dequeueReusableCellWithIdentifier("accountTableCell", forIndexPath: indexPath) as! AccountTableViewCell let account = accountModel.accountList[indexPath.row] - + cell.account = account cell.accountNameLabel.text = account.alias cell.activeSwitch.setOn(account.isEnabled, animated: false) cell.accountTypeLabel.text = account.accountType.rawValue - + return cell } else { let cell = tableView.dequeueReusableCellWithIdentifier("addAccountTableCell", forIndexPath: indexPath) return cell } - + } - + func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { if indexPath.row == accountModel.accountList.count { accountModel.addAccount() accountTableView.reloadData() } } - + func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool { if indexPath.row == accountModel.accountList.count { return false } return true } - + func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { if (editingStyle == UITableViewCellEditingStyle.Delete) { accountModel.removeAccount(indexPath.row) accountTableView.reloadData() } } - - //MARK: - Actions + + // MARK: - Actions @IBAction func addAccountClicked(sender: AnyObject) { let index = NSIndexPath(forRow: accountModel.accountList.count, inSection: 0) accountTableView.selectRowAtIndexPath(index, animated: false, scrollPosition: UITableViewScrollPosition.None) diff --git a/Ring/Ring/Ring-Bridging-Header.h b/Ring/Ring/Ring-Bridging-Header.h index 6ab7dee0afc9ef94f17837d6e83007f819744c7c..33faec73bd3c58e56379f7d410b00226062688e6 100644 --- a/Ring/Ring/Ring-Bridging-Header.h +++ b/Ring/Ring/Ring-Bridging-Header.h @@ -15,13 +15,14 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA. */ - // -// Use this file to import your target's public headers that you would like to expose to Swift. +// Use this file to import your target's public headers that you would like to +// expose to Swift. // -#import "DRingAdaptator.h" -#import "ConfigurationManagerAdaptator.h" \ No newline at end of file +#import "ConfigurationManagerAdaptator.h" +#import "DRingAdaptator.h" \ No newline at end of file diff --git a/Ring/Ring/Utils.h b/Ring/Ring/Utils.h index 0dc9984377ce65214015ffcc4902fab3397f6fd5..063752b5a3e168ac524b7bdf4366d93fbb12049b 100644 --- a/Ring/Ring/Utils.h +++ b/Ring/Ring/Utils.h @@ -15,19 +15,21 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA. */ #import <Foundation/Foundation.h> +#import <map> #import <string> #import <vector> -#import <map> @interface Utils : NSObject -+ (NSArray*) vectorToArray: (const std::vector<std::string>&) vector; -+ (NSMutableDictionary*) mapToDictionnary: (const std::map<std::string, std::string>&) map; -+ (std::map<std::string, std::string>) dictionnaryToMap: (NSDictionary*) dict; ++ (NSArray*)vectorToArray:(const std::vector<std::string>&)vector; ++ (NSMutableDictionary*)mapToDictionnary: + (const std::map<std::string, std::string>&)map; ++ (std::map<std::string, std::string>)dictionnaryToMap:(NSDictionary*)dict; @end diff --git a/Ring/Ring/Utils.mm b/Ring/Ring/Utils.mm index d9ec801ee8de7195c5387d3a2a0515fcdeccd5bc..332ff1157eed0f2c3b1f542d9c77cdc5f624b8ba 100644 --- a/Ring/Ring/Utils.mm +++ b/Ring/Ring/Utils.mm @@ -15,43 +15,45 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + * USA. */ #import "Utils.h" @implementation Utils -+ (NSArray*) vectorToArray: (const std::vector<std::string>&) vector -{ - NSMutableArray* resArray = [NSMutableArray new]; - std::for_each(vector.begin(), vector.end(), ^(std::string str) { - id nsstr = [NSString stringWithUTF8String:str.c_str()]; - [resArray addObject:nsstr]; - }); - return resArray; ++ (NSArray*)vectorToArray:(const std::vector<std::string>&)vector { + NSMutableArray* resArray = [NSMutableArray new]; + std::for_each(vector.begin(), vector.end(), ^(std::string str) { + id nsstr = [NSString stringWithUTF8String:str.c_str()]; + [resArray addObject:nsstr]; + }); + return resArray; } -+ (NSMutableDictionary*) mapToDictionnary: (const std::map<std::string, std::string>&) map -{ - NSMutableDictionary* resDictionnary = [NSMutableDictionary new]; ++ (NSMutableDictionary*)mapToDictionnary: + (const std::map<std::string, std::string>&)map { + NSMutableDictionary* resDictionnary = [NSMutableDictionary new]; - std::for_each(map.begin(), map.end(), ^(std::pair<std::string, std::string> keyValue) { + std::for_each( + map.begin(), map.end(), ^(std::pair<std::string, std::string> keyValue) { id key = [NSString stringWithUTF8String:keyValue.first.c_str()]; id value = [NSString stringWithUTF8String:keyValue.second.c_str()]; [resDictionnary setObject:value forKey:key]; - }); + }); - return resDictionnary; + return resDictionnary; } -+ (std::map<std::string, std::string>) dictionnaryToMap: (NSDictionary*) dict -{ - std::map<std::string, std::string>resMap; - for (id key in dict) - resMap.insert(std::pair<std::string, std::string>(std::string([key UTF8String]), std::string([[dict objectForKey:key] UTF8String]))); ++ (std::map<std::string, std::string>)dictionnaryToMap:(NSDictionary*)dict { + std::map<std::string, std::string> resMap; + for (id key in dict) + resMap.insert(std::pair<std::string, std::string>( + std::string([key UTF8String]), + std::string([[dict objectForKey:key] UTF8String]))); - return resMap; + return resMap; } @end