# Get directory this script is in.
dirname = os.path.dirname(os.path.realpath(__file__))
+outdirname = "bindings/cxx"
+if not os.path.exists(os.path.join(outdirname, 'include/libsigrok')):
+ os.makedirs(os.path.join(outdirname, 'include/libsigrok'))
+
mapping = dict([
('sr_loglevel', ('LogLevel', 'Log verbosity level')),
('sr_packettype', ('PacketType', 'Type of datafeed packet')),
if name in mapping:
classes[member] = mapping[name]
-header = open(os.path.join(dirname, 'include/libsigrok/enums.hpp'), 'w')
-code = open(os.path.join(dirname, 'enums.cpp'), 'w')
+header = open(os.path.join(outdirname, 'include/libsigrok/enums.hpp'), 'w')
+code = open(os.path.join(outdirname, 'enums.cpp'), 'w')
for file in (header, code):
print >> file, "/* Generated file - edit enums.py instead! */"
# Template for beginning of private members.
header_private_template = """
private:
- static const std::map<enum {enumname}, const {classname} *> values;
+ static const std::map<enum {enumname}, const {classname} *> _values;
{classname}(enum {enumname} id, const char name[]);
"""
const {classname} *{classname}::get(int id)
{{
- return {classname}::values.at(static_cast<{enumname}>(id));
+ if (_values.find(static_cast<{enumname}>(id)) == _values.end())
+ throw Error(SR_ERR_ARG);
+
+ return {classname}::_values.at(static_cast<{enumname}>(id));
}}
"""
classname, classname, trimmed_name, classname, trimmed_name)
# Define map of enum values to constants
- print >> code, 'const std::map<enum %s, const %s *> %s::values = {' % (
+ print >> code, 'const std::map<enum %s, const %s *> %s::_values = {' % (
enum_name, classname, classname)
for name, trimmed_name in zip(member_names, trimmed_names):
print >> code, '\t{%s, %s::%s},' % (name, classname, trimmed_name)