M>http://www.nedbatchelder.com/code/cog/index_ru.html
http://www.pythonology.com/success&story=cog
Here's a concrete but slightly contrived example. The properties are described in an XML file:
<!-- Properties.xml -->
<props>
<property name='Id' type='String' />
<property name='RevNum' type='Integer' />
<property name='Subject' type='String' />
<property name='ModDate' type='Date' />
</props>
We can write a C++ file with inlined Python code:
// SchemaPropEnum.h
enum SchemaPropEnum {
/* [[[cog
import cog, handyxml
for p in handyxml.xpath('Properties.xml', '//property'):
cog.outl("Property%s," % p.name)
]]] */
// [[[end]]]
};
After running this file through Cog, it looks like this:
// SchemaPropEnum.h
enum SchemaPropEnum {
/* [[[cog
import cog, handyxml
for p in handyxml.xpath('Properties.xml', '//property'):
cog.outl("Property%s," % p.name)
]]] */
PropertyId,
PropertyRevNum,
PropertySubject,
PropertyModDate,
// [[[end]]]
};
... << RSDN@Home 1.1.4 stable rev. 510>>