Try to make signals.h.py more cross-python-version compatible.
git-svn-id: svn://localhost/ardour2/branches/3.0@12285 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
b936f971e8
commit
b54779ec41
@ -25,15 +25,16 @@
|
||||
# than this if you want to read the code!
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
import sys
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print 'Syntax: %s <path>' % sys.argv[0]
|
||||
print('Syntax: %s <path>' % sys.argv[0])
|
||||
sys.exit(1)
|
||||
|
||||
f = open(sys.argv[1], 'w')
|
||||
|
||||
print >>f,"/** THIS FILE IS AUTOGENERATED by signals.py: CHANGES WILL BE LOST */\n"
|
||||
print("/** THIS FILE IS AUTOGENERATED by signals.py: CHANGES WILL BE LOST */\n", file=f)
|
||||
|
||||
# Produce a comma-separated string from a list of substrings,
|
||||
# giving an optional prefix to each substring
|
||||
@ -75,48 +76,48 @@ def signal(f, n, v):
|
||||
typename = "typename "
|
||||
|
||||
if v:
|
||||
print >>f, "/** A signal with %d parameters (specialisation for a void return) */" % n
|
||||
print("/** A signal with %d parameters (specialisation for a void return) */" % n, file=f)
|
||||
else:
|
||||
print >>f, "/** A signal with %d parameters */" % n
|
||||
print("/** A signal with %d parameters */" % n, file=f)
|
||||
if v:
|
||||
print >>f,"template <%s>" % comma_separated(An, "typename ")
|
||||
print >>f,"class Signal%d<%s> : public SignalBase" % (n, comma_separated(["void"] + An))
|
||||
print("template <%s>" % comma_separated(An, "typename "), file=f)
|
||||
print("class Signal%d<%s> : public SignalBase" % (n, comma_separated(["void"] + An)), file=f)
|
||||
else:
|
||||
print >>f,"template <%s>" % comma_separated(["R"] + An + ["C = OptionalLastValue<R> "], "typename ")
|
||||
print >>f,"class Signal%d : public SignalBase" % n
|
||||
print("template <%s>" % comma_separated(["R"] + An + ["C = OptionalLastValue<R> "], "typename "), file=f)
|
||||
print("class Signal%d : public SignalBase" % n, file=f)
|
||||
|
||||
print >>f,"{"
|
||||
print >>f,"public:"
|
||||
print >>f,""
|
||||
print("{", file=f)
|
||||
print("public:", file=f)
|
||||
print("", file=f)
|
||||
if v:
|
||||
print >>f,"\ttypedef boost::function<void(%s)> slot_function_type;" % comma_separated(An)
|
||||
print >>f,"\ttypedef void result_type;"
|
||||
print("\ttypedef boost::function<void(%s)> slot_function_type;" % comma_separated(An), file=f)
|
||||
print("\ttypedef void result_type;", file=f)
|
||||
else:
|
||||
print >>f,"\ttypedef boost::function<R(%s)> slot_function_type;" % comma_separated(An)
|
||||
print >>f,"\ttypedef boost::optional<R> result_type;"
|
||||
print("\ttypedef boost::function<R(%s)> slot_function_type;" % comma_separated(An), file=f)
|
||||
print("\ttypedef boost::optional<R> result_type;", file=f)
|
||||
|
||||
print >>f,""
|
||||
print("", file=f)
|
||||
|
||||
print >>f,"private:"
|
||||
print("private:", file=f)
|
||||
|
||||
print >>f,"""
|
||||
print("""
|
||||
/** The slots that this signal will call on emission */
|
||||
typedef std::map<boost::shared_ptr<Connection>, slot_function_type> Slots;
|
||||
Slots _slots;
|
||||
"""
|
||||
""", file=f)
|
||||
|
||||
print >>f,"public:"
|
||||
print >>f,""
|
||||
print >>f,"\t~Signal%d () {" % n
|
||||
print("public:", file=f)
|
||||
print("", file=f)
|
||||
print("\t~Signal%d () {" % n, file=f)
|
||||
|
||||
print >>f,"\t\tboost::mutex::scoped_lock lm (_mutex);"
|
||||
print >>f,"\t\t/* Tell our connection objects that we are going away, so they don't try to call us */"
|
||||
print >>f,"\t\tfor (%sSlots::iterator i = _slots.begin(); i != _slots.end(); ++i) {" % typename
|
||||
print("\t\tboost::mutex::scoped_lock lm (_mutex);", file=f)
|
||||
print("\t\t/* Tell our connection objects that we are going away, so they don't try to call us */", file=f)
|
||||
print("\t\tfor (%sSlots::iterator i = _slots.begin(); i != _slots.end(); ++i) {" % typename, file=f)
|
||||
|
||||
print >>f,"\t\t\ti->first->signal_going_away ();"
|
||||
print >>f,"\t\t}"
|
||||
print >>f,"\t}"
|
||||
print >>f,""
|
||||
print("\t\t\ti->first->signal_going_away ();", file=f)
|
||||
print("\t\t}", file=f)
|
||||
print("\t}", file=f)
|
||||
print("", file=f)
|
||||
|
||||
if n == 0:
|
||||
p = ""
|
||||
@ -125,11 +126,11 @@ def signal(f, n, v):
|
||||
p = ", %s" % comma_separated(Anan)
|
||||
q = ", %s" % comma_separated(an)
|
||||
|
||||
print >>f,"\tstatic void compositor (%sboost::function<void(%s)> f, EventLoop* event_loop, EventLoop::InvalidationRecord* ir%s) {" % (typename, comma_separated(An), p)
|
||||
print >>f,"\t\tevent_loop->call_slot (ir, boost::bind (f%s));" % q
|
||||
print >>f,"\t}"
|
||||
print("\tstatic void compositor (%sboost::function<void(%s)> f, EventLoop* event_loop, EventLoop::InvalidationRecord* ir%s) {" % (typename, comma_separated(An), p), file=f)
|
||||
print("\t\tevent_loop->call_slot (ir, boost::bind (f%s));" % q, file=f)
|
||||
print("\t}", file=f)
|
||||
|
||||
print >>f,"""
|
||||
print("""
|
||||
/** Arrange for @a slot to be executed whenever this signal is emitted.
|
||||
Store the connection that represents this arrangement in @a c.
|
||||
|
||||
@ -185,7 +186,7 @@ def signal(f, n, v):
|
||||
if (ir) {
|
||||
ir->event_loop = event_loop;
|
||||
}
|
||||
"""
|
||||
""", file=f)
|
||||
u = []
|
||||
for i in range(0, n):
|
||||
u.append("_%d" % (i + 1))
|
||||
@ -195,9 +196,9 @@ def signal(f, n, v):
|
||||
else:
|
||||
p = ", %s" % comma_separated(u)
|
||||
|
||||
print >>f,"\t\tclist.add_connection (_connect (boost::bind (&compositor, slot, event_loop, ir%s)));" % p
|
||||
print("\t\tclist.add_connection (_connect (boost::bind (&compositor, slot, event_loop, ir%s)));" % p, file=f)
|
||||
|
||||
print >>f,"""
|
||||
print("""
|
||||
}
|
||||
|
||||
/** See notes for the ScopedConnectionList variant of this function. This
|
||||
@ -213,34 +214,34 @@ def signal(f, n, v):
|
||||
if (ir) {
|
||||
ir->event_loop = event_loop;
|
||||
}
|
||||
"""
|
||||
print >>f,"\t\tc = _connect (boost::bind (&compositor, slot, event_loop, ir%s));" % p
|
||||
print >>f,"\t}"
|
||||
""", file=f)
|
||||
print("\t\tc = _connect (boost::bind (&compositor, slot, event_loop, ir%s));" % p, file=f)
|
||||
print("\t}", file=f)
|
||||
|
||||
print >>f,"""
|
||||
print("""
|
||||
/** Emit this signal. This will cause all slots connected to it be executed
|
||||
in the order that they were connected (cross-thread issues may alter
|
||||
the precise execution time of cross-thread slots).
|
||||
*/
|
||||
"""
|
||||
""", file=f)
|
||||
|
||||
if v:
|
||||
print >>f,"\tvoid operator() (%s)" % comma_separated(Anan)
|
||||
print("\tvoid operator() (%s)" % comma_separated(Anan), file=f)
|
||||
else:
|
||||
print >>f,"\ttypename C::result_type operator() (%s)" % comma_separated(Anan)
|
||||
print >>f,"\t{"
|
||||
print >>f,"\t\t/* First, take a copy of our list of slots as it is now */"
|
||||
print >>f,""
|
||||
print >>f,"\t\tSlots s;"
|
||||
print >>f,"\t\t{"
|
||||
print >>f,"\t\t\tboost::mutex::scoped_lock lm (_mutex);"
|
||||
print >>f,"\t\t\ts = _slots;"
|
||||
print >>f,"\t\t}"
|
||||
print >>f,""
|
||||
print("\ttypename C::result_type operator() (%s)" % comma_separated(Anan), file=f)
|
||||
print("\t{", file=f)
|
||||
print("\t\t/* First, take a copy of our list of slots as it is now */", file=f)
|
||||
print("", file=f)
|
||||
print("\t\tSlots s;", file=f)
|
||||
print("\t\t{", file=f)
|
||||
print("\t\t\tboost::mutex::scoped_lock lm (_mutex);", file=f)
|
||||
print("\t\t\ts = _slots;", file=f)
|
||||
print("\t\t}", file=f)
|
||||
print("", file=f)
|
||||
if not v:
|
||||
print >>f,"\t\tstd::list<R> r;"
|
||||
print >>f,"\t\tfor (%sSlots::iterator i = s.begin(); i != s.end(); ++i) {" % typename
|
||||
print >>f,"""
|
||||
print("\t\tstd::list<R> r;", file=f)
|
||||
print("\t\tfor (%sSlots::iterator i = s.begin(); i != s.end(); ++i) {" % typename, file=f)
|
||||
print("""
|
||||
/* We may have just called a slot, and this may have resulted in
|
||||
disconnection of other slots from us. The list copy means that
|
||||
this won't cause any problems with invalidated iterators, but we
|
||||
@ -252,53 +253,53 @@ def signal(f, n, v):
|
||||
still_there = _slots.find (i->first) != _slots.end ();
|
||||
}
|
||||
|
||||
if (still_there) {"""
|
||||
if (still_there) {""", file=f)
|
||||
if v:
|
||||
print >>f,"\t\t\t\t(i->second)(%s);" % comma_separated(an)
|
||||
print("\t\t\t\t(i->second)(%s);" % comma_separated(an), file=f)
|
||||
else:
|
||||
print >>f,"\t\t\t\tr.push_back ((i->second)(%s));" % comma_separated(an)
|
||||
print >>f,"\t\t\t}"
|
||||
print >>f,"\t\t}"
|
||||
print >>f,""
|
||||
print("\t\t\t\tr.push_back ((i->second)(%s));" % comma_separated(an), file=f)
|
||||
print("\t\t\t}", file=f)
|
||||
print("\t\t}", file=f)
|
||||
print("", file=f)
|
||||
if not v:
|
||||
print >>f,"\t\t/* Call our combiner to do whatever is required to the result values */"
|
||||
print >>f,"\t\tC c;"
|
||||
print >>f,"\t\treturn c (r.begin(), r.end());"
|
||||
print >>f,"\t}"
|
||||
print("\t\t/* Call our combiner to do whatever is required to the result values */", file=f)
|
||||
print("\t\tC c;", file=f)
|
||||
print("\t\treturn c (r.begin(), r.end());", file=f)
|
||||
print("\t}", file=f)
|
||||
|
||||
print >>f,"""
|
||||
print("""
|
||||
bool empty () {
|
||||
boost::mutex::scoped_lock lm (_mutex);
|
||||
return _slots.empty ();
|
||||
}
|
||||
"""
|
||||
""", file=f)
|
||||
|
||||
if v:
|
||||
tp = comma_separated(["void"] + An)
|
||||
else:
|
||||
tp = comma_separated(["R"] + An + ["C"])
|
||||
|
||||
print >>f,"private:"
|
||||
print >>f,""
|
||||
print >>f,"\tfriend class Connection;"
|
||||
print("private:", file=f)
|
||||
print("", file=f)
|
||||
print("\tfriend class Connection;", file=f)
|
||||
|
||||
print >>f,"""
|
||||
print("""
|
||||
boost::shared_ptr<Connection> _connect (slot_function_type f)
|
||||
{
|
||||
boost::shared_ptr<Connection> c (new Connection (this));
|
||||
boost::mutex::scoped_lock lm (_mutex);
|
||||
_slots[c] = f;
|
||||
return c;
|
||||
}"""
|
||||
}""", file=f)
|
||||
|
||||
print >>f,"""
|
||||
print("""
|
||||
void disconnect (boost::shared_ptr<Connection> c)
|
||||
{
|
||||
boost::mutex::scoped_lock lm (_mutex);
|
||||
_slots.erase (c);
|
||||
}
|
||||
};
|
||||
"""
|
||||
""", file=f)
|
||||
|
||||
for i in range(0, 6):
|
||||
signal(f, i, False)
|
||||
|
Loading…
Reference in New Issue
Block a user