00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <vos/corelibs/vos/vos.hh>
00015 #include <vos/metaobjects/property/property.hh>
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 class TutorialChildListener : public ChildChangeListener
00033 {
00034 public:
00035 virtual void notifyChildInserted(VobjectEvent& e);
00036 virtual void notifyChildReplaced(VobjectEvent& e);
00037 virtual void notifyChildRemoved(VobjectEvent& e);
00038 };
00039
00040 void TutorialChildListener::notifyChildInserted(VobjectEvent& e)
00041 {
00042
00043
00044
00045
00046
00047 cout << "Parent " << e.getParent()->getURL().getString()
00048 << " has added child " << e.getChild()->getURL().getString()
00049 << "\n at position " << e.getPosition()
00050 << " with contextual name \"" << e.getContextualName() << "\"\n";
00051 }
00052
00053 void TutorialChildListener::notifyChildReplaced(VobjectEvent& e)
00054 {
00055 cout << "Parent " << e.getParent()->getURL().getString()
00056 << " has replaced child " << e.getOldChild()->getURL().getString()
00057 << "\n with " << e.getNewChild()->getURL().getString()
00058 << "\n at position " << e.getPosition()
00059 << " with contextual name \"" << e.getContextualName() << "\"\n";
00060 }
00061
00062 void TutorialChildListener::notifyChildRemoved(VobjectEvent& e)
00063 {
00064 cout << "Parent " << e.getParent()->getURL().getString()
00065 << " has removed child " << e.getChild()->getURL().getString()
00066 << "\n from position " << e.getPosition()
00067 << " (old contextual name \"" << e.getContextualName() << "\")\n";
00068 }
00069
00070
00071 class TutorialPropertyListener : public PropertyListener
00072 {
00073 public:
00074 virtual void notifyPropertyChange(const PropertyEvent& e);
00075 };
00076
00077
00078 void TutorialPropertyListener::notifyPropertyChange(const PropertyEvent& e)
00079 {
00080
00081
00082
00083
00084
00085 cout << "Property " << e.getProperty()->getURL().getString()
00086 << " has changed value from \"" << e.getOldValue()
00087 << "\" to \"" << e.getNewValue() << "\"\n";
00088
00089 }
00090
00091 int main(int argc, char** argv)
00092 {
00093 cout << "VOS Tutorial 6\n\n";
00094
00095 LocalSocketSite localsite(&NoAccessControl::static_);
00096 localsite.setTimeoutOnSelect(-1);
00097
00098 Property::registerExtenders();
00099
00100 vRef<Vobject> sphere = localsite.createMetaObject("sphere", 0);
00101 vRef<Vobject> tertius = localsite.createMetaObject("tertius", 0);
00102 vRef<Vobject> quartus = localsite.createMetaObject("quartus", typeid(Property).name(), 0);
00103 vRef<Vobject> quintus = localsite.createMetaObject("quintus", 0);
00104 vRef<Vobject> sextus = localsite.createMetaObject("sextus", 0);
00105 vRef<Vobject> septimus = localsite.createMetaObject("septimus", 0);
00106
00107 sphere->insertChild(-1, "position", &tertius);
00108 sphere->insertChild(-1, "orientation", &quartus);
00109
00110
00111
00112
00113
00114
00115
00116
00117 sphere->addChildListener(new TutorialChildListener());
00118
00119
00120
00121
00122
00123 sphere->insertChild(-1, "radius", &quintus);
00124 sphere->insertChild(-1, "position", &quartus);
00125 sphere->insertChild(2, "color", &sextus);
00126 sphere->setChild(4, "mass", &septimus);
00127 sphere->removeChild(1);
00128 sphere->removeChild(-1);
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145 Property* positionproperty = MetaObject::meta_cast<Property*>(&quartus);
00146
00147 positionproperty->addPropertyListener(new TutorialPropertyListener());
00148
00149 positionproperty->replace("1 2 3", "text/x-vector-float");
00150
00151 positionproperty->write(2, "4");
00152
00153 }