Conversation
|
Idea: remove |
|
|
Another idea (which I'm not quite convinced of): |
|
or maybe |
|
And by the way, it would be nice to have also a "string" version yarp::os::makeVocab("abcd"); |
|
Actually there is a |
6b6de85 to
ed43a28
Compare
jgvictores
left a comment
There was a problem hiding this comment.
In its current state, the PR introduces some issues regarding SWIG bindings:
-
Regression on VOCABs defined in the global scope: The changes introduced at #1696 have been removed. Even with an advanced version of SWIG, there is no generation of VOCABs defined in the global scope required by interfaces (e.g. no
VOCAB_CM_POSITION). Not caught on Travis because of used SWIG version
Recovering some of thebindings/yarp.ilogic and the preprocessor protection should suffice. 😄 -
Malformed results via wrapped new
makeVocabfunction:
In [1]: yarp.encode("abcd")
Out[1]: 1684234849
In [2]: yarp.makeVocab('a','b','c','d')
Out[2]: <Swig Object of type 'int32_t *' at 0x7f95d9443840>Not caught on Travis because it's new. Could definitely be added in Lua tests at tests/test_vocab.lua! 😃
|
Thanks @jgvictores for checking the bindings part, I wasn't sure about the changes, but I thought that if the compiler and the test doesn't complain is ok 😅 About the 1.: createVocab takes place of VOCAB and it is now scoped, these changes you made are still necessary? |
| // We need a constexpr for efficient switching. | ||
| // Use as, for example, makeVocab('s','e','t') | ||
| constexpr yarp::conf::vocab32_t createVocab(char a, char b = 0, char c = 0, char d = 0) { | ||
| return ((((yarp::conf::vocab32_t)(d))<<24)+(((yarp::conf::vocab32_t)(c))<<16)+(((yarp::conf::vocab32_t)(b))<<8)+((yarp::conf::vocab32_t)(a))); |
There was a problem hiding this comment.
A bit cleaner:
return ((yarp::conf::vocab32_t)d << 24) + ((yarp::conf::vocab32_t)c << 16) + ((yarp::conf::vocab32_t)b << 8) + (yarp::conf::vocab32_t)a;I'd remove those parentheses around each parameter, the final return, and each C-style cast (ref), here and at VOCABX below, as an unnecessary remnant of the former implementation via C preprocessor macros.
There was a problem hiding this comment.
What would you think about c++-style casts, which are more explicit?
There was a problem hiding this comment.
Also I'd really appreciate if you could expand this on more than one line, and add them in the proper order (i.e. a-b-c-d, not d-c-b-a) in order to make it more readable, like here:
46b9edd to
be976de
Compare
| YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead") | ||
| constexpr int32_t VOCAB2(char a, char b) { return yarp::os::createVocab((a),(b),(0),(0)); } | ||
| YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead") | ||
| constexpr int32_t VOCAB1(char a) { return yarp::os::createVocab((a),(0),(0),(0)); } |
There was a problem hiding this comment.
Same as #1764 (comment): yarp::os::createVocab(a,b,c,d).
Moreover: - `Vocab` is now a namespace. - `vocab32_t` has been defined in yarp/conf/numeric.h
Moreover change test_vocab.lua to make it work after the changes in Vocab and add an additional test.
| YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead") | ||
| constexpr int32_t VOCAB2(char a, char b) { return yarp::os::createVocab(a,b,0,0); } | ||
| YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead") | ||
| constexpr int32_t VOCAB1(char a) { return yarp::os::createVocab(a,0,0,0); } |
There was a problem hiding this comment.
I think these methods should be returning yarp::conf::vocab32_t as well
This PR makes vocab constexpr.
Merge this PR after : robotology/robot-testing-framework#98
Please review code