{"action":"created","issue":{"url":"https://api.github.com/repos/opensim-org/opensim-core/issues/574","labels_url":"https://api.github.com/repos/opensim-org/opensim-core/issues/574/labels{/name}","comments_url":"https://api.github.com/repos/opensim-org/opensim-core/issues/574/comments","events_url":"https://api.github.com/repos/opensim-org/opensim-core/issues/574/events","html_url":"https://github.com/opensim-org/opensim-core/pull/574","id":99855522,"number":574,"title":"Use in-class member initializers for OpenSim_DECLARE_PROPERTY","user":{"login":"chrisdembia","id":846001,"avatar_url":"https://avatars.githubusercontent.com/u/846001?v=3","gravatar_id":"","url":"https://api.github.com/users/chrisdembia","html_url":"https://github.com/chrisdembia","followers_url":"https://api.github.com/users/chrisdembia/followers","following_url":"https://api.github.com/users/chrisdembia/following{/other_user}","gists_url":"https://api.github.com/users/chrisdembia/gists{/gist_id}","starred_url":"https://api.github.com/users/chrisdembia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chrisdembia/subscriptions","organizations_url":"https://api.github.com/users/chrisdembia/orgs","repos_url":"https://api.github.com/users/chrisdembia/repos","events_url":"https://api.github.com/users/chrisdembia/events{/privacy}","received_events_url":"https://api.github.com/users/chrisdembia/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-08-09T02:47:58Z","updated_at":"2015-08-09T19:47:50Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/opensim-org/opensim-core/pulls/574","html_url":"https://github.com/opensim-org/opensim-core/pull/574","diff_url":"https://github.com/opensim-org/opensim-core/pull/574.diff","patch_url":"https://github.com/opensim-org/opensim-core/pull/574.patch"},"body":"We've all forgotten to call `constructProperty_my_prop()` in our constructors. Thankfully, we get a great error message when this happens.\r\n\r\nWith the introduction of inputs, outputs, and structural connectors, there's a lot more that must happen during construction and we need a way to manage all of these tasks. For this reason, @aseth1 introduced `constructInfrastructure()`; unfortunately there are some issues with that approach.\r\n\r\nAn alternative is to avoid adding any code into constructors by using C++11 in-class member initializers.\r\n\r\nThis PR is an attempt to allow one to initialize (and set the default value for) required properties (those declared with OpenSim_DECLARE_PROPERTY) from the macro call, removing the need for a call to `constructProperty_my_prop()`. For example:\r\n\r\n```\r\nOpenSim_DECLARE_PROPERTY(mass, double, \"Subject mass\", SimTK::NaN);\r\n```\r\n\r\nWith this new macro, we automatically add the default value to the doxygen documentation for the property (should it be called initial value instead?). Automatically documenting the default value is a huge plus; since otherwise it's undocumented or it is documented in an unmaintainable way.\r\n\r\nHere's the documentation for the macro:\r\n\r\n![image](https://cloud.githubusercontent.com/assets/846001/9153355/b65b08fc-3e05-11e5-800c-807c102270b8.png)\r\n\r\nHere's the brief description for 3 properties that use the new macro:\r\n![image](https://cloud.githubusercontent.com/assets/846001/9153358/dd7a0532-3e05-11e5-8ad3-fa793300247c.png)\r\n\r\nAnd here's a detailed description:\r\n![image](https://cloud.githubusercontent.com/assets/846001/9153359/eccd1240-3e05-11e5-8115-1b7fb9d56adc.png)\r\n\r\nI want this change to be backwards-compatible, so I introduced an overloaded macro. This adds quite a bit of complexity. For example, compiler errors will be harder to interpret, since there are more intermediate macros.\r\n\r\nIf we decide that the complexity is unwarranted, I can create a separate macro `OpenSim_DECLARE_PROPERTY_INIT` that takes the additional argument.\r\n\r\nIf we like the change, I can go ahead and make the same change for the remaining property macros. Notice that this PR does not go into the master branch; it goes into a feature branch."},"comment":{"url":"https://api.github.com/repos/opensim-org/opensim-core/issues/comments/129229977","html_url":"https://github.com/opensim-org/opensim-core/pull/574#issuecomment-129229977","issue_url":"https://api.github.com/repos/opensim-org/opensim-core/issues/574","id":129229977,"user":{"login":"sherm1","id":4088016,"avatar_url":"https://avatars.githubusercontent.com/u/4088016?v=3","gravatar_id":"","url":"https://api.github.com/users/sherm1","html_url":"https://github.com/sherm1","followers_url":"https://api.github.com/users/sherm1/followers","following_url":"https://api.github.com/users/sherm1/following{/other_user}","gists_url":"https://api.github.com/users/sherm1/gists{/gist_id}","starred_url":"https://api.github.com/users/sherm1/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sherm1/subscriptions","organizations_url":"https://api.github.com/users/sherm1/orgs","repos_url":"https://api.github.com/users/sherm1/repos","events_url":"https://api.github.com/users/sherm1/events{/privacy}","received_events_url":"https://api.github.com/users/sherm1/received_events","type":"User","site_admin":false},"created_at":"2015-08-09T19:47:50Z","updated_at":"2015-08-09T19:47:50Z","body":"> We could use the default constructor for each object to initialize the property if the user doesn't provide an initial value, but I prefer requiring a default value.\r\n\r\nUsing a default constructor would probably be a reasonable choice since that's what C++ does anyway, so people will expect that behavior. That would allow for backwards compatibility at the macro. For compatibility with existing `constructProperty_xxx` calls we could still generate those methods and maybe deprecate them.\r\n\r\nWe would need to invent some defaults for the built-in types, like setting an int property to 0."}}