Лучший способ:
Делают Ваш собственный матричный класс, тот способ, которым Вы управляете каждым последним аспектом его, включая проверку диапазона.
, например, Если Вам нравится" [x] [y]" нотация, сделайте это:
class my_matrix {
std::vector<std::vector<bool> >m;
public:
my_matrix(unsigned int x, unsigned int y) {
m.resize(x, std::vector<bool>(y,false));
}
class matrix_row {
std::vector<bool>& row;
public:
matrix_row(std::vector<bool>& r) : row(r) {
}
bool& operator[](unsigned int y) {
return row.at(y);
}
};
matrix_row& operator[](unsigned int x) {
return matrix_row(m.at(x));
}
};
// Example usage
my_matrix mm(100,100);
mm[10][10] = true;
нбар. Если Вы программируете как это тогда, C++ так же безопасен как все те другие "безопасные" языки.
The Model-View-ViewModel (MVVM) design pattern aims at achieving exactly that goal, and Josh Smith's excellent article explains how to apply it.
For commands you can use the RelayCommand
class described in the article.
Since you already have a presenter object, you can let that class expose an ICommand
property that implements the desired logic, and then bind the XAML to that command. It's all explained in the article.