//.............................................................................. // // This file is part of the Jancy toolkit. // // Jancy is distributed under the MIT license. // For details see accompanying license.txt file, // the public copy of which is also available at: // http://tibbo.com/downloads/archive/jancy/license.txt // //.............................................................................. // Jancy supports 'bindable' properties, which notify subscribers after they // have changed. // The firing of the bindable event must be done manually, unless the entire // property is compiler-generated. In this latter case the property is called // bindable data. //.............................................................................. // simple bindable property declaration syntax int autoget bindable property g_simpleProp; // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . // setter implementation g_simpleProp.set (int x) { printf ("g_simpleProp.set (%d)\n", x); if (m_value == x) return; m_value = x; // by default, the name of compiler-generated event is 'm_onChanged' m_onChanged (); } //.............................................................................. // similar property declared using the full syntax property g_prop { // declaring a field with 'autoget' modifier implicitly makes the whole // property autoget autoget int m_x; // declaring an event with 'bindable' modifier implicitly makes the whole // property bindable bindable event m_e (); set (int x); set (double x); } // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . // setters implementation g_prop.set (int x) { printf ("g_prop.set (int %d)\n", x); if (m_x == x) return; m_x = x; m_e (); } g_prop.set (double x) { printf ("g_prop.set (double %f)\n", x); if (m_x == (int) x) return; m_x = (int) x; m_e (); } //.............................................................................. // bindable data is a wholly compiler-generated property with trivial getter // and setter - the sole purpose of bindable data is to track data changes int bindable g_data; //.............................................................................. // onChanged event handlers onSimplePropChanged () { printf ("g_simpleProp has changed (new value = %d)\n", g_simpleProp); } onPropChanged () { printf ("g_prop has changed (new value = %d)\n", g_prop); } onDataChanged () { printf ("g_data has changed (new value = %d)\n", g_data); } //.............................................................................. // entry point int main () { printf ("main ()\n"); // use 'bindingof' to access a bindable event of a property bindingof (g_simpleProp) += onSimplePropChanged; bindingof (g_prop) += onPropChanged; bindingof (g_data) += onDataChanged; g_simpleProp = 100; g_simpleProp = 100; // bindable event is not going to get fired g_prop = 500; g_prop = 5.2; g_prop = 5; // bindable event is not going to get fired g_data = 1000; g_data = 1000; // bindable event is not going to get fired return 0; } //..............................................................................