Title: Template programming for schema independent code · Issue #1333 · IfcOpenShell/IfcOpenShell · GitHub
Open Graph Title: Template programming for schema independent code · Issue #1333 · IfcOpenShell/IfcOpenShell
X Title: Template programming for schema independent code · Issue #1333 · IfcOpenShell/IfcOpenShell
Description: If you case to IfcBaseEntity, you can use the latebound attribute access: IfcBaseEntity* space; auto attr = space->get("Name"); if (!attr->isNull()) { std::string name = *attr; } Otherwise you can do some sort of if statement (but it's u...
Open Graph Description: If you case to IfcBaseEntity, you can use the latebound attribute access: IfcBaseEntity* space; auto attr = space->get("Name"); if (!attr->isNull()) { std::string name = *attr; } Otherwise you can ...
X Description: If you case to IfcBaseEntity, you can use the latebound attribute access: IfcBaseEntity* space; auto attr = space->get("Name"); if (!attr->isNull()) { std::string name = *attr; } Ot...
Opengraph URL: https://github.com/IfcOpenShell/IfcOpenShell/issues/1333
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Template programming for schema independent code","articleBody":"If you case to IfcBaseEntity, you can use the latebound attribute access:\r\n\r\n```\r\nIfcBaseEntity* space;\r\nauto attr = space->get(\"Name\");\r\nif (!attr->isNull()) {\r\n std::string name = *attr; \r\n}\r\n```\r\n\r\nOtherwise you can do some sort of if statement (but it's ugly) either with\r\n\r\n`dynamic_cast\u003cIfc2x3::IfcSpace>` or `dynamic_cast\u003cIfc4::IfcSpace>` \r\n\r\nOr with `space->declaration().schema()` (I think)\r\n\r\nWe could also think of some sort of visitor:\r\n\r\n```\r\ntemplate \u003ctypename Schema>\r\nstd::string get_name(typename Schema::IfcSpace*) {\r\n...\r\n}\r\n\r\ntemplate \u003ctypename Fn>\r\nstd::string apply_visitor(IfcBaseEntity* x, Fn fn) {\r\n if (dynamic_cast\u003cIfc2x3::IfcSpace>(x)) {\r\n fn(dynamic_cast\u003cIfc2x3::IfcSpace>(x))\r\n } else (dynamic_cast\u003cIfc4::IfcSpace>(x)) { ...\r\n}\r\n\r\nIfcBaseEntity* space;\r\napply_visitor(space, get_name);\r\n```\r\n\r\nBut in that last approach it would be nice to be able to reuse it to other classes not only IfcSpace but I haven't found a way yet to do that.;\r\n\r\nMaybe the only way is to create some sort of meta schema that unifies all IFC schemas so that you have a \r\n\r\n`meta::IfcSpace` that is maybe a `boost::mpl::list` of (`Ifc2x3::IfcSpace`, `Ifc4::IfcSpace`, ...) so that you do a compile time iteration.\r\n\r\nhttps://sourceforge.net/p/ifcopenshell/discussion/1782717/thread/cc4c489825/?limit=25\r\n\r\nSee also http://blog.ifcopenshell.org/2019/12/v060.html","author":{"url":"https://github.com/aothms","@type":"Person","name":"aothms"},"datePublished":"2021-02-20T10:10:18Z","url":"https://github.com/IfcOpenShell/IfcOpenShell/issues/1333"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c39000c3-73a0-b2fc-1b61-50ef086f77ce |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C6DA:10AF43:7BB9F7:A9987D:6B04AAFA |
| html-safe-nonce | c4de3512961a5ff299f519af7bbd2db9af82517deea0e1974c98f4271bfc810a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNkRBOjEwQUY0Mzo3QkI5Rjc6QTk5ODdEOjZCMDRBQUZBIiwidmlzaXRvcl9pZCI6IjIyMjQ3MzY3MjgzMzI0MTM2OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 471965e33eb484c93110269958e7dd76a53b827bf79b8ddd4ac31db39c67a439 |
| hovercard-subject-tag | issue:812571172 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/IfcOpenShell/IfcOpenShell/1333/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9dbb8581879a69a5fa836ece95545ddfd4cc1a3a8037aa7e8a8098dfaed7c08b/IfcOpenShell/IfcOpenShell/issues/1333 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9dbb8581879a69a5fa836ece95545ddfd4cc1a3a8037aa7e8a8098dfaed7c08b/IfcOpenShell/IfcOpenShell/issues/1333 |
| og:image:alt | If you case to IfcBaseEntity, you can use the latebound attribute access: IfcBaseEntity* space; auto attr = space->get("Name"); if (!attr->isNull()) { std::string name = *attr; } Otherwise you can ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aothms |
| hostname | github.com |
| expected-hostname | github.com |
| None | f1d110ea058a0915c1d8aa3fc2069fa15801e128f591e5762525abe77490ecb1 |
| turbo-cache-control | no-preview |
| go-import | github.com/IfcOpenShell/IfcOpenShell git https://github.com/IfcOpenShell/IfcOpenShell.git |
| octolytics-dimension-user_id | 13692563 |
| octolytics-dimension-user_login | IfcOpenShell |
| octolytics-dimension-repository_id | 40473201 |
| octolytics-dimension-repository_nwo | IfcOpenShell/IfcOpenShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 40473201 |
| octolytics-dimension-repository_network_root_nwo | IfcOpenShell/IfcOpenShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ffa22a65e4c46d376940fe34b05e6a7e9c7fdb9b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width