{"action":"created","issue":{"url":"https://api.github.com/repos/gtorrent/gtorrent-core/issues/125","labels_url":"https://api.github.com/repos/gtorrent/gtorrent-core/issues/125/labels{/name}","comments_url":"https://api.github.com/repos/gtorrent/gtorrent-core/issues/125/comments","events_url":"https://api.github.com/repos/gtorrent/gtorrent-core/issues/125/events","html_url":"https://github.com/gtorrent/gtorrent-core/issues/125","id":66361980,"number":125,"title":"Alternative to global static settings dictionary map for config","user":{"login":"nyanpasu","id":6234817,"avatar_url":"https://avatars.githubusercontent.com/u/6234817?v=3","gravatar_id":"","url":"https://api.github.com/users/nyanpasu","html_url":"https://github.com/nyanpasu","followers_url":"https://api.github.com/users/nyanpasu/followers","following_url":"https://api.github.com/users/nyanpasu/following{/other_user}","gists_url":"https://api.github.com/users/nyanpasu/gists{/gist_id}","starred_url":"https://api.github.com/users/nyanpasu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nyanpasu/subscriptions","organizations_url":"https://api.github.com/users/nyanpasu/orgs","repos_url":"https://api.github.com/users/nyanpasu/repos","events_url":"https://api.github.com/users/nyanpasu/events{/privacy}","received_events_url":"https://api.github.com/users/nyanpasu/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":15,"created_at":"2015-04-04T20:21:44Z","updated_at":"2015-04-06T14:24:07Z","closed_at":null,"body":"Current implementation is a hash map with string keys to string values.\r\n\r\nIt's simple, but not effective.\r\n\r\nAlso a hash map is so fucking noob.\r\n\r\nI propose creating a new class called SettingsOption, which will contain:\r\n - Name\r\n - Value\r\n - Description (optional)\r\n - Type (optional)\r\n - Permitted values (i.e range, string regex)\r\n - Callback functions that will be called when a change occurs (so that any function could register for changes in option)\r\n\r\nThis could allow the config file to be self documenting when it's first generated.\r\n\r\nEven though most config options should be self documenting by name alone.\r\n\r\nAlong the way we could consider:\r\n - SettingSection (settingOption can be grouped by category)\r\n\r\nThe current Setting class will be replaced with a abstract Setting parent that will contain:\r\n - init\r\n - clean up\r\n - default\r\n - read/parse\r\n - write/update/generate\r\n\r\nAnd other modules will inherit from it, adding their own options."},"comment":{"url":"https://api.github.com/repos/gtorrent/gtorrent-core/issues/comments/90080713","html_url":"https://github.com/gtorrent/gtorrent-core/issues/125#issuecomment-90080713","issue_url":"https://api.github.com/repos/gtorrent/gtorrent-core/issues/125","id":90080713,"user":{"login":"IGI-111","id":7190144,"avatar_url":"https://avatars.githubusercontent.com/u/7190144?v=3","gravatar_id":"","url":"https://api.github.com/users/IGI-111","html_url":"https://github.com/IGI-111","followers_url":"https://api.github.com/users/IGI-111/followers","following_url":"https://api.github.com/users/IGI-111/following{/other_user}","gists_url":"https://api.github.com/users/IGI-111/gists{/gist_id}","starred_url":"https://api.github.com/users/IGI-111/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IGI-111/subscriptions","organizations_url":"https://api.github.com/users/IGI-111/orgs","repos_url":"https://api.github.com/users/IGI-111/repos","events_url":"https://api.github.com/users/IGI-111/events{/privacy}","received_events_url":"https://api.github.com/users/IGI-111/received_events","type":"User","site_admin":false},"created_at":"2015-04-06T14:24:07Z","updated_at":"2015-04-06T14:24:07Z","body":"@nyanpasu \r\n>Will we still be able to iterate through the options?\r\n\r\nWell you will just have to iterate through the map, but the only case where you'd have to do such a thing is when you're reading/writing them and that's handled in plain strings, what i wrote is the abstraction layer to use inside the application that will be generated by that very code.\r\n\r\n>How would one do it and be able to retrieve the correct values (their types?)?\r\n\r\nIn this particular instance I'm using static casts (they do compile time checks) so you just have to document what type each option is and specify it when you store or retrieve them, since C++ is statically typed there is no way to store the types, you have to tell the compiler each time you call ``put()`` or ``get()`` because templates cannot deduce the type on their own (this is not Haskell).\r\n\r\nThe good thing with this approach (versus dynamic casts) is that the coherence of the ``put()``s and ``get()``s is checked at compile time and not at run time.\r\nThough if you ever find a way to only specify the option type once without resorting to huge ugly type enums and switches i'll be interested."}}