VISH  0.2
stockvish.cpp
stockfish.jpg

This application of vish is without any fancy user interface, user interaction, module loading, scripting or whatsoever. It is a very dry application of VISH. Such a dried fish is called stockfish. Thus, we end up with stockvish as the canonical name for this application example

In this example the VISH module implements an application which enables to run VISH objects (aka VISHES) without a graphical user interface, and implements some simple VISH objects to demonstrate the usage and functionality of the request() propagation. It demonstrates a self-standing VISH application which is reduced to a minimum. It uses VISH as a library, not even with dynamic module loading, although this could easily be added. The application defines three objects which communicate in a chain through two types. After setting up an execution chain, the end of the chain is queried for input and the chain is traversed. The output looks like this:

initialize
ALPHA parameter chain ok
BETA parameter chain ok
Chain Status:
DS: 5
DF: 0
DT: 1
DATAFILTER: update()
DATASINK: update()
exit
Note:
This is preliminiary and emphasizes bugs and non-finalized concepts. For instance, it is not yet clear how to initialize the entire queue, and when the datasource's update() function actually shall be called...
#include <ocean/plankton/VModules.hpp>
#include <ocean/plankton/VCreator.hpp>



#define override

using namespace Wizt;

struct  Alpha
{
        void operator=(int)
        {}
};

struct  Beta
{
        void operator=(int)
        {}
};

namespace Wizt
{
        template <> 
        class VValueTrait<Alpha>
        {
        public:
                
        static  bool setValueFromText(Alpha&i, const string&s)
                {       return false;   }

        static  string Text(const Alpha&)
                {       return "";      }               
        };


        template <> 
        class VValueTrait<Beta>
        {
        public:
        static  bool setValueFromText(Beta&i, const string&s)
                {       return false;   }

        static  string Text(const Beta&)
                {       return ""; }            
        };
}




class   AlphaInput : public VInputValue<Alpha>
{
public:
        AlphaInput(const RefPtr<VValueParameter<Alpha> >&P)
        : VInputValue<Alpha>(P)
        {}

        override void valueChanged(const RefPtr<VValueBase>&, const ValueNotifierList*, const ValueMap*)
        {
                touch();
        }
};


class   BetaInput : public VInputValue<Beta>
{
public:
        BetaInput(const RefPtr<VValueParameter<Beta> >&P)
        : VInputValue<Beta>(P)
        {}

        override void valueChanged(const RefPtr<VValueBase>&, const ValueNotifierList*, const ValueMap*)
        {
                touch();
        }
};




/*
  A VObject which provides alpha's
 */
class   DataSource : public Wizt::VObject
{
public:
        RefPtr<VInputValue<Alpha> > myAlpha;
        RefPtr<VParameter>          AlphaParameter;

        DataSource(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
        : VObject(name, p, VP)
        {
        Alpha InitialAlphaValue; 

                AlphaParameter = new VValueParameter<Alpha>( InitialAlphaValue, "alpha", NullPtr() );
                myAlpha = new AlphaInput( AlphaParameter ); 
                AlphaParameter->setSource( self() );
                myAlpha->activateNotification();
        }


        override bool update(VRequest&R, double precision)
        {
                puts("DATASOURCE: update");

                return true;
        }


        override void iterateOutputs(VOutputIterator&VOut, const type_info&just_these)
        {
        bool    DoAll = (just_these == typeid(void) ); 

                if (just_these == typeid(Alpha) || DoAll)
                {
                        VOut.apply( typeid(Alpha), "alpha" ); 
                }
        }

        override RefPtr<VParameter> getImplementation(const type_info&what, const string&name)
        {
                if (what == typeid(Alpha) )
                        return this->AlphaParameter; 

                return NullPtr();
        }
};



/*
  A VObject which takes an alpha and converts it into a beta
 */
class   DataFilter : public Wizt::VObject
{
        RefPtr<VInputValue<Beta> >      myBeta;
        RefPtr<VParameter>              BetaParameter;

public:
        DataFilter(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
        : VObject(name, p, VP)
        {
                addParam("alphaInput", Alpha() ); 


        Beta    InitialBetaValue; 

                BetaParameter = new VValueParameter<Beta>( InitialBetaValue, "beta", NullPtr() );
                myBeta = new BetaInput( BetaParameter ); 
                BetaParameter->setSource( self() );
                myBeta->activateNotification();
        }

        override bool update(VRequest&R, double precision)
        {
                puts("DATAFILTER: update()");

                return true;
        }



        override void iterateOutputs(VOutputIterator&VOut, const type_info&just_these)
        {
        bool    DoAll = (just_these == typeid(void) ); 

                if (just_these == typeid(Beta) || DoAll)
                {
                        VOut.apply( typeid(Beta), "beta" ); 
                }
        }

        override RefPtr<VParameter> getImplementation(const type_info&what, const string&name)
        {
                if (what == typeid(Beta) )
                        return this->BetaParameter; 

                return NullPtr();
        }
};

/*
  A VObject which requires beta's
 */
class   DataSink : public Wizt::VObject
{
public:
        DataSink(const string&name, int p, const RefPtr<VCreationPreferences>&VP)
        : VObject(name, p, VP)
        {
                addParam("betaInput", Beta() );
        }


        override bool update(VRequest&R, double precision)
        {
                puts("DATASINK: update()");
                return true;
        }
};

static VCreator<DataSource> VDataSourceCreator("DataSource");
static VCreator<DataFilter> VDataFilterCreator("DataFilter");
static VCreator<DataSink>   VDataSinkCreator("DataSink");

int main( int argc, char **argv )
{
        puts("initialize"); 

// 
// Here, we create the VObjects through the VCreatorBase::find() interface. 
// Note that we could also create them using a simple C++ new. 
// Also, we could have found and created these objects through querying 
// VISH for a certain input type, e.g. asking for an input of Beta or 
// Alpha. This code here is just for simplification of this setup part. 
// 
//
RefPtr<VCreatorBase> VC = VCreatorBase::find("DataSource"); 
        if (!VC) { puts("DataSource creator not found"); return 1; } 
RefPtr<DataSource>   DS = VC->create("MySource"); 
        if (!DS) { puts("Could not create DataSource"); return 1; } 

        VC = VCreatorBase::find("DataFilter"); 
        if (!VC) { puts("DataFilter creator not found"); return 1; } 
RefPtr<DataFilter>  DF = VC->create("MyFilter"); 
        if (!DF) { puts("Could not create DataFilter"); return 1; } 

        VC = VCreatorBase::find("DataSink"); 
        if (!VC) { puts("DataSink creator not found"); return 1; } 
RefPtr<DataSink>  DT = VC->create("MySink"); 
        if (!DT) { puts("Could not create DataSink"); return 1; } 




// 
// Setting up link from DataSource to DataFilter via communication object type Alpha
// 
{
RefPtr<VParameter> OldParam = DF->getParameter("alphaInput"); 
RefPtr<VParameter> NewParam = DS->getImplementation( typeid(Alpha), "" ); 

        switch( DF->attach( OldParam, NewParam) )
        {
        default:
                puts("Error in setting up ALPHA parameter chain");
                return 0;

        case VObject::AttachmentOk:  puts("ALPHA parameter chain ok");
        } 
}


// 
// Setting up link from DataFilter to DataSink via object type Beta 
// 
{
RefPtr<VParameter> OldParam = DT->getParameter("betaInput"); 
RefPtr<VParameter> NewParam = DF->getImplementation( typeid(Beta), "" ); 

        switch( DT->attach( OldParam, NewParam) )
        {
        default:
                puts("Error in setting up BETA parameter chain");
                return 0;

        case VObject::AttachmentOk:  puts("BETA parameter chain ok");
        } 
}

// 
// Done, now we are ready to issue a request chain 
//

VRequest myRequest; 
        DS->touch();

        puts("Chain Status:"); 
        printf("DS: %d\n", int(DS->time_value()) ); 
        printf("DF: %d\n", int(DF->time_value()) ); 
        printf("DT: %d\n", int(DT->time_value()) );

        DT->request(myRequest, 1.0);


        puts("exit");
        return 0;
}