Refactor Java director swig_override array code
Remove code duplication: Use new Swig::BoolArray to replace multiple instances of ZeroedBoolArray. Refactors #403 and #413.
This commit is contained in:
parent
b06ec2c847
commit
775afd3579
2 changed files with 15 additions and 7 deletions
|
|
@ -209,6 +209,20 @@ namespace Swig {
|
|||
}
|
||||
};
|
||||
|
||||
// Zero initialized bool array
|
||||
template<size_t N> class BoolArray {
|
||||
bool array_[N];
|
||||
public:
|
||||
BoolArray() {
|
||||
memset(array_, sizeof(array_), 0);
|
||||
}
|
||||
bool& operator[](size_t n) {
|
||||
return array_[n];
|
||||
}
|
||||
bool operator[](size_t n) const {
|
||||
return array_[n];
|
||||
}
|
||||
};
|
||||
|
||||
// Utility classes and functions for exception handling.
|
||||
|
||||
|
|
|
|||
|
|
@ -4489,13 +4489,7 @@ public:
|
|||
Printf(f_directors_h, " return (n < %d ? swig_override[n] : false);\n", n_methods);
|
||||
Printf(f_directors_h, " }\n");
|
||||
Printf(f_directors_h, "protected:\n");
|
||||
Printf(f_directors_h, " struct ZeroedBoolArray {\n");
|
||||
Printf(f_directors_h, " bool array[%d];\n", n_methods);
|
||||
Printf(f_directors_h, " ZeroedBoolArray() { memset(array, sizeof(array), 0); }\n");
|
||||
Printf(f_directors_h, " bool& operator[](int n) { return array[n]; }\n");
|
||||
Printf(f_directors_h, " bool operator[](int n) const { return array[n]; }\n");
|
||||
Printf(f_directors_h, " };\n");
|
||||
Printf(f_directors_h, " ZeroedBoolArray swig_override;\n");
|
||||
Printf(f_directors_h, " Swig::BoolArray<%d> swig_override;\n", n_methods);
|
||||
|
||||
/* Emit the code to look up the class's methods, initialize the override array */
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue