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