Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members  

Test.h

00001 /*
00002   Copyright 1996-2002
00003   Simon Whiteside
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 /*
00020  * This small class can be used to trace calls into an iterator from a foreach statement in a script
00021  */
00022 class skTestIterator : public skExecutableIterator {
00023   int m_Count;
00024 public:
00025   skTestIterator() : m_Count(0){
00026   }
00027   bool next(skRValue& v){
00028     bool ret=false;
00029     if (m_Count<10){
00030       v=m_Count;
00031       skTracer::trace(skSTR("skTestIterator::next\n"));
00032       m_Count++;
00033       ret=true;
00034     }
00035     return ret;
00036   }
00037 };
00038 /*
00039  * You can use this small class to trace calls into a C++ object from a script. The class supports the method "createObject" and an instance is put as a global variable called "Test". This means you can do the following in Simkin script:
00040  * <pre>
00041  * a=Test.createObject();
00042  * b=a:name;
00043  * </pre>
00044  * And watch a trace of the "getValue" function being called
00045  */
00046 
00047 class skTest : public skExecutable{
00048 public:
00049   skTest(){
00050   }
00051   skExecutableIterator * createIterator(const skString& qualifier){
00052     skTracer::trace(skSTR("skTest::createIterator qualified by ")+qualifier+skSTR("\n"));
00053     return new skTestIterator();
00054   }
00055   skExecutableIterator * createIterator(){
00056     skTracer::trace(skSTR("skTest::createIterator\n"));
00057     return new skTestIterator();
00058   }
00059   bool getValue(const skString& field_name,const skString& attribute,skRValue& value){
00060     skTracer::trace(skSTR("skTest::getValue field_name=")+field_name+skSTR(" attribute=")+attribute+skSTR("\n"));
00061     return true;
00062   }
00063   bool setValue(const skString& field_name,const skString& attribute,const skRValue& value){
00064     skTracer::trace(skSTR("skTest::setValue field_name=")+field_name+skSTR(" attribute=")+attribute+skSTR("\n"));
00065     return true;
00066   }
00067   bool setValueAt(const skRValue& array_index, const skString& attribute,const skRValue& value)
00068   {
00069     skTracer::trace(skSTR("skTest::setValueAt array_index")+array_index.str()+skSTR(" attribute=")+attribute+skSTR(" value=")+value.str()+skSTR("\n"));
00070     return true;
00071   }
00072 
00073   bool getValueAt(const skRValue& array_index, const skString& attribute, skRValue& value)
00074   {
00075     skTracer::trace(skSTR("skTest::getValueAt array_index=")+array_index.str()+skSTR(" attribute=")+attribute+skSTR("\n"));
00076     return true;
00077   }
00078   bool method(const skString& method_name,skRValueArray& arguments,skRValue& return_value,skExecutableContext& ctxt)
00079   {
00080     skTracer::trace(skSTR("skTest::method method_name=")+method_name+skSTR("\n"));
00081     bool bRet=false;
00082     if (method_name==skSTR("createObject")){
00083       return_value=skRValue(new skTest(),true);
00084       bRet=true;
00085     }else{
00086       bRet=skExecutable::method(method_name,arguments,return_value,ctxt);
00087     }
00088     return bRet;
00089   }
00090 };
00091 

Generated on Thu Jan 23 15:25:39 2003 for Simkin by doxygen1.3-rc1