Last active
November 3, 2015 13:09
-
-
Save varhub/c002b6405db170eaee7c to your computer and use it in GitHub Desktop.
Related to JdeRobot #211
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Code example related to | |
https://github.com/RoboticsURJC/JdeRobot/issues/211 | |
Additional docs: | |
- http://www.boost.org/doc/libs/1_59_0/libs/format/doc/format.html | |
- http://studiofreya.com/cpp/a-few-boostformat-examples/ | |
*/ | |
#include <iostream> | |
#include <boost/format.hpp> | |
int main(){ | |
/* this reduce code length but could produce collisions. Be aware | |
using namespace std; | |
using namespace boost; | |
*/ | |
string iceName = "NAME"; | |
string iceInterface("INTERFACE"); | |
/* Equivalent code for | |
https://github.com/reysam93/JdeRobot/blob/0bf2194392c941c91e72c822ae5708bd29cd9468/src/stable/components/visualHFSM/generate.cpp#L1013#L1029 | |
*/ | |
std::cout<<boost::format( | |
" # Contact to %1%\n\ | |
%1% = self.ic.propertyToProxy('automata.%2%.Proxy')\n\ | |
if(not %1%):\n\ | |
raise Exception('could not create proxy with %1%')\n\ | |
self.%1%Prx = %2%Prx.checkedCast(%1%)\n\ | |
if(not self.%1%Prx):\n\ | |
raise Exception('invalid proxy automata.%2%.Proxy')\n\ | |
print '%1% connected'\n\ | |
\n" | |
) % iceName % iceInterface; | |
/* Pay attention. | |
Above is a single string. | |
'\' at end of line means that this line continues below. | |
'\n' is Linux new line. This is worse than std::endl because | |
there are several combinations: | |
- \n Linux | |
- \r Unix (Mac) | |
- \r\n Windows | |
\n\ produces a new line without add spaces at end of line (lighter code!) | |
also is ease to use and remember. | |
Using ' for python strings because do not require escaping. | |
*/ | |
return 0; | |
} | |
/* Run it: | |
g++ generate_code.cpp | |
./a.out | |
# Contact to NAME | |
NAME = self.ic.propertyToProxy('automata.INTERFACE.Proxy') | |
if(not NAME): | |
raise Exception('could not create proxy with NAME') | |
self.NAMEPrx = INTERFACEPrx.checkedCast(NAME) | |
if(not self.NAMEPrx): | |
raise Exception('invalid proxy automata.INTERFACE.Proxy') | |
print 'NAME connected' | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment