diff --git a/Doc/Manual/Contract.html b/Doc/Manual/Contract.html index f6a4b5ad9..2711788cd 100644 --- a/Doc/Manual/Contract.html +++ b/Doc/Manual/Contract.html @@ -18,7 +18,7 @@ using it in a way that wasn't intended.
This chapter describes SWIG's support for software contracts. In the context
-of SWIG, a contract can be viewed as a constraint that is attached
+of SWIG, a contract can be viewed as a runtime constraint that is attached
to a declaration. For example, you can easily attach argument checking rules,
check the output values of a function and more.
When one of the rules is violated by a script, a runtime exception is
@@ -68,13 +68,81 @@ resulting module. For example:
>>> example.sqrt(-2)
Traceback (most recent call last):
File "%contract and classes
+The %contract directive can also be applied to class methods and constructors. For example:
+
+
+
+
+The way in which %contract is applied is exactly the same as the %feature directive.
+Thus, any contract that you specified for a base class will also be attached to inherited methods. For example:
+
+
+%contract Foo::bar(int x, int y) {
+require:
+ x > 0;
+ensure:
+ bar > 0;
+}
+
+%contract Foo::Foo(int a) {
+require:
+ a > 0;
+}
+
+class Foo {
+public:
+ Foo(int);
+ int bar(int, int);
+};
+
+
+
+
+In addition to this, separate contracts can be applied to both the base class and a derived class. For example:
+
+
+class Spam : public Foo {
+public:
+ int bar(int,int); // Gets contract defined for Foo::bar(int,int)
+};
+
+
+
+
+When more than one contract is applied, the conditions specified in a
+"require:" section are combined together using a logical-AND operation.
+In other words conditions specified for the base class and conditions
+specified for the derived class all must hold. In the above example,
+this means that both the arguments to Spam::bar must be positive.
+
+%contract Foo::bar(int x, int) {
+require:
+ x > 0;
+}
+
+%contract Spam::bar(int, int y) {
+require:
+ y > 0;
+}
+
+class Foo {
+public:
+ int bar(int,int); // Gets Foo::bar contract.
+};
+
+class Spam : public Foo {
+public:
+ int bar(int,int); // Gets Foo::bar and Spam::bar contract
+};
+
+Constant aggregation and %aggregate_check