/* Copyright (c) 2008-09 Joshua R. Rodgers Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ %include "phppointers.i" //Ignore some public members we do not want exposed to PHP %ignore aw_sequence_3x3::bound; %ignore aw_sequence_3x3::get_sequence(); %ignore aw_sequence_5x5::bound; %ignore aw_sequence_5x5::get_sequence(); //Define data structures needed to wrap sequences into PHP %inline { class aw_sequence_3x3 { public: static const int bound = 3; private: int sequence[bound][bound]; public: aw_sequence_3x3() { memset(sequence, 0, sizeof(sequence)); } void set_element(int r, int c, int value) { register int upper_bound = bound-1; // Attempt to place in a register, so we can do things quickly. if(r < 0 || c < 0 || r > upper_bound || c > upper_bound) zend_error(E_WARNING, "Out of bounds. Call ignored."); else sequence[r][c] = value; } int get_element(int r, int c) { register int upper_bound = bound-1; // Attempt to place in a register, so we can do things quickly. if(r < 0 || c < 0 || r > upper_bound || c > upper_bound) zend_error(E_WARNING, "Out of bounds. Call ignored."); else return sequence[r][c]; } int (*get_sequence())[bound] { return sequence; } }; class aw_sequence_5x5 { public: static const int bound = 5; private: int sequence[bound][bound]; public: aw_sequence_5x5() { memset(sequence, 0, sizeof(sequence)); } void set_element(int r, int c, int value) { register int upper_bound = bound-1; // Attempt to place in a register, so we can do things quickly. if(r < 0 || c < 0 || r > upper_bound || c > upper_bound) zend_error(E_WARNING, "AWSDK: Out of bounds. Call ignored."); else sequence[r][c] = value; } int get_element(int r, int c) { register int upper_bound = bound-1; // Attempt to place in a register, so we can do things quickly. if(r < 0 || c < 0 || r > upper_bound || upper_bound) zend_error(E_WARNING, "AWSDK: Out of bounds. Call ignored."); else return sequence[r][c]; } int (*get_sequence())[bound] { return sequence; } }; } //Declare methods as extern, to apply typemappings extern int aw_php_query (int x_sector, int z_sector, aw_sequence_3x3 &REF); extern int aw_php_query_5x5 (int x_sector, int z_sector, aw_sequence_5x5 &REF); //Rename methods to their C counter-parts' names. %rename(aw_query) aw_php_query; %rename(aw_query_5x5) aw_php_query_5x5; //Define wrapper methods %inline { int aw_php_query(int x_sector, int z_sector, aw_sequence_3x3 &sequence) { return aw_query(x_sector, z_sector, sequence.get_sequence()); } int aw_php_query_5x5(int x_sector, int z_sector, aw_sequence_5x5 &sequence) { return aw_query_5x5(x_sector, z_sector, sequence.get_sequence()); } }